-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andrew Block <[email protected]>
- Loading branch information
Showing
13 changed files
with
251 additions
and
289 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 |
---|---|---|
|
@@ -9,5 +9,8 @@ jobs: | |
name: shared-operator-workflow | ||
uses: redhat-cop/github-workflows-operators/.github/workflows/[email protected] | ||
with: | ||
GO_VERSION: ~1.18 | ||
GO_VERSION: ~1.21 | ||
RUN_UNIT_TESTS: true | ||
RUN_INTEGRATION_TESTS: false | ||
RUN_HELMCHART_TEST: false | ||
OPERATOR_SDK_VERSION: v1.25.2 |
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 |
---|---|---|
|
@@ -16,5 +16,8 @@ jobs: | |
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} | ||
with: | ||
PR_ACTOR: "[email protected]" | ||
GO_VERSION: ~1.18 | ||
GO_VERSION: ~1.21 | ||
RUN_UNIT_TESTS: true | ||
RUN_INTEGRATION_TESTS: false | ||
RUN_HELMCHART_TEST: false | ||
OPERATOR_SDK_VERSION: v1.25.2 |
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
CHART_REPO_URL ?= http://example.com | ||
HELM_REPO_DEST ?= /tmp/gh-pages | ||
OPERATOR_NAME ?=$(shell basename -z `pwd`) | ||
OPERATOR_NAME ?=$(shell basename `pwd` | tr -d '\n') | ||
|
||
# Platform | ||
ifeq ($(OS),Windows_NT) | ||
|
@@ -15,17 +15,13 @@ else | |
endif | ||
endif | ||
|
||
|
||
SHELL := /bin/bash | ||
# Current Operator version | ||
VERSION ?= 0.0.1 | ||
# Operator SDK | ||
OPERATOR_SDK ?= operator-sdk | ||
# YQ Version | ||
YQ_VERSION ?= 4.9.8 | ||
YQ_VERSION ?= 4.44.1 | ||
|
||
# Default bundle image tag | ||
BUNDLE_IMG ?= quay.io/redhat-cop/group-sync-operator-bundle:$(VERSION) | ||
# Options for 'bundle-build' | ||
ifneq ($(origin CHANNELS), undefined) | ||
BUNDLE_CHANNELS := --channels=$(CHANNELS) | ||
|
@@ -38,7 +34,10 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) | |
# Image URL to use all building/pushing image targets | ||
IMG ?= quay.io/redhat-cop/group-sync-operator:$(VERSION) | ||
|
||
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. | ||
ENVTEST_K8S_VERSION = 1.25.0 | ||
|
||
ENVTEST_VERSION ?= release-0.16 | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
|
@@ -93,6 +92,10 @@ IMG ?= controller:latest | |
SHELL = /usr/bin/env bash -o pipefail | ||
.SHELLFLAGS = -ec | ||
|
||
# Enable multiple container tools | ||
CONTAINER_TOOL ?= docker | ||
|
||
.PHONY: all | ||
all: build | ||
|
||
##@ General | ||
|
@@ -108,31 +111,35 @@ all: build | |
# More info on the awk command: | ||
# http://linuxcommand.org/lc3_adv_awk.php | ||
|
||
.PHONY: help | ||
help: ## Display this help. | ||
@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) | ||
|
||
##@ Development | ||
|
||
.PHONY: manifests | ||
manifests: controller-gen yq ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. | ||
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
YQ=$(YQ) $(shell pwd)/hack/fix-ldap-provider-crd.sh | ||
|
||
.PHONY: generate | ||
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
.PHONY: fmt | ||
fmt: ## Run go fmt against code. | ||
go fmt ./... | ||
|
||
.PHONY: vet | ||
vet: ## Run go vet against code. | ||
go vet ./... | ||
|
||
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin | ||
test: manifests generate fmt vet ## Run tests. | ||
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.8.3/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 | ||
.PHONY: test | ||
test: manifests generate fmt vet envtest ## Run tests. | ||
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out | ||
|
||
YQ=$(shell pwd)/bin/yq | ||
.PHONY: yq | ||
YQ=$(LOCALBIN)/yq | ||
yq: | ||
ifeq ("$(wildcard $(YQ))","") | ||
@{ \ | ||
|
@@ -145,66 +152,87 @@ yq: | |
|
||
##@ Build | ||
|
||
.PHONY: build | ||
build: generate fmt vet ## Build manager binary. | ||
go build -o bin/manager main.go | ||
|
||
.PHONY: run | ||
run: manifests generate fmt vet ## Run a controller from your host. | ||
go run ./main.go | ||
|
||
.PHONY: docker-build | ||
docker-build: test ## Build docker image with the manager. | ||
docker build -t ${IMG} . | ||
$(CONTAINER_TOOL) build -t ${IMG} . | ||
|
||
.PHONY: docker-push | ||
docker-push: ## Push docker image with the manager. | ||
docker push ${IMG} | ||
$(CONTAINER_TOOL) push ${IMG} | ||
|
||
##@ Deployment | ||
|
||
ifndef ignore-not-found | ||
ignore-not-found = false | ||
endif | ||
|
||
.PHONY: install | ||
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. | ||
$(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
||
.PHONY: uninstall | ||
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. | ||
$(KUSTOMIZE) build config/crd | kubectl delete -f - | ||
|
||
.PHONY: deploy | ||
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
|
||
.PHONY: undeploy | ||
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. | ||
$(KUSTOMIZE) build config/default | kubectl delete -f - | ||
|
||
##@ Build Dependencies | ||
|
||
## Location to install dependencies to | ||
LOCALBIN ?= $(shell pwd)/bin | ||
$(LOCALBIN): | ||
mkdir -p $(LOCALBIN) | ||
|
||
## Tool Binaries | ||
KUSTOMIZE ?= $(LOCALBIN)/kustomize | ||
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen | ||
ENVTEST ?= $(LOCALBIN)/setup-envtest | ||
|
||
## Tool Versions | ||
KUSTOMIZE_VERSION ?= v3.8.7 | ||
CONTROLLER_TOOLS_VERSION ?= v0.10.0 | ||
|
||
.PHONY: controller-gen | ||
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. | ||
$(CONTROLLER_GEN): $(LOCALBIN) | ||
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) | ||
|
||
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | ||
.PHONY: kustomize | ||
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. | ||
$(KUSTOMIZE): $(LOCALBIN) | ||
curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN) | ||
|
||
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen | ||
controller-gen: ## Download controller-gen locally if necessary. | ||
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
|
||
KUSTOMIZE = $(shell pwd)/bin/kustomize | ||
kustomize: ## Download kustomize locally if necessary. | ||
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected]) | ||
|
||
#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 | ||
@[ -f $(1) ] || { \ | ||
set -e ;\ | ||
TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
echo "Downloading $(2)" ;\ | ||
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ | ||
rm -rf $$TMP_DIR ;\ | ||
} | ||
endef | ||
.PHONY: envtest | ||
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. | ||
$(ENVTEST): $(LOCALBIN) | ||
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION) | ||
|
||
.PHONY: bundle | ||
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files. | ||
operator-sdk generate kustomize manifests -q | ||
$(OPERATOR_SDK) generate kustomize manifests -q | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) | ||
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) | ||
operator-sdk bundle validate ./bundle | ||
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) | ||
$(OPERATOR_SDK) bundle validate ./bundle | ||
|
||
.PHONY: bundle-build | ||
bundle-build: ## Build the bundle image. | ||
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . | ||
$(CONTAINER_TOOL) build -f bundle.Dockerfile -t $(BUNDLE_IMG) . | ||
|
||
.PHONY: bundle-push | ||
bundle-push: ## Push the bundle image. | ||
|
@@ -244,7 +272,7 @@ endif | |
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator | ||
.PHONY: catalog-build | ||
catalog-build: opm ## Build a catalog image. | ||
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) | ||
$(OPM) index add --container-tool $(CONTAINER_TOOL) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) | ||
|
||
# Push the catalog image. | ||
.PHONY: catalog-push | ||
|
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -9,4 +9,4 @@ spec: | |
- port: 443 | ||
targetPort: 9443 | ||
selector: | ||
control-plane: controller-manager | ||
control-plane: group-sync-operator |
Oops, something went wrong.