diff --git a/exp/api/v1alpha3/conversion.go b/exp/api/v1alpha3/conversion.go index 8f6903b81abc..b1eccab89345 100644 --- a/exp/api/v1alpha3/conversion.go +++ b/exp/api/v1alpha3/conversion.go @@ -76,6 +76,7 @@ func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error { } dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout dst.Spec.Template.Spec.NodeVolumeDetachTimeout = restored.Spec.Template.Spec.NodeVolumeDetachTimeout + dst.Spec.Selector = restored.Spec.Selector return nil } diff --git a/exp/api/v1alpha4/conversion.go b/exp/api/v1alpha4/conversion.go index fa9d49368d8d..d66548e85829 100644 --- a/exp/api/v1alpha4/conversion.go +++ b/exp/api/v1alpha4/conversion.go @@ -42,6 +42,7 @@ func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error { } dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout dst.Spec.Template.Spec.NodeVolumeDetachTimeout = restored.Spec.Template.Spec.NodeVolumeDetachTimeout + dst.Spec.Selector = restored.Spec.Selector return nil } diff --git a/internal/webhooks/patch_validation.go b/internal/webhooks/patch_validation.go index 81557bc06b57..d08016c3f9c9 100644 --- a/internal/webhooks/patch_validation.go +++ b/internal/webhooks/patch_validation.go @@ -207,6 +207,7 @@ func validateSelectors(selector clusterv1.PatchSelector, class *clusterv1.Cluste if selector.MatchResources.MachineDeploymentClass != nil && len(selector.MatchResources.MachineDeploymentClass.Names) > 0 { for i, name := range selector.MatchResources.MachineDeploymentClass.Names { + match := false if strings.Contains(name, "*") { // selector can at most have a single * rune if strings.Count(name, "*") > 1 { @@ -248,10 +249,18 @@ func validateSelectors(selector clusterv1.PatchSelector, class *clusterv1.Cluste if matches { if selectorMatchTemplate(selector, md.Template.Infrastructure.Ref) || selectorMatchTemplate(selector, md.Template.Bootstrap.Ref) { + match = true break } } } + if !match { + allErrs = append(allErrs, field.Invalid( + path.Child("matchResources", "machineDeploymentClass", "names").Index(i), + name, + "selector is enabled but matches neither the bootstrap ref nor the infrastructure ref of a MachineDeployment class", + )) + } } }