in pkg/api/v1alpha1/cluster_webhook.go [263:410]
func validateImmutableFieldsCluster(new, old *Cluster) field.ErrorList {
if old.IsReconcilePaused() {
return nil
}
var allErrs field.ErrorList
specPath := field.NewPath("spec")
if !old.ManagementClusterEqual(new) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("managementCluster", new.Spec.ManagementCluster.Name), fmt.Sprintf("field is immutable %v", new.Spec.ManagementCluster)))
}
if !new.Spec.DatacenterRef.Equal(&old.Spec.DatacenterRef) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("datacenterRef"), fmt.Sprintf("field is immutable %v", new.Spec.DatacenterRef)))
}
if !new.Spec.ControlPlaneConfiguration.Endpoint.Equal(old.Spec.ControlPlaneConfiguration.Endpoint, new.Spec.DatacenterRef.Kind) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("ControlPlaneConfiguration.endpoint"), fmt.Sprintf("field is immutable %v", new.Spec.ControlPlaneConfiguration.Endpoint)))
}
if !new.Spec.ClusterNetwork.Pods.Equal(&old.Spec.ClusterNetwork.Pods) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("clusterNetwork", "pods"), "field is immutable"))
}
if !new.Spec.ClusterNetwork.Services.Equal(&old.Spec.ClusterNetwork.Services) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("clusterNetwork", "services"), "field is immutable"))
}
if !new.Spec.ClusterNetwork.DNS.Equal(&old.Spec.ClusterNetwork.DNS) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("clusterNetwork", "dns"), "field is immutable"))
}
// We don't want users to be able to toggle off SkipUpgrade until we've understood the
// implications so we are temporarily disallowing it.
oCNI := old.Spec.ClusterNetwork.CNIConfig
nCNI := new.Spec.ClusterNetwork.CNIConfig
if oCNI != nil && oCNI.Cilium != nil && !oCNI.Cilium.IsManaged() && nCNI.Cilium.IsManaged() {
allErrs = append(
allErrs,
field.Forbidden(
specPath.Child("clusterNetwork", "cniConfig", "cilium", "skipUpgrade"),
"cannot toggle off skipUpgrade once enabled",
),
)
}
if !new.Spec.ClusterNetwork.Nodes.Equal(old.Spec.ClusterNetwork.Nodes) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("clusterNetwork", "nodes"), "field is immutable"))
}
if !new.Spec.ProxyConfiguration.Equal(old.Spec.ProxyConfiguration) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("ProxyConfiguration"), fmt.Sprintf("field is immutable %v", new.Spec.ProxyConfiguration)))
}
if new.Spec.ExternalEtcdConfiguration != nil && old.Spec.ExternalEtcdConfiguration == nil {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("externalEtcdConfiguration"), "cannot switch from stacked to external etcd topology"),
)
}
if new.Spec.ExternalEtcdConfiguration == nil && old.Spec.ExternalEtcdConfiguration != nil {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("externalEtcdConfiguration"), "cannot switch from external to stacked etcd topology"),
)
}
if !new.Spec.GitOpsRef.Equal(old.Spec.GitOpsRef) && !old.IsSelfManaged() {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("GitOpsRef"), fmt.Sprintf("field is immutable %v", new.Spec.GitOpsRef)))
}
if new.Spec.DatacenterRef.Kind == TinkerbellDatacenterKind {
if !reflect.DeepEqual(new.Spec.ControlPlaneConfiguration.Labels, old.Spec.ControlPlaneConfiguration.Labels) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("ControlPlaneConfiguration.labels"), fmt.Sprintf("field is immutable %v", new.Spec.ControlPlaneConfiguration.Labels)))
}
if !reflect.DeepEqual(new.Spec.ControlPlaneConfiguration.Taints, old.Spec.ControlPlaneConfiguration.Taints) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("ControlPlaneConfiguration.taints"), fmt.Sprintf("field is immutable %v", new.Spec.ControlPlaneConfiguration.Taints)))
}
workerNodeGroupMap := make(map[string]*WorkerNodeGroupConfiguration)
for i := range old.Spec.WorkerNodeGroupConfigurations {
workerNodeGroupMap[old.Spec.WorkerNodeGroupConfigurations[i].Name] = &old.Spec.WorkerNodeGroupConfigurations[i]
}
for _, nodeGroupNewSpec := range new.Spec.WorkerNodeGroupConfigurations {
if workerNodeGrpOldSpec, ok := workerNodeGroupMap[nodeGroupNewSpec.Name]; ok {
if !reflect.DeepEqual(workerNodeGrpOldSpec.Labels, nodeGroupNewSpec.Labels) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("WorkerNodeConfiguration.labels"), fmt.Sprintf("field is immutable %v", nodeGroupNewSpec.Labels)))
}
if !reflect.DeepEqual(workerNodeGrpOldSpec.Taints, nodeGroupNewSpec.Taints) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("WorkerNodeConfiguration.taints"), fmt.Sprintf("field is immutable %v", nodeGroupNewSpec.Taints)))
}
}
}
}
oldAWSIamConfig, newAWSIamConfig := &Ref{}, &Ref{}
for _, identityProvider := range new.Spec.IdentityProviderRefs {
if identityProvider.Kind == AWSIamConfigKind {
newAWSIamConfig = &identityProvider
break
}
}
for _, identityProvider := range old.Spec.IdentityProviderRefs {
if identityProvider.Kind == AWSIamConfigKind {
oldAWSIamConfig = &identityProvider
break
}
}
if !oldAWSIamConfig.Equal(newAWSIamConfig) {
allErrs = append(
allErrs,
field.Forbidden(specPath.Child("identityProviderRefs", AWSIamConfigKind), fmt.Sprintf("field is immutable %v", newAWSIamConfig.Kind)))
}
return allErrs
}