Skip to content

CMP-3863: Added new test TestMustGatherImageWorksAsExpected to cover 75670 test from downstream#1023

Open
taimurhafeez wants to merge 5 commits intoComplianceAsCode:masterfrom
taimurhafeez:CMP-3863
Open

CMP-3863: Added new test TestMustGatherImageWorksAsExpected to cover 75670 test from downstream#1023
taimurhafeez wants to merge 5 commits intoComplianceAsCode:masterfrom
taimurhafeez:CMP-3863

Conversation

@taimurhafeez
Copy link
Collaborator

@taimurhafeez taimurhafeez commented Dec 8, 2025

This TestMustGatherImageWorksAsExpected e2e test verifies that the must-gather debugging tool works correctly for the compliance-operator.

To run it:
make e2e-serial E2E_GO_TEST_FLAGS="-v -run TestMustGatherImageWorksAsExpected"

Expected Output on OCP 4.21:

2026/03/02 15:49:31 Must-gather content verification passed
--- PASS: TestMustGatherImageWorksAsExpected (112.26s)
PASS

@openshift-ci-robot
Copy link
Collaborator

@taimurhafeez: This pull request references CMP-3846 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.21.0" version, but no target version was set.

Details

In response to this:

To run it:
make e2e-serial E2E_GO_TEST_FLAGS="-v -run TestMustGatherImageWorksAsExpected"

Expected Output:

Must-gather content verification passed
--- PASS: TestMustGatherImageWorksAsExpected (129.04s)
PASS

Note: Must use PR-960

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
Copy link

openshift-ci bot commented Dec 8, 2025

Hi @taimurhafeez. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@taimurhafeez taimurhafeez changed the title CMP-3846: Added new test TestMustGatherImageWorksAsExpected to cover 75670 test from downstream CMP-3863: Added new test TestMustGatherImageWorksAsExpected to cover 75670 test from downstream Dec 8, 2025
@openshift-ci-robot
Copy link
Collaborator

@taimurhafeez: This pull request references CMP-3863 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.21.0" version, but no target version was set.

Details

In response to this:

To run it:
make e2e-serial E2E_GO_TEST_FLAGS="-v -run TestMustGatherImageWorksAsExpected"

Expected Output:

Must-gather content verification passed
--- PASS: TestMustGatherImageWorksAsExpected (129.04s)
PASS

Note: Must use PR-960

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.


// Wait for the ComplianceSuite scans to complete
log.Printf("Waiting for ComplianceSuite scans to complete...")
err = f.WaitForSuiteScansStatus(f.OperatorNamespace, scanSettingBindingName, compv1alpha1.PhaseDone, compv1alpha1.ResultNonCompliant)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Potential improvement here would be to consider implementing a backwards compatible change to WaitForSuiteScansStatus to accept a list of acceptable statues. That would allow us to say "wait for NonCompliant or Inconsistent - either are fine".

