Skip to content

Commit 855513f

Browse files
authored
Merge pull request #1011 from droot/running/bump-up-cr-ct
🏃 parameterize controller-runtime and tools version
2 parents 6236ac2 + e6e1b99 commit 855513f

12 files changed

+56
-18
lines changed

pkg/scaffold/project.go

+26-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ import (
3737
"sigs.k8s.io/kubebuilder/pkg/scaffold/v2/webhook"
3838
)
3939

40+
const (
41+
// controller runtime version to be used in the project
42+
controllerRuntimeVersion = "v0.2.2"
43+
// ControllerTools version to be used in the project
44+
controllerToolsVersion = "v0.2.1"
45+
)
46+
4047
type ProjectScaffolder interface {
4148
EnsureDependencies() (bool, error)
4249
Scaffold() error
@@ -147,11 +154,26 @@ func (p *V2Project) Validate() error {
147154
}
148155

149156
func (p *V2Project) EnsureDependencies() (bool, error) {
150-
c := exec.Command("go", "mod", "tidy") // #nosec
157+
// ensure that we are pinning controller-runtime version
158+
// xref: https://github.com/kubernetes-sigs/kubebuilder/issues/997
159+
c := exec.Command("go", "get", "sigs.k8s.io/controller-runtime@"+controllerRuntimeVersion) // #nosec
151160
c.Stderr = os.Stderr
152161
c.Stdout = os.Stdout
153162
fmt.Println(strings.Join(c.Args, " "))
154-
return true, c.Run()
163+
err := c.Run()
164+
if err != nil {
165+
return false, err
166+
}
167+
168+
c = exec.Command("go", "mod", "tidy") // #nosec
169+
c.Stderr = os.Stderr
170+
c.Stdout = os.Stdout
171+
fmt.Println(strings.Join(c.Args, " "))
172+
err = c.Run()
173+
if err != nil {
174+
return false, err
175+
}
176+
return true, err
155177
}
156178

157179
func (p *V2Project) buildUniverse() *model.Universe {
@@ -201,8 +223,8 @@ func (p *V2Project) Scaffold() error {
201223
&project.AuthProxyRoleBinding{},
202224
&managerv2.Config{Image: imgName},
203225
&scaffoldv2.Main{},
204-
&scaffoldv2.GoMod{},
205-
&scaffoldv2.Makefile{Image: imgName},
226+
&scaffoldv2.GoMod{ControllerRuntimeVersion: controllerRuntimeVersion},
227+
&scaffoldv2.Makefile{Image: imgName, ControllerToolsVersion: controllerToolsVersion},
206228
&scaffoldv2.Dockerfile{},
207229
&scaffoldv2.Kustomize{},
208230
&scaffoldv2.ManagerWebhookPatch{},

pkg/scaffold/v2/gomod.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var _ input.File = &GoMod{}
2525
// GoMod writes a templatefile for go.mod
2626
type GoMod struct {
2727
input.Input
28+
ControllerRuntimeVersion string
2829
}
2930

3031
// GetInput implements input.File
@@ -43,6 +44,6 @@ module {{ .Repo }}
4344
go 1.12
4445
4546
require (
46-
sigs.k8s.io/controller-runtime v0.2.0
47+
sigs.k8s.io/controller-runtime {{ .ControllerRuntimeVersion }}
4748
)
4849
`

pkg/scaffold/v2/makefile.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type Makefile struct {
2727
input.Input
2828
// Image is controller manager image name
2929
Image string
30+
// Controller tools version to use in the project
31+
ControllerToolsVersion string
3032
}
3133

3234
// GetInput implements input.File
@@ -106,7 +108,7 @@ docker-push:
106108
# download controller-gen if necessary
107109
controller-gen:
108110
ifeq (, $(shell which controller-gen))
109-
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.0
111+
go get sigs.k8s.io/controller-tools/cmd/controller-gen@{{.ControllerToolsVersion}}
110112
CONTROLLER_GEN=$(GOBIN)/controller-gen
111113
else
112114
CONTROLLER_GEN=$(shell which controller-gen)

testdata/project-v2/Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager
1919

2020
# Use distroless as minimal base image to package the manager binary
2121
# Refer to https://github.com/GoogleContainerTools/distroless for more details
22-
FROM gcr.io/distroless/static:latest
22+
FROM gcr.io/distroless/static:nonroot
2323
WORKDIR /
2424
COPY --from=builder /workspace/manager .
25+
USER nonroot:nonroot
26+
2527
ENTRYPOINT ["/manager"]

testdata/project-v2/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ docker-push:
6262
# download controller-gen if necessary
6363
controller-gen:
6464
ifeq (, $(shell which controller-gen))
65-
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.0
65+
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.1
6666
CONTROLLER_GEN=$(GOBIN)/controller-gen
6767
else
6868
CONTROLLER_GEN=$(shell which controller-gen)

testdata/project-v2/api/v1/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ spec:
99
group: crew.testproject.org
1010
names:
1111
kind: Admiral
12+
listKind: AdmiralList
1213
plural: admirals
14+
singular: admiral
1315
scope: Cluster
1416
validation:
1517
openAPIV3Schema:
@@ -34,6 +36,7 @@ spec:
3436
description: AdmiralStatus defines the observed state of Admiral
3537
type: object
3638
type: object
39+
version: v1
3740
versions:
3841
- name: v1
3942
served: true

testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ spec:
99
group: crew.testproject.org
1010
names:
1111
kind: Captain
12+
listKind: CaptainList
1213
plural: captains
14+
singular: captain
1315
scope: ""
1416
validation:
1517
openAPIV3Schema:
@@ -34,6 +36,7 @@ spec:
3436
description: CaptainStatus defines the observed state of Captain
3537
type: object
3638
type: object
39+
version: v1
3740
versions:
3841
- name: v1
3942
served: true

testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ spec:
99
group: crew.testproject.org
1010
names:
1111
kind: FirstMate
12+
listKind: FirstMateList
1213
plural: firstmates
14+
singular: firstmate
1315
scope: ""
1416
validation:
1517
openAPIV3Schema:
@@ -34,6 +36,7 @@ spec:
3436
description: FirstMateStatus defines the observed state of FirstMate
3537
type: object
3638
type: object
39+
version: v1
3740
versions:
3841
- name: v1
3942
served: true

testdata/project-v2/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ require (
99
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
1010
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
1111
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
12-
sigs.k8s.io/controller-runtime v0.2.0
12+
sigs.k8s.io/controller-runtime v0.2.2
1313
)

testdata/project-v2/go.sum

+9-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
55
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
66
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
77
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8+
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
89
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
910
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
1011
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
@@ -17,12 +18,13 @@ github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
1718
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
1819
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 h1:u4bArs140e9+AfE52mFHOXVFnOSBJBRlzTHrOPLOIhE=
1920
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
20-
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
2121
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
22+
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
23+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
2224
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck=
2325
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
24-
github.com/googleapis/gnostic v0.2.0 h1:l6N3VoaVzTncYYW+9yOz2LJJammFZGBO13sqgEhpy9g=
25-
github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
26+
github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJhYk=
27+
github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU=
2628
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47 h1:UnszMmmmm5vLwWzDjTFVIkfhvWF1NdrmChl8L2NUDCw=
2729
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
2830
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
@@ -79,7 +81,6 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73r
7981
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
8082
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
8183
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
82-
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
8384
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8485
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
8586
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -100,8 +101,9 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
100101
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
101102
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
102103
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
103-
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
104104
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
105+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
106+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
105107
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b h1:aBGgKJUM9Hk/3AE8WaZIApnTxG35kbuQba2w+SXqezo=
106108
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
107109
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8 h1:q1Qvjzs/iEdXF6A1a8H3AKVFDzJNcJn3nXMs6R6qFtA=
@@ -116,8 +118,8 @@ k8s.io/kube-openapi v0.0.0-20180731170545-e3762e86a74c h1:3KSCztE7gPitlZmWbNwue/
116118
k8s.io/kube-openapi v0.0.0-20180731170545-e3762e86a74c/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
117119
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5 h1:VBM/0P5TWxwk+Nw6Z+lAw3DKgO76g90ETOiA6rfLV1Y=
118120
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
119-
sigs.k8s.io/controller-runtime v0.2.0 h1:5gL30PXOisGZl+Osi4CmLhvMUj77BO3wJeouKF2va50=
120-
sigs.k8s.io/controller-runtime v0.2.0/go.mod h1:ZHqrRDZi3f6BzONcvlUxkqCKgwasGk5FZrnSv9TVZF4=
121+
sigs.k8s.io/controller-runtime v0.2.2 h1:JT/vJJhUjjL9NZNwnm8AXmqCBUXSCFKmTaNjwDi28N0=
122+
sigs.k8s.io/controller-runtime v0.2.2/go.mod h1:9dyohw3ZtoXQuV1e766PHUn+cmrRCIcBh6XIMFNMZ+I=
121123
sigs.k8s.io/testing_frameworks v0.1.1 h1:cP2l8fkA3O9vekpy5Ks8mmA0NW/F7yBdXf8brkWhVrs=
122124
sigs.k8s.io/testing_frameworks v0.1.1/go.mod h1:VVBKrHmJ6Ekkfz284YKhQePcdycOzNH9qL6ht1zEr/U=
123125
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=

testdata/project-v2/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func main() {
5858
Scheme: scheme,
5959
MetricsBindAddress: metricsAddr,
6060
LeaderElection: enableLeaderElection,
61-
Port: 9843,
61+
Port: 9443,
6262
})
6363
if err != nil {
6464
setupLog.Error(err, "unable to start manager")

0 commit comments

Comments
 (0)