e2e: add test to check the image validation #4693
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- review_stack_entry_start -->

<!-- review_stack_entry_end -->
<!-- This is an auto-generated comment: review paused by coderabbit.ai -->
[!NOTE]
## Reviews paused
> It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.> Use the following commands to manage reviews:
- @coderabbitai resume to resume automatic reviews.- @coderabbitai review to trigger a single review.> Use the checkboxes below for quick actions:
- [ ] <!-- {"checkboxId": "7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews
- [ ] <!-- {"checkboxId": "e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review
<!-- end of auto-generated comment: review paused by coderabbit.ai -->
<!-- walkthrough_start -->
<details>
<summary>📝 Walkthrough</summary>
Walkthrough
Adds a scheduler image validation E2E suite covering invalid and untrusted images, validation overrides, and status transitions. The Makefile builds the new test binary and getdigests, while the E2E runner executes the validation suite and records JUnit output.
Changes
Scheduler image validation e2e coverage
|Layer / File(s)|Summary|
|---|---|
|Scheduler image validation test flow <br> test/e2e/sched/image_validation/*, test/internal/envvar/envvar.go|Adds suite initialization and validates degraded, available, and cleanup states for invalid scheduler images and validation overrides. Polling uses the per-iteration context.|
|Scheduler validation binary and runner wiring <br> Makefile, hack/run-test-e2e.sh|Builds the scheduler image validation and getdigests binaries, then runs the validation suite when scheduler tests are enabled.|
Estimated code review effort: 3 (Moderate) | ~20 minutes
Suggested reviewers: mrniranjan, yanirq
Sequence Diagram(s)
sequenceDiagram
participant E2ETest
participant NUMAResourcesScheduler
participant Operator
participant Deployment
E2ETest->>NUMAResourcesScheduler: Set invalid scheduler image
NUMAResourcesScheduler-->>E2ETest: Report InvalidSchedulerImage degradation
E2ETest->>NUMAResourcesScheduler: Set untrusted digest-pinned image
NUMAResourcesScheduler-->>E2ETest: Report InvalidSchedulerImage degradation
E2ETest->>Operator: Set allowed scheduler image digest
Operator->>Deployment: Roll out updated environment
E2ETest->>NUMAResourcesScheduler: Recheck scheduler status
NUMAResourcesScheduler-->>E2ETest: Report available and not degraded
</details>
<!-- walkthrough_end -->
<!-- pre_merge_checks_walkthrough_start -->
<details>
<summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary>
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
| :----------------: | :--------- | :----------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 8.51% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
<details>
<summary>✅ Passed checks (4 passed)</summary>
| Check name | Status | Explanation |
| :------------------------: | :------- | :--------------------------------------------------------------------------------------------------------- |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Title check | ✅ Passed | The title clearly summarizes the main change: adding an e2e image validation test. |
| Description check | ✅ Passed | The description is directly related to the change and matches the new scheduler image validation e2e test. |
</details>
</details>
<!-- pre_merge_checks_walkthrough_end -->
<!-- finishing_touch_checkbox_start -->
<details>
<summary>✨ Finishing Touches</summary>
<details>
<summary>🧪 Generate unit tests (beta)</summary>
</details>
</details>
<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->
---
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
<details>
<summary>❤️ Share</summary>
</details>
<sub>Comment @coderabbitai help to get the list of available commands.</sub>
<!-- tips_end -->
_📐 Maintainability & Code Quality_ | _🟠 Major_ | _⚡ Quick win_
Disable-validation boilerplate is duplicated near-verbatim across five suite setup files. Each suite repeats the same "if not validation-enabled → SetOperatorEnvVar(..., 'false') → assert → DeferCleanup restore" block; consolidating into one shared helper (e.g. in test/internal/envvar or test/internal/nrosched) taking (ctx, cli) and internally registering the DeferCleanup would remove the duplication and prevent future drift between suites.
test/e2e/must-gather/must_gather_suite_test.go#L88-L100: replace this block with a call to the shared helper.test/e2e/sched/install/test_suite_install_test.go#L41-L53: replace this block with a call to the shared helper.test/e2e/sched/uninstall/test_suite_uninstall_test.go#L41-L53: replace this block with a call to the shared helper.test/e2e/serial/e2e_serial_test.go#L53-L65: replace this block with a call to the shared helper.test/e2e/sched/test_suite_sched_test.go#L39-L57: fold suiteSchedValidationSetup and its surrounding if/DeferCleanup into the same shared helper instead of a package-local partial extraction.<details>
<summary>📍 Affects 5 files</summary>
test/e2e/must-gather/must_gather_suite_test.go#L88-L100 (this comment)test/e2e/sched/install/test_suite_install_test.go#L41-L53test/e2e/sched/uninstall/test_suite_uninstall_test.go#L41-L53test/e2e/serial/e2e_serial_test.go#L53-L65test/e2e/sched/test_suite_sched_test.go#L39-L57</details>
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/e2e/must-gather/must_gather_suite_test.go` around lines 88 - 100,
Introduce one shared helper that accepts ctx and the Kubernetes client, checks
IsSchedulerImageValidationEnabled, disables validation via SetOperatorEnvVar,
asserts success, and registers cleanup to restore it. Replace the duplicated
blocks in test/e2e/must-gather/must_gather_suite_test.go#L88-L100,
test/e2e/sched/install/test_suite_install_test.go#L41-L53,
test/e2e/sched/uninstall/test_suite_uninstall_test.go#L41-L53, and
test/e2e/serial/e2e_serial_test.go#L53-L65 with calls to that helper; in
test/e2e/sched/test_suite_sched_test.go#L39-L57, remove
suiteSchedValidationSetup and its surrounding setup/cleanup in favor of the same
helper.
</details>
<!-- consolidated_sites_start -->
<!--
<consolidated_sites>
<site>
<role>anchor</role>
<file>test/e2e/must-gather/must_gather_suite_test.go</file>
<line_range>88-100</line_range>
</site>
<site>
<role>sibling</role>
<file>test/e2e/sched/install/test_suite_install_test.go</file>
<line_range>41-53</line_range>
</site>
<site>
<role>sibling</role>
<file>test/e2e/sched/uninstall/test_suite_uninstall_test.go</file>
<line_range>41-53</line_range>
</site>
<site>
<role>sibling</role>
<file>test/e2e/serial/e2e_serial_test.go</file>
<line_range>53-65</line_range>
</site>
<site>
<role>sibling</role>
<file>test/e2e/sched/test_suite_sched_test.go</file>
<line_range>39-57</line_range>
</site>
</consolidated_sites>
-->
<!-- consolidated_sites_end -->
<!-- fingerprinting:phantom:medusa:beignet -->
<!-- cr-indicator-types:refactor_suggestion -->
<!-- cr-comment:v1:652a985b26f2017231d9b284 -->
<!-- This is an auto-generated reply by CodeRabbit -->
_🎯 Functional Correctness_ | _🟠 Major_ | _⚡ Quick win_
DeferCleanup restores validation using the stale outer ctx instead of cleanupCtx.
Line 149 calls suiteSchedValidationSetup(ctx, e2eclient.Client) inside the DeferCleanup(func(cleanupCtx context.Context) {...}) closure, but uses the captured outer ctx rather than the supplied cleanupCtx. If the spec's context is already cancelled or past its deadline when cleanup runs (e.g. on failure/timeout — the exact scenario this cleanup exists to handle robustly), the restore call can fail with a cancelled context, leaving scheduler image validation enabled for subsequent specs/suites.
<details>
<summary>🐛 Proposed fix</summary>
DeferCleanup(func(cleanupCtx context.Context) {
if !e2esched.IsSchedulerImageValidationEnabled() {
- _, err := suiteSchedValidationSetup(ctx, e2eclient.Client)
+ _, err := suiteSchedValidationSetup(cleanupCtx, e2eclient.Client)
Expect(err).NotTo(HaveOccurred())
}
})
</details>
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
It("should degrade status when scheduler image is invalid and validation is enabled", func(ctx context.Context) {
// intentionally ignore the restore function because when the test fails and ginkgo retries it,
// the restore function will be pointing to inacurate values. Thus we do the defer cleanup
// based on the suite setup.
_, err := e2eenvvar.SetOperatorEnvVar(ctx, e2eclient.Client, scheduler.SchedulerImageValidationEnvVar, "true")
Expect(err).NotTo(HaveOccurred())
// eventhough BeforeEach handles the restoration of the environment variable to the initial state, we need to restore it here
// because we don't want to depend on the order of the cleanup functions in BeforeEach.
DeferCleanup(func(cleanupCtx context.Context) {
if !e2esched.IsSchedulerImageValidationEnabled() {
_, err := suiteSchedValidationSetup(cleanupCtx, e2eclient.Client)
Expect(err).NotTo(HaveOccurred())
}
})
testSchedObj := &nropv1.NUMAResourcesScheduler{}
e2efixture.By("switching the NROS image to %s which does not pass the image validation criteria", e2eimages.SchedTestImageCI)
Eventually(func(g Gomega) {
g.Expect(e2eclient.Client.Get(ctx, client.ObjectKeyFromObject(nroSchedObj), testSchedObj)).To(Succeed())
testSchedObj.Spec.SchedulerImage = e2eimages.SchedTestImageCI
g.Expect(e2eclient.Client.Update(ctx, testSchedObj)).To(Succeed())
}).WithTimeout(time.Minute).WithPolling(time.Second * 10).Should(Succeed())
Eventually(func(g Gomega) {
g.Expect(e2eclient.Client.Get(ctx, client.ObjectKeyFromObject(nroSchedObj), testSchedObj)).To(Succeed())
klog.InfoS("scheduler conditions", "conditions", testSchedObj.Status.Conditions)
degradedCondition := metahelper.FindStatusCondition(testSchedObj.Status.Conditions, status.ConditionDegraded)
g.Expect(degradedCondition).ToNot(BeNil(), "degraded condition not found")
g.Expect(degradedCondition.Status).To(Equal(metav1.ConditionTrue), "degraded condition status is not true")
g.Expect(degradedCondition.Reason).To(Equal(string(status.ReasonInvalidSchedulerImage)), "degraded condition reason is not untrusted scheduler image")
}).WithTimeout(3 * time.Minute).WithPolling(time.Second * 10).Should(Succeed())
// BeforeEach handles the restoration of the scheduler spec to the initial state
})
</details>
<!-- suggestion_end -->
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/e2e/sched/sched_test.go` around lines 139 - 174, Update the DeferCleanup
closure in the scheduler image validation test to pass cleanupCtx, not the
captured ctx, to suiteSchedValidationSetup when restoring validation. Keep the
existing conditional restoration and error assertion unchanged.
</details>
<!-- fingerprinting:phantom:medusa:beignet -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:f5d2e1bac23c3e5480d2f262 -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commits 0210ab7 to b2e74d5
_🩺 Stability & Availability_ | _🟡 Minor_ | _⚡ Quick win_
Poll callback ignores aContext, using stale outer ctx instead.
The PollUntilContextTimeout callback parameter aContext is unused; the Get call on line 281 uses the outer ctx. The sibling loop in waitForDeploymentRollout (line 322) correctly uses aContext. This is inconsistent and means the per-attempt Get doesn't respect the poll's own derived context.
<details>
<summary>🔧 Proposed fix</summary>
err := k8swait.PollUntilContextTimeout(ctx, 10*time.Second, 15*time.Minute, true, func(aContext context.Context) (bool, error) {
- if err := cli.Get(ctx, client.ObjectKeyFromObject(dp), dp); err != nil {
+ if err := cli.Get(aContext, client.ObjectKeyFromObject(dp), dp); err != nil {
klog.Warningf("failed getting the deployment %s: %v", dp.Name, err)
return false, nil
}
return true, nil
})
</details>
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func waitForDeploymentRolloutAfterSubscriptionUpdate(ctx context.Context, cli client.Client, dp *appsv1.Deployment, initialPods []corev1.Pod, expectedEnvVarValues []corev1.EnvVar) error {
// Sometimes OLM fails to immediately update the deployment with the new env value,
// so we workaround this by explicitly deleting the deployment. Note that recreating
// the deployment can also take some time, being affected by the OLM rollout behavior,
// hence we give long enough time for its recreation.
klog.Info("deleting deployment")
if err := cli.Delete(ctx, dp); err != nil {
return err
}
err := k8swait.PollUntilContextTimeout(ctx, 10*time.Second, 15*time.Minute, true, func(aContext context.Context) (bool, error) {
if err := cli.Get(aContext, client.ObjectKeyFromObject(dp), dp); err != nil {
klog.Warningf("failed getting the deployment %s: %v", dp.Name, err)
return false, nil
}
return true, nil
})
if err != nil {
return fmt.Errorf("failed to wait for deployment to be recreated: err=%v", err)
}
return waitForDeploymentRollout(ctx, cli, dp, initialPods, expectedEnvVarValues)
}
</details>
<!-- suggestion_end -->
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/internal/envvar/envvar.go` around lines 270 - 291, Update the
PollUntilContextTimeout callback in
waitForDeploymentRolloutAfterSubscriptionUpdate to use its aContext parameter
for the cli.Get call instead of the outer ctx. Preserve the existing retry and
error-handling behavior.
</details>
<!-- fingerprinting:phantom:medusa:beignet -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:f6c2bbacf1388a304b6447bd -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commits 535e436 to 9e92094
_🩺 Stability & Availability_ | _🟠 Major_ | _⚡ Quick win_
Unchecked type assertions can panic on valueFrom-based env entries.
entry["name"].(string) and entry["value"].(string) use the single-value form. If a pre-existing subscription env entry uses valueFrom (secretKeyRef/configMapKeyRef) rather than a literal value, the "value" key is absent (nil), and this assertion panics, crashing the e2e run instead of failing gracefully.
<details>
<summary>🛡️ Proposed fix using safe type assertions</summary>
func toEnvVars(envs []any) []corev1.EnvVar {
envVars := []corev1.EnvVar{}
for _, env := range envs {
entry, ok := env.(map[string]any)
if !ok {
continue
}
- envVars = append(envVars, corev1.EnvVar{
- Name: entry["name"].(string),
- Value: entry["value"].(string),
- })
+ name, ok := entry["name"].(string)
+ if !ok {
+ continue
+ }
+ value, _ := entry["value"].(string)
+ envVars = append(envVars, corev1.EnvVar{Name: name, Value: value})
}
return envVars
}
</details>
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func toEnvVars(envs []any) []corev1.EnvVar {
envVars := []corev1.EnvVar{}
for _, env := range envs {
entry, ok := env.(map[string]any)
if !ok {
continue
}
name, ok := entry["name"].(string)
if !ok {
continue
}
value, _ := entry["value"].(string)
envVars = append(envVars, corev1.EnvVar{Name: name, Value: value})
}
return envVars
}
</details>
<!-- suggestion_end -->
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/internal/envvar/envvar.go` around lines 467 - 480, Update toEnvVars to
use checked type assertions for the name and value fields before appending an
EnvVar. Skip entries missing a string literal value, including valueFrom-based
entries, and avoid panics from absent or incorrectly typed fields while
preserving conversion of valid literal env entries.
</details>
<!-- fingerprinting:phantom:medusa:beignet -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:e4b5e966d62de8d021746ee8 -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commits 42f8b0d to 756a55a
Actionable comments posted: 4
<details>
<summary>🧹 Nitpick comments (1)</summary><blockquote>
<details>
<summary>test/internal/envvar/envvar.go (1)</summary><blockquote>
358-387: _📐 Maintainability & Code Quality_ | _🔵 Trivial_
Custom retry loop duplicates retry.RetryOnConflict and busy-loops on Get failures.
This hand-rolled retry duplicates functionality already used elsewhere in this file (retry.RetryOnConflict, lines 167/195). Additionally, when cli.Get fails, the loop continues without sleeping (the time.Sleep(interval) only runs after a failed Update), so repeated Get failures retry immediately without backoff.
<details>
<summary>♻️ Suggested consolidation</summary>
- updated := &appsv1.Deployment{}
- for i := 0; i < retries; i++ {
- if err := cli.Get(ctx, key, updated); err != nil {
- continue
- }
-
- updated.Spec.Template.Spec.Containers[containerIdx] = *newContainer
- if err := cli.Update(ctx, updated); err == nil {
- updatedSuccessfully = true
- break
- }
- time.Sleep(interval)
- }
-
- if !updatedSuccessfully {
- return fmt.Errorf("failed to update deployment %q", key.String())
- }
+ updated := &appsv1.Deployment{}
+ if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
+ if err := cli.Get(ctx, key, updated); err != nil {
+ return err
+ }
+ updated.Spec.Template.Spec.Containers[containerIdx] = *newContainer
+ return cli.Update(ctx, updated)
+ }); err != nil {
+ return fmt.Errorf("failed to update deployment %q: %w", key.String(), err)
+ }
</details>
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/internal/envvar/envvar.go` around lines 358 - 387, Replace the
hand-rolled retry loop in updateDeploymentContainerAndWaitForRollout with
retry.RetryOnConflict, including both cli.Get and cli.Update in the retried
operation so Get failures receive the same backoff and retry handling. Preserve
the existing successful update behavior and return an error when retries are
exhausted.
</details>
<!-- cr-comment:v1:e77af8e7d913d1028773751c -->
</blockquote></details>
</blockquote></details>
<details>
<summary>🤖 Prompt for all review comments with AI agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/e2e/must-gather/must_gather_suite_test.go`:
- Around line 88-100: Introduce one shared helper that accepts ctx and the
Kubernetes client, checks IsSchedulerImageValidationEnabled, disables validation
via SetOperatorEnvVar, asserts success, and registers cleanup to restore it.
Replace the duplicated blocks in
test/e2e/must-gather/must_gather_suite_test.go#L88-L100,
test/e2e/sched/install/test_suite_install_test.go#L41-L53,
test/e2e/sched/uninstall/test_suite_uninstall_test.go#L41-L53, and
test/e2e/serial/e2e_serial_test.go#L53-L65 with calls to that helper; in
test/e2e/sched/test_suite_sched_test.go#L39-L57, remove
suiteSchedValidationSetup and its surrounding setup/cleanup in favor of the same
helper.
In `@test/e2e/sched/sched_test.go`:
- Around line 139-174: Update the DeferCleanup closure in the scheduler image
validation test to pass cleanupCtx, not the captured ctx, to
suiteSchedValidationSetup when restoring validation. Keep the existing
conditional restoration and error assertion unchanged.
In `@test/internal/envvar/envvar.go`:
- Around line 270-291: Update the PollUntilContextTimeout callback in
waitForDeploymentRolloutAfterSubscriptionUpdate to use its aContext parameter
for the cli.Get call instead of the outer ctx. Preserve the existing retry and
error-handling behavior.
- Around line 467-480: Update toEnvVars to use checked type assertions for the
name and value fields before appending an EnvVar. Skip entries missing a string
literal value, including valueFrom-based entries, and avoid panics from absent
or incorrectly typed fields while preserving conversion of valid literal env
entries.
---
Nitpick comments:
In `@test/internal/envvar/envvar.go`:
- Around line 358-387: Replace the hand-rolled retry loop in
updateDeploymentContainerAndWaitForRollout with retry.RetryOnConflict, including
both cli.Get and cli.Update in the retried operation so Get failures receive the
same backoff and retry handling. Preserve the existing successful update
behavior and return an error when retries are exhausted.
</details>
<details>
<summary>🪄 Autofix (Beta)</summary>
Fix all unresolved CodeRabbit comments on this PR:
</details>
---
<details>
<summary>ℹ️ Review info</summary>
<details>
<summary>⚙️ Run configuration</summary>
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 0283ff08-0390-4202-b90b-b308ab07ed49
</details>
<details>
<summary>📥 Commits</summary>
Reviewing files that changed from the base of the PR and between 464a04f6ac3af60b2cb4f441e6ee913b53fe0431 and be4a80c3a5111312739771082d03189bbe5b5b52.
</details>
<details>
<summary>📒 Files selected for processing (13)</summary>
.konflux/bundle/overlay/pin_images.in.yaml
.konflux/catalog/bundle.builds.in.yaml
test/e2e/must-gather/must_gather_suite_test.go
test/e2e/must-gather/must_gather_test.go
test/e2e/sched/install/test_suite_install_test.go
test/e2e/sched/sched_test.go
test/e2e/sched/test_suite_sched_test.go
test/e2e/sched/uninstall/test_suite_uninstall_test.go
test/e2e/serial/README.md
test/e2e/serial/e2e_serial_test.go
test/internal/consts/consts.go
test/internal/envvar/envvar.go
test/internal/nrosched/nrosched.go</details>
</details>
<!-- This is an auto-generated comment by CodeRabbit for review status -->
/retest
_🎯 Functional Correctness_ | _🟠 Major_ | _⚡ Quick win_
Ensure the untrusted-image assertion observes the second update.
The prior case already leaves Degraded=True with ReasonInvalidSchedulerImage, so this poll can pass before reconciliation evaluates the untrusted digest. Assert that the condition’s ObservedGeneration equals the fetched resource generation.
<details><summary>Proposed fix</summary>
g.Expect(degradedCondition).ToNot(BeNil(), "degraded condition not found")
g.Expect(degradedCondition.Status).To(Equal(metav1.ConditionTrue), "degraded condition status is not true")
g.Expect(degradedCondition.Reason).To(Equal(string(status.ReasonInvalidSchedulerImage)), "degraded condition reason is not untrusted scheduler image")
+ g.Expect(degradedCondition.ObservedGeneration).To(Equal(testSchedObj.Generation), "degraded condition has not observed the current scheduler generation")
</details>
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Eventually(func(g Gomega) {
g.Expect(e2eclient.Client.Get(ctx, client.ObjectKeyFromObject(nroSchedObj), testSchedObj)).To(Succeed())
klog.InfoS("scheduler conditions", "conditions", testSchedObj.Status.Conditions)
degradedCondition := metahelper.FindStatusCondition(testSchedObj.Status.Conditions, status.ConditionDegraded)
g.Expect(degradedCondition).ToNot(BeNil(), "degraded condition not found")
g.Expect(degradedCondition.Status).To(Equal(metav1.ConditionTrue), "degraded condition status is not true")
g.Expect(degradedCondition.Reason).To(Equal(string(status.ReasonInvalidSchedulerImage)), "degraded condition reason is not untrusted scheduler image")
g.Expect(degradedCondition.ObservedGeneration).To(Equal(testSchedObj.Generation), "degraded condition has not observed the current scheduler generation")
}).WithTimeout(5 * time.Minute).WithPolling(time.Second * 10).Should(Succeed())
</details>
<!-- suggestion_end -->
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/e2e/sched/image_validation/sched_test.go` around lines 107 - 115, In the
Eventually assertion for the fetched scheduler object, also verify that
degradedCondition.ObservedGeneration matches testSchedObj.Generation. Keep the
existing status and reason checks, ensuring the untrusted-image assertion only
passes after the second reconciliation update is observed.
</details>
<!-- fingerprinting:phantom:poseidon:terra -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:1ec1b595e16fc6974c79be52 -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commits 535e436 to 9e92094
Actionable comments posted: 1
<details>
<summary>🤖 Prompt for all review comments with AI agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/e2e/sched/image_validation/sched_test.go`:
- Around line 107-115: In the Eventually assertion for the fetched scheduler
object, also verify that degradedCondition.ObservedGeneration matches
testSchedObj.Generation. Keep the existing status and reason checks, ensuring
the untrusted-image assertion only passes after the second reconciliation update
is observed.
</details>
<details>
<summary>🪄 Autofix (Beta)</summary>
Fix all unresolved CodeRabbit comments on this PR:
</details>
---
<details>
<summary>ℹ️ Review info</summary>
<details>
<summary>⚙️ Run configuration</summary>
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1f51fa90-58a4-48d2-8f32-fc1476f3f000
</details>
<details>
<summary>📥 Commits</summary>
Reviewing files that changed from the base of the PR and between b2e74d539794d566de46fa976b1465ce8666bc8f and 756a55a800c7480601d0dd1416ea9bf5a0e377be.
</details>
<details>
<summary>📒 Files selected for processing (4)</summary>
Makefile
hack/run-test-e2e.sh
test/e2e/sched/image_validation/sched_test.go
test/e2e/sched/image_validation/test_suite_sched_test.go
</details>
</details>
<!-- This is an auto-generated comment by CodeRabbit for review status -->
_🎯 Functional Correctness_ | _🟠 Major_ | _⚡ Quick win_
Restore the fetched scheduler object.
Line 60 updates testSchedObj, but line 61 persists schedObj; cleanup therefore leaves the invalid image configured and can contaminate later E2E tests.
<details>
<summary>Proposed fix</summary>
- testSchedObj.Spec.SchedulerImage = initialSched.Spec.SchedulerImage
+ schedObj.Spec.SchedulerImage = initialSched.Spec.SchedulerImage
g.Expect(e2eclient.Client.Update(cleanupCtx, schedObj)).To(Succeed())
</details>
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
DeferCleanup(func(cleanupCtx context.Context) {
e2efixture.By("restore the scheduler image")
Eventually(func(g Gomega) {
schedObj := &nropv1.NUMAResourcesScheduler{}
g.Expect(e2eclient.Client.Get(cleanupCtx, nroSchedKey, schedObj)).To(Succeed())
schedObj.Spec.SchedulerImage = initialSched.Spec.SchedulerImage
g.Expect(e2eclient.Client.Update(cleanupCtx, schedObj)).To(Succeed())
}).WithTimeout(time.Minute).WithPolling(time.Second * 10).Should(Succeed())
</details>
<!-- suggestion_end -->
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/e2e/sched/image_validation/validation_test.go` around lines 55 - 62, In
the DeferCleanup scheduler-image restoration, assign
initialSched.Spec.SchedulerImage to the fetched schedObj.Spec.SchedulerImage
before calling e2eclient.Client.Update. Keep the existing fetch, retry, timeout,
and polling behavior unchanged so the restored object is the one persisted.
</details>
<!-- fingerprinting:phantom:poseidon:terra -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:9304f6e0ebb9d913b09715f5 -->
<!-- This is an auto-generated comment by CodeRabbit -->
✅ Addressed in commits 2f91649 to 691ec3a
Actionable comments posted: 1
<details>
<summary>🤖 Prompt for all review comments with AI agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/e2e/sched/image_validation/validation_test.go`:
- Around line 55-62: In the DeferCleanup scheduler-image restoration, assign
initialSched.Spec.SchedulerImage to the fetched schedObj.Spec.SchedulerImage
before calling e2eclient.Client.Update. Keep the existing fetch, retry, timeout,
and polling behavior unchanged so the restored object is the one persisted.
</details>
<details>
<summary>🪄 Autofix (Beta)</summary>
Fix all unresolved CodeRabbit comments on this PR:
</details>
---
<details>
<summary>ℹ️ Review info</summary>
<details>
<summary>⚙️ Run configuration</summary>
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e497d3ed-b4d9-49d6-b0f8-8ae3a1338652
</details>
<details>
<summary>📥 Commits</summary>
Reviewing files that changed from the base of the PR and between 756a55a800c7480601d0dd1416ea9bf5a0e377be and e4b4d685aceb9ba6ee53d4bd385659df2cbbe8b3.
</details>
<details>
<summary>📒 Files selected for processing (5)</summary>
Makefile
hack/run-test-e2e.sh
test/e2e/sched/image_validation/test_suite_validation_test.go
test/e2e/sched/image_validation/validation_test.go
test/internal/envvar/envvar.go
</details>
<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>
Makefile
</details>
</details>
<!-- This is an auto-generated comment by CodeRabbit for review status -->
/retest
/retest
handling in a different PR
@shajmakh, acknowledged—this refactor can be handled in the follow-up PR. Would you like me to open a tracking issue for it?
🐇↕️
<!-- This is an auto-generated reply by CodeRabbit -->
e2e passed, rerunning to ensure its success is stable:
/retest ci-e2e
/test ci-e2e
IIRC we agreed to remove the year, which is wrong date anyway.
Is there a reason to have the sched-image-validation test as a separate binary from the rest of sched tests?
ditto
Maybe here just keep the digest and remove the sha256 and pass it into invalidImage.
Another quick question can we get the digest dynamically instead of hardcoding or is it too much overhead?
this is the only place where we call restoreFunc why not simply inline the function?
overall looking good
minor comments
Maybe here just keep the digest and remove the sha256 and pass it into invalidImage.
we need the digest with the sha because we will use that in the next step to verify that intsched.CustomSchedulerDigestsEnvVar works as expected.
Another quick question can we get the digest dynamically instead of hardcoding or is it too much overhead?
not with the available infra, because pulling/inspecting the image dynamically needs a special infra. in this case all what we care about is the conditions of the scheduler so it doesn't matter the custom image we are using if it is old or not. I added a comment to clarify this. Thanks for raising this topic.
I'll remove it entirely, thanks!
it's a returned function from SetOperatorEnvVar we connot inline it because we don't know what is it: https://github.com/shajmakh/numaresources-operator/blob/main/test/internal/envvar/envvar.go#L52
Ack, yes adding a comment explaining that for future purposes is beneficial.
Thanks!
good question, yes, because there seems an OLM issue updating the subscription with the different values of env var consecutively, as raised n https://github.com/openshift-kni/numaresources-operator/pull/4595#issuecomment-5019925191. This test requires re-enabling the image validation right after having it disabled so we can check the default behavior of the validation. after many retries, I've seen that the multiple updates of the subcription and hence the operator deployment gets stuck for a while (sometimes over 15 mins) and is not stable in the prow ci. The last resort I had (before moving this test to d/s pipeline handling for more control over the operator installation - skipping subscription updates) was to have a new suite that works with the default configuration (meaning enabled image validation), so we don't hit the consecutive subscription updates.
I haven't spent enough time investigating the OLM timing issue because after a while, the updates resolve to the expected state.
I added a note about this in the suite in case we wondered about this in the future.
sure. lets add a comment and I'll approve (I don't see the comment atm)
/lgtm
Thank you for the changes
rebased to get this update: https://github.com/openshift-kni/numaresources-operator/pull/4784
no change in the reviewed and approved code.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: <a href="https://github.com/openshift-kni/numaresources-operator/pull/4693#" title="Author self-approved">shajmakh</a>, <a href="https://github.com/openshift-kni/numaresources-operator/pull/4693#pullrequestreview-4816658129" title="LGTM">Tal-or</a>
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
</details>
<!-- META={"approvers":[]} -->
/cherry-pick release-4.22
@shajmakh: #4693 failed to apply on top of branch "release-4.22":
Applying: e2e: add test to check the image validation
Using index info to reconstruct a base tree...
M Makefile
Falling back to patching base and 3-way merge...
Auto-merging Makefile
CONFLICT (content): Merge conflict in Makefile
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 e2e: add test to check the image validation
<details>
In response to this:
>/cherry-pick release-4.22
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.
</details>
Tal-or
shajmakh
Add an e2e test to verify the image validation causing the scheduler CR
to be degraded after not complying to the validation criteria.