Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/peter-evans/create…
Browse files Browse the repository at this point in the history
…-pull-request-6
  • Loading branch information
rdavid authored Jan 31, 2024
2 parents cd69bc6 + 2ccc336 commit a744905
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cnf-certification-test/platform/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,18 @@ func testTainted(check *checksdb.Check, env *provider.TestEnvironment) {
}

// Loop through the debug pods that are tied to each node.
for _, dp := range env.DebugPods {
nodeName := dp.Spec.NodeName

for _, n := range env.Nodes {
nodeName := n.Data.Name
check.LogInfo("Testing node %q", nodeName)

// Ensure we are only testing nodes that have CNF workload deployed on them.
if !n.HasWorkloadDeployed(env.Pods) {
check.LogInfo("Node %q has no workload deployed on it. Skipping tainted kernel check.", nodeName)
continue
}

dp := env.DebugPods[nodeName]

ocpContext := clientsholder.NewContext(dp.Namespace, dp.Name, dp.Spec.Containers[0].Name)
tf := nodetainted.NewNodeTaintedTester(&ocpContext, nodeName)

Expand Down
9 changes: 9 additions & 0 deletions pkg/provider/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,12 @@ func (node *Node) IsHyperThreadNode(env *TestEnvironment) (bool, error) {
}
return num > 1, nil
}

func (node *Node) HasWorkloadDeployed(podsUnderTest []*Pod) bool {
for _, pod := range podsUnderTest {
if pod.Spec.NodeName == node.Data.Name {
return true
}
}
return false
}
64 changes: 64 additions & 0 deletions pkg/provider/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,67 @@
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

package provider

import (
"testing"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestHasWorkloadDeployed(t *testing.T) {
generateNode := func(nodeName string) *Node {
return &Node{
Data: &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: nodeName,
},
},
}
}

testCases := []struct {
testNodeName string
testPods []*Pod
expected bool
}{
{
testNodeName: "node1",
testPods: []*Pod{
{
Pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod1",
},
Spec: corev1.PodSpec{
NodeName: "node1",
},
},
},
},
expected: true,
},
{
testNodeName: "node1",
testPods: []*Pod{
{
Pod: &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod1",
},
Spec: corev1.PodSpec{
NodeName: "node2",
},
},
},
},
expected: false,
},
}

for _, testCase := range testCases {
n := generateNode(testCase.testNodeName)
assert.Equal(t, testCase.expected, n.HasWorkloadDeployed(testCase.testPods))
}
}

0 comments on commit a744905

Please sign in to comment.