Skip to content

MCO-2142: Avoid OSImageStream defaultStream unset#2764

Open
pablintino wants to merge 1 commit intoopenshift:masterfrom
pablintino:validate-not-blank
Open

MCO-2142: Avoid OSImageStream defaultStream unset#2764
pablintino wants to merge 1 commit intoopenshift:masterfrom
pablintino:validate-not-blank

Conversation

@pablintino
Copy link
Contributor

This change prevents users from resetting the value of the OSImageStream.spec.defaultStream field once it's set. The main idea motivation behind this limitation is the design choice and agreement that makes all clusters have a default at install-time. Given that the field is not required (and it's not safe to make it required as the field already exist) this validation is the middle-ground we can provide without making the field required.

This change prevents users from resetting the value of the
OSImageStream.spec.defaultStream field once it's set.
The main idea motivation behind this limitation is the design choice and
agreement that makes all clusters have a default at install-time. Given
that the field is not required (and it's not safe to make it required as
the field already exist) this validation is the middle-ground we can
provide without making the field required.

Signed-off-by: Pablo Rodriguez Nava <git@amail.pablintino.eu>
@openshift-ci-robot
Copy link

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Mar 13, 2026
@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 13, 2026

@pablintino: This pull request references MCO-2142 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 change prevents users from resetting the value of the OSImageStream.spec.defaultStream field once it's set. The main idea motivation behind this limitation is the design choice and agreement that makes all clusters have a default at install-time. Given that the field is not required (and it's not safe to make it required as the field already exist) this validation is the middle-ground we can provide without making the field required.

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
Contributor

openshift-ci bot commented Mar 13, 2026

Hello @pablintino! Some important instructions when contributing to openshift/api:
API design plays an important part in the user experience of OpenShift and as such API PRs are subject to a high level of scrutiny to ensure they follow our best practices. If you haven't already done so, please review the OpenShift API Conventions and ensure that your proposed changes are compliant. Following these conventions will help expedite the api review process for your PR.

@openshift-ci openshift-ci bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 13, 2026
@openshift-ci openshift-ci bot requested review from JoelSpeed and yuqi-zhang March 13, 2026 12:34
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 13, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign everettraven for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@qodo-code-review
Copy link

ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

Review Summary by Qodo

Prevent removal of OSImageStream defaultStream once set

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Add validation rule preventing removal of spec.defaultStream once set
• Ensures clusters maintain default stream at install-time
• Update documentation and generated manifests with validation details
• Add test cases for removal prevention and edge cases
Diagram
flowchart LR
  A["OSImageStreamSpec Type"] -->|Add XValidation Rule| B["Validation Logic"]
  B -->|Rule: !has oldSelf.defaultStream OR has self.defaultStream| C["Prevent Removal"]
  C -->|Update Documentation| D["Comments & Swagger Docs"]
  D -->|Generate CRD Manifests| E["CRD YAML Files"]
  E -->|Add Test Cases| F["Test Suite"]
Loading

Grey Divider

File Changes

1. machineconfiguration/v1alpha1/types_osimagestream.go ✨ Enhancement +2/-0

Add validation rule for defaultStream immutability

• Add kubebuilder:validation:XValidation rule to OSImageStreamSpec type
• Rule prevents unsetting defaultStream once it has been set
• Update field documentation comment to note removal restriction

machineconfiguration/v1alpha1/types_osimagestream.go


2. machineconfiguration/v1alpha1/zz_generated.swagger_doc_generated.go 📝 Documentation +1/-1

Update swagger docs with removal restriction

• Update swagger documentation for defaultStream field
• Add note "Once set, this field cannot be removed" to field description

machineconfiguration/v1alpha1/zz_generated.swagger_doc_generated.go


3. openapi/generated_openapi/zz_generated.openapi.go 📝 Documentation +1/-1

Update OpenAPI schema documentation

• Update OpenAPI schema description for defaultStream field
• Add removal restriction note to field documentation

openapi/generated_openapi/zz_generated.openapi.go


View more (4)
4. machineconfiguration/v1alpha1/tests/osimagestreams.machineconfiguration.openshift.io/OSStreams.yaml 🧪 Tests +36/-0

Add test cases for defaultStream removal validation

• Add test case validating rejection when removing spec.defaultStream
• Add test case allowing updates when defaultStream was never set
• Verify error message matches validation rule

machineconfiguration/v1alpha1/tests/osimagestreams.machineconfiguration.openshift.io/OSStreams.yaml


