Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions internal/topology/check/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ func ClusterClassTemplateAreCompatible(current, desired clusterv1.ClusterClassTe

if currentGK.Group != desiredGK.Group {
allErrs = append(allErrs, field.Forbidden(
pathPrefix.Child("ref", "apiVersion"),
fmt.Sprintf("apiVersion.group cannot be changed from %q to %q to prevent incompatible changes in the Clusters",
pathPrefix.Child("apiVersion"),
fmt.Sprintf("group of apiVersion cannot be changed from %q to %q to prevent incompatible changes in the Clusters",
currentGK.Group, desiredGK.Group),
))
}
if currentGK.Kind != desiredGK.Kind {
allErrs = append(allErrs, field.Forbidden(
pathPrefix.Child("ref", "kind"),
fmt.Sprintf("apiVersion.kind cannot be changed from %q to %q to prevent incompatible changes in the Clusters",
pathPrefix.Child("kind"),
fmt.Sprintf("kind cannot be changed from %q to %q to prevent incompatible changes in the Clusters",
currentGK.Kind, desiredGK.Kind),
))
}
Expand Down Expand Up @@ -174,14 +174,14 @@ func ClusterClassesAreCompatible(current, desired *clusterv1.ClusterClass) field

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

// Validate control plane changes desired a compatible way.
allErrs = append(allErrs, ClusterClassTemplateAreCompatible(current.Spec.ControlPlane.TemplateRef, desired.Spec.ControlPlane.TemplateRef,
field.NewPath("spec", "controlPlane"))...)
field.NewPath("spec", "controlPlane", "templateRef"))...)
if desired.Spec.ControlPlane.MachineInfrastructure.TemplateRef.IsDefined() && current.Spec.ControlPlane.MachineInfrastructure.TemplateRef.IsDefined() {
allErrs = append(allErrs, ClusterClassTemplateAreCompatible(current.Spec.ControlPlane.MachineInfrastructure.TemplateRef, desired.Spec.ControlPlane.MachineInfrastructure.TemplateRef,
field.NewPath("spec", "controlPlane", "machineInfrastructure"))...)
field.NewPath("spec", "controlPlane", "machineInfrastructure", "templateRef"))...)
}

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

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

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

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

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

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

// Validates class.Template.Infrastructure template changes in a compatible way
allErrs = append(allErrs, ClusterClassTemplateAreCompatible(oldClass.Infrastructure.TemplateRef, class.Infrastructure.TemplateRef,
field.NewPath("spec", "workers", "machinePools").Index(i))...)
field.NewPath("spec", "workers", "machinePools").Index(i).Child("infrastructure", "templateRef"))...)
}
}
}
Expand Down