Skip to content

Commit 5bb9cf3

Browse files
authored
Merge pull request #45 from finleap-connect/feature/update-kubebuilder
Update kubebuilder
2 parents fda1979 + 91d1cd6 commit 5bb9cf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1224
-1028
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/
4+
testbin/

.github/workflows/golang.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ jobs:
5353
uses: actions/checkout@v3
5454
- name: test
5555
run: |
56-
make go-test
57-
make go-coverage
56+
make test
57+
make coverage
5858
- name: Convert coverage to lcov
5959
uses: jandelgado/gcov2lcov-action@v1.0.9
6060
with:

.gitignore

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
/tools/*
2-
!/tools/kubebuilder-wrapper
3-
!/tools/kubebuilder-install
4-
!/tools/goget-wrapper
5-
!/tools/helm3-install
6-
!/tools/vault-install
7-
/bin
8-
/reports
9-
/tmp
10-
11-
*.coverprofile
12-
131
# Binaries for programs and plugins
142
*.exe
153
*.exe~
164
*.dll
175
*.so
186
*.dylib
197
bin
8+
testbin/*
209

2110
# Test binary, build with `go test -c`
2211
*.test
@@ -34,4 +23,6 @@ bin
3423
*.swo
3524
*~
3625

26+
cover.out
3727
.vscode
28+
.coverprofile

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ COPY vault/ vault/
3131
COPY util/ util/
3232

3333
# Build
34-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
34+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
3535

3636
# Use distroless as minimal base image to package the manager binary
3737
# Refer to https://github.com/GoogleContainerTools/distroless for more details
3838
FROM gcr.io/distroless/static:nonroot
3939
WORKDIR /
4040
COPY --from=builder /workspace/manager .
41-
USER nonroot:nonroot
41+
USER 65532:65532
4242

4343
ENTRYPOINT ["/manager"]

Makefile

+152-67
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1-
# Directory, where all required tools are located (absolute path required)
2-
BUILD_PATH ?= $(shell pwd)
3-
TOOLS_DIR ?= $(shell cd tools 2>/dev/null && pwd)
4-
5-
YQ ?= yq
6-
7-
VERSION ?= 0.0.1-local
8-
KUBE_NAMESPACE ?= vault-operator
9-
LATEST_REV = $(shell git rev-list --tags --max-count=1)
10-
LATEST_TAG = $(shell git describe --tags $(LATEST_REV))
11-
12-
# Prerequisite tools
13-
GO ?= go
14-
GOOS ?= $(go env GOOS)
15-
GOARCH ?= $(go env GOARCH)
16-
DOCKER ?= docker
17-
KUBECTL ?= kubectl
18-
19-
KIND ?= $(TOOLS_DIR)/kind
20-
VAULT ?= $(TOOLS_DIR)/vault
21-
CONTROLLER_GEN ?= $(TOOLS_DIR)/controller-gen
22-
KUSTOMIZE ?= $(TOOLS_DIR)/kustomize
23-
KUBEBUILDER ?= $(TOOLS_DIR)/kubebuilder
24-
KUBEBUILDER_ASSETS ?= $(TOOLS_DIR)
25-
26-
# Variables
27-
MANAGER_BIN ?= bin/manager
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5+
ENVTEST_K8S_VERSION = 1.24.1
6+
7+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8+
ifeq (,$(shell go env GOBIN))
9+
GOBIN=$(shell go env GOPATH)/bin
10+
else
11+
GOBIN=$(shell go env GOBIN)
12+
endif
13+
14+
# Setting SHELL to bash allows bash commands to be executed by recipes.
15+
# This is a requirement for 'setup-envtest.sh' in the test target.
16+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
17+
SHELL = /usr/bin/env bash -o pipefail
18+
.SHELLFLAGS = -ec
19+
20+
.PHONY: all
21+
all: build
2822

2923
##@ General
3024

@@ -39,52 +33,143 @@ MANAGER_BIN ?= bin/manager
3933
# More info on the awk command:
4034
# http://linuxcommand.org/lc3_adv_awk.php
4135

36+
.PHONY: help
4237
help: ## Display this help.
4338
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
4439

45-
export
46-
47-
.PHONY: all go-test install uninstall deploy manifests
48-
49-
all: $(MANAGER_BIN)
50-
51-
$(MANAGER_BIN): generate fmt vet
52-
$(GO) build -o $(MANAGER_BIN) ./main.go
53-
54-
add-license: ## Adds the license to every file
55-
@docker run --rm -v "$(PWD):/src" -u $(shell id -u) ghcr.io/google/addlicense --ignore **/*.yaml --ignore **/*.yml -c "VaultOperator Authors" -l "apache" -v .
40+
##@ Development
5641

57-
check-license: ## Checks that the license is set on every file
58-
@docker run --rm -v "$(PWD):/src" -u $(shell id -u) ghcr.io/google/addlicense --ignore **/*.yaml --ignore **/*.yml -c "VaultOperator Authors" -l "apache" -v -check .
59-
60-
manifests: $(CONTROLLER_GEN) $(KUSTOMIZE) ## Generate manifests e.g. CRD, RBAC etc.
61-
$(CONTROLLER_GEN) crd:trivialVersions=false rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
62-
echo "# Generated by 'make manifests'\n" > $(HELM_CHART_DIR)/templates/crds.yaml
42+
.PHONY: manifests
43+
manifests: controller-gen kustomize ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
44+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
45+
echo "# Generated by 'make manifests'" > $(HELM_CHART_DIR)/templates/crds.yaml
6346
$(KUSTOMIZE) build config/crd-templates >> $(HELM_CHART_DIR)/templates/crds.yaml
64-
echo "# Generated by 'make manifests'\n" > $(HELM_CHART_DIR)/templates/webhook.yaml
47+
echo "# Generated by 'make manifests'" > $(HELM_CHART_DIR)/templates/webhook.yaml
6548
$(KUSTOMIZE) build config/webhook-templates >> $(HELM_CHART_DIR)/templates/webhook.yaml
6649

67-
generate: $(CONTROLLER_GEN) ## Generate code using controller-gen
68-
69-
tools: $(TOOLS_DIR)/kind $(TOOLS_DIR)/ginkgo $(TOOLS_DIR)/controller-gen $(TOOLS_DIR)/kustomize $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/kubebuilder ## Phony target to install all required tools into ${TOOLS_DIR}
70-
71-
$(TOOLS_DIR)/kind:
72-
@echo "Installing $@"
73-
@GOBIN=$(TOOLS_DIR) go install sigs.k8s.io/kind@v0.7.0
74-
75-
$(TOOLS_DIR)/controller-gen:
76-
@echo "Installing $@"
77-
@GOBIN=$(TOOLS_DIR) go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5
78-
79-
$(TOOLS_DIR)/kustomize:
80-
@echo "Installing $@"
81-
@$(TOOLS_DIR)/install_kustomize.sh $(TOOLS_DIR)
82-
83-
$(TOOLS_DIR)/vault:
84-
@$(TOOLS_DIR)/vault-install
85-
86-
$(TOOLS_DIR)/kubebuilder $(TOOLS_DIR)/kubectl $(TOOLS_DIR)/kube-apiserver $(TOOLS_DIR)/etcd:
87-
@$(TOOLS_DIR)/kubebuilder-install
50+
.PHONY: generate
51+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
52+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
53+
54+
.PHONY: fmt
55+
fmt: ## Run go fmt against code.
56+
go fmt ./...
57+
58+
.PHONY: vet
59+
vet: ## Run go vet against code.
60+
go vet ./...
61+
62+
.PHONY: lint
63+
lint: golangcilint ## Run linter against code.
64+
$(GOLANGCILINT) run -v -E goconst -E misspell
65+
66+
coverage: ## print coverage from coverprofiles
67+
go tool cover -func .coverprofile
68+
69+
.PHONY: test
70+
test: ginkgo manifests generate fmt vet envtest vault ## Run tests.
71+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" PATH="$(PATH):$(LOCALBIN)" $(GINKGO) -r -v -cover --failFast -requireSuite -covermode count -outputdir=. -coverprofile=.coverprofile
72+
73+
##@ Build
74+
75+
.PHONY: build
76+
build: generate fmt vet ## Build manager binary.
77+
go build -o bin/manager main.go
78+
79+
.PHONY: run
80+
run: manifests generate fmt vet ## Run a controller from your host.
81+
go run ./main.go
82+
83+
.PHONY: docker-build
84+
docker-build: test ## Build docker image with the manager.
85+
docker build -t ${IMG} .
86+
87+
.PHONY: docker-push
88+
docker-push: ## Push docker image with the manager.
89+
docker push ${IMG}
90+
91+
##@ Deployment
92+
93+
ifndef ignore-not-found
94+
ignore-not-found = false
95+
endif
96+
97+
.PHONY: install
98+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
99+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
100+
101+
.PHONY: uninstall
102+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
103+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
104+
105+
.PHONY: deploy
106+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
107+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
108+
$(KUSTOMIZE) build config/default | kubectl apply -f -
109+
110+
.PHONY: undeploy
111+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
112+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
113+
114+
##@ Build Dependencies
115+
116+
## Location to install dependencies to
117+
LOCALBIN ?= $(shell pwd)/bin
118+
$(LOCALBIN):
119+
mkdir -p $(LOCALBIN)
120+
121+
.PHONY:
122+
clean:
123+
rm -R $(LOCALBIN)
124+
125+
## Tool Binaries
126+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
127+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
128+
ENVTEST ?= $(LOCALBIN)/setup-envtest
129+
GINKGO ?= $(LOCALBIN)/ginkgo
130+
GOLANGCILINT ?= $(LOCALBIN)/golangci-lint
131+
VAULT ?= $(LOCALBIN)/vault
132+
133+
## Tool Versions
134+
KUSTOMIZE_VERSION ?= v4.5.5
135+
CONTROLLER_TOOLS_VERSION ?= v0.8.0
136+
GINKGO_VERSION ?= v1.16.5
137+
GOLANGCILINT_VERSION ?= v1.46.1
138+
VAULT_VERSION ?= 1.9.3
139+
GO_OS ?= $(shell go env GOOS)
140+
GO_ARCH ?= $(shell go env GOARCH)
141+
142+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
143+
.PHONY: kustomize
144+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
145+
$(KUSTOMIZE): $(LOCALBIN)
146+
curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
147+
148+
.PHONY: controller-gen
149+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
150+
$(CONTROLLER_GEN): $(LOCALBIN)
151+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
152+
153+
.PHONY: envtest
154+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
155+
$(ENVTEST): $(LOCALBIN)
156+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
157+
158+
.PHONY: ginkgo
159+
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
160+
$(GINKGO): $(LOCALBIN)
161+
GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/ginkgo@$(GINKGO_VERSION)
162+
163+
.PHONY: golangcilint
164+
golangcilint: $(GOLANGCILINT) ## Download golangci-lint locally if necessary.
165+
$(GOLANGCILINT): $(LOCALBIN)
166+
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION)
167+
168+
.PHONY: vault
169+
vault: $(VAULT) ## Download vault locally if necessary.
170+
$(VAULT): $(LOCALBIN)
171+
wget https://releases.hashicorp.com/vault/$(VAULT_VERSION)/vault_$(VAULT_VERSION)_$(GO_OS)_$(GO_ARCH).zip -O $(LOCALBIN)/vault.zip
172+
unzip -o $(LOCALBIN)/vault.zip -d $(LOCALBIN)
173+
rm $(LOCALBIN)/vault.zip
88174

89-
include go.mk
90175
include helm.mk

PROJECT

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
domain: github.com/finleap-connect/vaultoperator
2-
repo: https://github.com/finleap-connect/vaultoperator
1+
domain: vault.finleap.cloud
2+
layout:
3+
- go.kubebuilder.io/v3
4+
projectName: vaultoperator-new
5+
repo: github.com/finleap-connect/vaultoperator
36
resources:
4-
- group: vault
7+
- api:
8+
crdVersion: v1
9+
namespaced: true
10+
controller: true
11+
domain: vault.finleap.cloud
12+
group: vault.finleap.cloud
513
kind: VaultSecret
14+
path: github.com/finleap-connect/vaultoperator/api/v1alpha1
615
version: v1alpha1
7-
version: "2"
16+
version: "3"

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,3 @@ are significant differences to the [standard layout](https://github.com/golang-s
129129

130130
The test suite needs the kubebuilder assets. If they are not installed in the default
131131
path make sure to set `KUBEBUILDER_ASSETS` before running tests.
132-
Similarly the vault CLI needs to be setup, if it is outside your `PATH` make sure to
133-
set `VAULT_ASSETS` to the directory containing the vault executable.

api/v1alpha1/groupversion_info.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Package v1alpha1 contains API Schema definitions for the vault v1alpha1 API group
16-
// +kubebuilder:object:generate=true
17-
// +groupName=vault.finleap.cloud
15+
// Package v1alpha1 contains API Schema definitions for the vault.finleap.cloud v1alpha1 API group
16+
//+kubebuilder:object:generate=true
17+
//+groupName=vault.finleap.cloud
1818
package v1alpha1
1919

2020
import (

api/v1alpha1/vaultsecret_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type VaultSecretVariable struct {
6565
Location *VaultSecretLocation `json:"location,omitempty"`
6666
}
6767

68-
// Definition of a single data definiton
68+
// Definition of a single data definition
6969
type VaultSecretData struct {
7070
// Associated key name for the created secret data.
7171
// +kubebuilder:validation:MinLength=1

api/v1alpha1/vaultsecret_webhook.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (r *VaultSecret) SetupWebhookWithManager(mgr ctrl.Manager) error {
3232
Complete()
3333
}
3434

35-
// +kubebuilder:webhook:path=/validate-vault-finleap-cloud-v1alpha1-vaultsecret,mutating=false,failurePolicy=fail,groups=vault.finleap.cloud,resources=vaultsecrets,verbs=create;update,versions=v1alpha1,name=vvaultsecret.kb.io
35+
// +kubebuilder:webhook:path=/validate-vault-finleap-cloud-v1alpha1-vaultsecret,mutating=false,failurePolicy=fail,groups=vault.finleap.cloud,resources=vaultsecrets,verbs=create;update,versions=v1alpha1,name=vvaultsecret.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1;v1alpha1
3636

3737
var _ webhook.Validator = &VaultSecret{}
3838

api/v1alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)