From f9d7c9f3575ba854bd29da34d56dd3bb18558790 Mon Sep 17 00:00:00 2001 From: killianmuldoon Date: Mon, 30 Jan 2023 19:20:41 +0000 Subject: [PATCH] Make 'inline' a reserved name for patches --- api/v1beta1/common_types.go | 4 ++++ internal/webhooks/patch_validation.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index d505d1420413..3db08c79af79 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -120,6 +120,10 @@ const ( // instead of being a source of truth for eventual consistency. // This annotation can be used to inform MachinePool status during in-progress scaling scenarios. ReplicasManagedByAnnotation = "cluster.x-k8s.io/replicas-managed-by" + + // VariableDefinitionFromInline indicates a patch or variable was defined in the `.spec` of a ClusterClass + // rather than from an external patch extension. + VariableDefinitionFromInline = "inline" ) const ( diff --git a/internal/webhooks/patch_validation.go b/internal/webhooks/patch_validation.go index c8c3cb6e1bc6..8e7f98892246 100644 --- a/internal/webhooks/patch_validation.go +++ b/internal/webhooks/patch_validation.go @@ -69,6 +69,14 @@ func validatePatchName(patch clusterv1.ClusterClassPatch, names sets.Set[string] ), ) } + if patch.Name == clusterv1.VariableDefinitionFromInline { + allErrs = append(allErrs, + field.Required( + path.Child("name"), + fmt.Sprintf("%q can not be used as the name of a patch", clusterv1.VariableDefinitionFromInline), + ), + ) + } if names.Has(patch.Name) { allErrs = append(allErrs,