Skip to content

Commit 71b8578

Browse files
authored
Merge pull request #1968 from Adirio/config/v3
✨ Add the rest of the missing fields and stabilize config v3
2 parents e222f25 + 2aef3ad commit 71b8578

File tree

20 files changed

+274
-188
lines changed

20 files changed

+274
-188
lines changed

VERSIONING.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ take care of building and publishing the artifacts.
6464
| Name | Example | Description |
6565
|--- |--- |--- |
6666
| KubeBuilder version | `v2.2.0`, `v2.3.0`, `v2.3.1` | Tagged versions of the KubeBuilder project, representing changes to the source code in this repository. See the [releases][kb-releases] page for binary releases. |
67-
| Project version | `"1"`, `"2"`, `"3-alpha"` | Project version defines the scheme of a `PROJECT` configuration file. This version is defined in a `PROJECT` file's `version`. |
68-
| Plugin version | `v2`, `v3-alpha` | Represents the version of an individual plugin, as well as the corresponding scaffolding that it generates. This version is defined in a plugin key, ex. `go.kubebuilder.io/v2`. See the [design doc][cli-plugins-versioning] for more details. |
67+
| Project version | `"1"`, `"2"`, `"3"` | Project version defines the scheme of a `PROJECT` configuration file. This version is defined in a `PROJECT` file's `version`. |
68+
| Plugin version | `v2`, `v3` | Represents the version of an individual plugin, as well as the corresponding scaffolding that it generates. This version is defined in a plugin key, ex. `go.kubebuilder.io/v2`. See the [design doc][cli-plugins-versioning] for more details. |
6969

7070
### Incrementing versions
7171

@@ -76,32 +76,31 @@ Project versions should only be increased if a breaking change is introduced in
7676
Similarly, the introduction of a new plugin version might only lead to a new minor version release of KubeBuilder, since no breaking change is being made to the CLI itself. It'd only be a breaking change to KubeBuilder if we remove support for an older plugin version. See the plugins design doc [versioning section][cli-plugins-versioning]
7777
for more details on plugin versioning.
7878

79-
**NOTE:** the scheme for project version `"2"` was defined before the concept of plugins was introduced, so plugin `go.kubebuilder.io/v2` is implicitly used for those project types. Schema for project versions `"3-alpha"` and beyond define a `layout` key that informs the plugin system of which plugin to use.
79+
**NOTE:** the scheme for project version `"2"` was defined before the concept of plugins was introduced, so plugin `go.kubebuilder.io/v2` is implicitly used for those project types. Schema for project versions `"3"` and beyond define a `layout` key that informs the plugin system of which plugin to use.
8080

8181
## Introducing changes to plugins
8282

8383
Changes made to plugins only require a plugin version increase if and only if a change is made to a plugin
8484
that breaks projects scaffolded with the previous plugin version. Once a plugin version `vX` is stabilized (it doesn't
8585
have an "alpha" or "beta" suffix), a new plugin package should be created containing a new plugin with version
86-
`v(X+1)-alpha`. Typically this is done by (semantically) `cp -r pkg/plugin/vX pkg/plugin/v(X+1)` then updating
86+
`v(X+1)-alpha`. Typically this is done by (semantically) `cp -r pkg/plugins/golang/vX pkg/plugins/golang/v(X+1)` then updating
8787
version numbers and paths. All further breaking changes to the plugin should be made in this package; the `vX`
8888
plugin would then be frozen to breaking changes.
8989

