Skip to content

Commit 6a8d821

Browse files
committed
fix review findings
Signed-off-by: sivchari <[email protected]>
1 parent d0ec7be commit 6a8d821

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

test/infrastructure/docker/internal/webhooks/devcluster_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func validateDevClusterSpec(spec infrav1.DevClusterSpec) field.ErrorList {
112112
for _, fd := range spec.Backend.Docker.FailureDomains {
113113
domainNames = append(domainNames, fd.Name)
114114
}
115-
originalDomainNames := domainNames
115+
originalDomainNames := slices.Clone(domainNames)
116116
sort.Strings(domainNames)
117117
if !slices.Equal(originalDomainNames, domainNames) {
118118
return field.ErrorList{field.Invalid(field.NewPath("spec", "backend", "docker", "failureDomains"), spec.Backend.Docker.FailureDomains, "failure domains must be sorted by name")}

test/infrastructure/docker/internal/webhooks/dockercluster_webhook.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ func (webhook *DockerCluster) ValidateCreate(_ context.Context, obj runtime.Obje
7474
}
7575

7676
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
77-
func (webhook *DockerCluster) ValidateUpdate(_ context.Context, _, _ runtime.Object) (admission.Warnings, error) {
77+
func (webhook *DockerCluster) ValidateUpdate(_ context.Context, _, newObj runtime.Object) (admission.Warnings, error) {
78+
cluster, ok := newObj.(*infrav1.DockerCluster)
79+
if !ok {
80+
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a DockerCluster but got a %T", newObj))
81+
}
82+
if allErrs := validateDockerClusterSpec(cluster.Spec); len(allErrs) > 0 {
83+
return nil, apierrors.NewInvalid(infrav1.GroupVersion.WithKind("DockerCluster").GroupKind(), cluster.Name, allErrs)
84+
}
7885
return nil, nil
7986
}
8087

@@ -94,7 +101,7 @@ func validateDockerClusterSpec(spec infrav1.DockerClusterSpec) field.ErrorList {
94101
for _, fd := range spec.FailureDomains {
95102
domainNames = append(domainNames, fd.Name)
96103
}
97-
originalDomainNames := domainNames
104+
originalDomainNames := slices.Clone(domainNames)
98105
sort.Strings(domainNames)
99106
if !slices.Equal(originalDomainNames, domainNames) {
100107
return field.ErrorList{field.Invalid(field.NewPath("spec", "failureDomains"), spec.FailureDomains, "failure domains must be sorted by name")}

0 commit comments

Comments
 (0)