Skip to content

Commit 6c09d45

Browse files
authored
Merge pull request #342 from openshift-cherrypick-robot/cherry-pick-334-to-release-0.8
[release-0.8] Fix e2e
2 parents ebb1a10 + 556649f commit 6c09d45

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

controllers/nodehealthcheck_controller_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,6 @@ var _ = Describe("Node Health Check CR", func() {
996996
g.Expect(k8sClient.Get(context.Background(), client.ObjectKeyFromObject(newCr), newCr)).To(Succeed())
997997
g.Expect(cr.GetAnnotations()).To(HaveKeyWithValue(Equal("remediation.medik8s.io/nhc-timed-out"), Not(BeNil())))
998998
g.Expect(newCr.GetName()).To(Equal(unhealthyNodeName))
999-
g.Expect(newCr.GetAnnotations()).ToNot(HaveKey(Equal(commonannotations.NodeNameAnnotation)))
1000-
1001999
}, time.Second*10, time.Millisecond*300).Should(Succeed())
10021000

10031001
// get updated NHC

controllers/resources/manager.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package resources
22

33
import (
44
"context"
5+
"fmt"
56
"strings"
67
"time"
78

@@ -127,11 +128,11 @@ func (m *manager) generateRemediationCR(name string, healthCheckOwnerRef *metav1
127128
unstructured.SetNestedField(remediationCR.Object, templateSpec, "spec")
128129

129130
if annotations.HasMultipleTemplatesAnnotation(template) {
130-
remediationCR.SetGenerateName(name)
131-
remediationCR.SetAnnotations(map[string]string{commonannotations.NodeNameAnnotation: name, annotations.TemplateNameAnnotation: template.GetName()})
131+
remediationCR.SetGenerateName(fmt.Sprintf("%s-", name))
132132
} else {
133133
remediationCR.SetName(name)
134134
}
135+
remediationCR.SetAnnotations(map[string]string{commonannotations.NodeNameAnnotation: name, annotations.TemplateNameAnnotation: template.GetName()})
135136

136137
remediationCR.SetNamespace(template.GetNamespace())
137138
remediationCR.SetResourceVersion("")

e2e/common_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package e2e
22

33
import (
44
"context"
5+
"fmt"
6+
7+
commonannotations "github.com/medik8s/common/pkg/annotations"
58

69
"k8s.io/apimachinery/pkg/api/errors"
710
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -10,7 +13,9 @@ import (
1013

1114
func ensureRemediationResourceExists(name string, namespace string, remediationResource schema.GroupVersionResource) func() error {
1215
return func() error {
13-
_, err := dynamicClient.Resource(remediationResource).Namespace(namespace).Get(context.Background(), name, metav1.GetOptions{})
16+
// The CR name doesn't always match the node name in case multiple CRs of same type for the same node are supported
17+
// So list all, and look for the node name in the annotation
18+
list, err := dynamicClient.Resource(remediationResource).Namespace(namespace).List(context.Background(), metav1.ListOptions{})
1419
if err != nil {
1520
if errors.IsNotFound(err) {
1621
log.Info("didn't find remediation resource yet")
@@ -19,7 +24,13 @@ func ensureRemediationResourceExists(name string, namespace string, remediationR
1924
}
2025
return err
2126
}
22-
log.Info("found remediation resource")
23-
return nil
27+
for _, cr := range list.Items {
28+
if nodeName, exists := cr.GetAnnotations()[commonannotations.NodeNameAnnotation]; exists && nodeName == name {
29+
log.Info("found remediation resource")
30+
return nil
31+
}
32+
}
33+
log.Info("didn't find remediation resource yet")
34+
return fmt.Errorf("not found")
2435
}
2536
}

0 commit comments

Comments
 (0)