From 4d047c2680456639dd19f9f844bc49d19ae873e8 Mon Sep 17 00:00:00 2001 From: Michael Shitrit Date: Sun, 8 Sep 2024 20:50:02 +0300 Subject: [PATCH] - when generating a CR for MHC removing the multiple template support so the CR name will be created from the machine name without aditional generated suffix - remove annotation that are used to indicate the the multiple template in MHC since it's not supported Signed-off-by: Michael Shitrit --- controllers/machinehealthcheck_controller_test.go | 2 +- controllers/resources/manager.go | 10 +++++++++- controllers/utils/annotations/annotations.go | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/controllers/machinehealthcheck_controller_test.go b/controllers/machinehealthcheck_controller_test.go index 5442e5c7..e9330283 100644 --- a/controllers/machinehealthcheck_controller_test.go +++ b/controllers/machinehealthcheck_controller_test.go @@ -4,12 +4,12 @@ import ( "context" "errors" "fmt" - commonannotations "github.com/medik8s/common/pkg/annotations" "reflect" "strings" "testing" "time" + commonannotations "github.com/medik8s/common/pkg/annotations" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" diff --git a/controllers/resources/manager.go b/controllers/resources/manager.go index 6d2b6ea8..3870be32 100644 --- a/controllers/resources/manager.go +++ b/controllers/resources/manager.go @@ -116,7 +116,15 @@ func (m *manager) GenerateRemediationCRForMachine(machine *machinev1beta1.Machin // So it can be ignored here. } - return m.generateRemediationCR(machine.GetName(), mhcOwnerRef, machineOwnerRef, template) + cr, err := m.generateRemediationCR(machine.GetName(), mhcOwnerRef, machineOwnerRef, annotations.RemoveMultipleTemplatesAnnotation(template)) + //MHC does not support multiple templates so the annotations indicating the template aren't required + if err == nil && cr != nil { + ann := cr.GetAnnotations() + delete(ann, annotations.TemplateNameAnnotation) + delete(ann, commonannotations.NodeNameAnnotation) + cr.SetAnnotations(ann) + } + return cr, err } func (m *manager) generateRemediationCR(name string, healthCheckOwnerRef *metav1.OwnerReference, machineOwnerRef *metav1.OwnerReference, template *unstructured.Unstructured) (*unstructured.Unstructured, error) { diff --git a/controllers/utils/annotations/annotations.go b/controllers/utils/annotations/annotations.go index 49668bd7..0112097d 100644 --- a/controllers/utils/annotations/annotations.go +++ b/controllers/utils/annotations/annotations.go @@ -4,6 +4,7 @@ import ( commonannotations "github.com/medik8s/common/pkg/annotations" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) const ( @@ -20,6 +21,15 @@ func HasMultipleTemplatesAnnotation(o metav1.Object) bool { return hasAnnotation(o, commonannotations.MultipleTemplatesSupportedAnnotation) } +func RemoveMultipleTemplatesAnnotation(o *unstructured.Unstructured) *unstructured.Unstructured { + if HasMultipleTemplatesAnnotation(o) { + ann := o.GetAnnotations() + delete(ann, commonannotations.MultipleTemplatesSupportedAnnotation) + o.SetAnnotations(ann) + } + return o +} + func HasMHCPausedAnnotation(o metav1.Object) bool { return hasAnnotation(o, MHCPausedAnnotation) }