forked from konpyutaika/nifikop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
11,048 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ IMAGE_TAG ?= $(shell git describe --tags --abbrev=0 --match '[0-9].*[0-9].*[0 | |
IMAGE_NAME ?= $(SERVICE_NAME) | ||
BUILD_IMAGE ?= ghcr.io/konpyutaika/docker-images/nifikop-build | ||
GOLANG_VERSION ?= 1.15 | ||
IMAGE_TAG_BASE ?= <registry>/<operator name> | ||
OS = $(shell go env GOOS) | ||
ARCH = $(shell go env GOARCH) | ||
|
||
# workdir | ||
WORKDIR := /go/nifikop | ||
|
@@ -14,13 +17,28 @@ TELEPRESENCE_REGISTRY ?= datawire | |
|
||
DEV_DIR := docker/build-image | ||
|
||
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command | ||
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) | ||
|
||
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests | ||
# You can enable this value if you would like to use SHA Based Digests | ||
# To enable set flag to true | ||
USE_IMAGE_DIGESTS ?= false | ||
ifeq ($(USE_IMAGE_DIGESTS), true) | ||
BUNDLE_GEN_FLAGS += --use-image-digests | ||
endif | ||
|
||
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. | ||
ENVTEST_K8S_VERSION = 1.22 | ||
|
||
# Repository url for this project | ||
# in gitlab CI_REGISTRY_IMAGE=repo/path/name:tag | ||
ifdef CI_REGISTRY_IMAGE | ||
REPOSITORY := $(CI_REGISTRY_IMAGE) | ||
else | ||
REPOSITORY := $(DOCKER_REGISTRY_BASE)/$(IMAGE_NAME) | ||
endif | ||
IMAGE_TAG_BASE = $(REPOSITORY) | ||
|
||
# Branch is used for the docker image version | ||
ifdef CIRCLE_BRANCH | ||
|
@@ -53,8 +71,11 @@ ifeq ($(CIRCLE_BRANCH),master) | |
endif | ||
|
||
# The default action of this Makefile is to build the development docker image | ||
.PHONY: default | ||
default: build | ||
all: manager | ||
|
||
.PHONY: all | ||
all: build | ||
|
||
# Default bundle image tag | ||
BUNDLE_IMG ?= $(REPOSITORY)-bundle:$(VERSION) | ||
|
@@ -67,89 +88,111 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) | |
endif | ||
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) | ||
|
||
|
||
# ---- | ||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" | ||
|
||
# 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 | ||
|
||
# Setting SHELL to bash allows bash commands to be executed by recipes. | ||
# This is a requirement for 'setup-envtest.sh' in the test target. | ||
# Options are set to exit when a recipe line exits non-zero or a piped command fails. | ||
SHELL = /usr/bin/env bash -o pipefail | ||
.SHELLFLAGS = -ec | ||
|
||
# Build manager binary | ||
.PHONY: manager | ||
manager: generate fmt vet | ||
go build -o bin/manager main.go | ||
|
||
# Generate code | ||
.PHONY: generate | ||
generate: controller-gen | ||
@echo "Generate zzz-deepcopy objects" | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
# Generate manifests e.g. CRD, RBAC etc. | ||
.PHONY: manifests | ||
manifests: controller-gen | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/base | ||
mkdir -p helm/nifikop/crds && cp config/crd/bases/* helm/nifikop/crds | ||
|
||
# Build the docker image | ||
.PHONY: docker-build | ||
docker-build: | ||
docker build -t $(REPOSITORY):$(VERSION) . | ||
|
||
.PHONY: build | ||
build: manager manifests docker-build | ||
|
||
# Download controller-gen locally if necessary | ||
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen | ||
controller-gen: | ||
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
.PHONY: controller-gen | ||
controller-gen: ## Download controller-gen locally if necessary. | ||
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
|
||
# Run go fmt against code | ||
.PHONY: fmt | ||
fmt: | ||
go fmt ./... | ||
|
||
# Run go vet against code | ||
.PHONY: vet | ||
vet: | ||
go vet ./... | ||
|
||
# Run tests | ||
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin | ||
test: generate fmt vet manifests | ||
mkdir -p ${ENVTEST_ASSETS_DIR} | ||
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh | ||
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out; go tool cover -html=cover.out -o coverage.html | ||
.PHONY: test | ||
test: manifests generate fmt vet envtest | ||
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out | ||
|
||
test-with-vendor: generate fmt vet manifests | ||
mkdir -p ${ENVTEST_ASSETS_DIR} | ||
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh | ||
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test -mod=vendor ./... -coverprofile cover.out; go tool cover -html=cover.out -o coverage.html | ||
.PHONY: test-with-vendor | ||
test-with-vendor: manifests generate fmt vet envtest | ||
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -mod=vendor ./... -coverprofile cover.out | ||
|
||
# Run against the configured Kubernetes cluster in ~/.kube/config | ||
.PHONY: run | ||
run: generate fmt vet manifests | ||
go run ./main.go | ||
|
||
ifndef ignore-not-found | ||
ignore-not-found = false | ||
endif | ||
|
||
# Install CRDs into a cluster | ||
.PHONY: install | ||
install: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
||
# Uninstall CRDs from a cluster | ||
.PHONY: uninstall | ||
uninstall: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl delete -f - | ||
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - | ||
|
||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
.PHONY: deploy | ||
deploy: manifests kustomize | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=$(REPOSITORY):$(VERSION) | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
|
||
# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config | ||
.PHONY: undeploy | ||
undeploy: | ||
$(KUSTOMIZE) build config/default | kubectl delete -f - | ||
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - | ||
|
||
# Download kustomize locally if necessary | ||
KUSTOMIZE = $(shell pwd)/bin/kustomize | ||
.PHONY: kustomize | ||
kustomize: | ||
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected]) | ||
|
||
ENVTEST = $(shell pwd)/bin/setup-envtest | ||
.PHONY: envtest | ||
envtest: ## Download envtest-setup locally if necessary. | ||
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) | ||
|
||
# go-get-tool will 'go get' any package $2 and install it to $1. | ||
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
define go-get-tool | ||
|
@@ -167,16 +210,17 @@ endef | |
# Generate bundle manifests and metadata, then validate generated files. | ||
.PHONY: bundle | ||
bundle: manifests kustomize | ||
operator-sdk generate kustomize manifests -q | ||
operator-sdk generate kustomize manifests --interactive=false -q | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=$(REPOSITORY):$(VERSION) | ||
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) | ||
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS) | ||
operator-sdk bundle validate ./bundle | ||
|
||
# Build the bundle image. | ||
.PHONY: bundle-build | ||
bundle-build: | ||
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . | ||
|
||
.PHONY: helm-package | ||
helm-package: | ||
@echo Packaging $(CHART_VERSION) | ||
ifdef CHART_VERSION | ||
|
@@ -190,6 +234,7 @@ endif | |
helm repo index $(HELM_TARGET_DIR)/ | ||
|
||
# Push the docker image | ||
.PHONY: docker-push | ||
docker-push: | ||
docker push $(REPOSITORY):$(VERSION) | ||
ifdef PUSHLATEST | ||
|
@@ -199,19 +244,23 @@ endif | |
# ---- | ||
|
||
.DEFAULT_GOAL := help | ||
.PHONY: help | ||
help: | ||
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' | ||
|
||
.PHONY: get-version | ||
get-version: | ||
@echo $(VERSION) | ||
|
||
.PHONY: clean | ||
clean: | ||
@rm -rf $(OUT_BIN) || true | ||
@rm -f api/v1alpha1/zz_generated.deepcopy.go || true | ||
|
||
#Generate dep for graph | ||
UNAME := $(shell uname -s) | ||
|
||
.PHONY: dep-graph | ||
dep-graph: | ||
ifeq ($(UNAME), Darwin) | ||
dep status -dot | dot -T png | open -f -a /Applications/Preview.app | ||
|
@@ -220,9 +269,11 @@ ifeq ($(UNAME), Linux) | |
dep status -dot | dot -T png | display | ||
endif | ||
|
||
.PHONY: debug-port-forward | ||
debug-port-forward: | ||
kubectl port-forward `kubectl get pod -l app=nifikop -o jsonpath="{.items[0].metadata.name}"` 40000:40000 | ||
|
||
.PHONY: debug-pod-logs | ||
debug-pod-logs: | ||
kubectl logs -f `kubectl get pod -l app=nifikop -o jsonpath="{.items[0].metadata.name}"` | ||
|
||
|
@@ -236,13 +287,16 @@ define debug_telepresence | |
telepresence --swap-deployment $$tdep --mount=/tmp/known --env-file nifi-operator.env $1 $2 | ||
endef | ||
|
||
.PHONY: debug-telepresence | ||
debug-telepresence: | ||
$(call debug_telepresence) | ||
|
||
.PHONY: debug-telepresence-with-alias | ||
debug-telepresence-with-alias: | ||
$(call debug_telepresence,--also-proxy,10.40.0.0/16) | ||
|
||
# Build the docker development environment | ||
.PHONY: build-ci-image | ||
build-ci-image: | ||
docker build --cache-from $(BUILD_IMAGE):latest \ | ||
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \ | ||
|
@@ -251,6 +305,7 @@ build-ci-image: | |
-f $(DEV_DIR)/Dockerfile \ | ||
. | ||
|
||
.PHONY: push-ci-image | ||
push-ci-image: | ||
docker push $(BUILD_IMAGE):$(GOLANG_VERSION) | ||
ifdef PUSHLATEST | ||
|
@@ -262,4 +317,29 @@ endif | |
#ifndef DOCKER | ||
# @echo "Docker is not available. Please install docker" | ||
# @exit 1 | ||
#endif | ||
#endif | ||
|
||
.PHONY: opm | ||
OPM = ./bin/opm | ||
opm: | ||
ifeq (,$(wildcard $(OPM))) | ||
ifeq (,$(shell which opm 2>/dev/null)) | ||
@{ \ | ||
set -e ;\ | ||
mkdir -p $(dir $(OPM)) ;\ | ||
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.19.1/$(OS)-$(ARCH)-opm ;\ | ||
chmod +x $(OPM) ;\ | ||
} | ||
else | ||
OPM = $(shell which opm) | ||
endif | ||
endif | ||
BUNDLE_IMGS ?= $(BUNDLE_IMG) | ||
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION) ifneq ($(origin CATALOG_BASE_IMG), undefined) FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) endif | ||
.PHONY: catalog-build | ||
catalog-build: opm | ||
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) | ||
|
||
.PHONY: catalog-push | ||
catalog-push: ## Push the catalog image. | ||
$(MAKE) docker-push IMG=$(CATALOG_IMG) |
Oops, something went wrong.