Skip to content

Commit

Permalink
Upgrade: controller-gen v0.5.0, conversion-gen v0.21.0
Browse files Browse the repository at this point in the history
frameworks/constraint had previously been reliant on an outdated version
of the controller-gen library for generating CRDs with embedded
JSONSchemas.  The older version of the library wasn't built to detect
a nested JSONSchema, and thus would not refuse it.

With the requirement of v1 CRDs around the corner in k8s 1.22,
framework/constraint requires the newer controller-gen v0.5.0.  This
library version can output v1 CRD.

The conversion logic was also in need of a library upgrade, with
conversion-gen v0.21.0 now generating the necessary files.

This PR _does not_ output a v1 CRD for Constraint Template.  That will
be left for a future PR.  This PR brings the two binaries up-to-date.

Note: I attempted to dockerize these two binaries.  Controller-gen
worked fine, but for some reason conversion-gen couldn't write to the
filesystem.  The output looked fine, but no dice.  Rather than figure
out why, I decided to punt on the dockeriziation effort.

Signed-off-by: juliankatz <juliankatz@google.com>
  • Loading branch information
julianKatz committed Apr 30, 2021
1 parent 804ff2e commit a4911cf
Show file tree
Hide file tree
Showing 1,592 changed files with 198,193 additions and 80,377 deletions.
46 changes: 29 additions & 17 deletions constraint/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ endif
all: lint test

# Run tests
native-test: generate manifests
# TODO: Once https://github.com/kubernetes/kubernetes/issues/101567 is fixed, add `generate` back as a dependency target
native-test: gen-dependencies manifests
go test ./pkg/... -coverprofile cover.out

# Docker internal test
Expand All @@ -21,31 +22,42 @@ docker-internal-test:
# ./tests/test_remote_driver.sh

# Hook to run docker tests
test: generate
test:
docker build . -t constraint-test && docker run -t constraint-test

# Install CRDs into a cluster
install: manifests
kubectl apply -f config/crds

# Install the generation dependencies on the location machine
gen-dependencies:
GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0
GO111MODULE=on go get k8s.io/code-generator/cmd/conversion-gen@v0.20.2

# Generate manifests e.g. CRD, RBAC etc.
manifests: buildutils
controller-gen all
kustomize build config -o deploy/crds.yaml
manifests:
controller-gen \
crd:crdVersions="v1beta1",allowDangerousTypes="true" \
paths="./pkg/..." \
output:crd:artifacts:config=config/crds
cp config/crds/* deploy/crds.yaml

lint:
golangci-lint -v run ./... --timeout 5m

# Generate code
generate: buildutils
ifndef GOPATH
$(error GOPATH not defined, please define GOPATH. Run "go help gopath" to learn more about GOPATH)
endif
export GOROOT=$(go env root)
GO111MODULE=off go generate ./pkg/...

# find or download controller-gen
# download controller-gen if necessary
.PHONY: buildutils
buildutils:
cd buildutils && ./buildutils.sh
# Not working? Try running `make gen-dependencies`
generate:
controller-gen \
object:headerFile=./hack/boilerplate.go.txt \
paths="./pkg/..."
# This conversion-gen code is broken. For some reason, it does not include functions
# for converting from v1beta JSONSchemaProps to apiextensions JSONSchemaProps, even though
# those functions exist and can be added manually to the conversion file.
# TODO: Once https://github.com/kubernetes/kubernetes/issues/101567 is fixed, update
# conversion-gen and get us back to running `make generate` in our CI pipeline
conversion-gen \
--input-dirs "./pkg/apis/templates/..." \
--go-header-file=./hack/boilerplate.go.txt \
--output-file-base=zz_generated.conversion \
--extra-dirs=k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1
5 changes: 0 additions & 5 deletions constraint/buildutils/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions constraint/buildutils/buildutils.sh

This file was deleted.

48 changes: 0 additions & 48 deletions constraint/buildutils/go.mod

This file was deleted.

Loading

0 comments on commit a4911cf

Please sign in to comment.