Skip to content

Conversation

@grokspawn
Copy link
Contributor

Description

Adds new standard:description tag support to allow inclusion of standard-manifest-only field descriptions.
Adds new optional/required validation tag support to allow field tags to impact the required list of their parent field.
Adds unit tests for all new capabilities, since there are no existing uses of the new tags (yet!).

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

Signed-off-by: grokspawn <jordan@nimblewidget.com>
@grokspawn grokspawn requested a review from a team as a code owner November 21, 2025 18:47
Copilot AI review requested due to automatic review settings November 21, 2025 18:47
@netlify
Copy link

netlify bot commented Nov 21, 2025

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 2f93a69
🔍 Latest deploy log https://app.netlify.com/projects/olmv1/deploys/6920d72c970cfb00086a4293
😎 Deploy Preview https://deploy-preview-2358--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@openshift-ci openshift-ci bot requested review from oceanc80 and tmshort November 21, 2025 18:47
Copilot finished reviewing on behalf of grokspawn November 21, 2025 18:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds symmetric support for standard-specific field descriptions (complementing the existing experimental-specific descriptions) and introduces optional/required validation tags that allow field annotations to dynamically control the required fields list in generated CRDs. The changes maintain backward compatibility while extending the CRD generation capabilities.

Key Changes

  • Added support for <opcon:standard:description> tags (symmetric to existing experimental tags)
  • Implemented <opcon:*:validation:Optional> and <opcon:*:validation:Required> tags to control field requirement status
  • Enhanced opconTweaks and opconTweaksMap functions to return and process requirement status, updating the required fields list accordingly
  • Added comprehensive unit tests covering all new tag functionality including edge cases

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
hack/tools/crd-generator/main.go Extended opconTweaks and opconTweaksMap to handle required status; refactored formatDescription to support both standard and experimental description tags symmetrically; added Optional/Required validation tag processing
hack/tools/crd-generator/main_test.go Added comprehensive test suites for formatDescription, opconTweaks optional/required handling, and opconTweaksMap required list manipulation
hack/tools/crd-generator/README.md Documented new Optional and Required validation tags, and added Standard Description section to mirror Experimental Description documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +267 to +281
optReqRe := regexp.MustCompile(validationPrefix + "(Optional|Required)>")
optReqMatches := optReqRe.FindAllStringSubmatch(jsonProps.Description, 64)
for _, optReqMatch := range optReqMatches {
if len(optReqMatch) != 2 {
log.Fatalf("Invalid %s Optional/Required tag for %s", validationPrefix, name)
}

numValid++
switch optReqMatch[1] {
case "Optional":
requiredStatus = statusOptional
case "Required":
requiredStatus = statusRequired
}
}
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

[nitpick] If a field description contains multiple Optional/Required tags (e.g., both <opcon:standard:validation:Optional> and <opcon:standard:validation:Required>), the last one processed will determine the final status. Consider adding validation to detect and error on conflicting tags, or document that only one such tag should be used per field.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we should error if we try to set this a second time.

@codecov
Copy link

codecov bot commented Nov 21, 2025

Codecov Report

❌ Patch coverage is 92.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.63%. Comparing base (1355ff7) to head (2f93a69).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
hack/tools/crd-generator/main.go 92.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2358      +/-   ##
==========================================
- Coverage   74.23%   70.63%   -3.61%     
==========================================
  Files          91       91              
  Lines        7239     7266      +27     
==========================================
- Hits         5374     5132     -242     
- Misses       1433     1699     +266     
- Partials      432      435       +3     
Flag Coverage Δ
e2e 44.32% <ø> (-0.04%) ⬇️
experimental-e2e 14.08% <ø> (-34.40%) ⬇️
unit 58.67% <92.00%> (+0.12%) ⬆️

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: grokspawn <jordan@nimblewidget.com>
@pedjak
Copy link
Contributor

pedjak commented Nov 24, 2025

Adds unit tests for all new capabilities, since there are no existing uses of the new tags (yet!).

What is the motivation for adding this logic, if there are not need for it? Should we postpone it and add within a PR where such logic is needed?

@joelanford
Copy link
Member

@pedjak motivation is making the clusterextension.spec.serviceAccount field optional in the experimental channel. To me, it seems like a reasonable thing to split off from that.

Comment on lines +195 to +205
// Update required list based on tag
switch reqStatus {
case statusRequired:
if !slices.Contains(parentSchema.Required, name) {
parentSchema.Required = append(parentSchema.Required, name)
}
case statusOptional:
parentSchema.Required = slices.DeleteFunc(parentSchema.Required, func(s string) bool { return s == name })
default:
// "" (unspecified) means keep existing status
}
Copy link
Member

Choose a reason for hiding this comment

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

I was originally thinking that we'd pass parentSchema all the way down into opconTweaks (which I ultimately still think is the correct architectural decision).

However, I see that this function already had some pre-existing code for handling p == nil (or not) and making changes in the parent at this level.

With that in mind, I think your approach makes sense to align with the current architecture.

Maybe leave a comment that it might be worth refactoring in the future to allow opconTweaks to make any/all necessary changes to the parent to account for the markers that are on the name-ed field?

@joelanford
Copy link
Member

/approve

@openshift-ci
Copy link

openshift-ci bot commented Nov 24, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joelanford

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 24, 2025
@pedjak
Copy link
Contributor

pedjak commented Nov 25, 2025

@pedjak motivation is making the clusterextension.spec.serviceAccount field optional in the experimental channel. To me, it seems like a reasonable thing to split off from that.

Thanks @joelanford for the context. I see now that is extracted from #2355

// the limitations of Kubebuilder annotations.
func opconTweaks(channel string, name string, jsonProps apiextensionsv1.JSONSchemaProps) *apiextensionsv1.JSONSchemaProps {
// Returns the modified schema and a string indicating required status where indicated by opcon tags:
// "required", "optional", or "" (no decision -- preserve any non-opcon required status).
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of strings, would it make sense to use a *bool that can represent these three states as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

bool has a limited range of values (even if you include nil with *bool). Using string allows for additional flexibility.

Comment on lines +213 to +214
// Returns the modified schema and a string indicating required status where indicated by opcon tags:
// "required", "optional", or "" (no decision -- preserve any non-opcon required status).
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the documentatino for opconTweaks function? Should we move it next to the function signature?

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants