Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/e2e/framework/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,31 @@ func (f *Framework) GetPodsForScan(scanName string) ([]core.Pod, error) {
return pods.Items, nil
}

// Helper function to verify pod count matches node count
func (f *Framework) VerifyPodCountMatchesNodeCount(scanName, namespace string, nodeSelector map[string]string) error {
pods, err := f.GetPodsForScan(scanName)
if err != nil {
return fmt.Errorf("failed to get pods for scan %s: %w", scanName, err)
}

nodeScanPods := []core.Pod{}
for _, pod := range pods {
if _, hasTargetNode := pod.Labels["targetNode"]; hasTargetNode {
nodeScanPods = append(nodeScanPods, pod)
}
}

nodes, err := f.GetNodesWithSelector(nodeSelector)
if err != nil {
return fmt.Errorf("failed to get nodes with selector: %w", err)
}

if len(nodeScanPods) != len(nodes) {
return fmt.Errorf("pod count (%d) does not match node count (%d) for scan %s", len(nodeScanPods), len(nodes), scanName)
}
return nil
}

// WaitForRemediationState will poll until the complianceRemediation that we're lookingfor gets applied, or until
// a timeout is reached.
func (f *Framework) WaitForRemediationState(name, namespace string, state compv1alpha1.RemediationApplicationState) error {
Expand Down
56 changes: 56 additions & 0 deletions tests/e2e/serial/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,62 @@ func TestTolerations(t *testing.T) {
if err != nil {
t.Fatal(err)
}

// Test tolerations with TolerationOpEqual operator on all worker nodes
scanNameEquals := framework.GetObjNameFromTest(t) + "-equals"
scan := &compv1alpha1.ComplianceScan{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing test is for a compliancesuite on the taited nodes. Newly added function is a compliancescan for all worker nodes. Is my understanding correct? If so, I think no need to add new check points.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I kept it on all the worker nodes so that I can verify that the number of scanner pods created equals number of worker nodes, like it was in OCP-33610 https://github.com/openshift/openshift-tests-private/blob/abc442c4736b82b4ae15d6068f929c1121ee7111/test/extended/securityandcompliance/compliance_operator.go#L1092. If it was there just as another way to confirm that the scan would run on all nodes nevermind the taint, I wholeheartedly agree.

ObjectMeta: metav1.ObjectMeta{
Name: scanNameEquals,
Namespace: f.OperatorNamespace,
},
Spec: compv1alpha1.ComplianceScanSpec{
ContentImage: contentImagePath,
Profile: "xccdf_org.ssgproject.content_profile_moderate",
Rule: "xccdf_org.ssgproject.content_rule_no_netrc_files",
Content: framework.RhcosContentFile,
NodeSelector: map[string]string{
"node-role.kubernetes.io/worker": "",
},
ComplianceScanSettings: compv1alpha1.ComplianceScanSettings{
Debug: true,
ScanTolerations: []corev1.Toleration{
{
Key: taintKey,
Value: taintVal,
Operator: corev1.TolerationOpEqual,
Effect: corev1.TaintEffectNoSchedule,
},
},
},
},
}

if err = f.Client.Create(context.TODO(), scan, nil); err != nil {
t.Fatalf("failed to create scan %s: %s", scanNameEquals, err)
}
defer f.Client.Delete(context.TODO(), scan)

err = f.WaitForScanStatus(f.OperatorNamespace, scanNameEquals, compv1alpha1.PhaseDone)
if err != nil {
t.Fatal(err)
}

err = f.AssertScanIsCompliant(scanNameEquals, f.OperatorNamespace)
if err != nil {
t.Fatal(err)
}

exitCode, _, err := f.GetScanExitCodeAndErrorMsg(scanNameEquals, f.OperatorNamespace)
if err != nil {
t.Fatal(err)
}
if exitCode != "0" {
t.Fatalf("Expected ConfigMap exit-code to be '0', but got: '%s'", exitCode)
}

if err := f.VerifyPodCountMatchesNodeCount(scanNameEquals, f.OperatorNamespace, map[string]string{"node-role.kubernetes.io/worker": ""}); err != nil {
t.Fatalf("Pod count does not match node count for scan %s: %s", scanNameEquals, err)
}
}

func TestAutoRemediate(t *testing.T) {
Expand Down
Loading