Skip to content

Commit

Permalink
- when generating a CR for MHC removing the multiple template support…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
  • Loading branch information
mshitrit committed Sep 8, 2024
1 parent ba2843b commit 4d047c2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion controllers/machinehealthcheck_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion controllers/resources/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions controllers/utils/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
}
Expand Down

0 comments on commit 4d047c2

Please sign in to comment.