diff --git a/docs/book/src/reference/makefile-helpers.md b/docs/book/src/reference/makefile-helpers.md index 4e20e410470..091a5206112 100644 --- a/docs/book/src/reference/makefile-helpers.md +++ b/docs/book/src/reference/makefile-helpers.md @@ -1,6 +1,6 @@ # Makefile Helpers -By default, the projects are scaffolded with a `Makefile`. You can customize and update this file as please you. Here, you will find some helpers that can be useful. +By default, the projects are scaffolded with a `Makefile`. You can customize and update this file as please you. Here, you will find some helpers that can be useful. ## To debug with go-delve @@ -14,28 +14,24 @@ run-delve: generate fmt vet manifests dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./bin/manager ``` -## To change the version of CRDs +## To change the version of CRDs -The tool generate the CRDs by using [controller-tools](https://github.com/kubernetes-sigs/controller-tools), see in the manifests target: +The `controller-gen` program (from [controller-tools](https://github.com/kubernetes-sigs/controller-tools)) +generates CRDs for kubebuilder projects, wrapped in the following `make` rule: ```sh -# Generate manifests e.g. CRD, RBAC etc. manifests: controller-gen $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases ``` -In this way, update `CRD_OPTIONS` to define the version of the CRDs manifests which will be generated in the `config/crd/bases` directory: +`controller-gen` lets you specify what CRD API version to generate (either "v1", the default, or "v1beta1"). +You can direct it to generate a specific version by adding `crd:crdVersions={}` to your `CRD_OPTIONS`, +found at the top of your Makefile: ```sh -# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) -CRD_OPTIONS ?= "crd:trivialVersions=true" +CRD_OPTIONS ?= "crd:crdVersions={v1beta1},trivialVersions=true,preserveUnknownFields=false" ``` -| CRD_OPTIONS | API version | -|--- |--- | -| `"crd:trivialVersions=true"` | `apiextensions.k8s.io/v1beta1` | -| `"crd:crdVersions=v1"` | `apiextensions.k8s.io/v1` | - ## To get all the manifests without deploying By adding `make dry-run` you can get the patched manifests in the dry-run folder, unlike `make depĺoy` which runs `kustomize` and `kubectl apply`. diff --git a/pkg/model/config/config.go b/pkg/model/config/config.go index b319b0d04f0..1a3ec594866 100644 --- a/pkg/model/config/config.go +++ b/pkg/model/config/config.go @@ -87,17 +87,19 @@ func (c Config) HasResource(target GVK) bool { return false } -// AddResource appends the provided resource to the tracked ones -// It returns if the configuration was modified -func (c *Config) AddResource(gvk GVK) bool { - // No-op if the resource was already tracked, return false - if c.HasResource(gvk) { - return false +// UpdateResources either adds gvk to the tracked set or, if the resource already exists, +// updates the the equivalent resource in the set. +func (c *Config) UpdateResources(gvk GVK) { + // If the resource already exists, update it. + for i, r := range c.Resources { + if r.isEqualTo(gvk) { + c.Resources[i].merge(gvk) + return + } } - // Append the resource to the tracked ones, return true + // The resource does not exist, append the resource to the tracked ones. c.Resources = append(c.Resources, gvk) - return true } // HasGroup returns true if group is already tracked @@ -113,11 +115,44 @@ func (c Config) HasGroup(group string) bool { return false } +// IsCRDVersionCompatible returns true if crdVersion can be added to the existing set of CRD versions. +func (c Config) IsCRDVersionCompatible(crdVersion string) bool { + return c.resourceAPIVersionCompatible("crd", crdVersion) +} + +// IsWebhookVersionCompatible returns true if webhookVersion can be added to the existing set of Webhook versions. +func (c Config) IsWebhookVersionCompatible(webhookVersion string) bool { + return c.resourceAPIVersionCompatible("webhook", webhookVersion) +} + +// resourceAPIVersionCompatible returns true if version can be added to the existing set of versions +// for a given verType. +func (c Config) resourceAPIVersionCompatible(verType, version string) bool { + for _, res := range c.Resources { + var currVersion string + switch verType { + case "crd": + currVersion = res.CRDVersion + case "webhook": + currVersion = res.WebhookVersion + } + if currVersion != "" && version != currVersion { + return false + } + } + return true +} + // GVK contains information about scaffolded resources type GVK struct { Group string `json:"group,omitempty"` Version string `json:"version,omitempty"` Kind string `json:"kind,omitempty"` + + // CRDVersion holds the CustomResourceDefinition API version used for the GVK. + CRDVersion string `json:"crdVersion,omitempty"` + // WebhookVersion holds the {Validating,Mutating}WebhookConfiguration API version used for the GVK. + WebhookVersion string `json:"webhookVersion,omitempty"` } // isEqualTo compares it with another resource @@ -127,6 +162,17 @@ func (r GVK) isEqualTo(other GVK) bool { r.Kind == other.Kind } +// merge combines fields of two GVKs that have matching group, version, and kind, +// favoring the receiver's values. +func (r *GVK) merge(other GVK) { + if r.CRDVersion == "" && other.CRDVersion != "" { + r.CRDVersion = other.CRDVersion + } + if r.WebhookVersion == "" && other.WebhookVersion != "" { + r.WebhookVersion = other.WebhookVersion + } +} + // Marshal returns the bytes of c. func (c Config) Marshal() ([]byte, error) { // Ignore extra fields at first. diff --git a/pkg/model/config/config_test.go b/pkg/model/config/config_test.go index 10f828c13b1..02f30e520aa 100644 --- a/pkg/model/config/config_test.go +++ b/pkg/model/config/config_test.go @@ -21,7 +21,9 @@ import ( . "github.com/onsi/gomega" ) -var _ = Describe("Config", func() { +const v1beta1 = "v1beta1" + +var _ = Describe("PluginConfig", func() { // Test plugin config. Don't want to export this config, but need it to // be accessible by test. type PluginConfig struct { @@ -146,3 +148,94 @@ var _ = Describe("Config", func() { Expect(pluginConfig).To(Equal(expectedPluginConfig)) }) }) + +var _ = Describe("Resource Version Compatibility", func() { + + var ( + c *Config + gvk1, gvk2 GVK + + defaultVersion = "v1" + ) + + BeforeEach(func() { + c = &Config{} + gvk1 = GVK{Group: "example", Version: "v1", Kind: "TestKind"} + gvk2 = GVK{Group: "example", Version: "v1", Kind: "TestKind2"} + }) + + Context("resourceAPIVersionCompatible", func() { + It("returns true for a list of empty resources", func() { + Expect(c.resourceAPIVersionCompatible("crd", defaultVersion)).To(BeTrue()) + }) + It("returns true for one resource with an empty version", func() { + c.Resources = []GVK{gvk1} + Expect(c.resourceAPIVersionCompatible("crd", defaultVersion)).To(BeTrue()) + }) + It("returns true for one resource with matching version", func() { + gvk1.CRDVersion = defaultVersion + c.Resources = []GVK{gvk1} + Expect(c.resourceAPIVersionCompatible("crd", defaultVersion)).To(BeTrue()) + }) + It("returns true for two resources with matching versions", func() { + gvk1.CRDVersion = defaultVersion + gvk2.CRDVersion = defaultVersion + c.Resources = []GVK{gvk1, gvk2} + Expect(c.resourceAPIVersionCompatible("crd", defaultVersion)).To(BeTrue()) + }) + It("returns false for one resource with a non-matching version", func() { + gvk1.CRDVersion = v1beta1 + c.Resources = []GVK{gvk1} + Expect(c.resourceAPIVersionCompatible("crd", defaultVersion)).To(BeFalse()) + }) + It("returns false for two resources containing a non-matching version", func() { + gvk1.CRDVersion = v1beta1 + gvk2.CRDVersion = defaultVersion + c.Resources = []GVK{gvk1, gvk2} + Expect(c.resourceAPIVersionCompatible("crd", defaultVersion)).To(BeFalse()) + }) + + It("returns false for two resources containing a non-matching version (webhooks)", func() { + gvk1.WebhookVersion = v1beta1 + gvk2.WebhookVersion = defaultVersion + c.Resources = []GVK{gvk1, gvk2} + Expect(c.resourceAPIVersionCompatible("webhook", defaultVersion)).To(BeFalse()) + }) + }) +}) + +var _ = Describe("Config", func() { + var ( + c *Config + gvk1, gvk2 GVK + ) + + BeforeEach(func() { + c = &Config{} + gvk1 = GVK{Group: "example", Version: "v1", Kind: "TestKind"} + gvk2 = GVK{Group: "example", Version: "v1", Kind: "TestKind2"} + }) + + Context("UpdateResource", func() { + It("Adds a non-existing resource", func() { + c.UpdateResources(gvk1) + Expect(c.Resources).To(Equal([]GVK{gvk1})) + // Update again to ensure idempotency. + c.UpdateResources(gvk1) + Expect(c.Resources).To(Equal([]GVK{gvk1})) + }) + It("Updates an existing resource", func() { + c.UpdateResources(gvk1) + gvk := GVK{Group: gvk1.Group, Version: gvk1.Version, Kind: gvk1.Kind, CRDVersion: "v1"} + c.UpdateResources(gvk) + Expect(c.Resources).To(Equal([]GVK{gvk})) + }) + It("Updates an existing resource with more than one resource present", func() { + c.UpdateResources(gvk1) + c.UpdateResources(gvk2) + gvk := GVK{Group: gvk1.Group, Version: gvk1.Version, Kind: gvk1.Kind, CRDVersion: "v1"} + c.UpdateResources(gvk) + Expect(c.Resources).To(Equal([]GVK{gvk, gvk2})) + }) + }) +}) diff --git a/pkg/model/resource/options.go b/pkg/model/resource/options.go index ecbcc9ccad0..2dfc67e9f79 100644 --- a/pkg/model/resource/options.go +++ b/pkg/model/resource/options.go @@ -82,6 +82,11 @@ type Options struct { // Namespaced is true if the resource is namespaced. Namespaced bool + + // CRDVersion holds the CustomResourceDefinition API version used for the Options. + CRDVersion string + // WebhookVersion holds the {Validating,Mutating}WebhookConfiguration API version used for the Options. + WebhookVersion string } // ValidateV2 verifies that V2 project has all the fields have valid values @@ -183,6 +188,18 @@ func (opts *Options) Validate() error { return fmt.Errorf("invalid Kind: %#v", validationErrors) } + // Ensure apiVersions for k8s types are empty or valid. + for typ, apiVersion := range map[string]string{ + "CRD": opts.CRDVersion, + "Webhook": opts.WebhookVersion, + } { + switch apiVersion { + case "", "v1", "v1beta1": + default: + return fmt.Errorf("%s version must be one of: v1, v1beta1", typ) + } + } + // TODO: validate plural strings if provided return nil @@ -191,9 +208,11 @@ func (opts *Options) Validate() error { // GVK returns the group-version-kind information to check against tracked resources in the configuration file func (opts *Options) GVK() config.GVK { return config.GVK{ - Group: opts.Group, - Version: opts.Version, - Kind: opts.Kind, + Group: opts.Group, + Version: opts.Version, + Kind: opts.Kind, + CRDVersion: opts.CRDVersion, + WebhookVersion: opts.WebhookVersion, } } @@ -269,5 +288,7 @@ func (opts *Options) newResource() *Resource { Kind: opts.Kind, Plural: plural, ImportAlias: opts.safeImport(opts.Group + opts.Version), + CRDVersion: opts.CRDVersion, + WebhookVersion: opts.WebhookVersion, } } diff --git a/pkg/model/resource/resource.go b/pkg/model/resource/resource.go index 3a2c0395013..35a104757ee 100644 --- a/pkg/model/resource/resource.go +++ b/pkg/model/resource/resource.go @@ -51,14 +51,21 @@ type Resource struct { // Namespaced is true if the resource is namespaced. Namespaced bool `json:"namespaced,omitempty"` + + // CRDVersion holds the CustomResourceDefinition API version used for the Resource. + CRDVersion string `json:"crdVersion,omitempty"` + // WebhookVersion holds the {Validating,Mutating}WebhookConfiguration API version used for the Resource. + WebhookVersion string `json:"webhookVersion,omitempty"` } // GVK returns the group-version-kind information to check against tracked resources in the configuration file func (r *Resource) GVK() config.GVK { return config.GVK{ - Group: r.Group, - Version: r.Version, - Kind: r.Kind, + Group: r.Group, + Version: r.Version, + Kind: r.Kind, + CRDVersion: r.CRDVersion, + WebhookVersion: r.WebhookVersion, } } diff --git a/pkg/plugin/v2/scaffolds/api.go b/pkg/plugin/v2/scaffolds/api.go index 286cf5a5a54..8e809780903 100644 --- a/pkg/plugin/v2/scaffolds/api.go +++ b/pkg/plugin/v2/scaffolds/api.go @@ -93,7 +93,7 @@ func (s *apiScaffolder) newUniverse() *model.Universe { func (s *apiScaffolder) scaffold() error { if s.doResource { - s.config.AddResource(s.resource.GVK()) + s.config.UpdateResources(s.resource.GVK()) if err := machinery.NewScaffold(s.plugins...).Execute( s.newUniverse(), diff --git a/pkg/plugin/v3/api.go b/pkg/plugin/v3/api.go index 4f385b9fe77..da2c69180ce 100644 --- a/pkg/plugin/v3/api.go +++ b/pkg/plugin/v3/api.go @@ -37,10 +37,15 @@ import ( "sigs.k8s.io/kubebuilder/v2/plugins/addon" ) -// KbDeclarativePatternVersion is the sigs.k8s.io/kubebuilder-declarative-pattern version -// (used only to gen api with --pattern=addon) -// TODO: remove this when a better solution for using addons is implemented. -const KbDeclarativePatternVersion = "1cbf859290cab81ae8e73fc5caebe792280175d1" +const ( + // KbDeclarativePatternVersion is the sigs.k8s.io/kubebuilder-declarative-pattern version + // (used only to gen api with --pattern=addon) + // TODO: remove this when a better solution for using addons is implemented. + KbDeclarativePatternVersion = "1cbf859290cab81ae8e73fc5caebe792280175d1" + + // defaultCRDVersion is the default CRD API version to scaffold. + defaultCRDVersion = "v1" +) // DefaultMainPath is default file path of main.go const DefaultMainPath = "main.go" @@ -124,6 +129,8 @@ func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) { fs.StringVar(&p.resource.Group, "group", "", "resource Group") fs.StringVar(&p.resource.Version, "version", "", "resource Version") fs.BoolVar(&p.resource.Namespaced, "namespaced", true, "resource is namespaced") + fs.StringVar(&p.resource.CRDVersion, "crd-version", defaultCRDVersion, + "version of CustomResourceDefinition to scaffold. Options: [v1, v1beta1]") } func (p *createAPISubcommand) InjectConfig(c *config.Config) { @@ -172,6 +179,12 @@ func (p *createAPISubcommand) Validate() error { return fmt.Errorf("multiple groups are not allowed by default, " + "to enable multi-group visit kubebuilder.io/migration/multi-group.html") } + + // Check CRDVersion against all other CRDVersions in p.config for compatibility. + if !p.config.IsCRDVersionCompatible(p.resource.CRDVersion) { + return fmt.Errorf("only one CRD version can be used for all resources, cannot add %q", + p.resource.CRDVersion) + } } return nil diff --git a/pkg/plugin/v3/scaffolds/api.go b/pkg/plugin/v3/scaffolds/api.go index 859bf0a77bf..38f793a59b1 100644 --- a/pkg/plugin/v3/scaffolds/api.go +++ b/pkg/plugin/v3/scaffolds/api.go @@ -84,7 +84,8 @@ func (s *apiScaffolder) newUniverse() *model.Universe { // TODO: re-use universe created by s.newUniverse() if possible. func (s *apiScaffolder) scaffold() error { if s.doResource { - s.config.AddResource(s.resource.GVK()) + + s.config.UpdateResources(s.resource.GVK()) if err := machinery.NewScaffold(s.plugins...).Execute( s.newUniverse(), @@ -93,8 +94,8 @@ func (s *apiScaffolder) scaffold() error { &samples.CRDSample{}, &rbac.CRDEditorRole{}, &rbac.CRDViewerRole{}, - &patches.EnableWebhookPatch{}, - &patches.EnableCAInjectionPatch{}, + &patches.EnableWebhookPatch{CRDVersion: s.resource.CRDVersion}, + &patches.EnableCAInjectionPatch{CRDVersion: s.resource.CRDVersion}, ); err != nil { return fmt.Errorf("error scaffolding APIs: %v", err) } @@ -102,7 +103,7 @@ func (s *apiScaffolder) scaffold() error { if err := machinery.NewScaffold().Execute( s.newUniverse(), &crd.Kustomization{}, - &crd.KustomizeConfig{}, + &crd.KustomizeConfig{CRDVersion: s.resource.CRDVersion}, ); err != nil { return fmt.Errorf("error scaffolding kustomization: %v", err) } diff --git a/pkg/plugin/v3/scaffolds/init.go b/pkg/plugin/v3/scaffolds/init.go index 4e2aa9eafaa..61740fa0342 100644 --- a/pkg/plugin/v3/scaffolds/init.go +++ b/pkg/plugin/v3/scaffolds/init.go @@ -31,7 +31,6 @@ import ( "sigs.k8s.io/kubebuilder/v2/pkg/plugin/v3/scaffolds/internal/templates/config/manager" "sigs.k8s.io/kubebuilder/v2/pkg/plugin/v3/scaffolds/internal/templates/config/prometheus" "sigs.k8s.io/kubebuilder/v2/pkg/plugin/v3/scaffolds/internal/templates/config/rbac" - "sigs.k8s.io/kubebuilder/v2/pkg/plugin/v3/scaffolds/internal/templates/config/webhook" "sigs.k8s.io/kubebuilder/v2/pkg/plugin/v3/scaffolds/internal/templates/hack" ) @@ -39,7 +38,7 @@ const ( // ControllerRuntimeVersion is the kubernetes-sigs/controller-runtime version to be used in the project ControllerRuntimeVersion = "v0.7.0-alpha.6" // ControllerToolsVersion is the kubernetes-sigs/controller-tools version to be used in the project - ControllerToolsVersion = "v0.3.0" + ControllerToolsVersion = "v0.4.1" // KustomizeVersion is the kubernetes-sigs/kustomize version to be used in the project KustomizeVersion = "v3.5.4" @@ -98,15 +97,19 @@ func (s *initScaffolder) scaffold() error { return machinery.NewScaffold().Execute( s.newUniverse(string(boilerplate)), - &templates.GitIgnore{}, + &rbac.Kustomization{}, &rbac.AuthProxyRole{}, &rbac.AuthProxyRoleBinding{}, - &kdefault.ManagerAuthProxyPatch{}, &rbac.AuthProxyService{}, &rbac.AuthProxyClientRole{}, + &rbac.RoleBinding{}, + &rbac.LeaderElectionRole{}, + &rbac.LeaderElectionRoleBinding{}, + &manager.Kustomization{}, &manager.Config{Image: imageName}, &templates.Main{}, &templates.GoMod{ControllerRuntimeVersion: ControllerRuntimeVersion}, + &templates.GitIgnore{}, &templates.Makefile{ Image: imageName, BoilerplatePath: s.boilerplatePath, @@ -117,15 +120,7 @@ func (s *initScaffolder) scaffold() error { &templates.Dockerfile{}, &templates.DockerIgnore{}, &kdefault.Kustomization{}, - &kdefault.ManagerWebhookPatch{}, - &rbac.RoleBinding{}, - &rbac.LeaderElectionRole{}, - &rbac.LeaderElectionRoleBinding{}, - &rbac.Kustomization{}, - &manager.Kustomization{}, - &webhook.Kustomization{}, - &webhook.KustomizeConfig{}, - &webhook.Service{}, + &kdefault.ManagerAuthProxyPatch{}, &prometheus.Kustomization{}, &prometheus.Monitor{}, &certmanager.Certificate{}, diff --git a/pkg/plugin/v3/scaffolds/internal/templates/api/webhook.go b/pkg/plugin/v3/scaffolds/internal/templates/api/webhook.go index 8ec9d3aed78..6e31d2f75ab 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/api/webhook.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/api/webhook.go @@ -36,6 +36,8 @@ type Webhook struct { // nolint:maligned // Is the Group domain for the Resource replacing '.' with '-' GroupDomainWithDash string + // Version of webhook marker to scaffold + WebhookVersion string // If scaffold the defaulting webhook Defaulting bool // If scaffold the validating webhook @@ -71,6 +73,10 @@ func (f *Webhook) SetTemplateDefaults() error { f.GroupDomainWithDash = strings.Replace(f.Resource.Domain, ".", "-", -1) + if f.WebhookVersion == "" { + f.WebhookVersion = "v1" + } + return nil } @@ -102,9 +108,10 @@ func (r *{{ .Resource.Kind }}) SetupWebhookWithManager(mgr ctrl.Manager) error { // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! ` + // TODO(estroz): update admissionReviewVersions to include v1 when controller-runtime supports that version. //nolint:lll defaultingWebhookTemplate = ` -// +kubebuilder:webhook:path=/mutate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=true,failurePolicy=fail,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=create;update,versions={{ .Resource.Version }},name=m{{ lower .Resource.Kind }}.kb.io +// +kubebuilder:webhook:{{ if ne .WebhookVersion "v1" }}webhookVersions={{"{"}}{{ .WebhookVersion }}{{"}"}},{{ end }}path=/mutate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=true,failurePolicy=fail,sideEffects=None,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=create;update,versions={{ .Resource.Version }},name=m{{ lower .Resource.Kind }}.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Defaulter = &{{ .Resource.Kind }}{} @@ -115,10 +122,12 @@ func (r *{{ .Resource.Kind }}) Default() { // TODO(user): fill in your defaulting logic. } ` + + // TODO(estroz): update admissionReviewVersions to include v1 when controller-runtime supports that version. //nolint:lll validatingWebhookTemplate = ` // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. -// +kubebuilder:webhook:verbs=create;update,path=/validate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=false,failurePolicy=fail,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},versions={{ .Resource.Version }},name=v{{ lower .Resource.Kind }}.kb.io +// +kubebuilder:webhook:{{ if ne .WebhookVersion "v1" }}webhookVersions={{"{"}}{{ .WebhookVersion }}{{"}"}},{{ end }}path=/validate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=false,failurePolicy=fail,sideEffects=None,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=create;update,versions={{ .Resource.Version }},name=v{{ lower .Resource.Kind }}.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Validator = &{{ .Resource.Kind }}{} diff --git a/pkg/plugin/v3/scaffolds/internal/templates/config/crd/kustomizeconfig.go b/pkg/plugin/v3/scaffolds/internal/templates/config/crd/kustomizeconfig.go index 99698e2c444..2aff259fdbc 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/config/crd/kustomizeconfig.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/config/crd/kustomizeconfig.go @@ -22,11 +22,16 @@ import ( "sigs.k8s.io/kubebuilder/v2/pkg/model/file" ) +const v1 = "v1" + var _ file.Template = &KustomizeConfig{} // KustomizeConfig scaffolds a file that configures the kustomization for the crd folder type KustomizeConfig struct { file.TemplateMixin + + // Version of CRD patch generated. + CRDVersion string } // SetTemplateDefaults implements file.Template @@ -37,6 +42,10 @@ func (f *KustomizeConfig) SetTemplateDefaults() error { f.TemplateBody = kustomizeConfigTemplate + if f.CRDVersion == "" { + f.CRDVersion = v1 + } + return nil } @@ -47,13 +56,23 @@ nameReference: version: v1 fieldSpecs: - kind: CustomResourceDefinition + version: {{ .CRDVersion }} group: apiextensions.k8s.io + {{- if ne .CRDVersion "v1" }} path: spec/conversion/webhookClientConfig/service/name + {{- else }} + path: spec/conversion/webhook/clientConfig/service/name + {{- end }} namespace: - kind: CustomResourceDefinition + version: {{ .CRDVersion }} group: apiextensions.k8s.io + {{- if ne .CRDVersion "v1" }} path: spec/conversion/webhookClientConfig/service/namespace + {{- else }} + path: spec/conversion/webhook/clientConfig/service/namespace + {{- end }} create: false varReference: diff --git a/pkg/plugin/v3/scaffolds/internal/templates/config/crd/patches/enablecainjection_patch.go b/pkg/plugin/v3/scaffolds/internal/templates/config/crd/patches/enablecainjection_patch.go index 1610d559038..a61e42dd3f0 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/config/crd/patches/enablecainjection_patch.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/config/crd/patches/enablecainjection_patch.go @@ -22,12 +22,17 @@ import ( "sigs.k8s.io/kubebuilder/v2/pkg/model/file" ) +const v1 = "v1" + var _ file.Template = &EnableCAInjectionPatch{} // EnableCAInjectionPatch scaffolds a file that defines the patch that injects CA into the CRD type EnableCAInjectionPatch struct { file.TemplateMixin file.ResourceMixin + + // Version of CRD patch to generate. + CRDVersion string } // SetTemplateDefaults implements file.Template @@ -39,12 +44,19 @@ func (f *EnableCAInjectionPatch) SetTemplateDefaults() error { f.TemplateBody = enableCAInjectionPatchTemplate + if f.CRDVersion == "" { + f.CRDVersion = v1 + } + return nil } +//nolint:lll const enableCAInjectionPatchTemplate = `# The following patch adds a directive for certmanager to inject CA into the CRD +{{- if ne .CRDVersion "v1" }} # CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +{{- end }} +apiVersion: apiextensions.k8s.io/{{ .CRDVersion }} kind: CustomResourceDefinition metadata: annotations: diff --git a/pkg/plugin/v3/scaffolds/internal/templates/config/crd/patches/enablewebhook_patch.go b/pkg/plugin/v3/scaffolds/internal/templates/config/crd/patches/enablewebhook_patch.go index 7e34e271390..2fedd028b88 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/config/crd/patches/enablewebhook_patch.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/config/crd/patches/enablewebhook_patch.go @@ -28,6 +28,9 @@ var _ file.Template = &EnableWebhookPatch{} type EnableWebhookPatch struct { file.TemplateMixin file.ResourceMixin + + // Version of CRD patch to generate. + CRDVersion string } // SetTemplateDefaults implements file.Template @@ -39,21 +42,36 @@ func (f *EnableWebhookPatch) SetTemplateDefaults() error { f.TemplateBody = enableWebhookPatchTemplate + if f.CRDVersion == "" { + f.CRDVersion = v1 + } + return nil } -const enableWebhookPatchTemplate = `# The following patch enables conversion webhook for CRD +const enableWebhookPatchTemplate = `# The following patch enables a conversion webhook for the CRD +{{- if ne .CRDVersion "v1" }} # CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +{{- end }} +apiVersion: apiextensions.k8s.io/{{ .CRDVersion }} kind: CustomResourceDefinition metadata: name: {{ .Resource.Plural }}.{{ .Resource.Domain }} spec: conversion: strategy: Webhook + {{- if ne .CRDVersion "v1" }} webhookClientConfig: service: namespace: system name: webhook-service path: /convert + {{- else }} + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert + {{- end }} ` diff --git a/pkg/plugin/v3/scaffolds/internal/templates/config/kdefault/enablecainection_patch.go b/pkg/plugin/v3/scaffolds/internal/templates/config/kdefault/enablecainection_patch.go index 60e03bb6a12..90ff233f4f8 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/config/kdefault/enablecainection_patch.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/config/kdefault/enablecainection_patch.go @@ -27,6 +27,9 @@ var _ file.Template = &WebhookCAInjectionPatch{} // WebhookCAInjectionPatch scaffolds a file that defines the patch that adds annotation to webhooks type WebhookCAInjectionPatch struct { file.TemplateMixin + + // Version of webhook patch to generate. + WebhookVersion string } // SetTemplateDefaults implements file.Template @@ -37,22 +40,26 @@ func (f *WebhookCAInjectionPatch) SetTemplateDefaults() error { f.TemplateBody = injectCAPatchTemplate - // If file webhookcainjection_patch.yaml exist, skip its creation + // If file exists (ex. because a webhook was already created), skip creation. f.IfExistsAction = file.Skip + if f.WebhookVersion == "" { + f.WebhookVersion = "v1" + } + return nil } const injectCAPatchTemplate = `# This patch add annotation to admission webhook config and # the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize. -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/{{ .WebhookVersion }} kind: MutatingWebhookConfiguration metadata: name: mutating-webhook-configuration annotations: cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) --- -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/{{ .WebhookVersion }} kind: ValidatingWebhookConfiguration metadata: name: validating-webhook-configuration diff --git a/pkg/plugin/v3/scaffolds/internal/templates/config/kdefault/webhook_manager_patch.go b/pkg/plugin/v3/scaffolds/internal/templates/config/kdefault/webhook_manager_patch.go index f5a7da3a632..dcae5e3b893 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/config/kdefault/webhook_manager_patch.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/config/kdefault/webhook_manager_patch.go @@ -37,6 +37,9 @@ func (f *ManagerWebhookPatch) SetTemplateDefaults() error { f.TemplateBody = managerWebhookPatchTemplate + // If file exists (ex. because a webhook was already created), skip creation. + f.IfExistsAction = file.Skip + return nil } diff --git a/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/kustomization.go b/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/kustomization.go index c1d20620f68..9714fe9a22c 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/kustomization.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/kustomization.go @@ -27,6 +27,9 @@ var _ file.Template = &Kustomization{} // Kustomization scaffolds a file that defines the kustomization scheme for the webhook folder type Kustomization struct { file.TemplateMixin + + // Version of webhook the project was configured with. + WebhookVersion string } // SetTemplateDefaults implements file.Template @@ -37,13 +40,18 @@ func (f *Kustomization) SetTemplateDefaults() error { f.TemplateBody = kustomizeWebhookTemplate - f.IfExistsAction = file.Error + // If file exists (ex. because a webhook was already created), skip creation. + f.IfExistsAction = file.Skip + + if f.WebhookVersion == "" { + f.WebhookVersion = "v1" + } return nil } const kustomizeWebhookTemplate = `resources: -- manifests.yaml +- manifests{{ if ne .WebhookVersion "v1" }}.{{ .WebhookVersion }}{{ end }}.yaml - service.yaml configurations: diff --git a/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/kustomizeconfig.go b/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/kustomizeconfig.go index 4ad49d66a09..86a6fa5c5b4 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/kustomizeconfig.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/kustomizeconfig.go @@ -37,7 +37,8 @@ func (f *KustomizeConfig) SetTemplateDefaults() error { f.TemplateBody = kustomizeConfigWebhookTemplate - f.IfExistsAction = file.Error + // If file exists (ex. because a webhook was already created), skip creation. + f.IfExistsAction = file.Skip return nil } diff --git a/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/service.go b/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/service.go index 86b238a1e8d..2edae713a45 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/service.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/config/webhook/service.go @@ -37,7 +37,8 @@ func (f *Service) SetTemplateDefaults() error { f.TemplateBody = serviceTemplate - f.IfExistsAction = file.Error + // If file exists (ex. because a webhook was already created), skip creation. + f.IfExistsAction = file.Skip return nil } diff --git a/pkg/plugin/v3/scaffolds/internal/templates/makefile.go b/pkg/plugin/v3/scaffolds/internal/templates/makefile.go index fa7c94b0c71..0b678ba35b1 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/makefile.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/makefile.go @@ -60,7 +60,7 @@ const makefileTemplate = ` # Image URL to use all building/pushing image targets IMG ?= {{ .Image }} # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) -CRD_OPTIONS ?= "crd:trivialVersions=true" +CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) diff --git a/pkg/plugin/v3/scaffolds/webhook.go b/pkg/plugin/v3/scaffolds/webhook.go index bf300d3becb..6104b8c3d4e 100644 --- a/pkg/plugin/v3/scaffolds/webhook.go +++ b/pkg/plugin/v3/scaffolds/webhook.go @@ -27,6 +27,7 @@ import ( "sigs.k8s.io/kubebuilder/v2/pkg/plugin/v3/scaffolds/internal/templates" "sigs.k8s.io/kubebuilder/v2/pkg/plugin/v3/scaffolds/internal/templates/api" "sigs.k8s.io/kubebuilder/v2/pkg/plugin/v3/scaffolds/internal/templates/config/kdefault" + "sigs.k8s.io/kubebuilder/v2/pkg/plugin/v3/scaffolds/internal/templates/config/webhook" ) var _ cmdutil.Scaffolder = &webhookScaffolder{} @@ -79,11 +80,21 @@ func (s *webhookScaffolder) scaffold() error { You need to implement the conversion.Hub and conversion.Convertible interfaces for your CRD types.`) } + s.config.UpdateResources(s.resource.GVK()) + if err := machinery.NewScaffold().Execute( s.newUniverse(), - &api.Webhook{Defaulting: s.defaulting, Validating: s.validation}, + &api.Webhook{ + WebhookVersion: s.resource.WebhookVersion, + Defaulting: s.defaulting, + Validating: s.validation, + }, &templates.MainUpdater{WireWebhook: true}, - &kdefault.WebhookCAInjectionPatch{}, + &kdefault.WebhookCAInjectionPatch{WebhookVersion: s.resource.WebhookVersion}, + &kdefault.ManagerWebhookPatch{}, + &webhook.Kustomization{WebhookVersion: s.resource.WebhookVersion}, + &webhook.KustomizeConfig{}, + &webhook.Service{}, ); err != nil { return err } diff --git a/pkg/plugin/v3/webhook.go b/pkg/plugin/v3/webhook.go index 0e7d6df5e20..4dc7717d6ef 100644 --- a/pkg/plugin/v3/webhook.go +++ b/pkg/plugin/v3/webhook.go @@ -30,6 +30,9 @@ import ( "sigs.k8s.io/kubebuilder/v2/pkg/plugin/v3/scaffolds" ) +// defaultWebhookVersion is the default mutating/validating webhook config API version to scaffold. +const defaultWebhookVersion = "v1" + type createWebhookSubcommand struct { config *config.Config // For help text. @@ -68,6 +71,8 @@ func (p *createWebhookSubcommand) BindFlags(fs *pflag.FlagSet) { fs.StringVar(&p.resource.Version, "version", "", "resource Version") fs.StringVar(&p.resource.Kind, "kind", "", "resource Kind") fs.StringVar(&p.resource.Plural, "resource", "", "resource Resource") + fs.StringVar(&p.resource.WebhookVersion, "webhook-version", defaultWebhookVersion, + "version of {Mutating,Validating}WebhookConfigurations to scaffold. Options: [v1, v1beta1]") fs.BoolVar(&p.defaulting, "defaulting", false, "if set, scaffold the defaulting webhook") @@ -101,6 +106,11 @@ func (p *createWebhookSubcommand) Validate() error { " kind and version provided", p.commandName) } + if !p.config.IsWebhookVersionCompatible(p.resource.WebhookVersion) { + return fmt.Errorf("only one webhook version can be used for all resources, cannot add %q", + p.resource.WebhookVersion) + } + return nil } diff --git a/test/e2e/utils/kubectl.go b/test/e2e/utils/kubectl.go index e88533738aa..9ad324202dd 100644 --- a/test/e2e/utils/kubectl.go +++ b/test/e2e/utils/kubectl.go @@ -17,8 +17,10 @@ limitations under the License. package utils import ( + "encoding/json" "errors" "os/exec" + "strconv" "strings" ) @@ -90,3 +92,61 @@ func (k *Kubectl) Wait(inNamespace bool, cmdOptions ...string) (string, error) { } return k.Command(ops...) } + +// VersionInfo holds a subset of client/server version information. +type VersionInfo struct { + Major string `json:"major"` + Minor string `json:"minor"` + GitVersion string `json:"gitVersion"` + + // Leaving major/minor int fields unexported prevents them from being set + // while leaving their exported counterparts untouched -> incorrect marshaled format. + major, minor uint64 +} + +// GetMajorInt returns the uint64 representation of vi.Major. +func (vi VersionInfo) GetMajorInt() uint64 { return vi.major } + +// GetMinorInt returns the uint64 representation of vi.Minor. +func (vi VersionInfo) GetMinorInt() uint64 { return vi.minor } + +func (vi *VersionInfo) parseVersionInts() (err error) { + if vi.major, err = strconv.ParseUint(vi.Major, 10, 64); err != nil { + return err + } + if vi.minor, err = strconv.ParseUint(vi.Minor, 10, 64); err != nil { + return err + } + return nil +} + +// KubectlVersion holds a subset of both client and server versions. +type KubectlVersion struct { + ClientVersion VersionInfo `json:"clientVersion,omitempty"` + ServerVersion VersionInfo `json:"serverVersion,omitempty"` +} + +func (v *KubectlVersion) prepare() (err error) { + if err = v.ClientVersion.parseVersionInts(); err != nil { + return err + } + if err = v.ServerVersion.parseVersionInts(); err != nil { + return err + } + return nil +} + +// Version is a func to run kubectl version command +func (k *Kubectl) Version() (ver KubectlVersion, err error) { + var out string + if out, err = k.Command("version", "-o", "json"); err != nil { + return KubectlVersion{}, err + } + if err = json.Unmarshal([]byte(out), &ver); err != nil { + return KubectlVersion{}, err + } + if err = ver.prepare(); err != nil { + return KubectlVersion{}, err + } + return ver, nil +} diff --git a/test/e2e/v3/generate_test.go b/test/e2e/v3/generate_test.go index 3454e68d8f6..075f772c32f 100644 --- a/test/e2e/v3/generate_test.go +++ b/test/e2e/v3/generate_test.go @@ -18,6 +18,7 @@ package v3 import ( "fmt" + "io/ioutil" "path/filepath" "strings" @@ -122,7 +123,7 @@ Count int `+"`"+`json:"count,omitempty"`+"`"+` } // GenerateV3 implements a go/v3(-alpha) plugin project defined by a TestContext. -func GenerateV3(kbc *utils.TestContext) { +func GenerateV3(kbc *utils.TestContext, crdAndWebhookVersion string) { var err error By("initializing a v3 project") @@ -134,6 +135,22 @@ func GenerateV3(kbc *utils.TestContext) { ) ExpectWithOffset(1, err).NotTo(HaveOccurred()) + // Users have to manually add "crdVersions={non-default-version}" to their Makefile + // if using a non-default CRD version. + if crdAndWebhookVersion != "v1" { + makefilePath := filepath.Join(kbc.Dir, "Makefile") + bs, err := ioutil.ReadFile(makefilePath) + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + content, err := utils.EnsureExistAndReplace( + string(bs), + `CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"`, + fmt.Sprintf(`CRD_OPTIONS ?= "crd:crdVersions={%s},trivialVersions=true,preserveUnknownFields=false"`, + crdAndWebhookVersion), + ) + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + ExpectWithOffset(1, ioutil.WriteFile(makefilePath, []byte(content), 0600)).To(Succeed()) + } + By("creating API definition") err = kbc.CreateAPI( "--group", kbc.Group, @@ -143,6 +160,7 @@ func GenerateV3(kbc *utils.TestContext) { "--resource", "--controller", "--make=false", + "--crd-version", crdAndWebhookVersion, ) ExpectWithOffset(1, err).NotTo(HaveOccurred()) @@ -162,6 +180,7 @@ Count int `+"`"+`json:"count,omitempty"`+"`"+` "--kind", kbc.Kind, "--defaulting", "--programmatic-validation", + "--webhook-version", crdAndWebhookVersion, ) ExpectWithOffset(1, err).NotTo(HaveOccurred()) diff --git a/test/e2e/v3/plugin_cluster_test.go b/test/e2e/v3/plugin_cluster_test.go index b0a33727833..3c04b8e357c 100644 --- a/test/e2e/v3/plugin_cluster_test.go +++ b/test/e2e/v3/plugin_cluster_test.go @@ -33,7 +33,8 @@ import ( var _ = Describe("kubebuilder", func() { Context("project version 3", func() { var ( - kbc *utils.TestContext + kbc *utils.TestContext + k8sVer utils.KubectlVersion ) BeforeEach(func() { @@ -42,6 +43,10 @@ var _ = Describe("kubebuilder", func() { Expect(err).NotTo(HaveOccurred()) Expect(kbc.Prepare()).To(Succeed()) + // Get versions to determine which tests to skip. + k8sVer, err = kbc.Kubectl.Version() + Expect(err).NotTo(HaveOccurred()) + By("installing the cert-manager bundle") Expect(kbc.InstallCertManager()).To(Succeed()) @@ -71,7 +76,21 @@ var _ = Describe("kubebuilder", func() { }) Context("plugin go.kubebuilder.io/v3-alpha", func() { It("should generate a runnable project", func() { - GenerateV3(kbc) + // Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist. + if srvVer := k8sVer.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 16 { + Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks", srvVer.GitVersion)) + } + + GenerateV3(kbc, "v1") + Run(kbc) + }) + It("should generate a runnable project with v1beta1 CRDs and Webhooks", func() { + // Skip if cluster version < 1.15, when `.spec.preserveUnknownFields` was not a v1beta1 CRD field. + if srvVer := k8sVer.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 15 { + Skip(fmt.Sprintf("cluster version %s does not support project defaults", srvVer.GitVersion)) + } + + GenerateV3(kbc, "v1beta1") Run(kbc) }) }) diff --git a/testdata/project-v3-addon/Makefile b/testdata/project-v3-addon/Makefile index fb72a7e7fab..1e1f23f9f53 100644 --- a/testdata/project-v3-addon/Makefile +++ b/testdata/project-v3-addon/Makefile @@ -2,7 +2,7 @@ # Image URL to use all building/pushing image targets IMG ?= controller:latest # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) -CRD_OPTIONS ?= "crd:trivialVersions=true" +CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -72,7 +72,7 @@ docker-push: # Download controller-gen locally if necessary CONTROLLER_GEN = $(shell pwd)/bin/controller-gen controller-gen: - $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0) + $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1) # Download kustomize locally if necessary KUSTOMIZE = $(shell pwd)/bin/kustomize diff --git a/testdata/project-v3-addon/PROJECT b/testdata/project-v3-addon/PROJECT index 9732a2cd5e1..825040c5892 100644 --- a/testdata/project-v3-addon/PROJECT +++ b/testdata/project-v3-addon/PROJECT @@ -3,13 +3,16 @@ layout: go.kubebuilder.io/v3-alpha projectName: project-v3-addon repo: sigs.k8s.io/kubebuilder/testdata/project-v3-addon resources: -- group: crew +- crdVersion: v1 + group: crew kind: Captain version: v1 -- group: crew +- crdVersion: v1 + group: crew kind: FirstMate version: v1 -- group: crew +- crdVersion: v1 + group: crew kind: Admiral version: v1 version: 3-alpha diff --git a/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_admirals.yaml b/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_admirals.yaml index b63e938d239..57fd324668b 100644 --- a/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_admirals.yaml +++ b/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_admirals.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: admirals.crew.testproject.org spec: @@ -15,60 +15,59 @@ spec: plural: admirals singular: admiral scope: Cluster - subresources: - status: {} - validation: - openAPIV3Schema: - description: Admiral is the Schema for the admirals API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: AdmiralSpec defines the desired state of Admiral - properties: - channel: - description: 'Channel specifies a channel that can be used to resolve - a specific addon, eg: stable It will be ignored if Version is specified' - type: string - patches: - items: - type: object - type: array - version: - description: Version specifies the exact addon version to be deployed, - eg 1.2.3 It should not be specified if Channel is specified - type: string - type: object - status: - description: AdmiralStatus defines the observed state of Admiral - properties: - errors: - items: - type: string - type: array - healthy: - type: boolean - phase: - type: string - required: - - healthy - type: object - type: object - version: v1 versions: - name: v1 + schema: + openAPIV3Schema: + description: Admiral is the Schema for the admirals API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: AdmiralSpec defines the desired state of Admiral + properties: + channel: + description: 'Channel specifies a channel that can be used to resolve + a specific addon, eg: stable It will be ignored if Version is specified' + type: string + patches: + items: + type: object + type: array + version: + description: Version specifies the exact addon version to be deployed, + eg 1.2.3 It should not be specified if Channel is specified + type: string + type: object + status: + description: AdmiralStatus defines the observed state of Admiral + properties: + errors: + items: + type: string + type: array + healthy: + type: boolean + phase: + type: string + required: + - healthy + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_captains.yaml b/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_captains.yaml index f9a1e3de14d..fdc98d0233d 100644 --- a/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_captains.yaml +++ b/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_captains.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: captains.crew.testproject.org spec: @@ -15,60 +15,59 @@ spec: plural: captains singular: captain scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Captain is the Schema for the captains API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: CaptainSpec defines the desired state of Captain - properties: - channel: - description: 'Channel specifies a channel that can be used to resolve - a specific addon, eg: stable It will be ignored if Version is specified' - type: string - patches: - items: - type: object - type: array - version: - description: Version specifies the exact addon version to be deployed, - eg 1.2.3 It should not be specified if Channel is specified - type: string - type: object - status: - description: CaptainStatus defines the observed state of Captain - properties: - errors: - items: - type: string - type: array - healthy: - type: boolean - phase: - type: string - required: - - healthy - type: object - type: object - version: v1 versions: - name: v1 + schema: + openAPIV3Schema: + description: Captain is the Schema for the captains API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: CaptainSpec defines the desired state of Captain + properties: + channel: + description: 'Channel specifies a channel that can be used to resolve + a specific addon, eg: stable It will be ignored if Version is specified' + type: string + patches: + items: + type: object + type: array + version: + description: Version specifies the exact addon version to be deployed, + eg 1.2.3 It should not be specified if Channel is specified + type: string + type: object + status: + description: CaptainStatus defines the observed state of Captain + properties: + errors: + items: + type: string + type: array + healthy: + type: boolean + phase: + type: string + required: + - healthy + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_firstmates.yaml b/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_firstmates.yaml index da3f9410da9..dac655c8885 100644 --- a/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_firstmates.yaml +++ b/testdata/project-v3-addon/config/crd/bases/crew.testproject.org_firstmates.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: firstmates.crew.testproject.org spec: @@ -15,60 +15,59 @@ spec: plural: firstmates singular: firstmate scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: FirstMate is the Schema for the firstmates API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: FirstMateSpec defines the desired state of FirstMate - properties: - channel: - description: 'Channel specifies a channel that can be used to resolve - a specific addon, eg: stable It will be ignored if Version is specified' - type: string - patches: - items: - type: object - type: array - version: - description: Version specifies the exact addon version to be deployed, - eg 1.2.3 It should not be specified if Channel is specified - type: string - type: object - status: - description: FirstMateStatus defines the observed state of FirstMate - properties: - errors: - items: - type: string - type: array - healthy: - type: boolean - phase: - type: string - required: - - healthy - type: object - type: object - version: v1 versions: - name: v1 + schema: + openAPIV3Schema: + description: FirstMate is the Schema for the firstmates API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: FirstMateSpec defines the desired state of FirstMate + properties: + channel: + description: 'Channel specifies a channel that can be used to resolve + a specific addon, eg: stable It will be ignored if Version is specified' + type: string + patches: + items: + type: object + type: array + version: + description: Version specifies the exact addon version to be deployed, + eg 1.2.3 It should not be specified if Channel is specified + type: string + type: object + status: + description: FirstMateStatus defines the observed state of FirstMate + properties: + errors: + items: + type: string + type: array + healthy: + type: boolean + phase: + type: string + required: + - healthy + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-addon/config/crd/kustomizeconfig.yaml b/testdata/project-v3-addon/config/crd/kustomizeconfig.yaml index 6f83d9a94bc..ec5c150a9df 100644 --- a/testdata/project-v3-addon/config/crd/kustomizeconfig.yaml +++ b/testdata/project-v3-addon/config/crd/kustomizeconfig.yaml @@ -4,13 +4,15 @@ nameReference: version: v1 fieldSpecs: - kind: CustomResourceDefinition + version: v1 group: apiextensions.k8s.io - path: spec/conversion/webhookClientConfig/service/name + path: spec/conversion/webhook/clientConfig/service/name namespace: - kind: CustomResourceDefinition + version: v1 group: apiextensions.k8s.io - path: spec/conversion/webhookClientConfig/service/namespace + path: spec/conversion/webhook/clientConfig/service/namespace create: false varReference: diff --git a/testdata/project-v3-addon/config/crd/patches/cainjection_in_admirals.yaml b/testdata/project-v3-addon/config/crd/patches/cainjection_in_admirals.yaml index 8573317f652..ba7fea6e88d 100644 --- a/testdata/project-v3-addon/config/crd/patches/cainjection_in_admirals.yaml +++ b/testdata/project-v3-addon/config/crd/patches/cainjection_in_admirals.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-addon/config/crd/patches/cainjection_in_captains.yaml b/testdata/project-v3-addon/config/crd/patches/cainjection_in_captains.yaml index 72918ce20f4..9c9d61b0c97 100644 --- a/testdata/project-v3-addon/config/crd/patches/cainjection_in_captains.yaml +++ b/testdata/project-v3-addon/config/crd/patches/cainjection_in_captains.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-addon/config/crd/patches/cainjection_in_firstmates.yaml b/testdata/project-v3-addon/config/crd/patches/cainjection_in_firstmates.yaml index 271b973cb56..6849f00fb85 100644 --- a/testdata/project-v3-addon/config/crd/patches/cainjection_in_firstmates.yaml +++ b/testdata/project-v3-addon/config/crd/patches/cainjection_in_firstmates.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-addon/config/crd/patches/webhook_in_admirals.yaml b/testdata/project-v3-addon/config/crd/patches/webhook_in_admirals.yaml index a8865b0b87d..e7cef4898e3 100644 --- a/testdata/project-v3-addon/config/crd/patches/webhook_in_admirals.yaml +++ b/testdata/project-v3-addon/config/crd/patches/webhook_in_admirals.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: admirals.crew.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-addon/config/crd/patches/webhook_in_captains.yaml b/testdata/project-v3-addon/config/crd/patches/webhook_in_captains.yaml index 69ee3459f4e..39ef2528c5a 100644 --- a/testdata/project-v3-addon/config/crd/patches/webhook_in_captains.yaml +++ b/testdata/project-v3-addon/config/crd/patches/webhook_in_captains.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: captains.crew.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-addon/config/crd/patches/webhook_in_firstmates.yaml b/testdata/project-v3-addon/config/crd/patches/webhook_in_firstmates.yaml index 585eccf7af6..a644d053242 100644 --- a/testdata/project-v3-addon/config/crd/patches/webhook_in_firstmates.yaml +++ b/testdata/project-v3-addon/config/crd/patches/webhook_in_firstmates.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: firstmates.crew.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-addon/config/default/manager_webhook_patch.yaml b/testdata/project-v3-addon/config/default/manager_webhook_patch.yaml deleted file mode 100644 index 738de350b71..00000000000 --- a/testdata/project-v3-addon/config/default/manager_webhook_patch.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - ports: - - containerPort: 9443 - name: webhook-server - protocol: TCP - volumeMounts: - - mountPath: /tmp/k8s-webhook-server/serving-certs - name: cert - readOnly: true - volumes: - - name: cert - secret: - defaultMode: 420 - secretName: webhook-server-cert diff --git a/testdata/project-v3-addon/config/webhook/kustomization.yaml b/testdata/project-v3-addon/config/webhook/kustomization.yaml deleted file mode 100644 index 9cf26134e4d..00000000000 --- a/testdata/project-v3-addon/config/webhook/kustomization.yaml +++ /dev/null @@ -1,6 +0,0 @@ -resources: -- manifests.yaml -- service.yaml - -configurations: -- kustomizeconfig.yaml diff --git a/testdata/project-v3-addon/config/webhook/kustomizeconfig.yaml b/testdata/project-v3-addon/config/webhook/kustomizeconfig.yaml deleted file mode 100644 index 25e21e3c963..00000000000 --- a/testdata/project-v3-addon/config/webhook/kustomizeconfig.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# the following config is for teaching kustomize where to look at when substituting vars. -# It requires kustomize v2.1.0 or newer to work properly. -nameReference: -- kind: Service - version: v1 - fieldSpecs: - - kind: MutatingWebhookConfiguration - group: admissionregistration.k8s.io - path: webhooks/clientConfig/service/name - - kind: ValidatingWebhookConfiguration - group: admissionregistration.k8s.io - path: webhooks/clientConfig/service/name - -namespace: -- kind: MutatingWebhookConfiguration - group: admissionregistration.k8s.io - path: webhooks/clientConfig/service/namespace - create: true -- kind: ValidatingWebhookConfiguration - group: admissionregistration.k8s.io - path: webhooks/clientConfig/service/namespace - create: true - -varReference: -- path: metadata/annotations diff --git a/testdata/project-v3-addon/config/webhook/service.yaml b/testdata/project-v3-addon/config/webhook/service.yaml deleted file mode 100644 index 31e0f829591..00000000000 --- a/testdata/project-v3-addon/config/webhook/service.yaml +++ /dev/null @@ -1,12 +0,0 @@ - -apiVersion: v1 -kind: Service -metadata: - name: webhook-service - namespace: system -spec: - ports: - - port: 443 - targetPort: 9443 - selector: - control-plane: controller-manager diff --git a/testdata/project-v3-multigroup/Makefile b/testdata/project-v3-multigroup/Makefile index fb72a7e7fab..1e1f23f9f53 100644 --- a/testdata/project-v3-multigroup/Makefile +++ b/testdata/project-v3-multigroup/Makefile @@ -2,7 +2,7 @@ # Image URL to use all building/pushing image targets IMG ?= controller:latest # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) -CRD_OPTIONS ?= "crd:trivialVersions=true" +CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -72,7 +72,7 @@ docker-push: # Download controller-gen locally if necessary CONTROLLER_GEN = $(shell pwd)/bin/controller-gen controller-gen: - $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0) + $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1) # Download kustomize locally if necessary KUSTOMIZE = $(shell pwd)/bin/kustomize diff --git a/testdata/project-v3-multigroup/PROJECT b/testdata/project-v3-multigroup/PROJECT index b1bcfef24bb..a612501d6c5 100644 --- a/testdata/project-v3-multigroup/PROJECT +++ b/testdata/project-v3-multigroup/PROJECT @@ -4,27 +4,40 @@ multigroup: true projectName: project-v3-multigroup repo: sigs.k8s.io/kubebuilder/testdata/project-v3-multigroup resources: -- group: crew +- crdVersion: v1 + group: crew kind: Captain version: v1 -- group: ship + webhookVersion: v1 +- crdVersion: v1 + group: ship kind: Frigate version: v1beta1 -- group: ship + webhookVersion: v1 +- crdVersion: v1 + group: ship kind: Destroyer version: v1 -- group: ship + webhookVersion: v1 +- crdVersion: v1 + group: ship kind: Cruiser version: v2alpha1 -- group: sea-creatures + webhookVersion: v1 +- crdVersion: v1 + group: sea-creatures kind: Kraken version: v1beta1 -- group: sea-creatures +- crdVersion: v1 + group: sea-creatures kind: Leviathan version: v1beta2 -- group: foo.policy +- crdVersion: v1 + group: foo.policy kind: HealthCheckPolicy version: v1 -- kind: Lakers +- crdVersion: v1 + kind: Lakers version: v1 + webhookVersion: v1 version: 3-alpha diff --git a/testdata/project-v3-multigroup/apis/crew/v1/captain_webhook.go b/testdata/project-v3-multigroup/apis/crew/v1/captain_webhook.go index 6f206e0f7e5..1c6b4211fb6 100644 --- a/testdata/project-v3-multigroup/apis/crew/v1/captain_webhook.go +++ b/testdata/project-v3-multigroup/apis/crew/v1/captain_webhook.go @@ -34,7 +34,7 @@ func (r *Captain) SetupWebhookWithManager(mgr ctrl.Manager) error { // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// +kubebuilder:webhook:path=/mutate-crew-testproject-org-v1-captain,mutating=true,failurePolicy=fail,groups=crew.testproject.org,resources=captains,verbs=create;update,versions=v1,name=mcaptain.kb.io +// +kubebuilder:webhook:path=/mutate-crew-testproject-org-v1-captain,mutating=true,failurePolicy=fail,sideEffects=None,groups=crew.testproject.org,resources=captains,verbs=create;update,versions=v1,name=mcaptain.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Defaulter = &Captain{} @@ -46,7 +46,7 @@ func (r *Captain) Default() { } // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. -// +kubebuilder:webhook:verbs=create;update,path=/validate-crew-testproject-org-v1-captain,mutating=false,failurePolicy=fail,groups=crew.testproject.org,resources=captains,versions=v1,name=vcaptain.kb.io +// +kubebuilder:webhook:path=/validate-crew-testproject-org-v1-captain,mutating=false,failurePolicy=fail,sideEffects=None,groups=crew.testproject.org,resources=captains,verbs=create;update,versions=v1,name=vcaptain.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Validator = &Captain{} diff --git a/testdata/project-v3-multigroup/apis/ship/v1/destroyer_webhook.go b/testdata/project-v3-multigroup/apis/ship/v1/destroyer_webhook.go index 3fba6666a28..c9c9c8f8ff9 100644 --- a/testdata/project-v3-multigroup/apis/ship/v1/destroyer_webhook.go +++ b/testdata/project-v3-multigroup/apis/ship/v1/destroyer_webhook.go @@ -33,7 +33,7 @@ func (r *Destroyer) SetupWebhookWithManager(mgr ctrl.Manager) error { // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// +kubebuilder:webhook:path=/mutate-ship-testproject-org-v1-destroyer,mutating=true,failurePolicy=fail,groups=ship.testproject.org,resources=destroyers,verbs=create;update,versions=v1,name=mdestroyer.kb.io +// +kubebuilder:webhook:path=/mutate-ship-testproject-org-v1-destroyer,mutating=true,failurePolicy=fail,sideEffects=None,groups=ship.testproject.org,resources=destroyers,verbs=create;update,versions=v1,name=mdestroyer.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Defaulter = &Destroyer{} diff --git a/testdata/project-v3-multigroup/apis/ship/v2alpha1/cruiser_webhook.go b/testdata/project-v3-multigroup/apis/ship/v2alpha1/cruiser_webhook.go index eeb241633e8..fe63ee67e95 100644 --- a/testdata/project-v3-multigroup/apis/ship/v2alpha1/cruiser_webhook.go +++ b/testdata/project-v3-multigroup/apis/ship/v2alpha1/cruiser_webhook.go @@ -35,7 +35,7 @@ func (r *Cruiser) SetupWebhookWithManager(mgr ctrl.Manager) error { // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. -// +kubebuilder:webhook:verbs=create;update,path=/validate-ship-testproject-org-v2alpha1-cruiser,mutating=false,failurePolicy=fail,groups=ship.testproject.org,resources=cruisers,versions=v2alpha1,name=vcruiser.kb.io +// +kubebuilder:webhook:path=/validate-ship-testproject-org-v2alpha1-cruiser,mutating=false,failurePolicy=fail,sideEffects=None,groups=ship.testproject.org,resources=cruisers,verbs=create;update,versions=v2alpha1,name=vcruiser.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Validator = &Cruiser{} diff --git a/testdata/project-v3-multigroup/apis/v1/lakers_webhook.go b/testdata/project-v3-multigroup/apis/v1/lakers_webhook.go index c026c70cadd..525ca8c4788 100644 --- a/testdata/project-v3-multigroup/apis/v1/lakers_webhook.go +++ b/testdata/project-v3-multigroup/apis/v1/lakers_webhook.go @@ -34,7 +34,7 @@ func (r *Lakers) SetupWebhookWithManager(mgr ctrl.Manager) error { // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// +kubebuilder:webhook:path=/mutate-testproject-org-v1-lakers,mutating=true,failurePolicy=fail,groups=testproject.org,resources=lakers,verbs=create;update,versions=v1,name=mlakers.kb.io +// +kubebuilder:webhook:path=/mutate-testproject-org-v1-lakers,mutating=true,failurePolicy=fail,sideEffects=None,groups=testproject.org,resources=lakers,verbs=create;update,versions=v1,name=mlakers.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Defaulter = &Lakers{} @@ -46,7 +46,7 @@ func (r *Lakers) Default() { } // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. -// +kubebuilder:webhook:verbs=create;update,path=/validate-testproject-org-v1-lakers,mutating=false,failurePolicy=fail,groups=testproject.org,resources=lakers,versions=v1,name=vlakers.kb.io +// +kubebuilder:webhook:path=/validate-testproject-org-v1-lakers,mutating=false,failurePolicy=fail,sideEffects=None,groups=testproject.org,resources=lakers,verbs=create;update,versions=v1,name=vlakers.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Validator = &Lakers{} diff --git a/testdata/project-v3-multigroup/config/crd/bases/crew.testproject.org_captains.yaml b/testdata/project-v3-multigroup/config/crd/bases/crew.testproject.org_captains.yaml index 3efe21f23ef..012b4d166d8 100644 --- a/testdata/project-v3-multigroup/config/crd/bases/crew.testproject.org_captains.yaml +++ b/testdata/project-v3-multigroup/config/crd/bases/crew.testproject.org_captains.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: captains.crew.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: captains singular: captain scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Captain is the Schema for the captains API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: CaptainSpec defines the desired state of Captain - properties: - foo: - description: Foo is an example field of Captain. Edit Captain_types.go - to remove/update - type: string - type: object - status: - description: CaptainStatus defines the observed state of Captain - type: object - type: object - version: v1 versions: - name: v1 + schema: + openAPIV3Schema: + description: Captain is the Schema for the captains API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: CaptainSpec defines the desired state of Captain + properties: + foo: + description: Foo is an example field of Captain. Edit Captain_types.go + to remove/update + type: string + type: object + status: + description: CaptainStatus defines the observed state of Captain + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-multigroup/config/crd/bases/foo.policy.testproject.org_healthcheckpolicies.yaml b/testdata/project-v3-multigroup/config/crd/bases/foo.policy.testproject.org_healthcheckpolicies.yaml index 6b20d7989a3..7b789653505 100644 --- a/testdata/project-v3-multigroup/config/crd/bases/foo.policy.testproject.org_healthcheckpolicies.yaml +++ b/testdata/project-v3-multigroup/config/crd/bases/foo.policy.testproject.org_healthcheckpolicies.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: healthcheckpolicies.foo.policy.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: healthcheckpolicies singular: healthcheckpolicy scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: HealthCheckPolicy is the Schema for the healthcheckpolicies API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: HealthCheckPolicySpec defines the desired state of HealthCheckPolicy - properties: - foo: - description: Foo is an example field of HealthCheckPolicy. Edit HealthCheckPolicy_types.go - to remove/update - type: string - type: object - status: - description: HealthCheckPolicyStatus defines the observed state of HealthCheckPolicy - type: object - type: object - version: v1 versions: - name: v1 + schema: + openAPIV3Schema: + description: HealthCheckPolicy is the Schema for the healthcheckpolicies API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: HealthCheckPolicySpec defines the desired state of HealthCheckPolicy + properties: + foo: + description: Foo is an example field of HealthCheckPolicy. Edit HealthCheckPolicy_types.go + to remove/update + type: string + type: object + status: + description: HealthCheckPolicyStatus defines the observed state of HealthCheckPolicy + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-multigroup/config/crd/bases/sea-creatures.testproject.org_krakens.yaml b/testdata/project-v3-multigroup/config/crd/bases/sea-creatures.testproject.org_krakens.yaml index 9ba1252e889..1eab23080da 100644 --- a/testdata/project-v3-multigroup/config/crd/bases/sea-creatures.testproject.org_krakens.yaml +++ b/testdata/project-v3-multigroup/config/crd/bases/sea-creatures.testproject.org_krakens.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: krakens.sea-creatures.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: krakens singular: kraken scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Kraken is the Schema for the krakens API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: KrakenSpec defines the desired state of Kraken - properties: - foo: - description: Foo is an example field of Kraken. Edit Kraken_types.go - to remove/update - type: string - type: object - status: - description: KrakenStatus defines the observed state of Kraken - type: object - type: object - version: v1beta1 versions: - name: v1beta1 + schema: + openAPIV3Schema: + description: Kraken is the Schema for the krakens API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: KrakenSpec defines the desired state of Kraken + properties: + foo: + description: Foo is an example field of Kraken. Edit Kraken_types.go + to remove/update + type: string + type: object + status: + description: KrakenStatus defines the observed state of Kraken + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-multigroup/config/crd/bases/sea-creatures.testproject.org_leviathans.yaml b/testdata/project-v3-multigroup/config/crd/bases/sea-creatures.testproject.org_leviathans.yaml index 5417c98bc95..90d47587d99 100644 --- a/testdata/project-v3-multigroup/config/crd/bases/sea-creatures.testproject.org_leviathans.yaml +++ b/testdata/project-v3-multigroup/config/crd/bases/sea-creatures.testproject.org_leviathans.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: leviathans.sea-creatures.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: leviathans singular: leviathan scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Leviathan is the Schema for the leviathans API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: LeviathanSpec defines the desired state of Leviathan - properties: - foo: - description: Foo is an example field of Leviathan. Edit Leviathan_types.go - to remove/update - type: string - type: object - status: - description: LeviathanStatus defines the observed state of Leviathan - type: object - type: object - version: v1beta2 versions: - name: v1beta2 + schema: + openAPIV3Schema: + description: Leviathan is the Schema for the leviathans API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: LeviathanSpec defines the desired state of Leviathan + properties: + foo: + description: Foo is an example field of Leviathan. Edit Leviathan_types.go + to remove/update + type: string + type: object + status: + description: LeviathanStatus defines the observed state of Leviathan + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_cruisers.yaml b/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_cruisers.yaml index 1b104f5a97c..4155f5decf9 100644 --- a/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_cruisers.yaml +++ b/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_cruisers.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: cruisers.ship.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: cruisers singular: cruiser scope: Cluster - subresources: - status: {} - validation: - openAPIV3Schema: - description: Cruiser is the Schema for the cruisers API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: CruiserSpec defines the desired state of Cruiser - properties: - foo: - description: Foo is an example field of Cruiser. Edit Cruiser_types.go - to remove/update - type: string - type: object - status: - description: CruiserStatus defines the observed state of Cruiser - type: object - type: object - version: v2alpha1 versions: - name: v2alpha1 + schema: + openAPIV3Schema: + description: Cruiser is the Schema for the cruisers API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: CruiserSpec defines the desired state of Cruiser + properties: + foo: + description: Foo is an example field of Cruiser. Edit Cruiser_types.go + to remove/update + type: string + type: object + status: + description: CruiserStatus defines the observed state of Cruiser + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_destroyers.yaml b/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_destroyers.yaml index de78bd49fcc..d683f9ecd07 100644 --- a/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_destroyers.yaml +++ b/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_destroyers.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: destroyers.ship.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: destroyers singular: destroyer scope: Cluster - subresources: - status: {} - validation: - openAPIV3Schema: - description: Destroyer is the Schema for the destroyers API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: DestroyerSpec defines the desired state of Destroyer - properties: - foo: - description: Foo is an example field of Destroyer. Edit Destroyer_types.go - to remove/update - type: string - type: object - status: - description: DestroyerStatus defines the observed state of Destroyer - type: object - type: object - version: v1 versions: - name: v1 + schema: + openAPIV3Schema: + description: Destroyer is the Schema for the destroyers API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: DestroyerSpec defines the desired state of Destroyer + properties: + foo: + description: Foo is an example field of Destroyer. Edit Destroyer_types.go + to remove/update + type: string + type: object + status: + description: DestroyerStatus defines the observed state of Destroyer + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_frigates.yaml b/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_frigates.yaml index c73e2ce8920..36e2142c395 100644 --- a/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_frigates.yaml +++ b/testdata/project-v3-multigroup/config/crd/bases/ship.testproject.org_frigates.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: frigates.ship.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: frigates singular: frigate scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Frigate is the Schema for the frigates API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: FrigateSpec defines the desired state of Frigate - properties: - foo: - description: Foo is an example field of Frigate. Edit Frigate_types.go - to remove/update - type: string - type: object - status: - description: FrigateStatus defines the observed state of Frigate - type: object - type: object - version: v1beta1 versions: - name: v1beta1 + schema: + openAPIV3Schema: + description: Frigate is the Schema for the frigates API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: FrigateSpec defines the desired state of Frigate + properties: + foo: + description: Foo is an example field of Frigate. Edit Frigate_types.go + to remove/update + type: string + type: object + status: + description: FrigateStatus defines the observed state of Frigate + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-multigroup/config/crd/bases/testproject.org_lakers.yaml b/testdata/project-v3-multigroup/config/crd/bases/testproject.org_lakers.yaml index b0b15c08fd8..b028e81ca67 100644 --- a/testdata/project-v3-multigroup/config/crd/bases/testproject.org_lakers.yaml +++ b/testdata/project-v3-multigroup/config/crd/bases/testproject.org_lakers.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: lakers.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: lakers singular: lakers scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Lakers is the Schema for the lakers API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: LakersSpec defines the desired state of Lakers - properties: - foo: - description: Foo is an example field of Lakers. Edit Lakers_types.go - to remove/update - type: string - type: object - status: - description: LakersStatus defines the observed state of Lakers - type: object - type: object - version: v1 versions: - name: v1 + schema: + openAPIV3Schema: + description: Lakers is the Schema for the lakers API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: LakersSpec defines the desired state of Lakers + properties: + foo: + description: Foo is an example field of Lakers. Edit Lakers_types.go + to remove/update + type: string + type: object + status: + description: LakersStatus defines the observed state of Lakers + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3-multigroup/config/crd/kustomizeconfig.yaml b/testdata/project-v3-multigroup/config/crd/kustomizeconfig.yaml index 6f83d9a94bc..ec5c150a9df 100644 --- a/testdata/project-v3-multigroup/config/crd/kustomizeconfig.yaml +++ b/testdata/project-v3-multigroup/config/crd/kustomizeconfig.yaml @@ -4,13 +4,15 @@ nameReference: version: v1 fieldSpecs: - kind: CustomResourceDefinition + version: v1 group: apiextensions.k8s.io - path: spec/conversion/webhookClientConfig/service/name + path: spec/conversion/webhook/clientConfig/service/name namespace: - kind: CustomResourceDefinition + version: v1 group: apiextensions.k8s.io - path: spec/conversion/webhookClientConfig/service/namespace + path: spec/conversion/webhook/clientConfig/service/namespace create: false varReference: diff --git a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_captains.yaml b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_captains.yaml index 72918ce20f4..9c9d61b0c97 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_captains.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_captains.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_cruisers.yaml b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_cruisers.yaml index 57fbbaa0edc..f45c67e889a 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_cruisers.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_cruisers.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_destroyers.yaml b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_destroyers.yaml index a6876308d2e..420660947f2 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_destroyers.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_destroyers.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_frigates.yaml b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_frigates.yaml index 1945956fc7f..89bcb665a22 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_frigates.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_frigates.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_healthcheckpolicies.yaml b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_healthcheckpolicies.yaml index 47895401dd4..8bc7c37f105 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_healthcheckpolicies.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_healthcheckpolicies.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_krakens.yaml b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_krakens.yaml index 66ce9ed3c3d..cadcf28d0a0 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_krakens.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_krakens.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_lakers.yaml b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_lakers.yaml index c44afdfa1e3..99c8d3b175c 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_lakers.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_lakers.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_leviathans.yaml b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_leviathans.yaml index 06212739413..7fdf23361d9 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_leviathans.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/cainjection_in_leviathans.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_captains.yaml b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_captains.yaml index 69ee3459f4e..39ef2528c5a 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_captains.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_captains.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: captains.crew.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_cruisers.yaml b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_cruisers.yaml index 8d71c0cb96a..3d6f07a0d48 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_cruisers.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_cruisers.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: cruisers.ship.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_destroyers.yaml b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_destroyers.yaml index 3d1c6aa20fc..79115951424 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_destroyers.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_destroyers.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: destroyers.ship.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_frigates.yaml b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_frigates.yaml index 75ca2bfdbb3..19cd37cd6b2 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_frigates.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_frigates.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: frigates.ship.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_healthcheckpolicies.yaml b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_healthcheckpolicies.yaml index 19c3aa92048..1be37bd5985 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_healthcheckpolicies.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_healthcheckpolicies.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: healthcheckpolicies.foo.policy.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_krakens.yaml b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_krakens.yaml index 174fae0f998..17c9dee34b3 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_krakens.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_krakens.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: krakens.sea-creatures.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_lakers.yaml b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_lakers.yaml index ed67a5763b8..bb71ce27b27 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_lakers.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_lakers.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: lakers.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_leviathans.yaml b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_leviathans.yaml index 32dfa89ffe3..7076f04bd80 100644 --- a/testdata/project-v3-multigroup/config/crd/patches/webhook_in_leviathans.yaml +++ b/testdata/project-v3-multigroup/config/crd/patches/webhook_in_leviathans.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: leviathans.sea-creatures.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3-multigroup/config/default/webhookcainjection_patch.yaml b/testdata/project-v3-multigroup/config/default/webhookcainjection_patch.yaml index 7e79bf9955a..02ab515d428 100644 --- a/testdata/project-v3-multigroup/config/default/webhookcainjection_patch.yaml +++ b/testdata/project-v3-multigroup/config/default/webhookcainjection_patch.yaml @@ -1,13 +1,13 @@ # This patch add annotation to admission webhook config and # the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize. -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: mutating-webhook-configuration annotations: cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) --- -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: validating-webhook-configuration diff --git a/testdata/project-v3-multigroup/config/webhook/manifests.yaml b/testdata/project-v3-multigroup/config/webhook/manifests.yaml index d3399b0658b..3a463ddb6fd 100644 --- a/testdata/project-v3-multigroup/config/webhook/manifests.yaml +++ b/testdata/project-v3-multigroup/config/webhook/manifests.yaml @@ -1,13 +1,14 @@ --- -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: creationTimestamp: null name: mutating-webhook-configuration webhooks: -- clientConfig: - caBundle: Cg== +- admissionReviewVersions: + - v1beta1 + clientConfig: service: name: webhook-service namespace: system @@ -24,8 +25,10 @@ webhooks: - UPDATE resources: - captains -- clientConfig: - caBundle: Cg== + sideEffects: None +- admissionReviewVersions: + - v1beta1 + clientConfig: service: name: webhook-service namespace: system @@ -42,8 +45,10 @@ webhooks: - UPDATE resources: - destroyers -- clientConfig: - caBundle: Cg== + sideEffects: None +- admissionReviewVersions: + - v1beta1 + clientConfig: service: name: webhook-service namespace: system @@ -60,16 +65,18 @@ webhooks: - UPDATE resources: - lakers + sideEffects: None --- -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: creationTimestamp: null name: validating-webhook-configuration webhooks: -- clientConfig: - caBundle: Cg== +- admissionReviewVersions: + - v1beta1 + clientConfig: service: name: webhook-service namespace: system @@ -86,8 +93,10 @@ webhooks: - UPDATE resources: - captains -- clientConfig: - caBundle: Cg== + sideEffects: None +- admissionReviewVersions: + - v1beta1 + clientConfig: service: name: webhook-service namespace: system @@ -104,8 +113,10 @@ webhooks: - UPDATE resources: - cruisers -- clientConfig: - caBundle: Cg== + sideEffects: None +- admissionReviewVersions: + - v1beta1 + clientConfig: service: name: webhook-service namespace: system @@ -122,3 +133,4 @@ webhooks: - UPDATE resources: - lakers + sideEffects: None diff --git a/testdata/project-v3/Makefile b/testdata/project-v3/Makefile index fb72a7e7fab..1e1f23f9f53 100644 --- a/testdata/project-v3/Makefile +++ b/testdata/project-v3/Makefile @@ -2,7 +2,7 @@ # Image URL to use all building/pushing image targets IMG ?= controller:latest # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) -CRD_OPTIONS ?= "crd:trivialVersions=true" +CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -72,7 +72,7 @@ docker-push: # Download controller-gen locally if necessary CONTROLLER_GEN = $(shell pwd)/bin/controller-gen controller-gen: - $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0) + $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1) # Download kustomize locally if necessary KUSTOMIZE = $(shell pwd)/bin/kustomize diff --git a/testdata/project-v3/PROJECT b/testdata/project-v3/PROJECT index e5131b1728b..e64a848c894 100644 --- a/testdata/project-v3/PROJECT +++ b/testdata/project-v3/PROJECT @@ -3,13 +3,19 @@ layout: go.kubebuilder.io/v3-alpha projectName: project-v3 repo: sigs.k8s.io/kubebuilder/testdata/project-v3 resources: -- group: crew +- crdVersion: v1 + group: crew kind: Captain version: v1 -- group: crew + webhookVersion: v1 +- crdVersion: v1 + group: crew kind: FirstMate version: v1 -- group: crew + webhookVersion: v1 +- crdVersion: v1 + group: crew kind: Admiral version: v1 + webhookVersion: v1 version: 3-alpha diff --git a/testdata/project-v3/api/v1/admiral_webhook.go b/testdata/project-v3/api/v1/admiral_webhook.go index 8add0a90b92..cb2f2c70bdb 100644 --- a/testdata/project-v3/api/v1/admiral_webhook.go +++ b/testdata/project-v3/api/v1/admiral_webhook.go @@ -33,7 +33,7 @@ func (r *Admiral) SetupWebhookWithManager(mgr ctrl.Manager) error { // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// +kubebuilder:webhook:path=/mutate-crew-testproject-org-v1-admiral,mutating=true,failurePolicy=fail,groups=crew.testproject.org,resources=admirals,verbs=create;update,versions=v1,name=madmiral.kb.io +// +kubebuilder:webhook:path=/mutate-crew-testproject-org-v1-admiral,mutating=true,failurePolicy=fail,sideEffects=None,groups=crew.testproject.org,resources=admirals,verbs=create;update,versions=v1,name=madmiral.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Defaulter = &Admiral{} diff --git a/testdata/project-v3/api/v1/captain_webhook.go b/testdata/project-v3/api/v1/captain_webhook.go index 6f206e0f7e5..1c6b4211fb6 100644 --- a/testdata/project-v3/api/v1/captain_webhook.go +++ b/testdata/project-v3/api/v1/captain_webhook.go @@ -34,7 +34,7 @@ func (r *Captain) SetupWebhookWithManager(mgr ctrl.Manager) error { // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// +kubebuilder:webhook:path=/mutate-crew-testproject-org-v1-captain,mutating=true,failurePolicy=fail,groups=crew.testproject.org,resources=captains,verbs=create;update,versions=v1,name=mcaptain.kb.io +// +kubebuilder:webhook:path=/mutate-crew-testproject-org-v1-captain,mutating=true,failurePolicy=fail,sideEffects=None,groups=crew.testproject.org,resources=captains,verbs=create;update,versions=v1,name=mcaptain.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Defaulter = &Captain{} @@ -46,7 +46,7 @@ func (r *Captain) Default() { } // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. -// +kubebuilder:webhook:verbs=create;update,path=/validate-crew-testproject-org-v1-captain,mutating=false,failurePolicy=fail,groups=crew.testproject.org,resources=captains,versions=v1,name=vcaptain.kb.io +// +kubebuilder:webhook:path=/validate-crew-testproject-org-v1-captain,mutating=false,failurePolicy=fail,sideEffects=None,groups=crew.testproject.org,resources=captains,verbs=create;update,versions=v1,name=vcaptain.kb.io,admissionReviewVersions={v1beta1} var _ webhook.Validator = &Captain{} diff --git a/testdata/project-v3/config/crd/bases/crew.testproject.org_admirals.yaml b/testdata/project-v3/config/crd/bases/crew.testproject.org_admirals.yaml index a9debed1eca..4611bd1e654 100644 --- a/testdata/project-v3/config/crd/bases/crew.testproject.org_admirals.yaml +++ b/testdata/project-v3/config/crd/bases/crew.testproject.org_admirals.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: admirals.crew.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: admirals singular: admiral scope: Cluster - subresources: - status: {} - validation: - openAPIV3Schema: - description: Admiral is the Schema for the admirals API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: AdmiralSpec defines the desired state of Admiral - properties: - foo: - description: Foo is an example field of Admiral. Edit Admiral_types.go - to remove/update - type: string - type: object - status: - description: AdmiralStatus defines the observed state of Admiral - type: object - type: object - version: v1 versions: - name: v1 + schema: + openAPIV3Schema: + description: Admiral is the Schema for the admirals API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: AdmiralSpec defines the desired state of Admiral + properties: + foo: + description: Foo is an example field of Admiral. Edit Admiral_types.go + to remove/update + type: string + type: object + status: + description: AdmiralStatus defines the observed state of Admiral + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3/config/crd/bases/crew.testproject.org_captains.yaml b/testdata/project-v3/config/crd/bases/crew.testproject.org_captains.yaml index 3efe21f23ef..012b4d166d8 100644 --- a/testdata/project-v3/config/crd/bases/crew.testproject.org_captains.yaml +++ b/testdata/project-v3/config/crd/bases/crew.testproject.org_captains.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: captains.crew.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: captains singular: captain scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Captain is the Schema for the captains API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: CaptainSpec defines the desired state of Captain - properties: - foo: - description: Foo is an example field of Captain. Edit Captain_types.go - to remove/update - type: string - type: object - status: - description: CaptainStatus defines the observed state of Captain - type: object - type: object - version: v1 versions: - name: v1 + schema: + openAPIV3Schema: + description: Captain is the Schema for the captains API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: CaptainSpec defines the desired state of Captain + properties: + foo: + description: Foo is an example field of Captain. Edit Captain_types.go + to remove/update + type: string + type: object + status: + description: CaptainStatus defines the observed state of Captain + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3/config/crd/bases/crew.testproject.org_firstmates.yaml b/testdata/project-v3/config/crd/bases/crew.testproject.org_firstmates.yaml index d334fb8e690..40161cbd203 100644 --- a/testdata/project-v3/config/crd/bases/crew.testproject.org_firstmates.yaml +++ b/testdata/project-v3/config/crd/bases/crew.testproject.org_firstmates.yaml @@ -1,10 +1,10 @@ --- -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.3.0 + controller-gen.kubebuilder.io/version: v0.4.1 creationTimestamp: null name: firstmates.crew.testproject.org spec: @@ -15,41 +15,40 @@ spec: plural: firstmates singular: firstmate scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: FirstMate is the Schema for the firstmates API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: FirstMateSpec defines the desired state of FirstMate - properties: - foo: - description: Foo is an example field of FirstMate. Edit FirstMate_types.go - to remove/update - type: string - type: object - status: - description: FirstMateStatus defines the observed state of FirstMate - type: object - type: object - version: v1 versions: - name: v1 + schema: + openAPIV3Schema: + description: FirstMate is the Schema for the firstmates API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: FirstMateSpec defines the desired state of FirstMate + properties: + foo: + description: Foo is an example field of FirstMate. Edit FirstMate_types.go + to remove/update + type: string + type: object + status: + description: FirstMateStatus defines the observed state of FirstMate + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/testdata/project-v3/config/crd/kustomizeconfig.yaml b/testdata/project-v3/config/crd/kustomizeconfig.yaml index 6f83d9a94bc..ec5c150a9df 100644 --- a/testdata/project-v3/config/crd/kustomizeconfig.yaml +++ b/testdata/project-v3/config/crd/kustomizeconfig.yaml @@ -4,13 +4,15 @@ nameReference: version: v1 fieldSpecs: - kind: CustomResourceDefinition + version: v1 group: apiextensions.k8s.io - path: spec/conversion/webhookClientConfig/service/name + path: spec/conversion/webhook/clientConfig/service/name namespace: - kind: CustomResourceDefinition + version: v1 group: apiextensions.k8s.io - path: spec/conversion/webhookClientConfig/service/namespace + path: spec/conversion/webhook/clientConfig/service/namespace create: false varReference: diff --git a/testdata/project-v3/config/crd/patches/cainjection_in_admirals.yaml b/testdata/project-v3/config/crd/patches/cainjection_in_admirals.yaml index 8573317f652..ba7fea6e88d 100644 --- a/testdata/project-v3/config/crd/patches/cainjection_in_admirals.yaml +++ b/testdata/project-v3/config/crd/patches/cainjection_in_admirals.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3/config/crd/patches/cainjection_in_captains.yaml b/testdata/project-v3/config/crd/patches/cainjection_in_captains.yaml index 72918ce20f4..9c9d61b0c97 100644 --- a/testdata/project-v3/config/crd/patches/cainjection_in_captains.yaml +++ b/testdata/project-v3/config/crd/patches/cainjection_in_captains.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3/config/crd/patches/cainjection_in_firstmates.yaml b/testdata/project-v3/config/crd/patches/cainjection_in_firstmates.yaml index 271b973cb56..6849f00fb85 100644 --- a/testdata/project-v3/config/crd/patches/cainjection_in_firstmates.yaml +++ b/testdata/project-v3/config/crd/patches/cainjection_in_firstmates.yaml @@ -1,6 +1,5 @@ # The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: diff --git a/testdata/project-v3/config/crd/patches/webhook_in_admirals.yaml b/testdata/project-v3/config/crd/patches/webhook_in_admirals.yaml index a8865b0b87d..e7cef4898e3 100644 --- a/testdata/project-v3/config/crd/patches/webhook_in_admirals.yaml +++ b/testdata/project-v3/config/crd/patches/webhook_in_admirals.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: admirals.crew.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3/config/crd/patches/webhook_in_captains.yaml b/testdata/project-v3/config/crd/patches/webhook_in_captains.yaml index 69ee3459f4e..39ef2528c5a 100644 --- a/testdata/project-v3/config/crd/patches/webhook_in_captains.yaml +++ b/testdata/project-v3/config/crd/patches/webhook_in_captains.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: captains.crew.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3/config/crd/patches/webhook_in_firstmates.yaml b/testdata/project-v3/config/crd/patches/webhook_in_firstmates.yaml index 585eccf7af6..a644d053242 100644 --- a/testdata/project-v3/config/crd/patches/webhook_in_firstmates.yaml +++ b/testdata/project-v3/config/crd/patches/webhook_in_firstmates.yaml @@ -1,14 +1,14 @@ -# The following patch enables conversion webhook for CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: firstmates.crew.testproject.org spec: conversion: strategy: Webhook - webhookClientConfig: - service: - namespace: system - name: webhook-service - path: /convert + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert diff --git a/testdata/project-v3/config/default/webhookcainjection_patch.yaml b/testdata/project-v3/config/default/webhookcainjection_patch.yaml index 7e79bf9955a..02ab515d428 100644 --- a/testdata/project-v3/config/default/webhookcainjection_patch.yaml +++ b/testdata/project-v3/config/default/webhookcainjection_patch.yaml @@ -1,13 +1,13 @@ # This patch add annotation to admission webhook config and # the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize. -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: mutating-webhook-configuration annotations: cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) --- -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: validating-webhook-configuration diff --git a/testdata/project-v3/config/webhook/manifests.yaml b/testdata/project-v3/config/webhook/manifests.yaml index 387f0c3ea71..ecb1136b5d4 100644 --- a/testdata/project-v3/config/webhook/manifests.yaml +++ b/testdata/project-v3/config/webhook/manifests.yaml @@ -1,13 +1,14 @@ --- -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: creationTimestamp: null name: mutating-webhook-configuration webhooks: -- clientConfig: - caBundle: Cg== +- admissionReviewVersions: + - v1beta1 + clientConfig: service: name: webhook-service namespace: system @@ -24,8 +25,10 @@ webhooks: - UPDATE resources: - admirals -- clientConfig: - caBundle: Cg== + sideEffects: None +- admissionReviewVersions: + - v1beta1 + clientConfig: service: name: webhook-service namespace: system @@ -42,16 +45,18 @@ webhooks: - UPDATE resources: - captains + sideEffects: None --- -apiVersion: admissionregistration.k8s.io/v1beta1 +apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: creationTimestamp: null name: validating-webhook-configuration webhooks: -- clientConfig: - caBundle: Cg== +- admissionReviewVersions: + - v1beta1 + clientConfig: service: name: webhook-service namespace: system @@ -68,3 +73,4 @@ webhooks: - UPDATE resources: - captains + sideEffects: None