diff --git a/api/v1beta1/azuremanagedcontrolplane_webhook.go b/api/v1beta1/azuremanagedcontrolplane_webhook.go index d41be814c45..c76fea59c4c 100644 --- a/api/v1beta1/azuremanagedcontrolplane_webhook.go +++ b/api/v1beta1/azuremanagedcontrolplane_webhook.go @@ -30,7 +30,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/validation/field" - "k8s.io/utils/pointer" "k8s.io/utils/ptr" "sigs.k8s.io/cluster-api-provider-azure/feature" webhookutils "sigs.k8s.io/cluster-api-provider-azure/util/webhook" @@ -73,7 +72,7 @@ func (mw *azureManagedControlPlaneWebhook) Default(ctx context.Context, obj runt return apierrors.NewBadRequest("expected an AzureManagedControlPlane") } if m.Spec.NetworkPlugin == nil { - networkPlugin := "azure" + networkPlugin := CloudProviderName m.Spec.NetworkPlugin = &networkPlugin } if m.Spec.LoadBalancerSKU == nil { @@ -683,8 +682,8 @@ func validateAutoScalerProfile(autoScalerProfile *AutoScalerProfile, fldPath *fi // validateMaxNodeProvisionTime validates update to AutoscalerProfile.MaxNodeProvisionTime. func validateMaxNodeProvisionTime(maxNodeProvisionTime *string, fldPath *field.Path) field.ErrorList { var allErrs field.ErrorList - if pointer.StringDeref(maxNodeProvisionTime, "") != "" { - if !rMaxNodeProvisionTime.MatchString(pointer.StringDeref(maxNodeProvisionTime, "")) { + if ptr.Deref(maxNodeProvisionTime, "") != "" { + if !rMaxNodeProvisionTime.MatchString(ptr.Deref(maxNodeProvisionTime, "")) { allErrs = append(allErrs, field.Invalid(fldPath.Child("MaxNodeProvisionTime"), maxNodeProvisionTime, "invalid value")) } } @@ -694,8 +693,8 @@ func validateMaxNodeProvisionTime(maxNodeProvisionTime *string, fldPath *field.P // validateScanInterval validates update to AutoscalerProfile.ScanInterval. func validateScanInterval(scanInterval *string, fldPath *field.Path) field.ErrorList { var allErrs field.ErrorList - if pointer.StringDeref(scanInterval, "") != "" { - if !rScanInterval.MatchString(pointer.StringDeref(scanInterval, "")) { + if ptr.Deref(scanInterval, "") != "" { + if !rScanInterval.MatchString(ptr.Deref(scanInterval, "")) { allErrs = append(allErrs, field.Invalid(fldPath.Child("ScanInterval"), scanInterval, "invalid value")) } } @@ -705,8 +704,8 @@ func validateScanInterval(scanInterval *string, fldPath *field.Path) field.Error // validateNewPodScaleUpDelay validates update to AutoscalerProfile.NewPodScaleUpDelay. func validateNewPodScaleUpDelay(newPodScaleUpDelay *string, fldPath *field.Path) field.ErrorList { var allErrs field.ErrorList - if pointer.StringDeref(newPodScaleUpDelay, "") != "" { - _, err := time.ParseDuration(pointer.StringDeref(newPodScaleUpDelay, "")) + if ptr.Deref(newPodScaleUpDelay, "") != "" { + _, err := time.ParseDuration(ptr.Deref(newPodScaleUpDelay, "")) if err != nil { allErrs = append(allErrs, field.Invalid(fldPath.Child("NewPodScaleUpDelay"), newPodScaleUpDelay, "invalid value")) } @@ -717,9 +716,9 @@ func validateNewPodScaleUpDelay(newPodScaleUpDelay *string, fldPath *field.Path) // validateScaleDownDelayAfterDelete validates update to AutoscalerProfile.ScaleDownDelayAfterDelete value. func validateScaleDownDelayAfterDelete(scaleDownDelayAfterDelete *string, fldPath *field.Path) field.ErrorList { var allErrs field.ErrorList - if pointer.StringDeref(scaleDownDelayAfterDelete, "") != "" { - if !rScaleDownDelayAfterDelete.MatchString(pointer.StringDeref(scaleDownDelayAfterDelete, "")) { - allErrs = append(allErrs, field.Invalid(fldPath.Child("ScaleDownDelayAfterDelete"), pointer.StringDeref(scaleDownDelayAfterDelete, ""), "invalid value")) + if ptr.Deref(scaleDownDelayAfterDelete, "") != "" { + if !rScaleDownDelayAfterDelete.MatchString(ptr.Deref(scaleDownDelayAfterDelete, "")) { + allErrs = append(allErrs, field.Invalid(fldPath.Child("ScaleDownDelayAfterDelete"), ptr.Deref(scaleDownDelayAfterDelete, ""), "invalid value")) } } return allErrs @@ -728,9 +727,9 @@ func validateScaleDownDelayAfterDelete(scaleDownDelayAfterDelete *string, fldPat // validateScaleDownTime validates update to AutoscalerProfile.ScaleDown* values. func validateScaleDownTime(scaleDownValue *string, fldPath *field.Path, fieldName string) field.ErrorList { var allErrs field.ErrorList - if pointer.StringDeref(scaleDownValue, "") != "" { - if !rScaleDownTime.MatchString(pointer.StringDeref(scaleDownValue, "")) { - allErrs = append(allErrs, field.Invalid(fldPath.Child(fieldName), pointer.StringDeref(scaleDownValue, ""), "invalid value")) + if ptr.Deref(scaleDownValue, "") != "" { + if !rScaleDownTime.MatchString(ptr.Deref(scaleDownValue, "")) { + allErrs = append(allErrs, field.Invalid(fldPath.Child(fieldName), ptr.Deref(scaleDownValue, ""), "invalid value")) } } return allErrs diff --git a/api/v1beta1/azuremanagedcontrolplane_webhook_test.go b/api/v1beta1/azuremanagedcontrolplane_webhook_test.go index b3c6da911f2..b3110942952 100644 --- a/api/v1beta1/azuremanagedcontrolplane_webhook_test.go +++ b/api/v1beta1/azuremanagedcontrolplane_webhook_test.go @@ -24,7 +24,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation/field" utilfeature "k8s.io/component-base/featuregate/testing" - "k8s.io/utils/pointer" "k8s.io/utils/ptr" "sigs.k8s.io/cluster-api-provider-azure/feature" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" @@ -120,12 +119,12 @@ func TestValidateDNSServiceIP(t *testing.T) { }{ { name: "Testing valid DNSServiceIP", - dnsIP: pointer.String("192.168.0.0"), + dnsIP: ptr.To("192.168.0.0"), expectErr: false, }, { name: "Testing invalid DNSServiceIP", - dnsIP: pointer.String("192.168.0.0.3"), + dnsIP: ptr.To("192.168.0.0.3"), expectErr: false, }, } @@ -195,30 +194,30 @@ func TestValidateLoadBalancerProfile(t *testing.T) { { name: "Valid LoadBalancerProfile", profile: &LoadBalancerProfile{ - ManagedOutboundIPs: pointer.Int32(10), - AllocatedOutboundPorts: pointer.Int32(1000), - IdleTimeoutInMinutes: pointer.Int32(60), + ManagedOutboundIPs: ptr.To[int32](10), + AllocatedOutboundPorts: ptr.To[int32](1000), + IdleTimeoutInMinutes: ptr.To[int32](60), }, expectErr: false, }, { name: "Invalid LoadBalancerProfile.ManagedOutboundIPs", profile: &LoadBalancerProfile{ - ManagedOutboundIPs: pointer.Int32(200), + ManagedOutboundIPs: ptr.To[int32](200), }, expectErr: true, }, { name: "Invalid LoadBalancerProfile.IdleTimeoutInMinutes", profile: &LoadBalancerProfile{ - IdleTimeoutInMinutes: pointer.Int32(600), + IdleTimeoutInMinutes: ptr.To[int32](600), }, expectErr: true, }, { name: "LoadBalancerProfile must specify at most one of ManagedOutboundIPs, OutboundIPPrefixes and OutboundIPs", profile: &LoadBalancerProfile{ - ManagedOutboundIPs: pointer.Int32(1), + ManagedOutboundIPs: ptr.To[int32](1), OutboundIPs: []string{ "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo-bar/providers/Microsoft.Network/publicIPAddresses/my-public-ip", }, @@ -249,170 +248,170 @@ func TestValidateAutoScalerProfile(t *testing.T) { { name: "Valid AutoScalerProfile", profile: &AutoScalerProfile{ - BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsFalse))), - Expander: (*Expander)(pointer.String(string(ExpanderRandom))), - MaxEmptyBulkDelete: pointer.String("10"), - MaxGracefulTerminationSec: pointer.String("600"), - MaxNodeProvisionTime: pointer.String("10m"), - MaxTotalUnreadyPercentage: pointer.String("45"), - NewPodScaleUpDelay: pointer.String("10m"), - OkTotalUnreadyCount: pointer.String("3"), - ScanInterval: pointer.String("60s"), - ScaleDownDelayAfterAdd: pointer.String("10m"), - ScaleDownDelayAfterDelete: pointer.String("10s"), - ScaleDownDelayAfterFailure: pointer.String("10m"), - ScaleDownUnneededTime: pointer.String("10m"), - ScaleDownUnreadyTime: pointer.String("10m"), - ScaleDownUtilizationThreshold: pointer.String("0.5"), - SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(pointer.String(string(SkipNodesWithLocalStorageTrue))), - SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(pointer.String(string(SkipNodesWithSystemPodsTrue))), + BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(ptr.To(string(BalanceSimilarNodeGroupsFalse))), + Expander: (*Expander)(ptr.To(string(ExpanderRandom))), + MaxEmptyBulkDelete: ptr.To("10"), + MaxGracefulTerminationSec: ptr.To("600"), + MaxNodeProvisionTime: ptr.To("10m"), + MaxTotalUnreadyPercentage: ptr.To("45"), + NewPodScaleUpDelay: ptr.To("10m"), + OkTotalUnreadyCount: ptr.To("3"), + ScanInterval: ptr.To("60s"), + ScaleDownDelayAfterAdd: ptr.To("10m"), + ScaleDownDelayAfterDelete: ptr.To("10s"), + ScaleDownDelayAfterFailure: ptr.To("10m"), + ScaleDownUnneededTime: ptr.To("10m"), + ScaleDownUnreadyTime: ptr.To("10m"), + ScaleDownUtilizationThreshold: ptr.To("0.5"), + SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(ptr.To(string(SkipNodesWithLocalStorageTrue))), + SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(ptr.To(string(SkipNodesWithSystemPodsTrue))), }, expectErr: false, }, { name: "Testing valid AutoScalerProfile.ExpanderRandom", profile: &AutoScalerProfile{ - Expander: (*Expander)(pointer.String(string(ExpanderRandom))), + Expander: (*Expander)(ptr.To(string(ExpanderRandom))), }, expectErr: false, }, { name: "Testing valid AutoScalerProfile.ExpanderLeastWaste", profile: &AutoScalerProfile{ - Expander: (*Expander)(pointer.String(string(ExpanderLeastWaste))), + Expander: (*Expander)(ptr.To(string(ExpanderLeastWaste))), }, expectErr: false, }, { name: "Testing valid AutoScalerProfile.ExpanderMostPods", profile: &AutoScalerProfile{ - Expander: (*Expander)(pointer.String(string(ExpanderMostPods))), + Expander: (*Expander)(ptr.To(string(ExpanderMostPods))), }, expectErr: false, }, { name: "Testing valid AutoScalerProfile.ExpanderPriority", profile: &AutoScalerProfile{ - Expander: (*Expander)(pointer.String(string(ExpanderPriority))), + Expander: (*Expander)(ptr.To(string(ExpanderPriority))), }, expectErr: false, }, { name: "Testing valid AutoScalerProfile.BalanceSimilarNodeGroupsTrue", profile: &AutoScalerProfile{ - BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsTrue))), + BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(ptr.To(string(BalanceSimilarNodeGroupsTrue))), }, expectErr: false, }, { name: "Testing valid AutoScalerProfile.BalanceSimilarNodeGroupsFalse", profile: &AutoScalerProfile{ - BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsFalse))), + BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(ptr.To(string(BalanceSimilarNodeGroupsFalse))), }, expectErr: false, }, { name: "Testing invalid AutoScalerProfile.MaxEmptyBulkDelete", profile: &AutoScalerProfile{ - MaxEmptyBulkDelete: pointer.String("invalid"), + MaxEmptyBulkDelete: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.MaxGracefulTerminationSec", profile: &AutoScalerProfile{ - MaxGracefulTerminationSec: pointer.String("invalid"), + MaxGracefulTerminationSec: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.MaxNodeProvisionTime", profile: &AutoScalerProfile{ - MaxNodeProvisionTime: pointer.String("invalid"), + MaxNodeProvisionTime: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.MaxTotalUnreadyPercentage", profile: &AutoScalerProfile{ - MaxTotalUnreadyPercentage: pointer.String("invalid"), + MaxTotalUnreadyPercentage: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.NewPodScaleUpDelay", profile: &AutoScalerProfile{ - NewPodScaleUpDelay: pointer.String("invalid"), + NewPodScaleUpDelay: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.OkTotalUnreadyCount", profile: &AutoScalerProfile{ - OkTotalUnreadyCount: pointer.String("invalid"), + OkTotalUnreadyCount: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.ScanInterval", profile: &AutoScalerProfile{ - ScanInterval: pointer.String("invalid"), + ScanInterval: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.ScaleDownDelayAfterAdd", profile: &AutoScalerProfile{ - ScaleDownDelayAfterAdd: pointer.String("invalid"), + ScaleDownDelayAfterAdd: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.ScaleDownDelayAfterDelete", profile: &AutoScalerProfile{ - ScaleDownDelayAfterDelete: pointer.String("invalid"), + ScaleDownDelayAfterDelete: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.ScaleDownDelayAfterFailure", profile: &AutoScalerProfile{ - ScaleDownDelayAfterFailure: pointer.String("invalid"), + ScaleDownDelayAfterFailure: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.ScaleDownUnneededTime", profile: &AutoScalerProfile{ - ScaleDownUnneededTime: pointer.String("invalid"), + ScaleDownUnneededTime: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.ScaleDownUnreadyTime", profile: &AutoScalerProfile{ - ScaleDownUnreadyTime: pointer.String("invalid"), + ScaleDownUnreadyTime: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing invalid AutoScalerProfile.ScaleDownUtilizationThreshold", profile: &AutoScalerProfile{ - ScaleDownUtilizationThreshold: pointer.String("invalid"), + ScaleDownUtilizationThreshold: ptr.To("invalid"), }, expectErr: true, }, { name: "Testing valid AutoScalerProfile.SkipNodesWithLocalStorageTrue", profile: &AutoScalerProfile{ - SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(pointer.String(string(SkipNodesWithLocalStorageTrue))), + SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(ptr.To(string(SkipNodesWithLocalStorageTrue))), }, expectErr: false, }, { name: "Testing valid AutoScalerProfile.SkipNodesWithLocalStorageFalse", profile: &AutoScalerProfile{ - SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(pointer.String(string(SkipNodesWithSystemPodsFalse))), + SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(ptr.To(string(SkipNodesWithSystemPodsFalse))), }, expectErr: false, }, diff --git a/api/v1beta1/azuremanagedcontrolplanetemplate_default.go b/api/v1beta1/azuremanagedcontrolplanetemplate_default.go index 2feca15b274..1173fbe333d 100644 --- a/api/v1beta1/azuremanagedcontrolplanetemplate_default.go +++ b/api/v1beta1/azuremanagedcontrolplanetemplate_default.go @@ -19,12 +19,12 @@ package v1beta1 import ( "strings" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) func (mcp *AzureManagedControlPlaneTemplate) setDefaults() { if mcp.Spec.Template.Spec.NetworkPlugin == nil { - networkPlugin := "azure" + networkPlugin := CloudProviderName mcp.Spec.Template.Spec.NetworkPlugin = &networkPlugin } if mcp.Spec.Template.Spec.LoadBalancerSKU == nil { @@ -79,55 +79,55 @@ func (mcp *AzureManagedControlPlaneTemplate) setDefaultAutoScalerProfile() { // Default values are from https://learn.microsoft.com/en-us/azure/aks/cluster-autoscaler#using-the-autoscaler-profile // If any values are set, they all need to be set. if mcp.Spec.Template.Spec.AutoScalerProfile.BalanceSimilarNodeGroups == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.BalanceSimilarNodeGroups = (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsFalse))) + mcp.Spec.Template.Spec.AutoScalerProfile.BalanceSimilarNodeGroups = (*BalanceSimilarNodeGroups)(ptr.To(string(BalanceSimilarNodeGroupsFalse))) } if mcp.Spec.Template.Spec.AutoScalerProfile.Expander == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.Expander = (*Expander)(pointer.String(string(ExpanderRandom))) + mcp.Spec.Template.Spec.AutoScalerProfile.Expander = (*Expander)(ptr.To(string(ExpanderRandom))) } if mcp.Spec.Template.Spec.AutoScalerProfile.MaxEmptyBulkDelete == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.MaxEmptyBulkDelete = pointer.String("10") + mcp.Spec.Template.Spec.AutoScalerProfile.MaxEmptyBulkDelete = ptr.To("10") } if mcp.Spec.Template.Spec.AutoScalerProfile.MaxGracefulTerminationSec == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.MaxGracefulTerminationSec = pointer.String("600") + mcp.Spec.Template.Spec.AutoScalerProfile.MaxGracefulTerminationSec = ptr.To("600") } if mcp.Spec.Template.Spec.AutoScalerProfile.MaxNodeProvisionTime == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.MaxNodeProvisionTime = pointer.String("15m") + mcp.Spec.Template.Spec.AutoScalerProfile.MaxNodeProvisionTime = ptr.To("15m") } if mcp.Spec.Template.Spec.AutoScalerProfile.MaxTotalUnreadyPercentage == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.MaxTotalUnreadyPercentage = pointer.String("45") + mcp.Spec.Template.Spec.AutoScalerProfile.MaxTotalUnreadyPercentage = ptr.To("45") } if mcp.Spec.Template.Spec.AutoScalerProfile.NewPodScaleUpDelay == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.NewPodScaleUpDelay = pointer.String("0s") + mcp.Spec.Template.Spec.AutoScalerProfile.NewPodScaleUpDelay = ptr.To("0s") } if mcp.Spec.Template.Spec.AutoScalerProfile.OkTotalUnreadyCount == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.OkTotalUnreadyCount = pointer.String("3") + mcp.Spec.Template.Spec.AutoScalerProfile.OkTotalUnreadyCount = ptr.To("3") } if mcp.Spec.Template.Spec.AutoScalerProfile.ScanInterval == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.ScanInterval = pointer.String("10s") + mcp.Spec.Template.Spec.AutoScalerProfile.ScanInterval = ptr.To("10s") } if mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownDelayAfterAdd == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownDelayAfterAdd = pointer.String("10m") + mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownDelayAfterAdd = ptr.To("10m") } if mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete == nil { // Default is the same as the ScanInterval so default to that same value if it isn't set mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownDelayAfterDelete = mcp.Spec.Template.Spec.AutoScalerProfile.ScanInterval } if mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownDelayAfterFailure == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownDelayAfterFailure = pointer.String("3m") + mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownDelayAfterFailure = ptr.To("3m") } if mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownUnneededTime == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownUnneededTime = pointer.String("10m") + mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownUnneededTime = ptr.To("10m") } if mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownUnreadyTime == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownUnreadyTime = pointer.String("20m") + mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownUnreadyTime = ptr.To("20m") } if mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownUtilizationThreshold == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownUtilizationThreshold = pointer.String("0.5") + mcp.Spec.Template.Spec.AutoScalerProfile.ScaleDownUtilizationThreshold = ptr.To("0.5") } if mcp.Spec.Template.Spec.AutoScalerProfile.SkipNodesWithLocalStorage == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.SkipNodesWithLocalStorage = (*SkipNodesWithLocalStorage)(pointer.String(string(SkipNodesWithLocalStorageFalse))) + mcp.Spec.Template.Spec.AutoScalerProfile.SkipNodesWithLocalStorage = (*SkipNodesWithLocalStorage)(ptr.To(string(SkipNodesWithLocalStorageFalse))) } if mcp.Spec.Template.Spec.AutoScalerProfile.SkipNodesWithSystemPods == nil { - mcp.Spec.Template.Spec.AutoScalerProfile.SkipNodesWithSystemPods = (*SkipNodesWithSystemPods)(pointer.String(string(SkipNodesWithSystemPodsTrue))) + mcp.Spec.Template.Spec.AutoScalerProfile.SkipNodesWithSystemPods = (*SkipNodesWithSystemPods)(ptr.To(string(SkipNodesWithSystemPodsTrue))) } } diff --git a/api/v1beta1/azuremanagedcontrolplanetemplate_default_test.go b/api/v1beta1/azuremanagedcontrolplanetemplate_default_test.go index ec5c228d903..f3b51ef00dd 100644 --- a/api/v1beta1/azuremanagedcontrolplanetemplate_default_test.go +++ b/api/v1beta1/azuremanagedcontrolplanetemplate_default_test.go @@ -22,7 +22,7 @@ import ( "testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" + "k8s.io/utils/ptr" ) func TestDefaultVirtualNetworkTemplate(t *testing.T) { @@ -384,23 +384,23 @@ func TestDefaultAutoScalerProfile(t *testing.T) { Template: AzureManagedControlPlaneTemplateResource{ Spec: AzureManagedControlPlaneTemplateResourceSpec{ AutoScalerProfile: &AutoScalerProfile{ - BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(pointer.String(string(BalanceSimilarNodeGroupsFalse))), - Expander: (*Expander)(pointer.String(string(ExpanderRandom))), - MaxEmptyBulkDelete: pointer.String("10"), - MaxGracefulTerminationSec: pointer.String("600"), - MaxNodeProvisionTime: pointer.String("15m"), - MaxTotalUnreadyPercentage: pointer.String("45"), - NewPodScaleUpDelay: pointer.String("0s"), - OkTotalUnreadyCount: pointer.String("3"), - ScanInterval: pointer.String("10s"), - ScaleDownDelayAfterAdd: pointer.String("10m"), - ScaleDownDelayAfterDelete: pointer.String("10s"), - ScaleDownDelayAfterFailure: pointer.String("3m"), - ScaleDownUnneededTime: pointer.String("10m"), - ScaleDownUnreadyTime: pointer.String("20m"), - ScaleDownUtilizationThreshold: pointer.String("0.5"), - SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(pointer.String(string(SkipNodesWithLocalStorageFalse))), - SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(pointer.String(string(SkipNodesWithSystemPodsTrue))), + BalanceSimilarNodeGroups: (*BalanceSimilarNodeGroups)(ptr.To(string(BalanceSimilarNodeGroupsFalse))), + Expander: (*Expander)(ptr.To(string(ExpanderRandom))), + MaxEmptyBulkDelete: ptr.To("10"), + MaxGracefulTerminationSec: ptr.To("600"), + MaxNodeProvisionTime: ptr.To("15m"), + MaxTotalUnreadyPercentage: ptr.To("45"), + NewPodScaleUpDelay: ptr.To("0s"), + OkTotalUnreadyCount: ptr.To("3"), + ScanInterval: ptr.To("10s"), + ScaleDownDelayAfterAdd: ptr.To("10m"), + ScaleDownDelayAfterDelete: ptr.To("10s"), + ScaleDownDelayAfterFailure: ptr.To("3m"), + ScaleDownUnneededTime: ptr.To("10m"), + ScaleDownUnreadyTime: ptr.To("20m"), + ScaleDownUtilizationThreshold: ptr.To("0.5"), + SkipNodesWithLocalStorage: (*SkipNodesWithLocalStorage)(ptr.To(string(SkipNodesWithLocalStorageFalse))), + SkipNodesWithSystemPods: (*SkipNodesWithSystemPods)(ptr.To(string(SkipNodesWithSystemPodsTrue))), }, }, }, diff --git a/api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go b/api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go index 98a273ad996..4d8182ac223 100644 --- a/api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go +++ b/api/v1beta1/azuremanagedcontrolplanetemplate_webhook.go @@ -33,7 +33,7 @@ import ( // AzureManagedControlPlaneTemplateImmutableMsg is the message used for errors on fields that are immutable. const AzureManagedControlPlaneTemplateImmutableMsg = "AzureManagedControlPlaneTemplate spec.template.spec field is immutable. Please create new resource instead. ref doc: https://cluster-api.sigs.k8s.io/tasks/experimental-features/cluster-class/change-clusterclass.html" -// SetupWebhookWithManager will set up the webhook to be managed by the specified manager. +// SetupAzureManagedControlPlaneTemplateWithManager will set up the webhook to be managed by the specified manager. func SetupAzureManagedControlPlaneTemplateWithManager(mgr ctrl.Manager) error { mcpw := &azureManagedControlPlaneTemplateWebhook{Client: mgr.GetClient()} return ctrl.NewWebhookManagedBy(mgr). diff --git a/api/v1beta1/consts.go b/api/v1beta1/consts.go index 419cd3d8c63..8d7f48daad5 100644 --- a/api/v1beta1/consts.go +++ b/api/v1beta1/consts.go @@ -166,3 +166,8 @@ const ( // value for the label is the CAPI Cluster Name. OwnedByClusterLabelKey = NameAzureProviderPrefix + string(ResourceLifecycleOwned) ) + +const ( + // CloudProviderName is the name of the Azure cloud provider. + CloudProviderName = "azure" +) diff --git a/api/v1beta1/types_template.go b/api/v1beta1/types_template.go index d24233d9267..3d1015e477b 100644 --- a/api/v1beta1/types_template.go +++ b/api/v1beta1/types_template.go @@ -106,6 +106,7 @@ type AzureManagedControlPlaneTemplateResourceSpec struct { AutoScalerProfile *AutoScalerProfile `json:"autoscalerProfile,omitempty"` } +// AzureManagedControlPlaneTemplateMachineTemplate specifies an Azure managed control plane template. type AzureManagedControlPlaneTemplateMachineTemplate struct { // Standard object's metadata. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata @@ -130,6 +131,7 @@ type AzureManagedControlPlaneTemplateMachineTemplate struct { NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"` } +// AzureManagedMachinePoolTemplateResourceSpec specifies an Azure managed control plane template resource. type AzureManagedMachinePoolTemplateResourceSpec struct { // AdditionalTags is an optional set of tags to add to Azure resources managed by the // Azure provider, in addition to the ones added by default. @@ -271,6 +273,7 @@ type AzureManagedMachinePoolTemplateResourceSpec struct { EnableFIPS *bool `json:"enableFIPS,omitempty"` } +// APIServerAccessProfileTemplate specifies an API server access profile template. type APIServerAccessProfileTemplate struct { // EnablePrivateCluster - Whether to create the cluster as a private cluster or not. // +optional @@ -284,6 +287,7 @@ type APIServerAccessProfileTemplate struct { EnablePrivateClusterPublicFQDN *bool `json:"enablePrivateClusterPublicFQDN,omitempty"` } +// ManagedControlPlaneVirtualNetworkTemplate specifies a managed control plane virtual network template. type ManagedControlPlaneVirtualNetworkTemplate struct { Name string `json:"name"` CIDRBlock string `json:"cidrBlock"` diff --git a/test/e2e/common.go b/test/e2e/common.go index 30674d3e79b..aa683ee4e91 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -38,6 +38,7 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "k8s.io/utils/ptr" + infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" "sigs.k8s.io/cluster-api-provider-azure/azure" e2e_namespace "sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/namespace" azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure" @@ -275,7 +276,7 @@ func EnsureControlPlaneInitialized(ctx context.Context, input clusterctl.ApplyCu }, input.WaitForControlPlaneIntervals...).Should(Succeed(), "API Server was not reachable in time") _, hasWindows := cluster.Labels["cni-windows"] - if kubeadmControlPlane.Spec.KubeadmConfigSpec.ClusterConfiguration.ControllerManager.ExtraArgs["cloud-provider"] != "azure" { + if kubeadmControlPlane.Spec.KubeadmConfigSpec.ClusterConfiguration.ControllerManager.ExtraArgs["cloud-provider"] != infrav1.CloudProviderName { // There is a co-dependency between cloud-provider and CNI so we install both together if cloud-provider is external. InstallCalicoAndCloudProviderAzureHelmChart(ctx, input, cluster.Spec.ClusterNetwork.Pods.CIDRBlocks, hasWindows) } else {