diff --git a/api/v1alpha1/azurepublicipaddress_types.go b/api/v1alpha1/azurepublicipaddress_types.go index 3fe5e12adeb..2fb36da89af 100644 --- a/api/v1alpha1/azurepublicipaddress_types.go +++ b/api/v1alpha1/azurepublicipaddress_types.go @@ -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 @@ -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 diff --git a/api/v1alpha1/azurepublicipaddress_types_test.go b/api/v1alpha1/azurepublicipaddress_types_test.go index 4823287d00e..7988444ade5 100644 --- a/api/v1alpha1/azurepublicipaddress_types_test.go +++ b/api/v1alpha1/azurepublicipaddress_types_test.go @@ -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") diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index df74f74a710..7bc26b3928b 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -556,7 +556,7 @@ func (in *AzurePublicIPAddress) DeepCopyInto(out *AzurePublicIPAddress) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) in.Status.DeepCopyInto(&out.Status) } @@ -613,6 +613,13 @@ func (in *AzurePublicIPAddressList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AzurePublicIPAddressSpec) DeepCopyInto(out *AzurePublicIPAddressSpec) { *out = *in + if in.IPTags != nil { + in, out := &in.IPTags, &out.IPTags + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzurePublicIPAddressSpec. diff --git a/pkg/resourcemanager/pip/client.go b/pkg/resourcemanager/pip/client.go index 86108eb7186..4986533bce0 100644 --- a/pkg/resourcemanager/pip/client.go +++ b/pkg/resourcemanager/pip/client.go @@ -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() @@ -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, @@ -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() diff --git a/pkg/resourcemanager/pip/reconcile.go b/pkg/resourcemanager/pip/reconcile.go index 9f67f59f85c..94c76474490 100644 --- a/pkg/resourcemanager/pip/reconcile.go +++ b/pkg/resourcemanager/pip/reconcile.go @@ -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 @@ -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