-
Notifications
You must be signed in to change notification settings - Fork 76
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
Fix crd validation: Key should not be required anymore in bundle source resources #474
Fix crd validation: Key should not be required anymore in bundle source resources #474
Conversation
Hi @juliocamarero. Thanks for your PR. I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
/ok-to-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for coming back to fix this, @juliocamarero! I was expecting a minor fix, so my main question is why you are suggesting to rename a (Go) field.
//+optional | ||
KeySelector `json:",inline,omitempty"` | ||
Key *string `json:"key"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key *string `json:"key"` | |
Key *string `json:"key,omitempty"` |
What's your motivation for renaming this Go field? I don't think it's required to do, and I assume there was a reason for the extra abstraction when this field was introduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for having a look so fast @erikgb 🙇
What's your motivation for renaming this Go field?
It's not just a renaming. I am using a string pointer directly instead of using a struct which embeds a string.
If you look at the autogenerated changes in the CRD, the only change is that now the key
field is not required anymore, there isn't any field renamed there.
Let me explain the problem as I see it:
- The struct
SourceObjectKeySelector
doest not have an explicitKey
field, instead, it has aKeySelector
field of type struct which contains aKey
field, and theKeySelector
field is annotated withjson:inline
which makes the fieldkey
to be implicetly a field theSourceObjectKeySelector
in json. - We want the
key
field of the structSourceObjectKeySelector
in json to be optional (because it shouldn't be used whenincludeAllKeys: true
- The field
KeySelector
in theSourceObjectKeySelector
was already marked as optional. However, sinceKey
is required inside the KeySelector struct, when the CRD is autogenerated, the fieldkey
is always marked as required.
These are the different approaches I tried:
- changing the
KeySelector
to*KeySelector
in theSourceObjectKeySelector
, this didn't change anything in the CRD,key
was still required - changing the
Key
inside theKeySelector
struct to be optional. This change made thekey
field optional in the CRD, but not only for theSourceObjectKeySelector
, but also for several other models for which it shouldn't be optional.
I was expecting a minor fix
I was expecting a minor fix too 😅 Happy to try any other suggestion you may have :) (hopefully there is a secret trick to make this field not required in the CRD which I am not aware of 🪄 )
I only could think of another approach, which is to introduce a new struct called OptionalKeySelector
to be used instead of the existing KeySelector
in the SourceObjectKeySelector
. It would just contain the string pointer Key
. I couldn't think of any benefit of having this additional struct for wrapping a string pointer, so that's why I used the Key
directly.
Thanks again Erik!! 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for the explanation. This makes a lot more sense now. 👍 Since the KeySelector
struct is reused multiple places, I agree this must change somehow. But do we need to make the Key
field a string pointer - if we set omitEmpty
?
Key *string `json:"key"` | |
Key string `json:"key,omitEmpty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right! I hadn't thought of this 🙈
This simplifies the logic and reduces the amount of changes need 👌
8385cbb
to
edf3fa3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @juliocamarero! Just a minor suggestion to the field description. Let me know what you think. Can you update the PR title and squash everything into a single commit before we merge?
Signed-off-by: Julio Camarero <julio.camarero@elastic.co>
0bce615
to
18ba82c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this important fix @juliocamarero! It was required to change more code than anticipated, but I think the changes represented a simplification. 🚀
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: erikgb 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 |
Thanks a lot @erikgb! 🙇 |
Hi folks,
in my last contribution (#460) I made a mistake.
I didn't realize the "key" when specifying a source secret with "includeAllKeys" was still required in the CRD.
This causes the webhook to reject bundles which use the new field: