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

⚠️ controller-tools v0.2.0 scaffolding update #682

Merged

Conversation

DirectXMan12
Copy link
Contributor

@DirectXMan12 DirectXMan12 commented May 3, 2019

This updates the v2 scaffolding to support the upcoming v0.2.0 controller-tools branch. It disables webhook-related things, since v2 scaffolding doesn't scaffold webhook Go code yet and it was breaking stuff.

It also assumes controller-gen is packaged as a binary. Since we've got Go modules, we can just GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@<temporary-branch-for-now>, which is what this does.

Still waiting on:

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 3, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DirectXMan12

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 May 3, 2019
@DirectXMan12
Copy link
Contributor Author

@DirectXMan12 DirectXMan12 force-pushed the feature/controller-tools-0.2.0 branch from 233c626 to b681f06 Compare May 3, 2019 02:15
@DirectXMan12
Copy link
Contributor Author

hey, look 🎉 modules 🎉 (required some temporary branches)

@DirectXMan12 DirectXMan12 force-pushed the feature/controller-tools-0.2.0 branch from b094e61 to 227eded Compare May 3, 2019 06:02
@droot
Copy link
Contributor

droot commented May 3, 2019

Skim through it, looking good overall. Have a few questions related to go-modules. Will take a detailed look soon.

It also assumes controller-gen is packaged as a binary.

We haven't made that call yet, so lets discuss.

Copy link
Contributor

@droot droot 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.

pkg/scaffold/project/kustomize_rbac_base.go Outdated Show resolved Hide resolved
testdata/project_v2/config/rbac/kustomization.yaml Outdated Show resolved Hide resolved
@DirectXMan12 DirectXMan12 force-pushed the feature/controller-tools-0.2.0 branch from 1da248f to 000587d Compare May 4, 2019 06:52
@DirectXMan12
Copy link
Contributor Author

We haven't made that call yet, so lets discuss.

For posterity: we discussed a bit in person, and came to the consensus that just go-getting it with modules is a fine option, and easier to manage than wrangling it as an explicit dependency.

@DirectXMan12 DirectXMan12 force-pushed the feature/controller-tools-0.2.0 branch from 000587d to bc7bada Compare May 4, 2019 22:54
@DirectXMan12 DirectXMan12 changed the title [WIP] ⚠️ controller-tools v0.2.0 scaffolding update ⚠️ controller-tools v0.2.0 scaffolding update May 6, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 6, 2019
generated_golden.sh Show resolved Hide resolved
test.sh Outdated Show resolved Hide resolved
@@ -17,7 +17,7 @@ limitations under the License.
// Package v2alpha1 contains API Schema definitions for the creatures v2alpha1 API group
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen=sigs.k8s.io/kubebuilder/test/project/pkg/apis/creatures
// +k8s:conversion-gen=project/pkg/apis/creatures
// +k8s:defaulter-gen=TypeMeta
Copy link
Member

Choose a reason for hiding this comment

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

These markers actually can be removed.
Same comment for all the doc comments below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are all v1 scaffolding, which shouldn't change under this PR.

testdata/project_v2/Makefile Outdated Show resolved Hide resolved
testdata/project_v2/Makefile Outdated Show resolved Hide resolved
@@ -2,7 +2,7 @@
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/crew_firstmate.yaml
- bases/crew.testproject.org_firstmates.yaml
Copy link
Member

Choose a reason for hiding this comment

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

It looks strange with mixture of . and _.
If I understand what's happening here correctly,

before:
group=crew
domainName=testproject.org

after:
group=crew.testproject.org

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's how controller-tools generates its. I think it's fine -- the _ separates group from resource nicely. We could switch to <resource>.<group> in CT, but I'm not sure it's worth it.

