-
Notifications
You must be signed in to change notification settings - Fork 318
migrate to kubebuilder 2.3.1 #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d4cc2c4
fbf01ff
e70ac96
c1e7fa4
a30c3c0
5a75573
49681e0
bf53718
6bee99f
2ac2985
0579769
7b05cbc
91980b5
d9479d9
994e9ed
5151562
a941c0d
ba7625e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Build the manager binary | ||
| FROM registry.hub.docker.com/library/golang:1.14 AS builder | ||
|
|
||
| WORKDIR /workspace | ||
|
|
||
| # Bring in the go dependencies before anything else so we can take | ||
| # advantage of caching these layers in future builds. | ||
| COPY go.mod go.mod | ||
| COPY go.sum go.sum | ||
| RUN go mod download | ||
|
|
||
| COPY . . | ||
| RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o baremetal-operator main.go | ||
|
|
||
| # Copy the controller-manager into a thin image | ||
| # BMO has a dependency preventing us to use the static one, | ||
| # using the base one instead | ||
| FROM gcr.io/distroless/base:latest | ||
|
zaneb marked this conversation as resolved.
|
||
| WORKDIR / | ||
| COPY --from=builder /workspace/baremetal-operator . | ||
|
dhellmann marked this conversation as resolved.
|
||
| USER nonroot:nonroot | ||
| ENTRYPOINT ["/baremetal-operator"] | ||
|
|
||
| LABEL io.k8s.display-name="Metal3 BareMetal Operator" \ | ||
| io.k8s.description="This is the image for the Metal3 BareMetal Operator." | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,22 @@ | ||
| TEST_NAMESPACE = operator-test | ||
| RUN_NAMESPACE = metal3 | ||
| GO_TEST_FLAGS = $(VERBOSE) | ||
| DEBUG = --debug | ||
| SETUP = --no-setup | ||
| CODE_DIRS = ./cmd ./pkg ./version | ||
| PACKAGES = $(foreach dir,$(CODE_DIRS),$(dir)/...) | ||
| COVER_PROFILE = cover.out | ||
|
|
||
| # CRD Generation Options | ||
| # | ||
| # trivialVersions=false means generate the CRD with multiple versions, | ||
| # eventually allowing conversion webhooks | ||
| # allowDangerousTypes=true lets use the float64 field for clock speeds | ||
| # crdVersions=v1 generates the v1 version of the CRD type | ||
| # | ||
| # NOTE: Assumes the default is preserveUnknownFields=false with | ||
| # crdVersions=v1, so that the API server discards "extra" data | ||
| # instead of storing it | ||
| # | ||
| CRD_OPTIONS ?= "crd:trivialVersions=false,allowDangerousTypes=true,crdVersions=v1" | ||
| CONTROLLER_TOOLS_VERSION=v0.4.0 | ||
|
|
||
| # Directories. | ||
| TOOLS_DIR := tools | ||
| TOOLS_BIN_DIR := $(TOOLS_DIR)/bin | ||
|
|
@@ -38,153 +48,181 @@ help: ## Display this help | |
| @echo " GO_TEST_FLAGS -- flags to pass to --go-test-flags ($(GO_TEST_FLAGS))" | ||
| @echo " DEBUG -- debug flag, if any ($(DEBUG))" | ||
|
|
||
| .PHONY: $(KUSTOMIZE) | ||
| $(KUSTOMIZE): | ||
| cd $(TOOLS_DIR); ./install_kustomize.sh | ||
| # Image URL to use all building/pushing image targets | ||
| IMG ?= baremetal-operator:latest | ||
| # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
| CRD_OPTIONS ?= "crd:trivialVersions=true" | ||
|
|
||
| .PHONY: test | ||
| test: fmt generate lint vet unit ## Run common developer tests | ||
| # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
| ifeq (,$(shell go env GOBIN)) | ||
| GOBIN=$(shell go env GOPATH)/bin | ||
| else | ||
| GOBIN=$(shell go env GOBIN) | ||
| endif | ||
|
|
||
| .PHONY: show_packages show_dirs | ||
| show_packages: | ||
| @echo $(PACKAGES) | ||
| show_dirs: | ||
| @echo $(CODE_DIRS) | ||
| ## -------------------------------------- | ||
| ## Test Targets | ||
| ## -------------------------------------- | ||
|
|
||
| .PHONY: generate | ||
| generate: bin/operator-sdk ## Run the operator-sdk code generator | ||
| ./bin/operator-sdk generate $(VERBOSE) k8s | ||
| ./bin/operator-sdk generate $(VERBOSE) crds --crd-version=v1 | ||
| openapi-gen \ | ||
| --input-dirs ./pkg/apis/metal3/v1alpha1 \ | ||
| --output-package ./pkg/apis/metal3/v1alpha1 \ | ||
| --output-base "" \ | ||
| --output-file-base zz_generated.openapi \ | ||
| --report-filename "-" \ | ||
| --go-header-file /dev/null | ||
|
|
||
| bin/operator-sdk: bin | ||
| make -C tools/operator-sdk install | ||
|
|
||
| bin: | ||
| mkdir -p bin | ||
|
|
||
| .PHONY: travis | ||
| travis: unit-verbose lint | ||
| # Run tests | ||
| .PHONY: test | ||
| test: generate fmt lint vet manifests unit ## Run common developer tests | ||
|
|
||
| .PHONY: unit | ||
| unit: ## Run unit tests | ||
| go test $(GO_TEST_FLAGS) $(PACKAGES) | ||
| go test ./... $(VERBOSE) -coverprofile $(COVER_PROFILE) | ||
|
|
||
| .PHONY: unit-cover | ||
| unit-cover: ## Run unit tests with code coverage | ||
| go test -coverprofile=$(COVER_PROFILE) $(GO_TEST_FLAGS) $(PACKAGES) | ||
| go test -coverprofile=$(COVER_PROFILE) $(GO_TEST_FLAGS) ./... | ||
| go tool cover -func=$(COVER_PROFILE) | ||
|
|
||
| .PHONY: unit-cover-html | ||
| unit-cover-html: | ||
| go test -coverprofile=cover.out $(GO_TEST_FLAGS) $(PACKAGES) | ||
| go tool cover -html=cover.out | ||
|
|
||
| .PHONY: unit-verbose | ||
| unit-verbose: ## Run unit tests with verbose output | ||
| VERBOSE=-v make unit | ||
|
|
||
| ## -------------------------------------- | ||
| ## Linter Targets | ||
| ## -------------------------------------- | ||
|
|
||
| .PHONY: linters | ||
| linters: sec lint generate-check fmt-check vet ## Run all linters | ||
|
|
||
| .PHONY: vet | ||
| vet: ## Run go vet | ||
| go vet $(PACKAGES) | ||
|
|
||
| .PHONY: lint | ||
| lint: golint-binary ## Run golint | ||
| find $(CODE_DIRS) -type f -name \*.go |grep -v zz_ | xargs -L1 golint -set_exit_status | ||
|
|
||
| .PHONY: generate-check | ||
| generate-check: | ||
| ./hack/generate.sh | ||
|
|
||
| .PHONY: generate-check-local | ||
| generate-check-local: | ||
| IS_CONTAINER=local ./hack/generate.sh | ||
|
|
||
| .PHONY: sec | ||
| sec: $(GOPATH)/bin/gosec ## Run gosec | ||
| gosec -severity medium --confidence medium -quiet $(PACKAGES) | ||
| gosec -severity medium --confidence medium -quiet ./... | ||
|
|
||
| $(GOPATH)/bin/gosec: | ||
| go get -u github.com/securego/gosec/cmd/gosec | ||
|
|
||
| .PHONY: fmt | ||
| fmt: ## Run go fmt against code | ||
|
dhellmann marked this conversation as resolved.
|
||
| go fmt ./... | ||
|
|
||
| .PHONY: vet | ||
| vet: ## Run go vet against code | ||
| go vet ./... | ||
|
|
||
| .PHONY: lint | ||
| lint: golint-binary ## Run golint | ||
| find $(CODE_DIRS) -type f -name \*.go |grep -v zz_ | xargs -L1 golint -set_exit_status | ||
|
|
||
| .PHONY: golint-binary | ||
| golint-binary: | ||
| which golint 2>&1 >/dev/null || $(MAKE) $(GOPATH)/bin/golint | ||
| $(GOPATH)/bin/golint: | ||
| go get -u golang.org/x/lint/golint | ||
|
|
||
| .PHONY: fmt | ||
| fmt: ## Run gofmt and write changes to each file | ||
| gofmt -l -w $(CODE_DIRS) | ||
|
|
||
| .PHONY: fmt-check | ||
| fmt-check: ## Run gofmt and report an error if any changes are made | ||
| ./hack/gofmt.sh | ||
|
|
||
| .PHONY: docs | ||
| docs: $(patsubst %.dot,%.png,$(wildcard docs/*.dot)) | ||
| ## -------------------------------------- | ||
| ## Build/Run Targets | ||
| ## -------------------------------------- | ||
|
|
||
| %.png: %.dot | ||
| dot -Tpng $< >$@ | ||
| .PHONY: build | ||
| build: generate manifests manager tools ## Build everything | ||
|
|
||
| .PHONY: e2e-local | ||
| e2e-local: | ||
| operator-sdk test local ./test/e2e \ | ||
| --namespace $(TEST_NAMESPACE) \ | ||
| --up-local $(SETUP) \ | ||
| $(DEBUG) --go-test-flags "$(GO_TEST_FLAGS)" | ||
| .PHONY: manager | ||
| manager: generate fmt vet ## Build manager binary | ||
| go build -ldflags $(LDFLAGS) -o bin/manager main.go | ||
|
|
||
| .PHONY: run | ||
| run: ## Run the operator outside of a cluster in development mode | ||
| operator-sdk run --local \ | ||
| --go-ldflags=$(LDFLAGS) \ | ||
| --watch-namespace=$(RUN_NAMESPACE) \ | ||
| --operator-flags="-dev" | ||
| run: generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config | ||
| go run -ldflags $(LDFLAGS) ./main.go -namespace=$(RUN_NAMESPACE) -dev | ||
|
|
||
| .PHONY: demo | ||
| demo: ## Run the operator outside of a cluster using the demo driver | ||
| operator-sdk run --local \ | ||
| --go-ldflags=$(LDFLAGS) \ | ||
| --watch-namespace=$(RUN_NAMESPACE) \ | ||
| --operator-flags="-dev -demo-mode" | ||
| demo: generate fmt vet manifests ## Run in demo mode | ||
| go run -ldflags $(LDFLAGS) ./main.go -namespace=$(RUN_NAMESPACE) -dev -demo-mode | ||
|
|
||
| .PHONY: install | ||
| install: $(KUSTOMIZE) manifests ## Install CRDs into a cluster | ||
| $(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
|
||
| .PHONY: uninstall | ||
| uninstall: $(KUSTOMIZE) manifests ## Uninstall CRDs from a cluster | ||
| kustomize build config/crd | kubectl delete -f - | ||
|
|
||
| .PHONY: deploy | ||
| deploy: $(KUSTOMIZE) manifests ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
| cd config/manager && kustomize edit set image controller=${IMG} | ||
| kustomize build config/default | kubectl apply -f - | ||
|
|
||
| .PHONY: manifests | ||
| manifests: controller-gen ## Generate manifests e.g. CRD, RBAC etc. | ||
| $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
|
||
| .PHONY: generate | ||
| generate: controller-gen ## Generate code | ||
| $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
|
||
| .PHONY: $(KUSTOMIZE) | ||
| $(KUSTOMIZE): | ||
| cd $(TOOLS_DIR); ./install_kustomize.sh | ||
|
|
||
| # find or download controller-gen | ||
| # download controller-gen if necessary | ||
| .PHONY: controller-gen | ||
| controller-gen: | ||
| ifeq (, $(shell which controller-gen)) | ||
| @{ \ | ||
| set -e ;\ | ||
| CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
| cd $$CONTROLLER_GEN_TMP_DIR ;\ | ||
| go mod init tmp ;\ | ||
| go get sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) ;\ | ||
| rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ | ||
| } | ||
| CONTROLLER_GEN=$(GOBIN)/controller-gen | ||
| else | ||
| CONTROLLER_GEN=$(shell which controller-gen) | ||
| endif | ||
|
Comment on lines
+164
to
+176
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not ensure that we are running with a specific version of controller-gen. If the user has an outdated controller-gen installed on his machine, it might result in confusing behaviour. Should the executable be placed in a dedicated location, and referred as such, like Kustomize ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed this today in the community meeting and agreed that I will make this change as a follow-up PR. |
||
|
|
||
| ## -------------------------------------- | ||
| ## Docker Targets | ||
| ## -------------------------------------- | ||
|
|
||
| .PHONY: docker | ||
| docker: docker-operator docker-sdk docker-golint ## Build docker images | ||
| docker: test ## Build the docker image | ||
| docker build . -t ${IMG} | ||
|
|
||
| .PHONY: docker-operator | ||
| docker-operator: | ||
| docker build . -f build/Dockerfile | ||
| # Push the docker image | ||
| .PHONY: docker-push | ||
| docker-push: | ||
| docker push ${IMG} | ||
|
|
||
| .PHONY: docker-sdk | ||
| docker-sdk: | ||
| docker build . -f hack/Dockerfile.operator-sdk | ||
| ## -------------------------------------- | ||
| ## CI Targets | ||
| ## -------------------------------------- | ||
|
|
||
| .PHONY: docker-golint | ||
| docker-golint: | ||
| docker build . -f hack/Dockerfile.golint | ||
| .PHONY: generate-check | ||
| generate-check: | ||
| ./hack/generate.sh | ||
|
|
||
| .PHONY: build | ||
| build: ## Build the operator binary | ||
| @echo LDFLAGS=$(LDFLAGS) | ||
| go build -ldflags $(LDFLAGS) -o build/_output/bin/baremetal-operator cmd/manager/main.go | ||
| .PHONY: generate-check-local | ||
| generate-check-local: | ||
| IS_CONTAINER=local ./hack/generate.sh | ||
|
|
||
| .PHONY: fmt-check | ||
| fmt-check: ## Run gofmt and report an error if any changes are made | ||
| ./hack/gofmt.sh | ||
|
|
||
| ## -------------------------------------- | ||
| ## Documentation | ||
| ## -------------------------------------- | ||
|
|
||
| .PHONY: docs | ||
| docs: $(patsubst %.dot,%.png,$(wildcard docs/*.dot)) | ||
|
|
||
| %.png: %.dot | ||
| dot -Tpng $< >$@ | ||
|
|
||
| ## -------------------------------------- | ||
| ## Tool apps | ||
| ## -------------------------------------- | ||
|
|
||
| .PHONY: tools | ||
| tools: | ||
| go build -o build/_output/bin/get-hardware-details cmd/get-hardware-details/main.go | ||
|
|
||
| .PHONY: deploy | ||
| deploy: | ||
| cd deploy && kustomize edit set namespace $(RUN_NAMESPACE) && cd .. | ||
| kustomize build deploy | kubectl apply -f - | ||
| go build -o bin/get-hardware-details cmd/get-hardware-details/main.go | ||
| go build -o bin/make-bm-worker cmd/make-bm-worker/main.go | ||
| go build -o bin/make-virt-host cmd/make-virt-host/main.go | ||
|
|
||
| ## -------------------------------------- | ||
| ## Tilt / Kind | ||
|
|
@@ -201,3 +239,12 @@ tilt-up: $(KUSTOMIZE) kind-create ## start tilt and build kind cluster if needed | |
| .PHONY: kind-reset | ||
| kind-reset: ## Destroys the "bmo" kind cluster. | ||
| kind delete cluster --name=bmo || true | ||
|
|
||
| ## -------------------------------------- | ||
| ## Go module Targets | ||
| ## -------------------------------------- | ||
|
|
||
| .PHONY: | ||
| mod: ## Clean up go module settings | ||
| go mod tidy | ||
| go mod verify | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| multigroup: true | ||
| repo: github.com/metal3-io/baremetal-operator | ||
| resources: | ||
| - group: metal3.io | ||
| kind: BareMetalHost | ||
| version: v1alpha1 | ||
| version: "2" |
Uh oh!
There was an error while loading. Please reload this page.