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

Conversation

NikhilSharmaWe
Copy link
Member

@NikhilSharmaWe NikhilSharmaWe commented May 11, 2022

Closes: #2681

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 11, 2022
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution 🥇
See the comment: https://github.com/kubernetes-sigs/kubebuilder/pull/2679/files#r871211532

@NikhilSharmaWe NikhilSharmaWe changed the title ✨Updated controller-runtime to the latest release v0.12.0 ⚠️ (go/v3 and config-gen alpha command) Update controller-runtime dep from v0.11.2 to v0.12.0. ( you should explicitly set configmapsleases when configuring leader election, more info: kubernetes-sigs/controller-runtime#1773 ) May 12, 2022
@NikhilSharmaWe NikhilSharmaWe changed the title ⚠️ (go/v3 and config-gen alpha command) Update controller-runtime dep from v0.11.2 to v0.12.0. ( you should explicitly set configmapsleases when configuring leader election, more info: kubernetes-sigs/controller-runtime#1773 ) ⚠️ (go/v3 and config-gen alpha command) Update controller-runtime dep from v0.11.2 to v0.12.0. ( you should explicitly set configmapsleases when configuring leader election, more info: https://github.com/kubernetes-sigs/controller-runtime#1773 ) May 12, 2022
@NikhilSharmaWe NikhilSharmaWe changed the title ⚠️ (go/v3 and config-gen alpha command) Update controller-runtime dep from v0.11.2 to v0.12.0. ( you should explicitly set configmapsleases when configuring leader election, more info: https://github.com/kubernetes-sigs/controller-runtime#1773 ) ⚠️ (go/v3 and config-gen alpha command) Update controller-runtime dep from v0.11.2 to v0.12.0. May 12, 2022
@NikhilSharmaWe
Copy link
Member Author

NikhilSharmaWe commented May 12, 2022

@camilamacedo86 Unit tests are failing
Is it due to the versions of k8s.io/cli-runtime@v0.23.0 and k8s.io/kubectl@v0.22.2.

All error logs are like:

Error: cannot use oapi (type *"github.com/google/gnostic/openapiv2".Document) as type *"github.com/googleapis/gnostic/openapiv2".Document in argument to supportsDryRun

go.mod Show resolved Hide resolved
@camilamacedo86
Copy link
Member

camilamacedo86 commented May 20, 2022

This PR is blocked by upgrading the declarative project: kubernetes-sigs/kubebuilder-declarative-pattern#217.

PS.: The first version of go/v3 uses controller-runtime v0.7.2 ( see: https://github.com/kubernetes-sigs/kubebuilder/blob/v3.0.0/testdata/project-v3/go.mod#L12 ), so the changes described in kubernetes-sigs/controller-runtime#1903 is fine. However, we will need to update the migration guide doc from v2 to v3 with: kubernetes-sigs/controller-runtime#1903

@everettraven
Copy link
Contributor

Unit tests are failing Is it due to the versions of k8s.io/cli-runtime@v0.23.0 and k8s.io/kubectl@v0.22.2.

All error logs are like:

Error: cannot use oapi (type *"github.com/google/gnostic/openapiv2".Document) as type *"github.com/googleapis/gnostic/openapiv2".Document in argument to supportsDryRun

@NikhilSharmaWe these errors seem to be related to the kubebuilder-declarative-pattern dependency, so since your PR to bump it to support k8s 1.24 was merged, I think this line needs to be modified:

kbDeclarativePatternForV3 = "d0f104b6a96e152043e9c2d76229373a981ac96a"

to be:

kbDeclarativePatternForV3 = "fe5be9431eae158f86f9de23000a9a2ec06745fc"

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 3, 2022
@NikhilSharmaWe NikhilSharmaWe force-pushed the newReleaseUpdate branch 3 times, most recently from aba99f8 to 5528cde Compare June 3, 2022 15:28
@NikhilSharmaWe NikhilSharmaWe changed the title ⚠️ (go/v3 and config-gen alpha command) Update controller-runtime dep from v0.11.2 to v0.12.0. ⚠️ (go/v3 and config-gen alpha command) Update controller-runtime dep from v0.11.2 to v0.12.1. Jun 3, 2022
@everettraven
Copy link
Contributor

@NikhilSharmaWe I think I may have found the problem that is causing the tests to fail with the proto file issue.

Problem

The problem seems to be because the go.mod dependencies are being populated with indirect dependencies that map to the k8s packages with a version of v0.24.0. When the dependencies for the v1beta1 support are modified, the indirect dependencies aren't properly updated without removing all the indirect dependencies before running go mod tidy.

The exact indirect dependency that is causing the issue is github.com/google/gnostic v0.5.7-v3refs // indirect because client-go v0.24.0 and controller-runtime v0.12.1 have this dependency causing the scaffolded project to have it as an indirect dependency. client-go v0.21.2 and controller-runtime v0.9.2 use github.com/googleapis/gnostic v0.5.5 // indirect which is a different package path entirely.

Solution

The solution I found is to modify the pkg/plugins/golang/v3/commons.go file to remove all the indirect dependencies before running go mod tidy. This logic looks like:

// 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)
}

I will also leave a PR review comment around the area in the file it should be added.

@@ -145,7 +145,7 @@ 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)

go.mod Outdated
sigs.k8s.io/controller-runtime v0.11.2
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.8.0 // for `kubebuilder alpha config-gen`
Copy link
Contributor

Choose a reason for hiding this comment

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

controller-tools should be upgraded to v0.9.0 since it doesn't support k8s 1.24 until that release. More info on the v0.9.0 release can be found here: https://github.com/kubernetes-sigs/controller-tools/releases/tag/v0.9.0

Suggested change
sigs.k8s.io/controller-tools v0.8.0 // for `kubebuilder alpha config-gen`
sigs.k8s.io/controller-tools v0.9.0 // for `kubebuilder alpha config-gen`

Copy link
Member

Choose a reason for hiding this comment

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

@NikhilSharmaWe,
We need also add this info in the title and description
I am doing tha

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 3, 2022
@everettraven
Copy link
Contributor

@NikhilSharmaWe it looks like the new unit test failures are related to an update made in controller-tools v0.9.0 that no longer writes the status field in the CRD. The PR that made this change is here: kubernetes-sigs/controller-tools#630

Due to this we need to update the expected files to match the new format. To do this you need to:

  1. uncomment this line:
    // UpdateExpectedFromActual: true,
  2. In the pkg/cli/alpha/config-gen directory, run go test
  3. comment the changed line again

After that the unit tests should pass again.

Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

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

Looks good to me, great job @NikhilSharmaWe !

@everettraven
Copy link
Contributor

/cc @joelanford

Could you take a look at this so we can try and get this in ASAP? Thanks!

@jmrodri
Copy link
Contributor

jmrodri commented Jun 6, 2022

What does this error mean?

sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3/scaffolds
  Incompatible changes:
  - ControllerRuntimeVersion: value changed from "v0.11.2" to "v0.12.1"

@varshaprasad96
Copy link
Member

varshaprasad96 commented Jun 6, 2022

What does this error mean?

sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3/scaffolds
  Incompatible changes:
  - ControllerRuntimeVersion: value changed from "v0.11.2" to "v0.12.1"

That seems to be because of an APIDiff check - modifying an exported field. If someone with permissions could override that check, we can merge it.

@everettraven
Copy link
Contributor

What does this error mean?

sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3/scaffolds
  Incompatible changes:
  - ControllerRuntimeVersion: value changed from "v0.11.2" to "v0.12.1"

@jmrodri from what I can tell it seems to just be stating that the bump to v0.12.1 is a breaking change from v0.11.2 which we already knew. As @varshaprasad96 mentioned, I think this can be safely overridden.

Copy link
Contributor

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot
Copy link
Contributor

@jmrodri: changing LGTM is restricted to collaborators

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@jmrodri
Copy link
Contributor

jmrodri commented Jun 6, 2022

Looks pretty straight forward to me.

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

@camilamacedo86 camilamacedo86 changed the title ⚠️ (go/v3 and config-gen alpha command) Update controller-runtime dep from v0.11.2 to v0.12.1. ⚠️ (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 Jun 7, 2022
// 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

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

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.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approved

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 7, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, everettraven, jmrodri, NikhilSharmaWe

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 7, 2022
@camilamacedo86 camilamacedo86 merged commit f19b01d into kubernetes-sigs:master Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade controller-runtime to 0.12.0
6 participants