Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#1011 from droot/running/bump-up-cr-ct
Browse files Browse the repository at this point in the history
🏃 parameterize controller-runtime and tools version
  • Loading branch information
k8s-ci-robot authored Sep 24, 2019
2 parents 6236ac2 + e6e1b99 commit 855513f
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 18 deletions.
30 changes: 26 additions & 4 deletions pkg/scaffold/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ import (
"sigs.k8s.io/kubebuilder/pkg/scaffold/v2/webhook"
)

const (
// controller runtime version to be used in the project
controllerRuntimeVersion = "v0.2.2"
// ControllerTools version to be used in the project
controllerToolsVersion = "v0.2.1"
)

type ProjectScaffolder interface {
EnsureDependencies() (bool, error)
Scaffold() error
Expand Down Expand Up @@ -147,11 +154,26 @@ func (p *V2Project) Validate() error {
}

func (p *V2Project) EnsureDependencies() (bool, error) {
c := exec.Command("go", "mod", "tidy") // #nosec
// ensure that we are pinning controller-runtime version
// xref: https://github.com/kubernetes-sigs/kubebuilder/issues/997
c := exec.Command("go", "get", "sigs.k8s.io/controller-runtime@"+controllerRuntimeVersion) // #nosec
c.Stderr = os.Stderr
c.Stdout = os.Stdout
fmt.Println(strings.Join(c.Args, " "))
return true, c.Run()
err := c.Run()
if err != nil {
return false, err
}

c = exec.Command("go", "mod", "tidy") // #nosec
c.Stderr = os.Stderr
c.Stdout = os.Stdout
fmt.Println(strings.Join(c.Args, " "))
err = c.Run()
if err != nil {
return false, err
}
return true, err
}

func (p *V2Project) buildUniverse() *model.Universe {
Expand Down Expand Up @@ -201,8 +223,8 @@ func (p *V2Project) Scaffold() error {
&project.AuthProxyRoleBinding{},
&managerv2.Config{Image: imgName},
&scaffoldv2.Main{},
&scaffoldv2.GoMod{},
&scaffoldv2.Makefile{Image: imgName},
&scaffoldv2.GoMod{ControllerRuntimeVersion: controllerRuntimeVersion},
&scaffoldv2.Makefile{Image: imgName, ControllerToolsVersion: controllerToolsVersion},
&scaffoldv2.Dockerfile{},
&scaffoldv2.Kustomize{},
&scaffoldv2.ManagerWebhookPatch{},
Expand Down
3 changes: 2 additions & 1 deletion pkg/scaffold/v2/gomod.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var _ input.File = &GoMod{}
// GoMod writes a templatefile for go.mod
type GoMod struct {
input.Input
ControllerRuntimeVersion string
}

// GetInput implements input.File
Expand All @@ -43,6 +44,6 @@ module {{ .Repo }}
go 1.12
require (
sigs.k8s.io/controller-runtime v0.2.0
sigs.k8s.io/controller-runtime {{ .ControllerRuntimeVersion }}
)
`
4 changes: 3 additions & 1 deletion pkg/scaffold/v2/makefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Makefile struct {
input.Input
// Image is controller manager image name
Image string
// Controller tools version to use in the project
ControllerToolsVersion string
}

// GetInput implements input.File
Expand Down Expand Up @@ -106,7 +108,7 @@ docker-push:
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.0
go get sigs.k8s.io/controller-tools/cmd/controller-gen@{{.ControllerToolsVersion}}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
Expand Down
4 changes: 3 additions & 1 deletion testdata/project-v2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:latest
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER nonroot:nonroot

ENTRYPOINT ["/manager"]
2 changes: 1 addition & 1 deletion testdata/project-v2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ docker-push:
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
go get sigs.k8s.io/controller-tools/cmd/[email protected].0
go get sigs.k8s.io/controller-tools/cmd/[email protected].1
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
Expand Down
2 changes: 1 addition & 1 deletion testdata/project-v2/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ spec:
group: crew.testproject.org
names:
kind: Admiral
listKind: AdmiralList
plural: admirals
singular: admiral
scope: Cluster
validation:
openAPIV3Schema:
Expand All @@ -34,6 +36,7 @@ spec:
description: AdmiralStatus defines the observed state of Admiral
type: object
type: object
version: v1
versions:
- name: v1
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ spec:
group: crew.testproject.org
names:
kind: Captain
listKind: CaptainList
plural: captains
singular: captain
scope: ""
validation:
openAPIV3Schema:
Expand All @@ -34,6 +36,7 @@ spec:
description: CaptainStatus defines the observed state of Captain
type: object
type: object
version: v1
versions:
- name: v1
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ spec:
group: crew.testproject.org
names:
kind: FirstMate
listKind: FirstMateList
plural: firstmates
singular: firstmate
scope: ""
validation:
openAPIV3Schema:
Expand All @@ -34,6 +36,7 @@ spec:
description: FirstMateStatus defines the observed state of FirstMate
type: object
type: object
version: v1
versions:
- name: v1
served: true
Expand Down
2 changes: 1 addition & 1 deletion testdata/project-v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ require (
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
sigs.k8s.io/controller-runtime v0.2.0
sigs.k8s.io/controller-runtime v0.2.2
)
16 changes: 9 additions & 7 deletions testdata/project-v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
Expand All @@ -17,12 +18,13 @@ github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 h1:u4bArs140e9+AfE52mFHOXVFnOSBJBRlzTHrOPLOIhE=
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/googleapis/gnostic v0.2.0 h1:l6N3VoaVzTncYYW+9yOz2LJJammFZGBO13sqgEhpy9g=
github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJhYk=
github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU=
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47 h1:UnszMmmmm5vLwWzDjTFVIkfhvWF1NdrmChl8L2NUDCw=
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
Expand Down Expand Up @@ -79,7 +81,6 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -100,8 +101,9 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b h1:aBGgKJUM9Hk/3AE8WaZIApnTxG35kbuQba2w+SXqezo=
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8 h1:q1Qvjzs/iEdXF6A1a8H3AKVFDzJNcJn3nXMs6R6qFtA=
Expand All @@ -116,8 +118,8 @@ k8s.io/kube-openapi v0.0.0-20180731170545-e3762e86a74c h1:3KSCztE7gPitlZmWbNwue/
k8s.io/kube-openapi v0.0.0-20180731170545-e3762e86a74c/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5 h1:VBM/0P5TWxwk+Nw6Z+lAw3DKgO76g90ETOiA6rfLV1Y=
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
sigs.k8s.io/controller-runtime v0.2.0 h1:5gL30PXOisGZl+Osi4CmLhvMUj77BO3wJeouKF2va50=
sigs.k8s.io/controller-runtime v0.2.0/go.mod h1:ZHqrRDZi3f6BzONcvlUxkqCKgwasGk5FZrnSv9TVZF4=
sigs.k8s.io/controller-runtime v0.2.2 h1:JT/vJJhUjjL9NZNwnm8AXmqCBUXSCFKmTaNjwDi28N0=
sigs.k8s.io/controller-runtime v0.2.2/go.mod h1:9dyohw3ZtoXQuV1e766PHUn+cmrRCIcBh6XIMFNMZ+I=
sigs.k8s.io/testing_frameworks v0.1.1 h1:cP2l8fkA3O9vekpy5Ks8mmA0NW/F7yBdXf8brkWhVrs=
sigs.k8s.io/testing_frameworks v0.1.1/go.mod h1:VVBKrHmJ6Ekkfz284YKhQePcdycOzNH9qL6ht1zEr/U=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
Expand Down
2 changes: 1 addition & 1 deletion testdata/project-v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func main() {
Scheme: scheme,
MetricsBindAddress: metricsAddr,
LeaderElection: enableLeaderElection,
Port: 9843,
Port: 9443,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down

0 comments on commit 855513f

Please sign in to comment.