90+
You must also add a migration guide to the [migrations](https://book.kubebuilder.io/migrations.html)
91+
section of the KubeBuilder book in your PR. It should detail the steps required
92+
for users to upgrade their projects from `vX` to `v(X+1)-alpha`.
93+
9094
### Example
9195

92-
KubeBuilder scaffolds projects with plugin `go.kubebuilder.io/v2` by default. A `v3-alpha` version
93-
was created after `v2` stabilized.
96+
KubeBuilder scaffolds projects with plugin `go.kubebuilder.io/v3` by default.
9497

9598
You create a feature that adds a new marker to the file `main.go` scaffolded by `init`
9699
that `create api` will use to update that file. The changes introduced in your feature
97100
would cause errors if used with projects built with plugins `go.kubebuilder.io/v2`
98101
without users manually updating their projects. Thus, your changes introduce a breaking change
99102
to plugin `go.kubebuilder.io`, and can only be merged into plugin version `v3-alpha`.
100-
This plugin's package should exist already, so a PR must be made against the
101-
102-
You must also add a migration guide to the [migrations](https://book.kubebuilder.io/migrations.html)
103-
section of the KubeBuilder book in your PR. It should detail the steps required
104-
for users to upgrade their projects from `v2` to `v3-alpha`.
103+
This plugin's package should exist already.
105104

106105
[kb-releases]:https://github.com/kubernetes-sigs/kubebuilder/releases
107106
[cli-plugins-versioning]:docs/book/src/reference/cli-plugins.md

cmd/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
"sigs.k8s.io/kubebuilder/v3/pkg/cli"
2323
cfgv2 "sigs.k8s.io/kubebuilder/v3/pkg/config/v2"
24-
cfgv3alpha "sigs.k8s.io/kubebuilder/v3/pkg/config/v3alpha"
24+
cfgv3 "sigs.k8s.io/kubebuilder/v3/pkg/config/v3"
2525
pluginv2 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v2"
2626
pluginv3 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3"
2727
)
@@ -30,13 +30,13 @@ func main() {
3030
c, err := cli.New(
3131
cli.WithCommandName("kubebuilder"),
3232
cli.WithVersion(versionString()),
33-
cli.WithDefaultProjectVersion(cfgv3alpha.Version),
33+
cli.WithDefaultProjectVersion(cfgv3.Version),
3434
cli.WithPlugins(
3535
&pluginv2.Plugin{},
3636
&pluginv3.Plugin{},
3737
),
3838
cli.WithDefaultPlugins(cfgv2.Version, &pluginv2.Plugin{}),
39-
cli.WithDefaultPlugins(cfgv3alpha.Version, &pluginv3.Plugin{}),
39+
cli.WithDefaultPlugins(cfgv3.Version, &pluginv3.Plugin{}),
4040
cli.WithCompletion,
4141
)
4242
if err != nil {

docs/book/src/component-config-tutorial/testdata/project/PROJECT

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@ multigroup: true
55
projectName: project
66
repo: tutorial.kubebuilder.io/project
77
resources:
8-
- crdVersion: v1
8+
- api:
9+
crdVersion: v1
910
group: batch
1011
kind: CronJob
1112
version: v1
12-
webhookVersion: v1
13-
- crdVersion: v1
13+
webhooks:
14+
webhookVersion: v1
15+
- api:
16+
crdVersion: v1
1417
group: batch
1518
kind: CronJob
1619
version: v2
17-
webhookVersion: v1
18-
- crdVersion: v1
20+
webhooks:
21+
webhookVersion: v1
22+
- api:
23+
crdVersion: v1
1924
group: config
2025
kind: ProjectConfig
2126
version: v2
22-
version: 3-alpha
27+
version: "3"

docs/book/src/migration/project/v2_v3.md

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ layout: go.kubebuilder.io/v2
3939

4040
- Update the `version`
4141

42-
The `version` field represents the version of Project layouts. So, you ought to update this to `3-alpha`:
42+
The `version` field represents the version of Project layouts. So, you ought to update this to `"3"`:
4343

4444
```
4545
...
46-
version: 3-alpha`
46+
version: "3"
4747
...
4848
```
4949

@@ -58,7 +58,7 @@ resources:
5858
- group: webapp
5959
kind: Guestbook
6060
version: v1
61-
version: 3-alpha
61+
version: "3"
6262
```
6363

6464
### Verification
@@ -68,47 +68,23 @@ fine.
6868

6969
## Migrating your projects to use v3+ plugins
7070

71-
<aside class="note warning">
72-
73-
<h1>Note</h1>
74-
75-
`v3+` plugins are still in alpha phase and are not scaffolded by default. You are able to use them, try it out and get all improvements made so far by initializing projects with the arg `--plugins=go.kubebuilder.io/v3-alpha`:
76-
77-
```sh
78-
kubebuilder init --domain my.domain --plugins=go.kubebuilder.io/v3-alpha
79-
```
80-
81-
</aside>
82-
83-
<aside class="note warning">
84-
85-
<h1>Note</h1>
86-
87-
Currently, the plugin `v3-alpha` has NO breaking changes. However, until it is declared stable breaking changes can be made related to K8s API deprecations of `v1beta1` versions of `CustomResourceDefinition` and `ValidatingWebhookConfiguration` and to upgrade the `cert-manager`. More info:
88-
89-
- [cert-manager related configuration should be migrated to cert-manager.io/v1 #1666
90-
](https://github.com/kubernetes-sigs/kubebuilder/issues/1666)
91-
- [Set preserveUnknownFields to false in the CRD conversion webhook patch #933](https://github.com/kubernetes-sigs/kubebuilder/issues/933)
92-
- [Migrate existing KB project to v1 CRDs and Webhooks with minimal user effort #1065
93-
](https://github.com/kubernetes-sigs/kubebuilder/issues/1065)
94-
95-
</aside>
71+
In order to migrate your projects to v3 some changes need to be manually done to the PROJECT file, and some other scaffolded files.
9672

9773
### Update your PROJECT file
9874

99-
Update the `layout` setting to the new plugin version ` go.kubebuilder.io/v3-alpha` as follows:
75+
Update the `layout` setting to the new plugin version `go.kubebuilder.io/v3` as follows:
10076

10177
```sh
10278
$ cat PROJECT
10379
domain: my.domain
104-
layout: go.kubebuilder.io/v3-alpha
80+
layout: go.kubebuilder.io/v3
10581
projectName: example
10682
repo: example
10783
resources:
10884
- group: webapp
10985
kind: Guestbook
11086
version: v1
111-
version: 3-alpha
87+
version: "3"
11288

11389
```
11490

pkg/cli/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
internalconfig "sigs.k8s.io/kubebuilder/v3/pkg/cli/internal/config"
2828
"sigs.k8s.io/kubebuilder/v3/pkg/config"
29-
cfgv3alpha "sigs.k8s.io/kubebuilder/v3/pkg/config/v3alpha"
29+
cfgv3 "sigs.k8s.io/kubebuilder/v3/pkg/config/v3"
3030
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
3131
)
3232

@@ -131,7 +131,7 @@ func newCLI(opts ...Option) (*cli, error) {
131131
// Default cli options.
132132
c := &cli{
133133
commandName: "kubebuilder",
134-
defaultProjectVersion: cfgv3alpha.Version,
134+
defaultProjectVersion: cfgv3.Version,
135135
defaultPlugins: make(map[config.Version][]string),
136136
plugins: make(map[string]plugin.Plugin),
137137
}

pkg/cli/cli_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
"sigs.k8s.io/kubebuilder/v3/pkg/config"
2929
cfgv2 "sigs.k8s.io/kubebuilder/v3/pkg/config/v2"
30-
cfgv3alpha "sigs.k8s.io/kubebuilder/v3/pkg/config/v3alpha"
30+
cfgv3 "sigs.k8s.io/kubebuilder/v3/pkg/config/v3"
3131
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
3232
)
3333

@@ -203,7 +203,7 @@ var _ = Describe("CLI", func() {
203203

204204
When("having layout field", func() {
205205
It("should succeed", func() {
206-
projectConfig = cfgv3alpha.New()
206+
projectConfig = cfgv3.New()
207207
Expect(projectConfig.SetLayout("go.kubebuilder.io/v2")).To(Succeed())
208208
projectVersion, plugins, err = getInfoFromConfig(projectConfig)
209209
Expect(err).NotTo(HaveOccurred())

pkg/config/interface.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ type Config interface {
4040
SetRepository(repository string) error
4141

4242
// GetProjectName returns the project name
43-
// This method was introduced in project version 3-alpha.
43+
// This method was introduced in project version 3.
4444
GetProjectName() string
4545
// SetProjectName sets the project name
46-
// This method was introduced in project version 3-alpha.
46+
// This method was introduced in project version 3.
4747
SetProjectName(name string) error
4848

4949
// GetLayout returns the config layout
50-
// This method was introduced in project version 3-alpha.
50+
// This method was introduced in project version 3.
5151
GetLayout() string
5252
// SetLayout sets the Config layout
53-
// This method was introduced in project version 3-alpha.
53+
// This method was introduced in project version 3.
5454
SetLayout(layout string) error
5555

5656
/* Boolean fields */
@@ -63,13 +63,13 @@ type Config interface {
6363
ClearMultiGroup() error
6464

6565
// IsComponentConfig checks if component config is enabled
66-
// This method was introduced in project version 3-alpha.
66+
// This method was introduced in project version 3.
6767
IsComponentConfig() bool
6868
// SetComponentConfig enables component config
69-
// This method was introduced in project version 3-alpha.
69+
// This method was introduced in project version 3.
7070
SetComponentConfig() error
7171
// ClearComponentConfig disables component config
72-
// This method was introduced in project version 3-alpha.
72+
// This method was introduced in project version 3.
7373
ClearComponentConfig() error
7474

7575
/* Resources */
@@ -97,12 +97,10 @@ type Config interface {
9797
/* Plugins */
9898

9999
// DecodePluginConfig decodes a plugin config stored in Config into configObj, which must be a pointer.
100-
// This method is intended to be used for custom configuration objects, which were introduced in project version
101-
// 3-alpha.
100+
// This method is intended to be used for custom configuration objects, which were introduced in project version 3.
102101
DecodePluginConfig(key string, configObj interface{}) error
103102
// EncodePluginConfig encodes a config object into Config by overwriting the existing object stored under key.
104-
// This method is intended to be used for custom configuration objects, which were introduced in project version
105-
// 3-alpha.
103+
// This method is intended to be used for custom configuration objects, which were introduced in project version 3.
106104
EncodePluginConfig(key string, configObj interface{}) error
107105

108106
/* Persistence */

pkg/config/v2/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var _ = Describe("cfg", func() {
7878
})
7979
})
8080

81-
Context("Name", func() {
81+
Context("ProjectName", func() {
8282
It("GetProjectName should return an empty name", func() {
8383
Expect(c.GetProjectName()).To(Equal(""))
8484
})

pkg/config/v3alpha/config.go renamed to pkg/config/v3/config.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v3alpha
17+
package v3
1818

1919
import (
2020
"fmt"
@@ -24,11 +24,10 @@ import (
2424

2525
"sigs.k8s.io/kubebuilder/v3/pkg/config"
2626
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
27-
"sigs.k8s.io/kubebuilder/v3/pkg/model/stage"
2827
)
2928

30-
// Version is the config.Version for project configuration 3-alpha
31-
var Version = config.Version{Number: 3, Stage: stage.Alpha}
29+
// Version is the config.Version for project configuration 3
30+
var Version = config.Version{Number: 3}
3231

3332
type cfg struct {
3433
// Version
@@ -157,8 +156,6 @@ func (c cfg) ResourcesLength() int {
157156

158157
// HasResource implements config.Config
159158
func (c cfg) HasResource(gvk resource.GVK) bool {
160-
gvk.Domain = "" // Version 3 alpha does not include domain per resource
161-
162159
for _, res := range c.Resources {
163160
if gvk.IsEqualTo(res.GVK) {
164161
return true
@@ -170,11 +167,16 @@ func (c cfg) HasResource(gvk resource.GVK) bool {
170167

171168
// GetResource implements config.Config
172169
func (c cfg) GetResource(gvk resource.GVK) (resource.Resource, error) {
173-
gvk.Domain = "" // Version 3 alpha does not include domain per resource
174-
175170
for _, res := range c.Resources {
176171
if gvk.IsEqualTo(res.GVK) {
177-
return res.Copy(), nil
172+
r := res.Copy()
173+
174+
// Plural is only stored if irregular, so if it is empty recover the regular form
175+
if r.Plural == "" {
176+
r.Plural = resource.RegularPlural(r.Kind)
177+
}
178+
179+
return r, nil
178180
}
179181
}
180182

@@ -185,33 +187,28 @@ func (c cfg) GetResource(gvk resource.GVK) (resource.Resource, error) {
185187
func (c cfg) GetResources() ([]resource.Resource, error) {
186188
resources := make([]resource.Resource, 0, len(c.Resources))
187189
for _, res := range c.Resources {
188-
resources = append(resources, res.Copy())
189-
}
190+
r := res.Copy()
190191

191-
return resources, nil
192-
}
192+
// Plural is only stored if irregular, so if it is empty recover the regular form
193+
if r.Plural == "" {
194+
r.Plural = resource.RegularPlural(r.Kind)
195+
}
193196

194-
func discardNonIncludedFields(res *resource.Resource) {
195-
res.Domain = "" // Version 3 alpha does not include domain per resource
196-
res.Plural = "" // Version 3 alpha does not include plural forms
197-
res.Path = "" // Version 3 alpha does not include paths
198-
if res.API != nil {
199-
res.API.Namespaced = false // Version 3 alpha does not include if the api was namespaced
200-
}
201-
res.Controller = false // Version 3 alpha does not include if the controller was scaffolded
202-
if res.Webhooks != nil {
203-
res.Webhooks.Defaulting = false // Version 3 alpha does not include if the defaulting webhook was scaffolded
204-
res.Webhooks.Validation = false // Version 3 alpha does not include if the validation webhook was scaffolded
205-
res.Webhooks.Conversion = false // Version 3 alpha does not include if the conversion webhook was scaffolded
197+
resources = append(resources, r)
206198
}
199+
200+
return resources, nil
207201
}
208202

209203
// AddResource implements config.Config
210204
func (c *cfg) AddResource(res resource.Resource) error {
211205
// As res is passed by value it is already a shallow copy, but we need to make a deep copy
212206
res = res.Copy()
213207

214-
discardNonIncludedFields(&res) // Version 3 alpha does not include several fields from the Resource model
208+
// Plural is only stored if irregular
209+
if res.Plural == resource.RegularPlural(res.Kind) {
210+
res.Plural = ""
211+
}
215212

216213
if !c.HasResource(res.GVK) {
217214
c.Resources = append(c.Resources, res)
@@ -224,7 +221,10 @@ func (c *cfg) UpdateResource(res resource.Resource) error {
224221
// As res is passed by value it is already a shallow copy, but we need to make a deep copy
225222
res = res.Copy()
226223

227-
discardNonIncludedFields(&res) // Version 3 alpha does not include several fields from the Resource model
224+
// Plural is only stored if irregular
225+
if res.Plural == resource.RegularPlural(res.Kind) {
226+
res.Plural = ""
227+
}
228228

229229
for i, r := range c.Resources {
230230
if res.GVK.IsEqualTo(r.GVK) {

0 commit comments

Comments
 (0)