Skip to content

Commit

Permalink
Merge pull request #4820 from willie-yao/fleet-fixes-release-1.13
Browse files Browse the repository at this point in the history
[release-1.13] Don't allow fleetsMembers to have capital letters. Default spec.group.
  • Loading branch information
k8s-ci-robot authored May 7, 2024
2 parents bdee493 + f738741 commit 7cc0dce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
9 changes: 7 additions & 2 deletions api/v1beta1/azuremanagedcontrolplane_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@ func (m *AzureManagedControlPlane) setDefaultSubnet() {
// setDefaultFleetsMember sets the default FleetsMember for an AzureManagedControlPlane.
func setDefaultFleetsMember(fleetsMember *FleetsMember, labels map[string]string) *FleetsMember {
result := fleetsMember.DeepCopy()
if clusterName, ok := labels[clusterv1.ClusterNameLabel]; ok && fleetsMember != nil && fleetsMember.Name == "" {
result.Name = clusterName
if fleetsMember != nil {
if clusterName, ok := labels[clusterv1.ClusterNameLabel]; ok && fleetsMember.Name == "" {
result.Name = clusterName
}
if fleetsMember.Group == "" {
result.Group = "default"
}
}
return result
}
Expand Down
27 changes: 24 additions & 3 deletions api/v1beta1/azuremanagedcontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (mw *azureManagedControlPlaneWebhook) ValidateUpdate(ctx context.Context, o
allErrs = append(allErrs, errs...)
}

if errs := m.validateFleetsMember(old); len(errs) > 0 {
if errs := m.validateFleetsMemberUpdate(old); len(errs) > 0 {
allErrs = append(allErrs, errs...)
}

Expand Down Expand Up @@ -316,6 +316,8 @@ func (m *AzureManagedControlPlane) Validate(cli client.Client) error {

allErrs = append(allErrs, validateAMCPVirtualNetwork(m.Spec.VirtualNetwork, field.NewPath("spec").Child("VirtualNetwork"))...)

allErrs = append(allErrs, validateFleetsMember(m.Spec.FleetsMember, field.NewPath("spec").Child("FleetsMember"))...)

return allErrs.ToAggregate()
}

Expand Down Expand Up @@ -431,6 +433,25 @@ func validateAMCPVirtualNetwork(virtualNetwork ManagedControlPlaneVirtualNetwork
return allErrs
}

func validateFleetsMember(fleetsMember *FleetsMember, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList

if fleetsMember != nil && fleetsMember.Name != "" {
match, _ := regexp.MatchString(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`, fleetsMember.Name)
if !match {
allErrs = append(allErrs,
field.Invalid(
fldPath.Child("Name"),
fleetsMember.Name,
"Name must match ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$",
),
)
}
}

return allErrs
}

// validateAPIServerAccessProfile validates an APIServerAccessProfile.
func (m *AzureManagedControlPlane) validateAPIServerAccessProfile(_ client.Client) field.ErrorList {
if m.Spec.APIServerAccessProfile != nil {
Expand Down Expand Up @@ -714,8 +735,8 @@ func (m *AzureManagedControlPlane) validateOIDCIssuerProfileUpdate(old *AzureMan
return allErrs
}

// validateFleetsMember validates a FleetsMember.
func (m *AzureManagedControlPlane) validateFleetsMember(old *AzureManagedControlPlane) field.ErrorList {
// validateFleetsMemberUpdate validates a FleetsMember.
func (m *AzureManagedControlPlane) validateFleetsMemberUpdate(old *AzureManagedControlPlane) field.ErrorList {
var allErrs field.ErrorList

if old.Spec.FleetsMember == nil || m.Spec.FleetsMember == nil {
Expand Down

0 comments on commit 7cc0dce

Please sign in to comment.