@@ -30,6 +30,9 @@ type k8sObjectMonitorContextKey int
3030
3131const (
3232 k8sMonitorKeyNodeName k8sObjectMonitorContextKey = iota
33+
34+ annotationKey = "nvsentinel.nvidia.com/k8s-object-monitor-policy-matches"
35+ testConditionType = "TestCondition"
3336)
3437
3538func TestKubernetesObjectMonitor (t * testing.T ) {
@@ -41,12 +44,19 @@ func TestKubernetesObjectMonitor(t *testing.T) {
4144 client , err := c .NewClient ()
4245 require .NoError (t , err )
4346
44- pod , err := helpers .GetPodOnWorkerNode (ctx , t , client , helpers .NVSentinelNamespace , "kubernetes-object-monitor" )
47+ nodeList := & v1.NodeList {}
48+ err = client .Resources ().List (ctx , nodeList )
4549 require .NoError (t , err )
46- require .NotNil (t , pod )
4750
48- testNodeName := pod .Spec .NodeName
49- t .Logf ("Using kubernetes-object-monitor pod: %s on node: %s" , pod .Name , testNodeName )
51+ var testNodeName string
52+ for _ , node := range nodeList .Items {
53+ if node .Labels ["type" ] != "kwok" {
54+ testNodeName = node .Name
55+ break
56+ }
57+ }
58+ require .NotEmpty (t , testNodeName , "no real (non-KWOK) nodes found in cluster" )
59+ t .Logf ("Using test node: %s" , testNodeName )
5060
5161 return context .WithValue (ctx , k8sMonitorKeyNodeName , testNodeName )
5262 })
@@ -56,9 +66,9 @@ func TestKubernetesObjectMonitor(t *testing.T) {
5666 require .NoError (t , err )
5767
5868 nodeName := ctx .Value (k8sMonitorKeyNodeName ).(string )
59- t .Logf ("Marking node %s as NotReady " , nodeName )
69+ t .Logf ("Setting TestCondition to False on node %s" , nodeName )
6070
61- helpers .SetNodeConditionStatus (ctx , t , client , nodeName , v1 .NodeReady , v1 .ConditionFalse )
71+ helpers .SetNodeConditionStatus (ctx , t , client , nodeName , v1 .NodeConditionType ( testConditionType ) , v1 .ConditionFalse )
6272
6373 t .Log ("Waiting for policy match annotation on node" )
6474 require .Eventually (t , func () bool {
@@ -68,7 +78,7 @@ func TestKubernetesObjectMonitor(t *testing.T) {
6878 return false
6979 }
7080
71- annotation , exists := node .Annotations ["nvsentinel.nvidia.com/k8s-object-monitor-policy-matches" ]
81+ annotation , exists := node .Annotations [annotationKey ]
7282 if ! exists {
7383 return false
7484 }
@@ -85,9 +95,9 @@ func TestKubernetesObjectMonitor(t *testing.T) {
8595 require .NoError (t , err )
8696
8797 nodeName := ctx .Value (k8sMonitorKeyNodeName ).(string )
88- t .Logf ("Marking node %s as Ready " , nodeName )
98+ t .Logf ("Setting TestCondition to True on node %s" , nodeName )
8999
90- helpers .SetNodeConditionStatus (ctx , t , client , nodeName , v1 .NodeReady , v1 .ConditionTrue )
100+ helpers .SetNodeConditionStatus (ctx , t , client , nodeName , v1 .NodeConditionType ( testConditionType ) , v1 .ConditionTrue )
91101
92102 t .Log ("Waiting for policy match annotation to be cleared" )
93103 require .Eventually (t , func () bool {
@@ -97,7 +107,7 @@ func TestKubernetesObjectMonitor(t *testing.T) {
97107 return false
98108 }
99109
100- annotation , exists := node .Annotations ["nvsentinel.nvidia.com/k8s-object-monitor-policy-matches" ]
110+ annotation , exists := node .Annotations [annotationKey ]
101111 if exists && annotation != "" {
102112 t .Logf ("Annotation still exists: %s" , annotation )
103113 return false
0 commit comments