Skip to content

ROX-33465: Rework openshift auto-sensing in Helm chart#19482

Draft
mclasmeier wants to merge 12 commits intomasterfrom
mc/ROX-33465-openshift-autosensing
Draft

ROX-33465: Rework openshift auto-sensing in Helm chart#19482
mclasmeier wants to merge 12 commits intomasterfrom
mc/ROX-33465-openshift-autosensing

Conversation

@mclasmeier
Copy link
Copy Markdown
Contributor

@mclasmeier mclasmeier commented Mar 18, 2026

Description

The auto-sensing for openshift is completely reorganized.
It now contains an additional (higher-priority) check for the config.openshift.io/v1 API (CRD based, hence more reliable).

I had to keep the remaining logic because we also support OpenShift 3 and config.openshift.io/v1 is OpenShift 4-only.

The new code structure allows improved logs in case we have a discrepancy between the auto-sensed cluster type and what the user has specified.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

change me!

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 18, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@rhacs-bot
Copy link
Copy Markdown
Contributor

rhacs-bot commented Mar 18, 2026

Images are ready for the commit at 7725a46.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-476-g7725a46433.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.26%. Comparing base (26ad70f) to head (e5c1199).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19482      +/-   ##
==========================================
- Coverage   49.26%   49.26%   -0.01%     
==========================================
  Files        2727     2727              
  Lines      205821   205821              
