✨ Add crd:validation:Schemaless marker#528
✨ Add crd:validation:Schemaless marker#528k8s-ci-robot merged 2 commits intokubernetes-sigs:masterfrom
Conversation
|
Welcome @maxsmythe! |
This marker will avoid trying to do any type detection on any struct field on which it is set. This gives users a safety valve when they hit an edge case where type inference does the wrong thing for them. Signed-off-by: Max Smythe <smythe@google.com>
80b5507 to
ddfa00f
Compare
|
We have a situation where we want to model spec:
config: # we want this to be map[string]interface
foo: '{some-fun-json}'
members: 3Currently we're using: Config json.RawMessage `json:"config,omitempty"`And then converting to func (in *ProxyDefaults) convertConfig() map[string]interface{} {
if in.Spec.Config == nil {
return nil
}
var outConfig map[string]interface{}
json.Unmarshal(in.Spec.Config, &outConfig)
return outConfig
}The only CRD type we've found that works is properties:
config:
description: yada
type: objectHowever the CRD generation gives us: config:
description: yada
format: byte
type: stringIf we use the annotation // +kubebuilder:validation:Type=object
Config json.RawMessage `json:"config,omitempty"`We get an error: Would this change allow us to do: // +kubebuilder:validation:Type=object
// +kubebuilder:validation:Schemaless
Config json.RawMessage `json:"config,omitempty"`? |
|
It should be able to. Some alternatives for you:
If neither of these alternatives work for you, this PR would be helpful. |
DirectXMan12
left a comment
There was a problem hiding this comment.
minor comment on a go modules file change, otherwise lgtm
| @@ -1,6 +1,4 @@ | |||
| run: | |||
| modules-download-mode: readonly | |||
There was a problem hiding this comment.
That had fixed an error I was having running the linter. It's been a while, so I can't remember what the error was.
Testing again with this line re-added doesn't cause a problem anymore. I wonder if it only breaks if your go modules aren't already up-to-date?
In any case, not really in scope for this PR, so reverting.
Signed-off-by: Max Smythe <smythe@google.com>
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DirectXMan12, maxsmythe The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Thanks! |
This marker will avoid trying to do any type detection on any struct field on which it is set. This gives users a safety valve when they hit an edge case where type inference does the wrong thing for them.
This fixes #291, which was recently re-broken by fixing #502
Signed-off-by: Max Smythe smythe@google.com