Skip to content

Commit 51210c3

Browse files
authored
Merge pull request #12670 from k8s-infra-cherrypick-robot/cherry-pick-12660-to-release-1.11
[release-1.11] 🐛 Fix field paths in ClusterClass compatibility validation errors
2 parents d445f35 + 393a499 commit 51210c3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

internal/topology/check/compatibility.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ func ClusterClassTemplateAreCompatible(current, desired clusterv1.ClusterClassTe
9494

9595
if currentGK.Group != desiredGK.Group {
9696
allErrs = append(allErrs, field.Forbidden(
97-
pathPrefix.Child("ref", "apiVersion"),
98-
fmt.Sprintf("apiVersion.group cannot be changed from %q to %q to prevent incompatible changes in the Clusters",
97+
pathPrefix.Child("apiVersion"),
98+
fmt.Sprintf("group of apiVersion cannot be changed from %q to %q to prevent incompatible changes in the Clusters",
9999
currentGK.Group, desiredGK.Group),
100100
))
101101
}
102102
if currentGK.Kind != desiredGK.Kind {
103103
allErrs = append(allErrs, field.Forbidden(
104-
pathPrefix.Child("ref", "kind"),
105-
fmt.Sprintf("apiVersion.kind cannot be changed from %q to %q to prevent incompatible changes in the Clusters",
104+
pathPrefix.Child("kind"),
105+
fmt.Sprintf("kind cannot be changed from %q to %q to prevent incompatible changes in the Clusters",
106106
currentGK.Kind, desiredGK.Kind),
107107
))
108108
}
@@ -174,14 +174,14 @@ func ClusterClassesAreCompatible(current, desired *clusterv1.ClusterClass) field
174174

175175
// Validate InfrastructureClusterTemplate changes desired a compatible way.
176176
allErrs = append(allErrs, ClusterClassTemplateAreCompatible(current.Spec.Infrastructure.TemplateRef, desired.Spec.Infrastructure.TemplateRef,
177-
field.NewPath("spec", "infrastructure"))...)
177+
field.NewPath("spec", "infrastructure", "templateRef"))...)
178178

179179
// Validate control plane changes desired a compatible way.
180180
allErrs = append(allErrs, ClusterClassTemplateAreCompatible(current.Spec.ControlPlane.TemplateRef, desired.Spec.ControlPlane.TemplateRef,
181-
field.NewPath("spec", "controlPlane"))...)
181+
field.NewPath("spec", "controlPlane", "templateRef"))...)
182182
if desired.Spec.ControlPlane.MachineInfrastructure.TemplateRef.IsDefined() && current.Spec.ControlPlane.MachineInfrastructure.TemplateRef.IsDefined() {
183183
allErrs = append(allErrs, ClusterClassTemplateAreCompatible(current.Spec.ControlPlane.MachineInfrastructure.TemplateRef, desired.Spec.ControlPlane.MachineInfrastructure.TemplateRef,
184-
field.NewPath("spec", "controlPlane", "machineInfrastructure"))...)
184+
field.NewPath("spec", "controlPlane", "machineInfrastructure", "templateRef"))...)
185185
}
186186

187187
// Validate changes to MachineDeployments.
@@ -199,16 +199,16 @@ func MachineDeploymentClassesAreCompatible(current, desired *clusterv1.ClusterCl
199199
var allErrs field.ErrorList
200200

201201
// Ensure previous MachineDeployment class was modified in a compatible way.
202-
for _, class := range desired.Spec.Workers.MachineDeployments {
203-
for i, oldClass := range current.Spec.Workers.MachineDeployments {
202+
for i, class := range desired.Spec.Workers.MachineDeployments {
203+
for _, oldClass := range current.Spec.Workers.MachineDeployments {
204204
if class.Class == oldClass.Class {
205205
// NOTE: class.Template.Metadata and class.Template.Bootstrap are allowed to change;
206206

207207
// class.Template.Bootstrap is ensured syntactically correct by LocalObjectTemplateIsValid.
208208

209209
// Validates class.Template.Infrastructure template changes in a compatible way
210210
allErrs = append(allErrs, ClusterClassTemplateAreCompatible(oldClass.Infrastructure.TemplateRef, class.Infrastructure.TemplateRef,
211-
field.NewPath("spec", "workers", "machineDeployments").Index(i))...)
211+
field.NewPath("spec", "workers", "machineDeployments").Index(i).Child("infrastructure", "templateRef"))...)
212212
}
213213
}
214214
}
@@ -240,16 +240,16 @@ func MachinePoolClassesAreCompatible(current, desired *clusterv1.ClusterClass) f
240240
var allErrs field.ErrorList
241241

242242
// Ensure previous MachinePool class was modified in a compatible way.
243-
for _, class := range desired.Spec.Workers.MachinePools {
244-
for i, oldClass := range current.Spec.Workers.MachinePools {
243+
for i, class := range desired.Spec.Workers.MachinePools {
244+
for _, oldClass := range current.Spec.Workers.MachinePools {
245245
if class.Class == oldClass.Class {
246246
// NOTE: class.Template.Metadata and class.Template.Bootstrap are allowed to change;
247247

248248
// class.Template.Bootstrap is ensured syntactically correct by LocalObjectTemplateIsValid.
249249

250250
// Validates class.Template.Infrastructure template changes in a compatible way
251251
allErrs = append(allErrs, ClusterClassTemplateAreCompatible(oldClass.Infrastructure.TemplateRef, class.Infrastructure.TemplateRef,
252-
field.NewPath("spec", "workers", "machinePools").Index(i))...)
252+
field.NewPath("spec", "workers", "machinePools").Index(i).Child("infrastructure", "templateRef"))...)
253253
}
254254
}
255255
}

0 commit comments

Comments
 (0)