==========================================
- Hits       101404   101399       -5     
- Misses      96885    96888       +3     
- Partials     7532     7534       +2     
Flag Coverage Δ
go-unit-tests 49.26% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mclasmeier mclasmeier force-pushed the mc/ROX-33465-openshift-autosensing branch from 9d45c67 to 219d34f Compare March 18, 2026 15:53
@mclasmeier mclasmeier changed the title Rework openshift auto-sensing in Helm chart to also check for config.… ROX-33465: Rework openshift auto-sensing in Helm chart Mar 18, 2026
@mclasmeier mclasmeier marked this pull request as ready for review March 18, 2026 16:16
@mclasmeier mclasmeier requested a review from a team as a code owner March 18, 2026 16:16
@mclasmeier mclasmeier requested review from GrimmiMeloni and removed request for a team March 18, 2026 16:16
@mclasmeier mclasmeier requested a review from porridge March 18, 2026 16:56
{{/* Normalize user setting.*/}}
{{- if kindIs "string" $normalizedUserSpecifiedOpenShift -}}
{{/* User set something like env.openshift="4". */}}
{{- $normalizedUserSpecifiedOpenShift = int $normalizedUserSpecifiedOpenShift -}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens if they specify env.openshift="true"? Does int cast that to 0 or 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just checked, it is parsed as 0. Not sure if we should also try to catch that (where to stop?).

Copy link
Copy Markdown
Contributor

@porridge porridge Mar 25, 2026

Choose a reason for hiding this comment

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

Good question. I guess it depends on what value types worked sensibly in the previous code. If this was already broken before, then we should right out reject such values, rather than trying to interpret them. 🤔

@mclasmeier mclasmeier requested a review from porridge March 24, 2026 10:26
@mclasmeier
Copy link
Copy Markdown
Contributor Author

@porridge A missing conversion was caught by the run-scanner-v4-install-tests:
when doing helm install --set env.openshift="4", the Helm chart receives an int64 -- I have added conversion for that as well in the last commit.

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 24, 2026

@mclasmeier: The following test 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/ocp-4-12-qa-e2e-tests e5c1199 link false /test ocp-4-12-qa-e2e-tests

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.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • In srox.autoSenseOpenshiftVersion, a couple of printf calls pass extra arguments that are never interpolated (e.g. the warnings for env.openshift=false and env.openshift=%d), so the auto-sensed value is not actually included in the message; consider fixing the format strings to surface both values or dropping the unused arguments.
  • The new srox.fail usage is inconsistent with the other helpers (srox.note, srox.warn), which are always called with (list $ <message>); if srox.fail has a similar signature, the current include "srox.fail" $fmt may not provide the context object as expected and could fail or produce less-informative output.
  • In sensorGenerateOpenShiftCommand.ConstructOpenShift, s.openshiftVersion is now effectively ignored (no switch or validation), while roxctl central generate k8s still validates --openshift-version; consider either restoring basic validation or removing the flag to avoid confusing users with an option that has no effect.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `srox.autoSenseOpenshiftVersion`, a couple of `printf` calls pass extra arguments that are never interpolated (e.g. the warnings for `env.openshift=false` and `env.openshift=%d`), so the auto-sensed value is not actually included in the message; consider fixing the format strings to surface both values or dropping the unused arguments.
- The new `srox.fail` usage is inconsistent with the other helpers (`srox.note`, `srox.warn`), which are always called with `(list $ <message>)`; if `srox.fail` has a similar signature, the current `include "srox.fail" $fmt` may not provide the context object as expected and could fail or produce less-informative output.
- In `sensorGenerateOpenShiftCommand.ConstructOpenShift`, `s.openshiftVersion` is now effectively ignored (no switch or validation), while `roxctl central generate k8s` still validates `--openshift-version`; consider either restoring basic validation or removing the flag to avoid confusing users with an option that has no effect.

## Individual Comments

### Comment 1
<location path="image/templates/helm/shared/templates/_openshift.tpl" line_range="21-30" />
<code_context>
+{{- $normalizedUserSpecifiedOpenShift := $env.openshift -}}
+
+{{/* Normalize user setting. */}}
+{{- $userSpecifiedOpenShiftAsInt := int $normalizedUserSpecifiedOpenShift -}}
+{{- if kindIs "string" $normalizedUserSpecifiedOpenShift -}}
+  {{- if eq (printf "%d" $userSpecifiedOpenShiftAsInt) $normalizedUserSpecifiedOpenShift -}}
+    {{/* User set something like env.openshift="4". We allow this as well. */}}
+    {{- $normalizedUserSpecifiedOpenShift = $userSpecifiedOpenShiftAsInt -}}
+  {{- end -}}
+{{- end -}}
+{{- if kindIs "float64" $normalizedUserSpecifiedOpenShift -}}
+  {{/* YAML numeric values are sometimes parsed as float64... */}}
+  {{- $normalizedUserSpecifiedOpenShift = $userSpecifiedOpenShiftAsInt -}}
+{{- end -}}
+{{- if kindIs "int64" $normalizedUserSpecifiedOpenShift -}}
+  {{/* ... and sometimes as int64 (e.g. when doing helm --set env.openshift="4"). */}}
+  {{- $normalizedUserSpecifiedOpenShift = $userSpecifiedOpenShiftAsInt -}}
</code_context>
<issue_to_address>
**issue (bug_risk):** Casting `env.openshift` to `int` before validating its kind can cause template failures for unset or non-numeric values.

`int` is invoked on `$normalizedUserSpecifiedOpenShift` even when `env.openshift` is unset or non-numeric (e.g., `bool`), which can panic before the kind checks run. Move the `int` conversion into the branches that have already confirmed `$normalizedUserSpecifiedOpenShift` is a numeric or numeric-string value, and only then assign `$userSpecifiedOpenShiftAsInt`.
</issue_to_address>

### Comment 2
<location path="image/templates/helm/shared/templates/_openshift.tpl" line_range="80-97" />
<code_context>
+  {{/* User set env.openshift=false. */}}
+  {{- if gt $autoSensedOpenShift 0 -}}
+    {{/* Might indicate a configuration problem. */}}
+    {{- $fmt := printf
+          "User setting env.openshift=false is in contrast to the result of the auto-sensing, which yielded an OpenShift target cluster -- will proceed with user setting"
+          $autoSensedOpenShift -}}
+    {{- include "srox.warn" (list $ $fmt) -}}
+  {{- end -}}
+  {{- $_ := set $env "openshift" 0 -}}
+{{- else -}}
+  {{/* User set env.openshift=4. */}}
+  {{- if not (eq $normalizedUserSpecifiedOpenShift $autoSensedOpenShift) -}}
+    {{/* Might indicate a configuration problem. */}}
+    {{- $fmt := printf
+          "User setting env.openshift=%d is in contrast to the result of the auto-sensing, which yielded a non-OpenShift cluster -- will proceed with user setting"
+          $normalizedUserSpecifiedOpenShift $autoSensedOpenShift -}}
+    {{- include "srox.warn" (list $ $fmt) -}}
+  {{- end -}}
</code_context>
<issue_to_address>
**suggestion:** Several `printf` calls pass more arguments than there are format verbs, which is misleading and drops information.

In these warning branches, extra arguments are passed and then ignored by Go’s `printf` (e.g. the `env.openshift=false` case passes `$autoSensedOpenShift` but uses no `%` verbs, and the later message passes both `$normalizedUserSpecifiedOpenShift` and `$autoSensedOpenShift` but only has one `%d`). This hides the auto-sensed value and makes the intent harder to follow. Please either update the format strings to print all provided values or remove the unused arguments so calls and messages stay aligned.

```suggestion
  {{/* User set env.openshift=false. */}}
  {{- if gt $autoSensedOpenShift 0 -}}
    {{/* Might indicate a configuration problem. */}}
    {{- $fmt := printf
          "User setting env.openshift=false is in contrast to the result of the auto-sensing, which yielded an OpenShift target cluster (auto-sensed value: %d) -- will proceed with user setting"
          $autoSensedOpenShift -}}
    {{- include "srox.warn" (list $ $fmt) -}}
  {{- end -}}
  {{- $_ := set $env "openshift" 0 -}}
{{- else -}}
  {{/* User set env.openshift=4. */}}
  {{- if not (eq $normalizedUserSpecifiedOpenShift $autoSensedOpenShift) -}}
    {{/* Might indicate a configuration problem. */}}
    {{- $fmt := printf
          "User setting env.openshift=%d is in contrast to the result of the auto-sensing, which yielded a non-OpenShift cluster (auto-sensed value: %d) -- will proceed with user setting"
          $normalizedUserSpecifiedOpenShift $autoSensedOpenShift -}}
    {{- include "srox.warn" (list $ $fmt) -}}
  {{- end -}}
```
</issue_to_address>

### Comment 3
<location path="roxctl/sensor/generate/openshift.go" line_range="21-23" />
<code_context>

 func (s *sensorGenerateOpenShiftCommand) ConstructOpenShift() error {
 	s.cluster.Type = storage.ClusterType_OPENSHIFT4_CLUSTER
-	switch s.openshiftVersion {
-	case 0:
-	case 3:
-		s.cluster.Type = storage.ClusterType_OPENSHIFT_CLUSTER
-	case 4:
-	default:
-		return errox.InvalidArgs.Newf("invalid OpenShift version %d, supported values are '3' and '4'", s.openshiftVersion)
-	}
-
 	s.cluster.AdmissionControllerEvents = s.cluster.GetType() == storage.ClusterType_OPENSHIFT4_CLUSTER

 	// This is intentionally NOT feature-flagged, because we always want to set the correct (auto) value,
</code_context>
<issue_to_address>
**issue (bug_risk):** `openshiftVersion` is no longer validated and unsupported values are silently treated as OpenShift 4.

With the updated `ConstructOpenShift`, `s.cluster.Type` is always `OPENSHIFT4_CLUSTER` and `s.openshiftVersion` is ignored. This means values like `--openshift-version=3` or `--openshift-version=7` are silently treated as 4. In `roxctl/central/generate/k8s.go`, you still validate `openshiftVersion` and reject anything other than 0 or 4. For consistency and to avoid silent misconfiguration, please add equivalent validation here and return an error when `s.openshiftVersion` is non-zero and not 4.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +21 to +30
{{- $userSpecifiedOpenShiftAsInt := int $normalizedUserSpecifiedOpenShift -}}
{{- if kindIs "string" $normalizedUserSpecifiedOpenShift -}}
{{- if eq (printf "%d" $userSpecifiedOpenShiftAsInt) $normalizedUserSpecifiedOpenShift -}}
{{/* User set something like env.openshift="4". We allow this as well. */}}
{{- $normalizedUserSpecifiedOpenShift = $userSpecifiedOpenShiftAsInt -}}
{{- end -}}
{{- end -}}
{{- if kindIs "float64" $normalizedUserSpecifiedOpenShift -}}
{{/* YAML numeric values are sometimes parsed as float64... */}}
{{- $normalizedUserSpecifiedOpenShift = $userSpecifiedOpenShiftAsInt -}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Casting env.openshift to int before validating its kind can cause template failures for unset or non-numeric values.

int is invoked on $normalizedUserSpecifiedOpenShift even when env.openshift is unset or non-numeric (e.g., bool), which can panic before the kind checks run. Move the int conversion into the branches that have already confirmed $normalizedUserSpecifiedOpenShift is a numeric or numeric-string value, and only then assign $userSpecifiedOpenShiftAsInt.

Comment on lines +80 to +97
{{/* User set env.openshift=false. */}}
{{- if gt $autoSensedOpenShift 0 -}}
{{/* Might indicate a configuration problem. */}}
{{- $fmt := printf
"User setting env.openshift=false is in contrast to the result of the auto-sensing, which yielded an OpenShift target cluster -- will proceed with user setting"
$autoSensedOpenShift -}}
{{- include "srox.warn" (list $ $fmt) -}}
{{- end -}}
{{- $_ := set $env "openshift" 0 -}}
{{- else -}}
{{/* User set env.openshift=4. */}}
{{- if not (eq $normalizedUserSpecifiedOpenShift $autoSensedOpenShift) -}}
{{/* Might indicate a configuration problem. */}}
{{- $fmt := printf
"User setting env.openshift=%d is in contrast to the result of the auto-sensing, which yielded a non-OpenShift cluster -- will proceed with user setting"
$normalizedUserSpecifiedOpenShift $autoSensedOpenShift -}}
{{- include "srox.warn" (list $ $fmt) -}}
{{- end -}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Several printf calls pass more arguments than there are format verbs, which is misleading and drops information.

In these warning branches, extra arguments are passed and then ignored by Go’s printf (e.g. the env.openshift=false case passes $autoSensedOpenShift but uses no % verbs, and the later message passes both $normalizedUserSpecifiedOpenShift and $autoSensedOpenShift but only has one %d). This hides the auto-sensed value and makes the intent harder to follow. Please either update the format strings to print all provided values or remove the unused arguments so calls and messages stay aligned.

Suggested change
{{/* User set env.openshift=false. */}}
{{- if gt $autoSensedOpenShift 0 -}}
{{/* Might indicate a configuration problem. */}}
{{- $fmt := printf
"User setting env.openshift=false is in contrast to the result of the auto-sensing, which yielded an OpenShift target cluster -- will proceed with user setting"
$autoSensedOpenShift -}}
{{- include "srox.warn" (list $ $fmt) -}}
{{- end -}}
{{- $_ := set $env "openshift" 0 -}}
{{- else -}}
{{/* User set env.openshift=4. */}}
{{- if not (eq $normalizedUserSpecifiedOpenShift $autoSensedOpenShift) -}}
{{/* Might indicate a configuration problem. */}}
{{- $fmt := printf
"User setting env.openshift=%d is in contrast to the result of the auto-sensing, which yielded a non-OpenShift cluster -- will proceed with user setting"
$normalizedUserSpecifiedOpenShift $autoSensedOpenShift -}}
{{- include "srox.warn" (list $ $fmt) -}}
{{- end -}}
{{/* User set env.openshift=false. */}}
{{- if gt $autoSensedOpenShift 0 -}}
{{/* Might indicate a configuration problem. */}}
{{- $fmt := printf
"User setting env.openshift=false is in contrast to the result of the auto-sensing, which yielded an OpenShift target cluster (auto-sensed value: %d) -- will proceed with user setting"
$autoSensedOpenShift -}}
{{- include "srox.warn" (list $ $fmt) -}}
{{- end -}}
{{- $_ := set $env "openshift" 0 -}}
{{- else -}}
{{/* User set env.openshift=4. */}}
{{- if not (eq $normalizedUserSpecifiedOpenShift $autoSensedOpenShift) -}}
{{/* Might indicate a configuration problem. */}}
{{- $fmt := printf
"User setting env.openshift=%d is in contrast to the result of the auto-sensing, which yielded a non-OpenShift cluster (auto-sensed value: %d) -- will proceed with user setting"
$normalizedUserSpecifiedOpenShift $autoSensedOpenShift -}}
{{- include "srox.warn" (list $ $fmt) -}}
{{- end -}}

Comment on lines 21 to 23
func (s *sensorGenerateOpenShiftCommand) ConstructOpenShift() error {
s.cluster.Type = storage.ClusterType_OPENSHIFT4_CLUSTER
switch s.openshiftVersion {
case 0:
case 3:
s.cluster.Type = storage.ClusterType_OPENSHIFT_CLUSTER
case 4:
default:
return errox.InvalidArgs.Newf("invalid OpenShift version %d, supported values are '3' and '4'", s.openshiftVersion)
}

s.cluster.AdmissionControllerEvents = s.cluster.GetType() == storage.ClusterType_OPENSHIFT4_CLUSTER
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): openshiftVersion is no longer validated and unsupported values are silently treated as OpenShift 4.

With the updated ConstructOpenShift, s.cluster.Type is always OPENSHIFT4_CLUSTER and s.openshiftVersion is ignored. This means values like --openshift-version=3 or --openshift-version=7 are silently treated as 4. In roxctl/central/generate/k8s.go, you still validate openshiftVersion and reject anything other than 0 or 4. For consistency and to avoid silent misconfiguration, please add equivalent validation here and return an error when s.openshiftVersion is non-zero and not 4.

@mclasmeier mclasmeier force-pushed the mc/ROX-33465-openshift-autosensing branch from 6f5f421 to 2e0e00d Compare March 26, 2026 14:36
@mclasmeier mclasmeier marked this pull request as draft March 26, 2026 14:39
@mclasmeier mclasmeier force-pushed the mc/ROX-33465-openshift-autosensing branch from 2e0e00d to c9408f1 Compare March 27, 2026 09:48
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.

3 participants