@@ -1632,49 +1632,34 @@ func TestVariableTemplate(t *testing.T) {
16321632
16331633func TestKubeletConfigRemediation (t * testing.T ) {
16341634 f := framework .Global
1635- var baselineImage = fmt .Sprintf ("%s:%s" , brokenContentImagePath , "new_kubeletconfig" )
1636- const requiredRule = "kubelet-enable-streaming-connections"
1637- pbName := framework .GetObjNameFromTest (t )
1638- prefixName := func (profName , ruleBaseName string ) string { return profName + "-" + ruleBaseName }
1639-
1640- ocpPb , err := f .CreateProfileBundle (pbName , baselineImage , framework .OcpContentFile )
1641- if err != nil {
1642- t .Fatal (err )
1643- }
1644- defer f .Client .Delete (context .TODO (), ocpPb )
1645- if err := f .WaitForProfileBundleStatus (pbName , compv1alpha1 .DataStreamValid ); err != nil {
1646- t .Fatal (err )
1647- }
1648-
1649- // Check that if the rule we are going to test is there
1650- requiredRuleName := prefixName (pbName , requiredRule )
1651- requiredVersionRuleName := prefixName (pbName , "version-detect-in-ocp" )
1652- requiredVariableName := prefixName (pbName , "var-streaming-connection-timeouts" )
1653- suiteName := "kubelet-remediation-test-suite-node"
1635+ suiteName := framework .GetObjNameFromTest (t ) + "-kubelet-remediation"
16541636
16551637 tp := & compv1alpha1.TailoredProfile {
16561638 ObjectMeta : metav1.ObjectMeta {
16571639 Name : suiteName ,
16581640 Namespace : f .OperatorNamespace ,
1641+ Annotations : map [string ]string {
1642+ compv1alpha1 .ProductTypeAnnotation : "Node" ,
1643+ },
16591644 },
16601645 Spec : compv1alpha1.TailoredProfileSpec {
16611646 Title : "kubelet-remediation-test-node" ,
16621647 Description : "A test tailored profile to test kubelet remediation" ,
16631648 EnableRules : []compv1alpha1.RuleReferenceSpec {
16641649 {
1665- Name : requiredRuleName ,
1650+ Name : "ocp4-kubelet-eviction-thresholds-set-hard-imagefs-inodesfree" ,
16661651 Rationale : "To be tested" ,
16671652 },
16681653 {
1669- Name : requiredVersionRuleName ,
1654+ Name : "ocp4-version-detect-in-ocp" ,
16701655 Rationale : "To be tested" ,
16711656 },
16721657 },
16731658 SetValues : []compv1alpha1.VariableValueSpec {
16741659 {
1675- Name : requiredVariableName ,
1660+ Name : "ocp4-var-kubelet-evictionhard-imagefs-inodesfree" ,
16761661 Rationale : "Value to be set" ,
1677- Value : "8h0m0s " ,
1662+ Value : "1% " ,
16781663 },
16791664 },
16801665 },
@@ -1704,11 +1689,21 @@ func TestKubeletConfigRemediation(t *testing.T) {
17041689 },
17051690 }
17061691
1707- err = f .Client .Create (context .TODO (), ssb , nil )
1692+ err : = f .Client .Create (context .TODO (), ssb , nil )
17081693 if err != nil {
17091694 t .Fatal (err )
17101695 }
1711- defer f .Client .Delete (context .TODO (), ssb )
1696+ // Cleanup: Delete ScanSettingBinding first, then wait for ComplianceSuite to be cascade-deleted
1697+ // This ensures proper cleanup before the next test runs
1698+ defer func () {
1699+ if err := f .Client .Delete (context .TODO (), ssb ); err != nil {
1700+ t .Fatal (err )
1701+ return
1702+ }
1703+ if err := f .WaitForComplianceSuiteDeletion (suiteName , f .OperatorNamespace ); err != nil {
1704+ t .Fatal (err )
1705+ }
1706+ }()
17121707
17131708 // Ensure that all the scans in the suite have finished and are marked as Done
17141709 err = f .WaitForSuiteScansStatus (f .OperatorNamespace , suiteName , compv1alpha1 .PhaseDone , compv1alpha1 .ResultNonCompliant )
@@ -1727,6 +1722,21 @@ func TestKubeletConfigRemediation(t *testing.T) {
17271722 t .Fatal (err )
17281723 }
17291724
1725+ // Cleanup: Unapply the remediation before test ends to prevent leaving nodes in a modified state
1726+ // This ensures the cluster is reset after the test completes
1727+ defer func () {
1728+ // Finally clean up by removing the remediation and waiting for the nodes to reboot one more time
1729+ err = f .UnApplyRemediationAndCheck (f .OperatorNamespace , remName , "worker" )
1730+ if err != nil {
1731+ t .Fatal (err )
1732+ }
1733+
1734+ err = f .WaitForNodesToBeReady ()
1735+ if err != nil {
1736+ t .Fatalf ("failed waiting for nodes to reboot after unapplying MachineConfig: %s" , err )
1737+ }
1738+ }()
1739+
17301740 err = f .ReRunScan (scanName , f .OperatorNamespace )
17311741 if err != nil {
17321742 t .Fatal (err )
0 commit comments