From 8d73b155330d1150450293bdc884c9f7d7207207 Mon Sep 17 00:00:00 2001 From: Sunil Arora Date: Mon, 23 Sep 2019 16:52:08 -0700 Subject: [PATCH 1/2] :running: parameterize controller-runtime/tools version --- pkg/scaffold/project.go | 30 ++++++++++++++++--- pkg/scaffold/v2/gomod.go | 3 +- pkg/scaffold/v2/makefile.go | 4 ++- testdata/project-v2/Dockerfile | 4 ++- .../api/v1/zz_generated.deepcopy.go | 2 +- .../bases/crew.testproject.org_admirals.yaml | 3 ++ .../bases/crew.testproject.org_captains.yaml | 3 ++ .../crew.testproject.org_firstmates.yaml | 3 ++ testdata/project-v2/main.go | 2 +- 9 files changed, 45 insertions(+), 9 deletions(-) diff --git a/pkg/scaffold/project.go b/pkg/scaffold/project.go index bee9063c16a..bdfc0aab359 100644 --- a/pkg/scaffold/project.go +++ b/pkg/scaffold/project.go @@ -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.0" + // ControllerTools version to be used in the project + controllerToolsVersion = "v0.2.0" +) + type ProjectScaffolder interface { EnsureDependencies() (bool, error) Scaffold() error @@ -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 { @@ -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{}, diff --git a/pkg/scaffold/v2/gomod.go b/pkg/scaffold/v2/gomod.go index b2cf2d488d3..f7e2acc7cae 100644 --- a/pkg/scaffold/v2/gomod.go +++ b/pkg/scaffold/v2/gomod.go @@ -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 @@ -43,6 +44,6 @@ module {{ .Repo }} go 1.12 require ( - sigs.k8s.io/controller-runtime v0.2.0 + sigs.k8s.io/controller-runtime {{ .ControllerRuntimeVersion }} ) ` diff --git a/pkg/scaffold/v2/makefile.go b/pkg/scaffold/v2/makefile.go index 6335e5455c2..a4a3ba52637 100644 --- a/pkg/scaffold/v2/makefile.go +++ b/pkg/scaffold/v2/makefile.go @@ -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 @@ -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) diff --git a/testdata/project-v2/Dockerfile b/testdata/project-v2/Dockerfile index e6c589aebd9..f41875e64fc 100644 --- a/testdata/project-v2/Dockerfile +++ b/testdata/project-v2/Dockerfile @@ -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"] diff --git a/testdata/project-v2/api/v1/zz_generated.deepcopy.go b/testdata/project-v2/api/v1/zz_generated.deepcopy.go index 75068713cd8..2f2ee38bd31 100644 --- a/testdata/project-v2/api/v1/zz_generated.deepcopy.go +++ b/testdata/project-v2/api/v1/zz_generated.deepcopy.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// autogenerated by controller-gen object, do not modify manually +// Code generated by controller-gen. DO NOT EDIT. package v1 diff --git a/testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml b/testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml index 08a6ede151c..0be2c965b67 100644 --- a/testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml +++ b/testdata/project-v2/config/crd/bases/crew.testproject.org_admirals.yaml @@ -9,7 +9,9 @@ spec: group: crew.testproject.org names: kind: Admiral + listKind: AdmiralList plural: admirals + singular: admiral scope: Cluster validation: openAPIV3Schema: @@ -34,6 +36,7 @@ spec: description: AdmiralStatus defines the observed state of Admiral type: object type: object + version: v1 versions: - name: v1 served: true diff --git a/testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml b/testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml index d04eed290e4..41eb99af79f 100644 --- a/testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml +++ b/testdata/project-v2/config/crd/bases/crew.testproject.org_captains.yaml @@ -9,7 +9,9 @@ spec: group: crew.testproject.org names: kind: Captain + listKind: CaptainList plural: captains + singular: captain scope: "" validation: openAPIV3Schema: @@ -34,6 +36,7 @@ spec: description: CaptainStatus defines the observed state of Captain type: object type: object + version: v1 versions: - name: v1 served: true diff --git a/testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml b/testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml index fc1674a0adb..d828efa975e 100644 --- a/testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml +++ b/testdata/project-v2/config/crd/bases/crew.testproject.org_firstmates.yaml @@ -9,7 +9,9 @@ spec: group: crew.testproject.org names: kind: FirstMate + listKind: FirstMateList plural: firstmates + singular: firstmate scope: "" validation: openAPIV3Schema: @@ -34,6 +36,7 @@ spec: description: FirstMateStatus defines the observed state of FirstMate type: object type: object + version: v1 versions: - name: v1 served: true diff --git a/testdata/project-v2/main.go b/testdata/project-v2/main.go index 202379885c0..1bb4257dd50 100644 --- a/testdata/project-v2/main.go +++ b/testdata/project-v2/main.go @@ -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") From e6e1b9976864cb8c3d9ead105426d37e2ad5c660 Mon Sep 17 00:00:00 2001 From: Sunil Arora Date: Mon, 23 Sep 2019 16:54:38 -0700 Subject: [PATCH 2/2] :running: bumped up controller-runtime/tools version --- pkg/scaffold/project.go | 4 ++-- testdata/project-v2/Makefile | 2 +- testdata/project-v2/go.mod | 2 +- testdata/project-v2/go.sum | 16 +++++++++------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/scaffold/project.go b/pkg/scaffold/project.go index bdfc0aab359..849435ca885 100644 --- a/pkg/scaffold/project.go +++ b/pkg/scaffold/project.go @@ -39,9 +39,9 @@ import ( const ( // controller runtime version to be used in the project - controllerRuntimeVersion = "v0.2.0" + controllerRuntimeVersion = "v0.2.2" // ControllerTools version to be used in the project - controllerToolsVersion = "v0.2.0" + controllerToolsVersion = "v0.2.1" ) type ProjectScaffolder interface { diff --git a/testdata/project-v2/Makefile b/testdata/project-v2/Makefile index a87b374b6ba..27ed807ed07 100644 --- a/testdata/project-v2/Makefile +++ b/testdata/project-v2/Makefile @@ -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/controller-gen@v0.2.0 + go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.1 CONTROLLER_GEN=$(GOBIN)/controller-gen else CONTROLLER_GEN=$(shell which controller-gen) diff --git a/testdata/project-v2/go.mod b/testdata/project-v2/go.mod index e62ac62fb03..26717605c86 100644 --- a/testdata/project-v2/go.mod +++ b/testdata/project-v2/go.mod @@ -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 ) diff --git a/testdata/project-v2/go.sum b/testdata/project-v2/go.sum index 545b9e8055c..aaa4eb2668a 100644 --- a/testdata/project-v2/go.sum +++ b/testdata/project-v2/go.sum @@ -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= @@ -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= @@ -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= @@ -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= @@ -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=