@@ -36,7 +36,7 @@ type EnableWebhookPatch struct {
// GetInput implements input.File
func (p *EnableWebhookPatch) GetInput() (input.Input, error) {
if p.Path == "" {
p.Path = filepath.Join("config", "crds", "patches",
p.Path = filepath.Join("config", "crd", "patches",
Copy link
Member

Choose a reason for hiding this comment

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

Is there a convention to use singular or plural?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was by default just the name of the generator in CT. Since we're overriding it anyway, it can be whatever

kind: Service
version: v1
name: webhook-service
# vars:
Copy link
Member

Choose a reason for hiding this comment

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

Why comment these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we don't scaffold the webhook service, kustomize barfs on these variables.

This switches dependencies over to Go modules, dropping dep.  This does
so *only* for kubebuilder itself, not generated code.
This removes the vendor directory, since it's not needed by modules.
Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

reviewing commit by commit, first commit switch kb deps over to modules looks good.

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

reviewed Move test project to testdata commit, looks good. minor nits about adding some comments.

test.sh Outdated Show resolved Hide resolved
@@ -139,7 +140,7 @@ cd ${go_workspace}/src/sigs.k8s.io/kubebuilder
go test ./cmd/... ./pkg/...

# test project v1
test_project project 1
GO111MODULE=auto test_project gopath/src/project 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment explaining use of auto for GO111MODULE will help why is that being done for version 1 project.

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Reviewed Actually move test projects to testdata commit, have some minor comments.

.gitattributes Outdated
@@ -1 +1,2 @@
test/*.tgz filter=lfs diff=lfs merge=lfs -text
Copy link
Contributor

Choose a reason for hiding this comment

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

may be we can take out the first line ?

@@ -20,14 +20,15 @@ import (
"flag"
"os"

"project/pkg/apis"
"project/pkg/controller"
"project/pkg/webhook"
Copy link
Contributor

Choose a reason for hiding this comment

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

These imports look wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why?

@@ -23,13 +23,14 @@ import (
"sync"
"testing"

"project/pkg/apis"
Copy link
Contributor

Choose a reason for hiding this comment

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

is this import correct ? (or may be, because we set the gopath when we run test).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, because we're at $GOPATH/src/project

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Reviewed Switch v2 Scaffolding to Use Go Modules commit, have a few minor comments.

@@ -5,7 +5,7 @@ os:
- osx

go:
- "1.11"
- "1.12"
Copy link
Contributor

Choose a reason for hiding this comment

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

we should ensure the version check we have is also bumped up to 1.12.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nah, it's just for building KB, I believe. Everything else works fine with Go 1.11 (in fact, building KB also would work fine, except that Travis's Go 1.11 is slightly old and has a bug).

common.sh Outdated Show resolved Hide resolved
generated_golden.sh Outdated Show resolved Hide resolved
Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

reviewed Scaffold v1 with controller-runtime v0.1.8, have one minor comment.

pkg/scaffold/project/gopkg.go Show resolved Hide resolved
Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Reviewed Fix imports.Process being confused on v1, looks good.

pkg/scaffold/v1/resource/addtoscheme.go Show resolved Hide resolved
Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

reviewed Switch v2 scaffolding to controller-tools 0.2.0. Looks good except @mengqiy's comment about disabling some manifests.

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Reviewed Switch to current directory in tests, looks good.

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

reviewed the last commit fixup! Switch kb dependencies over to modules, and looks good.

Go tooling ignores testdata, so the Go module manipulation commands
(pretty much everything that Go does) will ignore the test projects.

The v1 scaffolding needs to be in its own gopath, otherwise the tooling
will ignore the vendor directory.
@DirectXMan12
Copy link
Contributor Author

Dep is having a conniption over v0.1.10 and a mismatch in patch versions on kubernetes libs, so I'll stick on v0.1.8 here for the v1 scaffolding.

This performs the move of the actual files that's set up in the previous
commit.
This switches the v2 scaffolding to use Go modules.  Currently,
a custom fork of controller-runtime is being used.  We'll need to merge
that to controller-runtime master before merging this.
A change was introduced to the v1 scaffolding at some point that
broke new scaffolding on v0.1.1, so upgrade to v0.1.8 to fix it again.
imports.Process makes some dubious assumptions about how import paths
correspond to package names (not wanting to believe that a normal import
path could possibly end in v1), and fails to properly double-check its
work.  Introduce an explicit alias to work around that.
This switches the v2 scaffolding to make use of (the upcoming) controller-tools
v0.2.0, which has rewritten generators and a bundled deepcopy.  It's
currently using a prerelease version.  controller-tools is now consumed
as a binary, available via `go get` with modules turned on.
Lots of the module stuff (and more) depends on the "context" of the
module, so being in the right directory when we run the imports.Process
from the tests is important.
@DirectXMan12 DirectXMan12 force-pushed the feature/controller-tools-0.2.0 branch from cf87637 to 82451fb Compare May 10, 2019 04:07
@DirectXMan12
Copy link
Contributor Author

comments should be addressed

@DirectXMan12
Copy link
Contributor Author

fixed a pluralization bug in the mean time

@DirectXMan12
Copy link
Contributor Author

The golden file unit tests are borked again. The pass locally for me, so 🤷‍♀️ . I'm half tempted to just nix them entirely and replace them with some bash that does the same thing, since the goimports library is so context-dependent. They're basically the equivalent of [[ -z $(git status --porcelain testdata/gopath/src/project ]]

They're roughly equivalent of generated_golden.sh and git status
--porcelain, so we should just do that.
@droot droot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 10, 2019
@k8s-ci-robot k8s-ci-robot merged commit e46e06e into kubernetes-sigs:master May 10, 2019
@DirectXMan12 DirectXMan12 deleted the feature/controller-tools-0.2.0 branch May 12, 2019 22:44
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants