Skip to content

Commit b97a37b

Browse files
committed
use new version of common with required annotations
Signed-off-by: Michael Shitrit <[email protected]>
1 parent 2401775 commit b97a37b

File tree

10 files changed

+61
-39
lines changed

10 files changed

+61
-39
lines changed

controllers/nodehealthcheck_controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import (
5757
"github.com/medik8s/node-healthcheck-operator/controllers/mhc"
5858
"github.com/medik8s/node-healthcheck-operator/controllers/resources"
5959
"github.com/medik8s/node-healthcheck-operator/controllers/utils"
60-
"github.com/medik8s/node-healthcheck-operator/controllers/utils/annotations"
6160
"github.com/medik8s/node-healthcheck-operator/metrics"
6261
)
6362

@@ -483,8 +482,8 @@ func (r *NodeHealthCheckReconciler) deleteOrphanedRemediationCRs(nhc *remediatio
483482
log.Info("Going to delete orphaned remediation CRs", "count", len(orphanedRemediationCRs))
484483
for _, cr := range orphanedRemediationCRs {
485484
nodeName := cr.GetName()
486-
if cr.GetAnnotations() != nil && len(cr.GetAnnotations()[annotations.NodeNameAnnotation]) > 0 {
487-
nodeName = cr.GetAnnotations()[annotations.NodeNameAnnotation]
485+
if cr.GetAnnotations() != nil && len(cr.GetAnnotations()[commonannotations.NodeNameAnnotation]) > 0 {
486+
nodeName = cr.GetAnnotations()[commonannotations.NodeNameAnnotation]
488487
}
489488
// do some housekeeping first. When the CRs are deleted, we never get back here...
490489
if err := rm.CleanUp(nodeName); err != nil {

controllers/nodehealthcheck_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ var _ = Describe("Node Health Check CR", func() {
960960
g.Expect(k8sClient.Get(context.Background(), client.ObjectKeyFromObject(newCr), newCr)).To(Succeed())
961961
g.Expect(cr.GetAnnotations()).To(HaveKeyWithValue(Equal("remediation.medik8s.io/nhc-timed-out"), Not(BeNil())))
962962
g.Expect(newCr.GetName()).To(Equal(unhealthyNodeName))
963-
g.Expect(newCr.GetAnnotations()).ToNot(HaveKey(Equal(annotations.NodeNameAnnotation)))
963+
g.Expect(newCr.GetAnnotations()).ToNot(HaveKey(Equal(commonannotations.NodeNameAnnotation)))
964964

965965
}, time.Second*10, time.Millisecond*300).Should(Succeed())
966966

@@ -979,7 +979,7 @@ var _ = Describe("Node Health Check CR", func() {
979979
thirdCR = getRemediationCRForMultiKindSupportTemplate(multiSupportTemplateRef.Name)
980980
g.Expect(thirdCR).ToNot(BeNil())
981981
g.Expect(thirdCR.GetName()).ToNot(Equal(unhealthyNodeName))
982-
g.Expect(thirdCR.GetAnnotations()[annotations.NodeNameAnnotation]).To(Equal(unhealthyNodeName))
982+
g.Expect(thirdCR.GetAnnotations()[commonannotations.NodeNameAnnotation]).To(Equal(unhealthyNodeName))
983983
g.Expect(thirdCR.GetAnnotations()[annotations.TemplateNameAnnotation]).To(Equal(multiSupportTemplateRef.Name))
984984
g.Expect(thirdCR.GetAnnotations()).ToNot(HaveKey(Equal("remediation.medik8s.io/nhc-timed-out")))
985985
}, time.Second*10, time.Millisecond*300).Should(Succeed())
@@ -990,7 +990,7 @@ var _ = Describe("Node Health Check CR", func() {
990990
thirdCR = getRemediationCRForMultiKindSupportTemplate(multiSupportTemplateRef.Name)
991991
g.Expect(thirdCR).ToNot(BeNil())
992992
g.Expect(thirdCR.GetName()).ToNot(Equal(unhealthyNodeName))
993-
g.Expect(thirdCR.GetAnnotations()[annotations.NodeNameAnnotation]).To(Equal(unhealthyNodeName))
993+
g.Expect(thirdCR.GetAnnotations()[commonannotations.NodeNameAnnotation]).To(Equal(unhealthyNodeName))
994994
g.Expect(thirdCR.GetAnnotations()[annotations.TemplateNameAnnotation]).To(Equal(multiSupportTemplateRef.Name))
995995
g.Expect(thirdCR.GetAnnotations()).To(HaveKeyWithValue(Equal("remediation.medik8s.io/nhc-timed-out"), Not(BeNil())))
996996
}, time.Second*10, time.Millisecond*300).Should(Succeed())
@@ -1001,7 +1001,7 @@ var _ = Describe("Node Health Check CR", func() {
10011001
forthCR = getRemediationCRForMultiKindSupportTemplate(secondMultiSupportTemplateRef.Name)
10021002
g.Expect(forthCR).ToNot(BeNil())
10031003
g.Expect(forthCR.GetName()).ToNot(Equal(unhealthyNodeName))
1004-
g.Expect(forthCR.GetAnnotations()[annotations.NodeNameAnnotation]).To(Equal(unhealthyNodeName))
1004+
g.Expect(forthCR.GetAnnotations()[commonannotations.NodeNameAnnotation]).To(Equal(unhealthyNodeName))
10051005
g.Expect(forthCR.GetAnnotations()[annotations.TemplateNameAnnotation]).To(Equal(secondMultiSupportTemplateRef.Name))
10061006
g.Expect(forthCR.GetAnnotations()).ToNot(HaveKey(Equal("remediation.medik8s.io/nhc-timed-out")))
10071007
}, time.Second*10, time.Millisecond*300).Should(Succeed())

controllers/resources/manager.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/go-logr/logr"
9+
commonannotations "github.com/medik8s/common/pkg/annotations"
910
commonevents "github.com/medik8s/common/pkg/events"
1011
"github.com/pkg/errors"
1112

@@ -127,7 +128,7 @@ func (m *manager) generateRemediationCR(name string, healthCheckOwnerRef *metav1
127128

128129
if annotations.HasMultipleTemplatesAnnotation(template) {
129130
remediationCR.SetGenerateName(name)
130-
remediationCR.SetAnnotations(map[string]string{annotations.NodeNameAnnotation: name, annotations.TemplateNameAnnotation: template.GetName()})
131+
remediationCR.SetAnnotations(map[string]string{commonannotations.NodeNameAnnotation: name, annotations.TemplateNameAnnotation: template.GetName()})
131132
} else {
132133
remediationCR.SetName(name)
133134
}
@@ -177,7 +178,7 @@ func (m *manager) GenerateRemediationCRBase(gvk schema.GroupVersionKind) *unstru
177178
// CreateRemediationCR creates the given remediation CR from remediationCR it'll return: a bool indicator of success, a *time.Duration an indicator on when requeue is needed in order to extend the lease, a *unstructured.Unstructured of the created/existing CR and an error
178179
func (m *manager) CreateRemediationCR(remediationCR *unstructured.Unstructured, owner client.Object, nodeName *string, currentRemediationDuration, previousRemediationsDuration time.Duration) (bool, *time.Duration, *unstructured.Unstructured, error) {
179180
var err error
180-
if remediationCR.GetAnnotations() == nil || len(remediationCR.GetAnnotations()[annotations.NodeNameAnnotation]) == 0 {
181+
if remediationCR.GetAnnotations() == nil || len(remediationCR.GetAnnotations()[commonannotations.NodeNameAnnotation]) == 0 {
181182
err = m.Get(m.ctx, client.ObjectKeyFromObject(remediationCR), remediationCR)
182183
} else {
183184
remediationCR, err = m.getCRWithNodeNameAnnotation(remediationCR)
@@ -358,7 +359,7 @@ func (m *manager) getOwningMachineWithNamespace(node *corev1.Node) (*metav1.Owne
358359
}
359360

360361
func (m *manager) getCRWithNodeNameAnnotation(remediationCR *unstructured.Unstructured) (*unstructured.Unstructured, error) {
361-
nodeName := remediationCR.GetAnnotations()[annotations.NodeNameAnnotation]
362+
nodeName := remediationCR.GetAnnotations()[commonannotations.NodeNameAnnotation]
362363
templateName := remediationCR.GetAnnotations()[annotations.TemplateNameAnnotation]
363364

364365
resourceList := &unstructured.UnstructuredList{Object: m.GenerateRemediationCRBase(remediationCR.GroupVersionKind()).Object}
@@ -386,7 +387,7 @@ func (m *manager) isMatchNodeTemplate(cr unstructured.Unstructured, nodeName str
386387
if _, isMultiSupported := ann[annotations.TemplateNameAnnotation]; !isMultiSupported {
387388
return cr.GetName() == nodeName
388389
}
389-
return ann[annotations.TemplateNameAnnotation] == templateName && ann[annotations.NodeNameAnnotation] == nodeName
390+
return ann[annotations.TemplateNameAnnotation] == templateName && ann[commonannotations.NodeNameAnnotation] == nodeName
390391
}
391392

392393
func (m *manager) extractNodeName(cr unstructured.Unstructured) string {
@@ -397,7 +398,7 @@ func (m *manager) extractNodeName(cr unstructured.Unstructured) string {
397398
if _, isMultiSupported := ann[annotations.TemplateNameAnnotation]; !isMultiSupported {
398399
return cr.GetName()
399400
}
400-
return ann[annotations.NodeNameAnnotation]
401+
return ann[commonannotations.NodeNameAnnotation]
401402
}
402403

403404
func createOwnerRef(obj client.Object) *metav1.OwnerReference {

controllers/suite_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"testing"
2626
"time"
2727

28+
commonannotations "github.com/medik8s/common/pkg/annotations"
2829
. "github.com/onsi/ginkgo/v2"
2930
. "github.com/onsi/gomega"
3031
"go.uber.org/zap/zapcore"
@@ -54,9 +55,6 @@ import (
5455
"github.com/medik8s/node-healthcheck-operator/controllers/cluster"
5556
"github.com/medik8s/node-healthcheck-operator/controllers/featuregates"
5657
"github.com/medik8s/node-healthcheck-operator/controllers/mhc"
57-
58-
// +kubebuilder:scaffold:imports
59-
"github.com/medik8s/node-healthcheck-operator/controllers/utils/annotations"
6058
)
6159

6260
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
@@ -187,10 +185,10 @@ var _ = BeforeSuite(func() {
187185
Expect(k8sClient.Create(context.Background(), newTestRemediationCRD(multiSupportTestKind))).To(Succeed())
188186
time.Sleep(time.Second)
189187
multiSupportTemplate := newTestRemediationTemplateCR(multiSupportTestKind, MachineNamespace, MultipleSupportTemplateName)
190-
multiSupportTemplate.SetAnnotations(map[string]string{annotations.MultipleTemplatesSupportedAnnotation: "true"})
188+
multiSupportTemplate.SetAnnotations(map[string]string{commonannotations.MultipleTemplatesSupportedAnnotation: "true"})
191189
Expect(k8sClient.Create(context.Background(), multiSupportTemplate)).To(Succeed())
192190
secondMultiSupportTemplate := newTestRemediationTemplateCR(multiSupportTestKind, MachineNamespace, SecondMultipleSupportTemplateName)
193-
secondMultiSupportTemplate.SetAnnotations(map[string]string{annotations.MultipleTemplatesSupportedAnnotation: "true"})
191+
secondMultiSupportTemplate.SetAnnotations(map[string]string{commonannotations.MultipleTemplatesSupportedAnnotation: "true"})
194192
Expect(k8sClient.Create(context.Background(), secondMultiSupportTemplate)).To(Succeed())
195193

196194
upgradeChecker = &fakeClusterUpgradeChecker{

controllers/utils/annotations/annotations.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
package annotations
22

3-
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3+
import (
4+
commonannotations "github.com/medik8s/common/pkg/annotations"
5+
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
)
48

59
const (
610
// MHCPausedAnnotation is an annotation that can be applied to MachineHealthCheck objects to prevent the MHC
711
// controller from processing it.
812
MHCPausedAnnotation = "cluster.x-k8s.io/paused"
9-
// MultipleTemplatesSupportedAnnotation is an annotation that indicates whether multiple templates of the same kind are supported by the template's remediator
10-
MultipleTemplatesSupportedAnnotation = "remediation.medik8s.io/multiple-templates-support"
11-
// NodeNameAnnotation is an annotation that will be placed on the CRs of remediatiors who support multiple templates of the same remediator.
12-
// This is done because the CR will no longer be created with the node name.
13-
NodeNameAnnotation = "remediation.medik8s.io/node-name"
1413
// TemplateNameAnnotation is an annotation that will be placed on the CRs of remediatiors who support multiple templates of the same remediator.
1514
// This is done because when checking for timeout CRs we need to know whether a CR was already created or not by that template.
1615
TemplateNameAnnotation = "remediation.medik8s.io/template-name"
1716
)
1817

1918
// HasMultipleTemplatesAnnotation returns true if the object has the medik8s `multiple-templates-support` annotation.
2019
func HasMultipleTemplatesAnnotation(o metav1.Object) bool {
21-
return hasAnnotation(o, MultipleTemplatesSupportedAnnotation)
20+
return hasAnnotation(o, commonannotations.MultipleTemplatesSupportedAnnotation)
2221
}
2322

2423
func HasMHCPausedAnnotation(o metav1.Object) bool {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.21
44

55
require (
66
github.com/go-logr/logr v1.4.1
7-
github.com/medik8s/common v1.15.1
7+
github.com/medik8s/common v1.17.0
88
github.com/onsi/ginkgo/v2 v2.15.0
99
github.com/onsi/gomega v1.31.1
1010
github.com/openshift/api v0.0.0-20240124164020-e2ce40831f2e // release-4.16

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
8080
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
8181
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
8282
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
83-
github.com/medik8s/common v1.15.1 h1:qo2FBZGSegf5q35AZlWzrmgwW1GfUPNmmWaPhb/Uurc=
84-
github.com/medik8s/common v1.15.1/go.mod h1:A9jYldC6PZcAuBowNNm712FqWdASB2ey5Vjp8MYN/PY=
83+
github.com/medik8s/common v1.17.0 h1:AmJKx0tzqGZF27Ot0A4ak85q0F0zqUkVyCvYmm67rtY=
84+
github.com/medik8s/common v1.17.0/go.mod h1:A9jYldC6PZcAuBowNNm712FqWdASB2ey5Vjp8MYN/PY=
8585
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
8686
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
8787
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

vendor/github.com/medik8s/common/pkg/annotations/annotations.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/medik8s/common/pkg/events/events.go

Lines changed: 29 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ github.com/mailru/easyjson/jwriter
106106
# github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0
107107
## explicit; go 1.19
108108
github.com/matttproud/golang_protobuf_extensions/v2/pbutil
109-
# github.com/medik8s/common v1.15.1
109+
# github.com/medik8s/common v1.17.0
110110
## explicit; go 1.20
111111
github.com/medik8s/common/pkg/annotations
112112
github.com/medik8s/common/pkg/conditions

0 commit comments

Comments
 (0)