Skip to content
Open
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
55 changes: 54 additions & 1 deletion tests/e2e/framework/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3210,4 +3210,57 @@ func (f *Framework) AssertNodeNameIsInTargetAndFactIdentifierInCM(nodes []core.N
}
}
return nil
}
}

// AssertSuiteRerunnerResourcesInJobs verifies the suitererunner resource limits and requests through Jobs
func (f *Framework) AssertSuiteRerunnerResourcesInJobs(namespace, suiteName, cpuLimit, memLimit, cpuRequest, memRequest string) error {
jobList := &batchv1.JobList{}
labelSelector := labels.SelectorFromSet(map[string]string{
"compliance.openshift.io/suite": suiteName,
"workload": "suitererunner",
})
listOpts := &client.ListOptions{
LabelSelector: labelSelector,
Namespace: namespace,
}

err := f.Client.List(context.TODO(), jobList, listOpts)
if err != nil {
return fmt.Errorf("failed to list jobs for suite %s: %w", suiteName, err)
}

if len(jobList.Items) == 0 {
return fmt.Errorf("no suitererunner jobs found for suite %s", suiteName)
}

// Check the first job's container resources
job := jobList.Items[0]
if len(job.Spec.Template.Spec.Containers) == 0 {
return fmt.Errorf("job %s has no containers", job.Name)
}

container := job.Spec.Template.Spec.Containers[0]

// Verify CPU limit
if container.Resources.Limits.Cpu().String() != cpuLimit {
return fmt.Errorf("expected CPU limit %s, got %s in job %s", cpuLimit, container.Resources.Limits.Cpu().String(), job.Name)
}

// Verify Memory limit
if container.Resources.Limits.Memory().String() != memLimit {
return fmt.Errorf("expected Memory limit %s, got %s in job %s", memLimit, container.Resources.Limits.Memory().String(), job.Name)
}

// Verify CPU request
if container.Resources.Requests.Cpu().String() != cpuRequest {
return fmt.Errorf("expected CPU request %s, got %s in job %s", cpuRequest, container.Resources.Requests.Cpu().String(), job.Name)
}

// Verify Memory request
if container.Resources.Requests.Memory().String() != memRequest {
return fmt.Errorf("expected Memory request %s, got %s in job %s", memRequest, container.Resources.Requests.Memory().String(), job.Name)
}

log.Printf("Suite rerunner job %s has correct resource limits and requests", job.Name)
return nil
}
18 changes: 18 additions & 0 deletions tests/e2e/parallel/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,24 @@ func TestScheduledSuiteUpdate(t *testing.T) {
t.Fatal(err)
}

// Ensure that all the scans in the suite have finished and are marked as Done
err = f.WaitForSuiteScansStatus(f.OperatorNamespace, suiteName, compv1alpha1.PhaseDone, compv1alpha1.ResultCompliant)
if err != nil {
t.Fatal(err)
}

// Wait for one re-scan
err = f.WaitForReScanStatus(f.OperatorNamespace, workerScanName, compv1alpha1.PhaseDone)
if err != nil {
t.Fatal(err)
}

// Verify suitererunner resource limits and requests through Jobs
err = f.AssertSuiteRerunnerResourcesInJobs(f.OperatorNamespace, suiteName, "50m", "100Mi", "10m", "20Mi")
if err != nil {
t.Fatal(err)
}

// Clean up
// Get new reference of suite
foundSuite = &compv1alpha1.ComplianceSuite{}
Expand Down
Loading