Skip to content

Commit

Permalink
Merge pull request #1246 from MarcPow/pip-iptags
Browse files Browse the repository at this point in the history
Add support for allocation of public ips with ip-tags
  • Loading branch information
theunrepentantgeek authored Jul 30, 2020
2 parents 85bba13 + e1b8f1a commit 46752b1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
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"`
}

// +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

0 comments on commit 46752b1

Please sign in to comment.