Skip to content

✨ Update fields in the spec to no longer be a pointer #1171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

rashmigottipati
Copy link
Member

Description

Fixes #1146

Reviewer Checklist

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

@rashmigottipati rashmigottipati requested a review from a team as a code owner August 26, 2024 14:33
Copy link

netlify bot commented Aug 26, 2024

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 25c5f55
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/66cc93d3d471b20008f7f174
😎 Deploy Preview https://deploy-preview-1171--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 site configuration.

@@ -319,7 +319,7 @@ type PreflightConfig struct {
// consequences of upgrading a CRD, such as data loss.
//
// This field is required if the spec.preflight field is specified.
CRDUpgradeSafety *CRDUpgradeSafetyPreflightConfig `json:"crdUpgradeSafety"`
CRDUpgradeSafety CRDUpgradeSafetyPreflightConfig `json:"crdUpgradeSafety,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This field is a required field and therefore should not have the omitempty in the JSON tag:

Suggested change
CRDUpgradeSafety CRDUpgradeSafetyPreflightConfig `json:"crdUpgradeSafety,omitempty"`
CRDUpgradeSafety CRDUpgradeSafetyPreflightConfig `json:"crdUpgradeSafety"`

Copy link
Member Author

Choose a reason for hiding this comment

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

I originally left it without the omitempty tag, however, unit tests are failing with the below error i.e. the field having a null value when it is empty:
Error Trace: /Users/rashmigottipati/go/src/github.com/operator-framework/operator-controller/internal/controllers/clusterextension_controller_test.go:63 Error: Received unexpected error: ClusterExtension.olm.operatorframework.io "cluster-extension-test-s58x6kfr" is invalid: [spec.preflight.crdUpgradeSafety.policy: Unsupported value: "": supported values: "Enabled", "Disabled", <nil>: Invalid value: "null": some validation rules were not checked because the object was invalid; correct the existing errors to complete validation]

Since these fields are required only if the spec.preflight field is specified, there's a possibility of it being null when the spec.preflight field is not being set and so I think it would be ok to add the omitempty tag to this field and also the Policy field but open to suggestions on how to appropriately handle this in a better way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way we could ensure the default value is set when the top level spec.preflight field is not explicitly set?

Copy link
Contributor

Choose a reason for hiding this comment

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

if not, we may need to have some more complex CEL validations in place. We need to be careful there as well though to ensure the cost of the CEL expression is not too expensive.

Copy link
Contributor

Choose a reason for hiding this comment

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

I found kubernetes-sigs/controller-tools#622 (comment) which may be what we need to do in this case.

Copy link
Member

@joelanford joelanford Aug 26, 2024

Choose a reason for hiding this comment

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

Keep in mind. This is required for now, only because there are no other sibling preflight check configurations. As soon as there are sibling configurations (e.g. for a permissions preflight check), then we'll need a validation like "at least one of the preflight check fields is required".

With that in mind, perhaps it is reasonable to go ahead and implement a CEL expression based validation that checks "at least one of" semantics, where the check starts out as at least one of: [crdUpgradeSafety]

Copy link
Contributor

Choose a reason for hiding this comment

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

Thats a good point @joelanford . I do think it makes sense to go ahead and update it such that we have the "at least one of" approach

@@ -340,7 +340,7 @@ type CRDUpgradeSafetyPreflightConfig struct {
//
//+kubebuilder:validation:Enum:="Enabled";"Disabled"
//+kubebuilder:default:=Enabled
Policy CRDUpgradeSafetyPolicy `json:"policy"`
Policy CRDUpgradeSafetyPolicy `json:"policy,omitempty"`
Copy link
Contributor

@everettraven everettraven Aug 26, 2024

Choose a reason for hiding this comment

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

This is a required field and therefore should not have the omitempty JSON tag:

Suggested change
Policy CRDUpgradeSafetyPolicy `json:"policy,omitempty"`
Policy CRDUpgradeSafetyPolicy `json:"policy"`

Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 75.66%. Comparing base (2391092) to head (25c5f55).
Report is 43 commits behind head on main.

Files with missing lines Patch % Lines
internal/applier/helm.go 0.00% 1 Missing and 1 partial ⚠️
api/v1alpha1/zz_generated.deepcopy.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1171      +/-   ##
==========================================
+ Coverage   75.33%   75.66%   +0.32%     
==========================================
  Files          35       35              
  Lines        1934     1927       -7     
==========================================
+ Hits         1457     1458       +1     
+ Misses        331      324       -7     
+ Partials      146      145       -1     
Flag Coverage Δ
e2e 58.58% <25.00%> (+0.26%) ⬆️
unit 50.96% <0.00%> (+0.18%) ⬆️

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.

@openshift-merge-robot
Copy link

PR needs rebase.

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.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 30, 2024
@grokspawn
Copy link
Contributor

Superseded by #1223

@grokspawn grokspawn closed this Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update fields in the spec to no longer be a pointer
5 participants