From e2bdc5e8e868d5471a07268295a20f95aa3b4d99 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Fri, 3 Dec 2021 15:24:04 -0500 Subject: [PATCH 1/6] Add controller-gen to tools.go This way we can use the go tool's built in pinning functionality that is already used in this project. Signed-off-by: Manuel Mendez --- go.mod | 1 + go.sum | 10 ++++++++++ tools.go | 1 + 3 files changed, 12 insertions(+) diff --git a/go.mod b/go.mod index f8bc4a5b1..8ccfcecaa 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,7 @@ require ( k8s.io/apimachinery v0.22.2 mvdan.cc/gofumpt v0.1.1 sigs.k8s.io/controller-runtime v0.10.1 + sigs.k8s.io/controller-tools v0.7.0 ) replace github.com/stormcat24/protodep => github.com/ackintosh/protodep v0.0.0-20200728152107-abf8eb579d6c diff --git a/go.sum b/go.sum index 0fd7e4984..2bd96065a 100644 --- a/go.sum +++ b/go.sum @@ -413,6 +413,7 @@ github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQL github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= +github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc= github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= @@ -503,6 +504,8 @@ github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b/go.mod h1:aUCEOzz github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= github.com/gobuffalo/envy v1.7.1 h1:OQl5ys5MBea7OGCdvPbBJWRgnhC/fGona6QKfvFeau8= github.com/gobuffalo/envy v1.7.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w= +github.com/gobuffalo/flect v0.2.3 h1:f/ZukRnSNA/DUpSNDadko7Qc0PhGvsew35p/2tu+CRY= +github.com/gobuffalo/flect v0.2.3/go.mod h1:vmkQwuZYhN5Pc4ljYQZzP+1sq+NEkK+lh20jmEmX3jc= github.com/gobuffalo/logger v1.0.1 h1:ZEgyRGgAm4ZAhAO45YXMs5Fp+bzGLESFewzAVBMKuTg= github.com/gobuffalo/logger v1.0.1/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs= github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4= @@ -876,6 +879,7 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -885,6 +889,7 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA= github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-oci8 v0.0.7/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI= github.com/mattn/go-pipeline v0.0.0-20170920030317-cfb87a531e2b/go.mod h1:THCMZVX5asLpinN+6hFlR1xKFcFsaDpAtUltGqZauBM= @@ -1008,6 +1013,7 @@ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQLTUg= +github.com/onsi/gomega v1.14.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0= github.com/onsi/gomega v1.15.0 h1:WjP/FQ/sk43MRmnEcT+MlDw2TFvkrXlprrPST/IudjU= github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= @@ -2039,6 +2045,7 @@ honnef.co/go/tools v0.2.0/go.mod h1:lPVVZ2BS5TfnjLyizF7o7hv7j9/L+8cZY2hLyjP9cGY= k8s.io/api v0.20.1/go.mod h1:KqwcCVogGxQY3nBlRpwt+wpAMF/KjaCc7RpywacvqUo= k8s.io/api v0.22.2 h1:M8ZzAD0V6725Fjg53fKeTJxGsJvRbk4TEm/fexHMtfw= k8s.io/api v0.22.2/go.mod h1:y3ydYpLJAaDI+BbSe2xmGcqxiWHmWjkEeIbiwHvnPR8= +k8s.io/apiextensions-apiserver v0.22.2 h1:zK7qI8Ery7j2CaN23UCFaC1hj7dMiI87n01+nKuewd4= k8s.io/apiextensions-apiserver v0.22.2/go.mod h1:2E0Ve/isxNl7tWLSUDgi6+cmwHi5fQRdwGVCxbC+KFA= k8s.io/apimachinery v0.20.1/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU= k8s.io/apimachinery v0.22.2 h1:ejz6y/zNma8clPVfNDLnPbleBo6MpoFy/HBiBqCouVk= @@ -2063,6 +2070,7 @@ k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAG k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e/go.mod h1:vHXdDvt9+2spS2Rx9ql3I8tycm3H9FDfdUoIuKCefvw= k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= +k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a h1:8dYfu/Fc9Gz2rNJKB9IQRGgQOh2clmRzNIPPY1xLY5g= k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= mvdan.cc/gofumpt v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA= mvdan.cc/gofumpt v0.1.1/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48= @@ -2078,6 +2086,8 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14/go.mod h1:LEScyz sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.22/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg= sigs.k8s.io/controller-runtime v0.10.1 h1:+eLHgY/VrJWnfg6iXUqhCUqNXgPH1NZeP9drNAAgWlg= sigs.k8s.io/controller-runtime v0.10.1/go.mod h1:CQp8eyUQZ/Q7PJvnIrB6/hgfTC1kBkGylwsLgOQi1WY= +sigs.k8s.io/controller-tools v0.7.0 h1:iZIz1vEcavyEfxjcTLs1WH/MPf4vhPCtTKhoHqV8/G0= +sigs.k8s.io/controller-tools v0.7.0/go.mod h1:bpBAo0VcSDDLuWt47evLhMLPxRPxMDInTEH/YbdeMK0= sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw= sigs.k8s.io/structured-merge-diff/v4 v4.1.2 h1:Hr/htKFmJEbtMgS/UD0N+gtgctAqz81t3nu+sPzynno= sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4= diff --git a/tools.go b/tools.go index be7209cfd..177df0590 100644 --- a/tools.go +++ b/tools.go @@ -9,4 +9,5 @@ import ( _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc" _ "google.golang.org/protobuf/cmd/protoc-gen-go" _ "mvdan.cc/gofumpt" + _ "sigs.k8s.io/controller-tools/cmd/controller-gen" ) From a022b020a912f11173a8c7d84e33b43b23d6ee68 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Fri, 3 Dec 2021 16:15:57 -0500 Subject: [PATCH 2/6] ci: Run make generate using nix-shell Next commit is going to add prettier to one of the generated recipes and it's not available outside of nix-shell here. Signed-off-by: Manuel Mendez --- .github/workflows/ci.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b1cdb321c..a0e031fb4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,8 +26,11 @@ jobs: uses: actions/setup-go@v2 with: go-version: "1.17" + - uses: cachix/install-nix-action@v12 + with: + nix_path: nixpkgs=channel:nixos-unstable - name: Generate - run: make generate + run: nix-shell --run 'make generate' - name: go clean -testcache run: go clean -testcache - name: go test From c8343cecab6e74f58b2a12223113e2f843218a7e Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Fri, 3 Dec 2021 15:24:33 -0500 Subject: [PATCH 3/6] Use tools.go based method to install controller-gen No need to have 2 different ways to manage go based tooling, we already have tools.go based install using simple `go install` calls. This also has the benefit that make has proper knowledge of the dependency on the binary and how to generate it so we don't need to do recursive make which is harmful. Signed-off-by: Manuel Mendez --- kube.mk | 34 +++++-------------- .../core/v1alpha1/zz_generated.deepcopy.go | 1 + 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/kube.mk b/kube.mk index 338fa14fb..7e1b3e942 100644 --- a/kube.mk +++ b/kube.mk @@ -1,36 +1,18 @@ -GO_INSTALL = ./scripts/go_install.sh -TOOLS_DIR := hack/tools -TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin) - -CONTROLLER_GEN_VER := v0.7.0 -CONTROLLER_GEN_BIN := controller-gen -CONTROLLER_GEN := $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER) - -ENVSUBST_BIN := envsubst -ENVSUBST := $(TOOLS_BIN_DIR)/$(ENVSUBST_BIN)-drone - -# -------------------------------------- -# Tooling Binaries -# -------------------------------------- - -$(CONTROLLER_GEN): # Build controller-gen from tools folder. - GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) sigs.k8s.io/controller-tools/cmd/controller-gen $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER) - -.PHONY: generate -generate: # Generate code, manifests etc. - $(MAKE) generate-go - $(MAKE) generate-manifests +PHONY: generate +generate: generate-go generate-manifests # Generate code, manifests etc. .PHONY: generate-go -generate-go: $(CONTROLLER_GEN) # Generate Go code. - $(CONTROLLER_GEN) object:headerFile="hack/boilerplate/boilerplate.generatego.txt" paths="./pkg/apis/..." +generate-go: bin/controller-gen bin/gofumpt # Generate Go code. + controller-gen object:headerFile="hack/boilerplate/boilerplate.generatego.txt" paths="./pkg/apis/..." + gofumpt -w -s ./pkg/apis .PHONY: generate-manifests -generate-manifests: $(CONTROLLER_GEN) # Generate manifests e.g. CRD, RBAC etc. - $(CONTROLLER_GEN) \ +generate-manifests: bin/controller-gen # Generate manifests e.g. CRD, RBAC etc. + controller-gen \ paths=./pkg/apis/... \ crd:crdVersions=v1 \ rbac:roleName=manager-role \ output:crd:dir=./config/crd/bases \ output:webhook:dir=./config/webhook \ webhook + prettier --write ./config/crd/ diff --git a/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go index f5ce0329e..ce95fc290 100644 --- a/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go @@ -1,3 +1,4 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated /* From 4ab4f75c74e7cadbc0bc50e8eb57f80cf1fa85d7 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Fri, 3 Dec 2021 15:31:53 -0500 Subject: [PATCH 4/6] Delete scripts/go_install.sh It is no longer needed. Signed-off-by: Manuel Mendez --- scripts/go_install.sh | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100755 scripts/go_install.sh diff --git a/scripts/go_install.sh b/scripts/go_install.sh deleted file mode 100755 index 0f691ed81..000000000 --- a/scripts/go_install.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o nounset -set -o pipefail - -if [ -z "${1}" ]; then - echo "must provide module as first parameter" - exit 1 -fi - -if [ -z "${2}" ]; then - echo "must provide binary name as second parameter" - exit 1 -fi - -if [ -z "${3}" ]; then - echo "must provide version as third parameter" - exit 1 -fi - -if [ -z "${GOBIN}" ]; then - echo "GOBIN is not set. Must set GOBIN to install the bin in a specified directory." - exit 1 -fi - -tmp_dir=$(mktemp -d -t goinstall_XXXXXXXXXX) -function clean() { - rm -rf "${tmp_dir}" -} -trap clean EXIT - -rm "${GOBIN}/${2}"* || true - -cd "${tmp_dir}" - -# create a new module in the tmp directory -go mod init fake/mod - -# install the golang module specified as the first argument -go get -tags tools "${1}@${3}" -mv "${GOBIN}/${2}" "${GOBIN}/${2}-${3}" -ln -sf "${GOBIN}/${2}-${3}" "${GOBIN}/${2}" From fe7ecaeec76e23f9a1424682d0983ea7fc39464a Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Fri, 3 Dec 2021 17:15:29 -0500 Subject: [PATCH 5/6] ci: Split nix package fetching from running of command/script To get more accurate numbers of timing for the actual action. Signed-off-by: Manuel Mendez --- .github/workflows/ci.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a0e031fb4..385b60f3f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,9 +26,12 @@ jobs: uses: actions/setup-go@v2 with: go-version: "1.17" - - uses: cachix/install-nix-action@v12 + - name: Install nix + uses: cachix/install-nix-action@v12 with: nix_path: nixpkgs=channel:nixos-unstable + - name: Fetch Nix Packages + run: nix-shell --run 'true' - name: Generate run: nix-shell --run 'make generate' - name: go clean -testcache @@ -42,9 +45,12 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 - - uses: cachix/install-nix-action@v12 + - name: Install nix + uses: cachix/install-nix-action@v12 with: nix_path: nixpkgs=channel:nixos-unstable + - name: Fetch Nix Packages + run: nix-shell --run 'true' - run: ./ci-checks.sh validation: runs-on: ubuntu-latest From b0eb3c6e25c2b464785439146223d376a1470da7 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Fri, 3 Dec 2021 17:16:44 -0500 Subject: [PATCH 6/6] ci: Bump cachix/install-nix-action to v16 Signed-off-by: Manuel Mendez --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 385b60f3f..5fc701aa8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,7 +27,7 @@ jobs: with: go-version: "1.17" - name: Install nix - uses: cachix/install-nix-action@v12 + uses: cachix/install-nix-action@v16 with: nix_path: nixpkgs=channel:nixos-unstable - name: Fetch Nix Packages @@ -46,7 +46,7 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Install nix - uses: cachix/install-nix-action@v12 + uses: cachix/install-nix-action@v16 with: nix_path: nixpkgs=channel:nixos-unstable - name: Fetch Nix Packages