5. machineconfiguration/v1alpha1/zz_generated.crd-manifests/0000_80_machine-config_01_osimagestreams.crd.yaml ⚙️ Configuration changes +4/-0

Add validation rule to generated CRD manifest

• Add x-kubernetes-validations rule to spec section
• Include validation rule preventing defaultStream removal
• Update field description with removal restriction note

machineconfiguration/v1alpha1/zz_generated.crd-manifests/0000_80_machine-config_01_osimagestreams.crd.yaml


6. machineconfiguration/v1alpha1/zz_generated.featuregated-crd-manifests/osimagestreams.machineconfiguration.openshift.io/OSStreams.yaml ⚙️ Configuration changes +4/-0

Add validation rule to featuregated CRD manifest

• Add x-kubernetes-validations rule to spec section
• Include validation rule preventing defaultStream removal
• Update field description with removal restriction note

machineconfiguration/v1alpha1/zz_generated.featuregated-crd-manifests/osimagestreams.machineconfiguration.openshift.io/OSStreams.yaml


7. payload-manifests/crds/0000_80_machine-config_01_osimagestreams.crd.yaml ⚙️ Configuration changes +4/-0

Add validation rule to payload CRD manifest

• Add x-kubernetes-validations rule to spec section
• Include validation rule preventing defaultStream removal
• Update field description with removal restriction note

payload-manifests/crds/0000_80_machine-config_01_osimagestreams.crd.yaml


Grey Divider

Qodo Logo

@qodo-code-review
Copy link

qodo-code-review bot commented Mar 13, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 2d463f6e-02e8-4346-97c8-951a41445517

📥 Commits

Reviewing files that changed from the base of the PR and between 5e946e2 and ca4b06c.

⛔ Files ignored due to path filters (4)
  • machineconfiguration/v1alpha1/zz_generated.crd-manifests/0000_80_machine-config_01_osimagestreams.crd.yaml is excluded by !**/zz_generated.crd-manifests/*
  • machineconfiguration/v1alpha1/zz_generated.featuregated-crd-manifests/osimagestreams.machineconfiguration.openshift.io/OSStreams.yaml is excluded by !**/zz_generated.featuregated-crd-manifests/**
  • machineconfiguration/v1alpha1/zz_generated.swagger_doc_generated.go is excluded by !**/zz_generated*
  • openapi/generated_openapi/zz_generated.openapi.go is excluded by !openapi/**, !**/zz_generated*
📒 Files selected for processing (3)
  • machineconfiguration/v1alpha1/tests/osimagestreams.machineconfiguration.openshift.io/OSStreams.yaml
  • machineconfiguration/v1alpha1/types_osimagestream.go
  • payload-manifests/crds/0000_80_machine-config_01_osimagestreams.crd.yaml

📝 Walkthrough

Walkthrough

This change introduces validation to prevent removal of the spec.defaultStream field in OSImageStream resources once it has been set. The validation is implemented through a CEL-based XValidation rule applied to the OSImageStreamSpec type, which is subsequently reflected in the generated CRD manifest. The rule enforces that if defaultStream existed in the previous state, it must continue to exist in the updated state. Corresponding test cases are added to verify that removal attempts are rejected while updates without defaultStream remain permitted when the field was never set.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'MCO-2142: Avoid OSImageStream defaultStream unset' accurately describes the main change: preventing removal of the defaultStream field once set.
Description check ✅ Passed The description clearly explains the purpose of the change: preventing users from resetting defaultStream once set, and provides context about the design rationale.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Stable And Deterministic Test Names ✅ Passed PR does not contain any Ginkgo test files with test names (It, Describe, Context, When). Changes consist only of CRD validation rules and Go type annotations, not Ginkgo tests.
Test Structure And Quality ✅ Passed Tests follow established patterns with single responsibility, proper setup/cleanup, timeouts, and assertion messages consistent with codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.3)

Error: build linters: unable to load custom analyzer "kubeapilinter": tools/_output/bin/kube-api-linter.so, plugin: not implemented
The command is terminated due to an error: build linters: unable to load custom analyzer "kubeapilinter": tools/_output/bin/kube-api-linter.so, plugin: not implemented


Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 13, 2026

@pablintino: all tests passed!

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.

kind: OSImageStream
metadata:
name: cluster
spec: {}
Copy link
Contributor

Choose a reason for hiding this comment

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

There isn't a sibling field apart from defaultStream right?

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

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants