Skip to content
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

[POC] Defaulting CR values without defaulting webhook [TB: 1d] #38

Closed
4 tasks done
Tracked by #8
k15r opened this issue May 12, 2023 · 2 comments
Closed
4 tasks done
Tracked by #8

[POC] Defaulting CR values without defaulting webhook [TB: 1d] #38

k15r opened this issue May 12, 2023 · 2 comments
Assignees

Comments

@k15r
Copy link
Contributor

k15r commented May 12, 2023

Prepare a quick demo for defaulting mechanics without a defaulting webhook:

  • defaulting of simple types
  • defaulting of complex types
  • which version of kubernetes is required
  • how to implement in a kubebuilder environment
@k15r k15r mentioned this issue May 12, 2023
14 tasks
@k15r k15r changed the title Defaulting webhook? [POC] Defaulting CR values without defaulting webhook May 12, 2023
@k15r k15r changed the title [POC] Defaulting CR values without defaulting webhook [POC] Defaulting CR values without defaulting webhook [TB: 1d] May 12, 2023
@grischperl grischperl self-assigned this May 23, 2023
@friedrichwilken
Copy link
Contributor

We can use kubebuilder default annotation to do this.

type MyCRD struct {
// +kubebuilder:default:={myProperty:{myValue:3}}
Spec MySpec `json:"spec"`
}

type MySpec struct {
// +kubebuilder:default:={myValue:3}
MyProperty `json:"myProperty"`
}

type MyProperty struct {
// +kubebuilder:default:=3
MyValue int `json:"myValue"`
}

If one deploys a CR that misses myValue, myPropery.myValue, spec.myProperty.myValue the CR will be automatically have spec.myProperty.myValue=3. The same will happen if one deletes any of the aforementioned fields.

So, this can be used for simple types as ints, complex objects like spec. This works at least on Kubernetes v1.25 and above, which is the version used by SKR and Gardener. Older versions were not tested.

@friedrichwilken
Copy link
Contributor

As a follow up, let's define the required defaults for the NATS-CR and then let's validate, if this approach is sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants