Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ (go/v3 and config-gen alpha command) Update controller-runtime dep from v0.11.2 to v0.12.1, controller-tools from v0.8.0 to v0.9.0 and k8s deps from 1.23 to 1.24.1 #2679

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ go 1.17

require (
github.com/cloudflare/cfssl v1.5.0 // for `kubebuilder alpha config-gen`
github.com/gobuffalo/flect v0.2.3
github.com/gobuffalo/flect v0.2.5
github.com/joelanford/go-apidiff v0.1.0
github.com/onsi/ginkgo v1.16.5
camilamacedo86 marked this conversation as resolved.
Show resolved Hide resolved
github.com/onsi/gomega v1.17.0
github.com/onsi/gomega v1.18.1
github.com/sirupsen/logrus v1.8.1
github.com/spf13/afero v1.6.0
github.com/spf13/cobra v1.2.1
github.com/spf13/cobra v1.4.0
github.com/spf13/pflag v1.0.5
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff
k8s.io/apimachinery v0.23.5 // for `kubebuilder alpha config-gen`
sigs.k8s.io/controller-runtime v0.11.2
sigs.k8s.io/controller-tools v0.8.0 // for `kubebuilder alpha config-gen`
golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717
k8s.io/apimachinery v0.24.0 // for `kubebuilder alpha config-gen`
sigs.k8s.io/controller-runtime v0.12.1
sigs.k8s.io/controller-tools v0.9.0 // for `kubebuilder alpha config-gen`
sigs.k8s.io/kustomize/kyaml v0.13.6 // for `kubebuilder alpha config-gen`
sigs.k8s.io/yaml v1.3.0
)
Expand All @@ -37,7 +37,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/certificate-transparency-go v1.0.21 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
Expand All @@ -62,11 +61,11 @@ require (
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
github.com/zmap/zcrypto v0.0.0-20200911161511-43ff0ea04f21 // indirect
github.com/zmap/zlint/v2 v2.2.1 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand All @@ -76,11 +75,11 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.23.5 // indirect
k8s.io/apiextensions-apiserver v0.23.5 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
k8s.io/api v0.24.0 // indirect
k8s.io/apiextensions-apiserver v0.24.0 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)
125 changes: 66 additions & 59 deletions go.sum

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions pkg/cli/alpha/config-gen/testdata/componentconfig/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -96,12 +90,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it was removed?
Do we know that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to this PR: kubernetes-sigs/controller-tools#630

It changed the generation of a CRD to no longer include the status fields. This PR was included in the v0.9.0 release of controller-tools. Here is the link to the release: https://github.com/kubernetes-sigs/controller-tools/releases/tag/v0.9.0

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
12 changes: 0 additions & 12 deletions pkg/cli/alpha/config-gen/testdata/default/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -96,12 +90,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
12 changes: 0 additions & 12 deletions pkg/cli/alpha/config-gen/testdata/disableauthproxy/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -96,12 +90,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
12 changes: 0 additions & 12 deletions pkg/cli/alpha/config-gen/testdata/enablecertmanager/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -96,12 +90,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ spec:
namespace: simple-system
name: webhook-service
path: /convert
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -105,12 +99,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
12 changes: 0 additions & 12 deletions pkg/cli/alpha/config-gen/testdata/enableprometheus/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -96,12 +90,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
12 changes: 0 additions & 12 deletions pkg/cli/alpha/config-gen/testdata/enablewebhooks/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -96,12 +90,6 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/golang/declarative/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
const (
// kbDeclarativePattern is the sigs.k8s.io/kubebuilder-declarative-pattern version
kbDeclarativePatternForV2 = "v0.0.0-20200522144838-848d48e5b073"
kbDeclarativePatternForV3 = "d0f104b6a96e152043e9c2d76229373a981ac96a"
kbDeclarativePatternForV3 = "fe5be9431eae158f86f9de23000a9a2ec06745fc"
)

