Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for allocation of public ips with ip-tags #1246

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/v1alpha1/azurepublicipaddress_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
type AzurePublicIPAddressSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

Location string `json:"location"`
// +kubebuilder:validation:Pattern=^[-\w\._\(\)]+$
// +kubebuilder:validation:MinLength:1
Expand All @@ -23,6 +24,8 @@ type AzurePublicIPAddressSpec struct {
IdleTimeoutInMinutes int `json:"idleTimeoutInMinutes"`
PublicIPAddressVersion string `json:"publicIPAddressVersion"`
SkuName string `json:"skuName"`
// +optional
IPTags map[string]string `json:"ipTags,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frodopwns - should we regenerate the helm pkg stuff now or do we just do it before we ship?

}

// +kubebuilder:object:root=true
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/azurepublicipaddress_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var _ = Describe("AzurePublicIPAddress", func() {
IdleTimeoutInMinutes: 3,
PublicIPAddressVersion: "IPv4",
SkuName: "Basic",
IPTags: map[string]string{"TestIpTag": "/Test/VipPool"},
}}

By("creating an API obj")
Expand Down
9 changes: 8 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion pkg/resourcemanager/pip/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ func getPublicIPAddressClient() vnetwork.PublicIPAddressesClient {
return pipClient
}

func (m *AzurePublicIPAddressClient) CreatePublicIPAddress(ctx context.Context, location string, resourceGroupName string, resourceName string, publicIPAllocationMethod string, idleTimeoutInMinutes int, publicIPAddressVersion string, skuName string) (future vnetwork.PublicIPAddressesCreateOrUpdateFuture, err error) {
func (m *AzurePublicIPAddressClient) CreatePublicIPAddress(ctx context.Context,
location string,
resourceGroupName string,
resourceName string,
publicIPAllocationMethod string,
idleTimeoutInMinutes int,
publicIPAddressVersion string,
skuName string,
ipTags map[string]string) (future vnetwork.PublicIPAddressesCreateOrUpdateFuture, err error) {

client := getPublicIPAddressClient()

Expand Down Expand Up @@ -62,6 +70,7 @@ func (m *AzurePublicIPAddressClient) CreatePublicIPAddress(ctx context.Context,
PublicIPAllocationMethod: publicIPAllocationMethodField,
IdleTimeoutInMinutes: &idleTimeoutInMinutesInt32,
PublicIPAddressVersion: publicIPAddressVersionField,
IPTags: getIPTagsForPublicIP(ipTags),
},
Sku: &vnetwork.PublicIPAddressSku{
Name: skuNameInput,
Expand All @@ -72,6 +81,21 @@ func (m *AzurePublicIPAddressClient) CreatePublicIPAddress(ctx context.Context,
return future, err
}

func getIPTagsForPublicIP(tags map[string]string) *[]vnetwork.IPTag {
if tags == nil || len(tags) == 0 {
return nil
}

outputTags := []vnetwork.IPTag{}
for k, v := range tags {
outputTags = append(outputTags, vnetwork.IPTag{
IPTagType: &k,
Tag: &v,
})
}
return &outputTags
}

func (m *AzurePublicIPAddressClient) DeletePublicIPAddress(ctx context.Context, publicIPAddressName string, resourcegroup string) (status string, err error) {

client := getPublicIPAddressClient()
Expand Down
2 changes: 2 additions & 0 deletions pkg/resourcemanager/pip/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (g *AzurePublicIPAddressClient) Ensure(ctx context.Context, obj runtime.Obj
idleTimeoutInMinutes := instance.Spec.IdleTimeoutInMinutes
publicIPAddressVersion := instance.Spec.PublicIPAddressVersion
skuName := instance.Spec.SkuName
ipTags := instance.Spec.IPTags

instance.Status.Provisioning = true
// Check if this item already exists. This is required
Expand All @@ -51,6 +52,7 @@ func (g *AzurePublicIPAddressClient) Ensure(ctx context.Context, obj runtime.Obj
idleTimeoutInMinutes,
publicIPAddressVersion,
skuName,
ipTags,
)
if err != nil {
// let the user know what happened
Expand Down