From c668049c8ed2cda2c09a843ad92972428e5b0984 Mon Sep 17 00:00:00 2001 From: willie-yao Date: Mon, 4 Dec 2023 21:39:23 +0000 Subject: [PATCH] Test fixes --- .../azuremanagedcontrolplane_webhook.go | 30 ++++++++++++++----- test/e2e/aks_fleets_member.go | 9 +++--- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/api/v1beta1/azuremanagedcontrolplane_webhook.go b/api/v1beta1/azuremanagedcontrolplane_webhook.go index a1964cb5ac7..9af5da940af 100644 --- a/api/v1beta1/azuremanagedcontrolplane_webhook.go +++ b/api/v1beta1/azuremanagedcontrolplane_webhook.go @@ -216,14 +216,6 @@ func (mw *azureManagedControlPlaneWebhook) ValidateUpdate(ctx context.Context, o allErrs = append(allErrs, err) } - if err := webhookutils.ValidateImmutable( - field.NewPath("Spec", "FleetsMember.Name"), - m.Spec.FleetsMember.Name, - old.Spec.FleetsMember.Name, - ); err != nil { - allErrs = append(allErrs, err) - } - // Consider removing this once moves out of preview // Updating outboundType after cluster creation (PREVIEW) // https://learn.microsoft.com/en-us/azure/aks/egress-outboundtype#updating-outboundtype-after-cluster-creation-preview @@ -258,6 +250,10 @@ func (mw *azureManagedControlPlaneWebhook) ValidateUpdate(ctx context.Context, o allErrs = append(allErrs, errs...) } + if errs := m.validateFleetsMember(old); len(errs) > 0 { + allErrs = append(allErrs, errs...) + } + if len(allErrs) == 0 { return nil, m.Validate(mw.Client) } @@ -685,6 +681,24 @@ func (m *AzureManagedControlPlane) validateOIDCIssuerProfileUpdate(old *AzureMan return allErrs } +// validateFleetsMember validates a FleetsMember. +func (m *AzureManagedControlPlane) validateFleetsMember(old *AzureManagedControlPlane) field.ErrorList { + var allErrs field.ErrorList + + if old.Spec.FleetsMember != nil && m.Spec.FleetsMember != nil { + if old.Spec.FleetsMember.Name != m.Spec.FleetsMember.Name { + allErrs = append(allErrs, + field.Forbidden( + field.NewPath("Spec", "FleetsMember", "Name"), + "Name is immutable", + ), + ) + } + } + + return allErrs +} + func validateName(name string, fldPath *field.Path) field.ErrorList { var allErrs field.ErrorList if lName := strings.ToLower(name); strings.Contains(lName, "microsoft") || diff --git a/test/e2e/aks_fleets_member.go b/test/e2e/aks_fleets_member.go index dd24d59d5ed..b6d18109b23 100644 --- a/test/e2e/aks_fleets_member.go +++ b/test/e2e/aks_fleets_member.go @@ -83,11 +83,10 @@ func AKSFleetsMemberSpec(ctx context.Context, inputGetter func() AKSFleetsMember Location: ptr.To(os.Getenv(AzureLocation)), }, nil) Expect(err).To(BeNil()) - - Eventually(func(g Gomega) { - _, err := poller.PollUntilDone(ctx, nil) - Expect(err).NotTo(HaveOccurred()) - }, input.WaitIntervals...).Should(Succeed(), "failed to create fleet manager") + res, err := poller.PollUntilDone(ctx, nil) + Expect(err).To(BeNil()) + Logf("Fleet manager created: %v", res.Fleet.Name) + Logf("Fleet manager arm id: %v", *res.Fleet.ID) By("Joining the cluster to the fleet hub") var infraControlPlane = &infrav1.AzureManagedControlPlane{}