var _ plugin.CreateAPISubcommand = &createAPISubcommand{}
Expand Down
20 changes: 13 additions & 7 deletions pkg/plugins/golang/v3/commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,39 +94,39 @@ manifests: controller-gen`
}

if err := util.ReplaceInFile("go.mod",
"k8s.io/api v0.23.5",
"k8s.io/api v0.24.0",
"k8s.io/api v0.21.2"); err != nil {
log.Warnf("unable to update the go.mod with k8s.io/api v0.21.2: %s", err)
}

if err := util.ReplaceInFile("go.mod",
"k8s.io/apimachinery v0.23.5",
"k8s.io/apimachinery v0.24.0",
"k8s.io/apimachinery v0.21.2"); err != nil {
log.Warnf("unable to update the go.mod with k8s.io/apimachinery v0.21.2: %s", err)
}

if err := util.ReplaceInFile("go.mod",
"k8s.io/client-go v0.23.5",
"k8s.io/client-go v0.24.0",
"k8s.io/client-go v0.21.2"); err != nil {
log.Warnf("unable to update the go.mod with k8s.io/client-go v0.21.2: %s", err)
}

// During the scaffolding phase, this gets added to go.mod file, running go mod tidy bumps back
// the version from 21.2 to the latest
if err := util.ReplaceInFile("go.mod",
"k8s.io/api v0.23.5",
"k8s.io/api v0.24.0",
"k8s.io/api v0.21.2"); err != nil {
log.Warnf("unable to update the go.mod with k8s.io/api v0.21.2: %s", err)
}

if err := util.ReplaceInFile("go.mod",
"k8s.io/apiextensions-apiserver v0.23.5",
"k8s.io/apiextensions-apiserver v0.24.0",
"k8s.io/apiextensions-apiserver v0.21.2"); err != nil {
log.Warnf("unable to update the go.mod with k8s.io/apiextensions-apiserver v0.21.2: %s", err)
}

if err := util.ReplaceInFile("go.mod",
"k8s.io/component-base v0.23.5",
"k8s.io/component-base v0.24.0",
"k8s.io/component-base v0.21.2"); err != nil {
log.Warnf("unable to update the go.mod with k8s.io/component-base v0.21.2: %s", err)
}
Expand All @@ -145,11 +145,17 @@ manifests: controller-gen`
}

if err := util.ReplaceInFile("go.mod",
"k8s.io/klog/v2 v2.30.0",
"k8s.io/klog/v2 v2.60.1",
"k8s.io/klog/v2 v2.9.0"); err != nil {
log.Warnf("unable to update the go.mod with k8s.io/klog/v2 v2.9.0: %s", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this line we should add:

// Due to some indirect dependency changes with a bump in k8s packages from 0.23.x --> 0.24.x we need to
// clear out all indirect dependencies before we run `go mod tidy` so that the above changes get resolved correctly
if err := util.ReplaceRegexInFile("go.mod", `(require \(\n(\t.* \/\/ indirect\n)+\))`, ""); err != nil {
	log.Warnf("unable to update the go.mod indirect dependencies: %s", err)
}

The reasoning for this change can be seen here: #2679 (comment)


// Due to some indirect dependency changes with a bump in k8s packages from 0.23.x --> 0.24.x we need to
// clear out all indirect dependencies before we run `go mod tidy` so that the above changes get resolved correctly
if err := util.ReplaceRegexInFile("go.mod", `(require \(\n(\t.* \/\/ indirect\n)+\))`, ""); err != nil {
log.Warnf("unable to update the go.mod indirect dependencies: %s", err)
}
Copy link
Member

@camilamacedo86 camilamacedo86 Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On top we are been very precisely about what dep we should downgrade
So, why do we need to add this one?
I think is better we just update what we scaffold by default instead of all it might change things that were not done in the default scaffold.

Copy link
Contributor

@everettraven everettraven Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a change that I recommended. I think it is fine if we want to change this to only include changing the dependency that was causing an issue, however I will explain my reasoning for the recommendation below.

Reasoning for recommended change

  • The indirect dependencies in the go.mod seem to be getting populated with the indirect dependencies that correlate to the base scaffolding (e.g. k8s 1.24 dependencies) and are not properly updated when the direct dependency versions are downgraded. When I tested this locally, running go mod tidy did not update the indirect dependencies when downgrading direct dependencies.
  • As a result of the above, the indirect dependencies that are being used may be incompatible with the versions that the direct dependencies are using. I think we should be ensuring that the indirect dependencies that are being used are the same as those that are used when manually creating a new go.mod that contains the same direct dependencies. The best way I found to do this with Kubebuilder's scaffolding is to remove all the indirect dependencies and then run go mod tidy to repopulate them. This also helps to ensure that all the indirect dependencies will be compatible with the expectations of the downgraded direct dependencies.

@camilamacedo86 WDYT? If this should be considered out of the scope of this PR and this is something we should still change, I am happy to create an issue to track this and just have this PR fix the dependencies it needs to fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@everettraven I am ok with we better address it as you suggest in a follow up since it is only used with the deprecated flag --crd-version=v1beta1 which no longer works with k8s >= 1.22.


err = util.RunCmd("Update dependencies", "go", "mod", "tidy")
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/golang/v3/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

const (
// ControllerRuntimeVersion is the kubernetes-sigs/controller-runtime version to be used in the project
ControllerRuntimeVersion = "v0.11.2"
ControllerRuntimeVersion = "v0.12.1"
// ControllerToolsVersion is the kubernetes-sigs/controller-tools version to be used in the project
ControllerToolsVersion = "v0.8.0"
// KustomizeVersion is the kubernetes-sigs/kustomize version to be used in the project
Expand Down
Loading