crdPath := fmt.Sprintf("%s/%s", complianceNamespaceDir, crd)
if _, err := os.Stat(crdPath); err == nil {
log.Printf("Found CRD directory: %s", crd)
foundCRD = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will only get set on the first occurrence, so if we have compliance scans but not a compliance suite, for example. Since we're using a binding, all three should certainly exist.

Comment on lines +2450 to +2490
if !foundCRD {
// Check if there are CRD directories at the parent level (timestampDir)
// The gather script collects CRDs across all namespaces at lines 8-20
log.Printf("Checking for CRD directories at the parent level...")
for _, crd := range complianceCRDs {
crdPath := fmt.Sprintf("%s/%s", timestampDir, crd)
if _, err := os.Stat(crdPath); err == nil {
log.Printf("Found CRD directory at parent level: %s", crd)
foundCRD = true
}
}
}

if !foundCRD {
// Check in other namespace directories (e.g., test namespace osdk-e2e-*)
// Scans may be created in the test namespace, not openshift-compliance
log.Printf("Checking for CRD directories in other namespace directories...")
timestampEntries, err := os.ReadDir(timestampDir)
if err == nil {
for _, entry := range timestampEntries {
if entry.IsDir() && entry.Name() != "openshift-compliance" && entry.Name() != "gather.logs" {
for _, crd := range complianceCRDs {
crdPath := fmt.Sprintf("%s/%s/%s", timestampDir, entry.Name(), crd)
if _, err := os.Stat(crdPath); err == nil {
log.Printf("Found CRD directory in %s: %s", entry.Name(), crd)
foundCRD = true
}
}
}
}
}
}

if !foundCRD {
// CRD directories are created by gather_compliance script at lines 8-20
// They may not exist if the script encounters errors or if CRDs are not found
// This is a warning but not a failure since core must-gather functionality works
t.Logf("WARNING: No compliance CRD directories found in any namespace")
t.Logf("This may indicate the gather script failed to collect CRD data - check gather.logs")
log.Printf("WARNING: No compliance CRD directories found, but core must-gather data was collected successfully")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could these be consolidated into a single conditional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it has been addressed.

Copy link
Collaborator

@rhmdnd rhmdnd left a comment

Choose a reason for hiding this comment

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

A few suggestions/questions inline.

})
if createErr != nil {
return fmt.Errorf("failed to create Machine Config Pool %s: %w", n, createErr)
//return fmt.Errorf("failed to create Machine Config Pool %s: %w", n, createErr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the comment, please

// Wait for the ComplianceSuite scans to complete
log.Printf("Waiting for ComplianceSuite scans to complete...")
err = f.WaitForSuiteScansStatus(f.OperatorNamespace, scanSettingBindingName, compv1alpha1.PhaseDone, compv1alpha1.ResultNonCompliant)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nested if statements here. How about below if statements?

  suite := &compv1alpha1.ComplianceSuite{}
  if suite.Status.Result != compv1alpha1.ResultNonCompliant && suite.Status.Result != compv1alpha1.ResultInconsistent {
      t.Fatalf("Unexpected scan result: %v", suite.Status.Result)
  }

t.Fatalf("Scan did not complete successfully: %v", err)
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the empty line, please

@taimurhafeez
Copy link
Collaborator Author

/retest

@rhmdnd
Copy link
Collaborator

rhmdnd commented Feb 27, 2026

This can be rebased now that #960 landed.

Copy link
Collaborator

@rhmdnd rhmdnd left a comment

Choose a reason for hiding this comment

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

A few suggestions, specifically for handling the CRD failure case.


// The must-gather data is written directly to the timestamped directory
// Verify openshift-compliance namespace directory exists
complianceNamespaceDir := fmt.Sprintf("%s/openshift-compliance", timestampDir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could use f.OperatorNamespace if we pass the framework in, or at the very least pass in the namespace (especially if we don't need the whole framework object).

// Returns an error if CSV doesn't exist or doesn't have the must-gather image
func getMustGatherImageFromCSV(f *framework.Framework) (string, error) {
// First, try to get the CSV name
csvName, err := runOCandGetOutput([]string{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we just use the CSV API directly instead of using oc?

// Verify that compliance resources exist before running must-gather
log.Printf("Verifying compliance resources exist in namespace %s...", f.OperatorNamespace)
scansOutput, err := runOCandGetOutput([]string{
"get", "compliancescans,compliancesuites,compliancecheckresults",
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could grab these using the API like we do elsewhere in the tests, right?

"-n", f.OperatorNamespace,
})
if err != nil {
log.Printf("Warning: Failed to check for compliance resources: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we can't verify that the CRDs exist, we might want to fail hard. I'm wondering if it would be valuable to continue running the tests in the event the CRDs aren't present, when the must-gather functionality is going to be looking for them anyway, right?


// Try to get from CSV if it exists (for OLM deployments)
csvImage, err := getMustGatherImageFromCSV(f)
if err == nil && csvImage != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't look like we do anything with this err if it is set to something. We could log it, but in cases where OLM isn't on the cluster, we'd always be emitting a log about that, which could get noisy.

Might be an opportunity to be more deterministic if OLM is present, and short-circuit entirely if it isn't there.

// Execute must-gather
log.Printf("Executing must-gather with image %s to directory %s...", mustGatherImage, mustGatherDir)
_, err = runOCandGetOutput([]string{
"adm", "must-gather",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes sense for shelling out to oc since I don't think there is a client for must-gather.

@openshift-ci
Copy link

openshift-ci bot commented Feb 27, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: taimurhafeez

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot
Copy link
Collaborator

@taimurhafeez: This pull request references CMP-3863 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set.

Details

In response to this:

This TestMustGatherImageWorksAsExpected e2e test verifies that the must-gather debugging tool works correctly for the compliance-operator.

To run it:
make e2e-serial E2E_GO_TEST_FLAGS="-v -run TestMustGatherImageWorksAsExpected"

Expected Output on OCP 4.21:

2026/03/02 15:49:31 Must-gather content verification passed
--- PASS: TestMustGatherImageWorksAsExpected (112.26s)
PASS

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

…cation, Detect OLM presence, Extract must-gather image from CSV , Support dynamic operator namespace, Fail early if required compliance resources are missing
@taimurhafeez
Copy link
Collaborator Author

A few suggestions, specifically for handling the CRD failure case.

Thanks, Lance. I have addressed most comments, except the one where I replied and asked for your suggestion.

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:1023-2578b283b622ac9ebe22d383f2509df61c697546

Copy link
Collaborator

@rhmdnd rhmdnd left a comment

Choose a reason for hiding this comment

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

Looks like CI tripped on infrastructure issues that also affected other PRs over the weekend.

/retest

csvItem := &csvList.Items[i]
if name := csvItem.GetName(); name != "" {
// CSVs typically have names like "compliance-operator.vX.Y.Z"
if len(name) >= 18 && name[:18] == "compliance-operator" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we off by one here?

https://go.dev/play/p/BttP3b4ZLyE

missingCRDs = append(missingCRDs, crd)
}
}
t.Logf("WARNING: Not all compliance CRD directories found. Missing: %v", missingCRDs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If these directories are missing - don't we have a bug in the must-gather image? Shouldn't we fail the test if we hit this?

@rhmdnd
Copy link
Collaborator

rhmdnd commented Mar 2, 2026

/retest-required

@openshift-ci
Copy link

openshift-ci bot commented Mar 2, 2026

@taimurhafeez: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-rosa 2578b28 link true /test e2e-rosa
ci/prow/e2e-aws-serial-arm 2578b28 link true /test e2e-aws-serial-arm

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants