Skip to content

Commit e453026

Browse files
authored
CMP-4116: Fix platform scan pod stuck when RawResultStorage is disabled (#1097)
* Fix platform scan pod stuck when RawResultStorage is disabled The addResultsCollectionPods function unconditionally added the TLS volume and mount referencing the result-client-cert secret, which is only created when RawResultStorage.Enabled=true. This caused the platform scan pod to get stuck in Init:0/2 when RawResultStorage was disabled. Reuse getLogCollectorVolumeMounts and conditionally append the TLS volume, matching the existing behavior in getNodeScannerPodVolumes. Made-with: Cursor * Add e2e test for platform scan with RawResultStorage disabled Made-with: Cursor * Move PVC check after scan completes to avoid race condition * Use reliably compliant rule in platform no-storage e2e test
1 parent 5746e95 commit e453026

2 files changed

Lines changed: 66 additions & 14 deletions

File tree

pkg/controller/compliancescan/scan.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -516,18 +516,7 @@ func addResultsCollectionPods(scanInstance *compv1alpha1.ComplianceScan, pod *co
516516
corev1.ResourceCPU: resource.MustParse("100m"),
517517
},
518518
},
519-
VolumeMounts: []corev1.VolumeMount{
520-
{
521-
Name: "report-dir",
522-
MountPath: "/reports",
523-
ReadOnly: true,
524-
},
525-
{
526-
Name: "tls",
527-
MountPath: "/etc/pki/tls",
528-
ReadOnly: true,
529-
},
530-
},
519+
VolumeMounts: getLogCollectorVolumeMounts(scanInstance),
531520
},
532521
}
533522

@@ -549,14 +538,16 @@ func addResultsCollectionPods(scanInstance *compv1alpha1.ComplianceScan, pod *co
549538
},
550539
},
551540
},
552-
{
541+
}
542+
if scanInstance.Spec.RawResultStorage.Enabled != nil && *scanInstance.Spec.RawResultStorage.Enabled {
543+
podVolumes = append(podVolumes, corev1.Volume{
553544
Name: "tls",
554545
VolumeSource: corev1.VolumeSource{
555546
Secret: &corev1.SecretVolumeSource{
556547
SecretName: ClientCertPrefix + scanInstance.Name,
557548
},
558549
},
559-
},
550+
})
560551
}
561552

562553
pod.Spec.Volumes = append(pod.Spec.Volumes, podVolumes...)

tests/e2e/parallel/main_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,67 @@ func TestScheduledSuiteNoStorage(t *testing.T) {
24092409
}
24102410
}
24112411

2412+
func TestScheduledSuitePlatformNoStorage(t *testing.T) {
2413+
t.Parallel()
2414+
f := framework.Global
2415+
suiteName := "test-scheduled-suite-platform-no-storage"
2416+
platformScanName := fmt.Sprintf("%s-platform-scan", suiteName)
2417+
2418+
falseValue := false
2419+
testSuite := &compv1alpha1.ComplianceSuite{
2420+
ObjectMeta: metav1.ObjectMeta{
2421+
Name: suiteName,
2422+
Namespace: f.OperatorNamespace,
2423+
},
2424+
Spec: compv1alpha1.ComplianceSuiteSpec{
2425+
ComplianceSuiteSettings: compv1alpha1.ComplianceSuiteSettings{
2426+
AutoApplyRemediations: false,
2427+
},
2428+
Scans: []compv1alpha1.ComplianceScanSpecWrapper{
2429+
{
2430+
Name: platformScanName,
2431+
ComplianceScanSpec: compv1alpha1.ComplianceScanSpec{
2432+
ContentImage: contentImagePath,
2433+
Profile: "xccdf_org.ssgproject.content_profile_moderate",
2434+
Content: framework.OcpContentFile,
2435+
Rule: "xccdf_org.ssgproject.content_rule_ocp_idp_no_htpasswd",
2436+
ScanType: compv1alpha1.ScanTypePlatform,
2437+
ComplianceScanSettings: compv1alpha1.ComplianceScanSettings{
2438+
RawResultStorage: compv1alpha1.RawResultStorageSettings{
2439+
Enabled: &falseValue,
2440+
},
2441+
Debug: true,
2442+
},
2443+
},
2444+
},
2445+
},
2446+
},
2447+
}
2448+
2449+
err := f.Client.Create(context.TODO(), testSuite, nil)
2450+
if err != nil {
2451+
t.Fatal(err)
2452+
}
2453+
defer f.Client.Delete(context.TODO(), testSuite)
2454+
2455+
// Ensure that all the scans in the suite have finished and are marked as Done
2456+
err = f.WaitForSuiteScansStatus(f.OperatorNamespace, suiteName, compv1alpha1.PhaseDone, compv1alpha1.ResultCompliant)
2457+
if err != nil {
2458+
t.Fatal(err)
2459+
}
2460+
2461+
pvcList := &corev1.PersistentVolumeClaimList{}
2462+
err = f.Client.List(context.TODO(), pvcList, client.InNamespace(f.OperatorNamespace), client.MatchingLabels(map[string]string{
2463+
compv1alpha1.ComplianceScanLabel: platformScanName,
2464+
}))
2465+
if err != nil {
2466+
t.Fatal(err)
2467+
}
2468+
for _, pvc := range pvcList.Items {
2469+
t.Fatalf("Found unexpected PVC %s", pvc.Name)
2470+
}
2471+
}
2472+
24122473
func TestScheduledSuiteInvalidPriorityClass(t *testing.T) {
24132474
t.Parallel()
24142475
f := framework.Global

0 commit comments

Comments
 (0)