forked from pravega/zookeeper-operator
-
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.
Refactor structure and rewrite e2e test acconding to https://sdk.operatorframework.io/docs/building-operators/golang/migration Fixes: pravega#443 Signed-off-by: akamyshnikova <[email protected]>
- Loading branch information
1 parent
b150f81
commit 3dc56c8
Showing
68 changed files
with
6,505 additions
and
2,136 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
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 |
---|---|---|
|
@@ -7,6 +7,23 @@ | |
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
SHELL=/bin/bash -o pipefail | ||
# Current Operator version | ||
VERSION ?= 0.0.1 | ||
# Default bundle image tag | ||
BUNDLE_IMG ?= controller-bundle:$(VERSION) | ||
# Options for 'bundle-build' | ||
ifneq ($(origin CHANNELS), undefined) | ||
BUNDLE_CHANNELS := --channels=$(CHANNELS) | ||
endif | ||
ifneq ($(origin DEFAULT_CHANNEL), undefined) | ||
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) | ||
endif | ||
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG ?= controller:latest | ||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
CRD_OPTIONS ?= "crd:trivialVersions=true" | ||
|
||
PROJECT_NAME=zookeeper-operator | ||
EXPORTER_NAME=zookeeper-exporter | ||
|
@@ -24,17 +41,109 @@ TEST_IMAGE=$(TEST_REPO)-testimages:$(VERSION) | |
DOCKER_TEST_PASS=testzkop@123 | ||
DOCKER_TEST_USER=testzkop | ||
.PHONY: all build check clean test | ||
# 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 | ||
|
||
# Install CRDs into a cluster | ||
install: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
||
# Uninstall CRDs from a cluster | ||
uninstall: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl delete -f - | ||
|
||
crds: ## Generate CRDs | ||
- make controller-gen | ||
- $(CONTROLLER_GEN) crd paths=./api/... output:dir=./config/crd/bases schemapatch:manifests=./config/crd/bases | ||
|
||
|
||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
deploy: manifests kustomize | ||
cd config/manager && $(KUSTOMIZE) edit set image pravega/zookeeper-operator=$(TEST_IMAGE) | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
|
||
|
||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
deploy-test: manifests kustomize | ||
cd config/test | ||
$(KUSTOMIZE) build config/test | kubectl apply -f - | ||
|
||
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
undeploy-test: manifests kustomize | ||
cd config/test | ||
$(KUSTOMIZE) build config/test | kubectl apply -f - | ||
|
||
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
undeploy: | ||
$(KUSTOMIZE) build config/default | kubectl delete -f - | ||
|
||
# Generate manifests e.g. CRD, RBAC etc. | ||
manifests: controller-gen | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
||
# Run go fmt against code | ||
fmt: | ||
go fmt ./... | ||
|
||
# Run go vet against code | ||
vet: | ||
go vet ./... | ||
|
||
|
||
# Build the docker image | ||
docker-build: test | ||
docker build . -t ${IMG} | ||
|
||
# Push the docker image | ||
docker-push: | ||
docker push ${IMG} | ||
|
||
# find or download controller-gen | ||
# download controller-gen if necessary | ||
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/[email protected] ;\ | ||
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ | ||
} | ||
CONTROLLER_GEN=$(GOBIN)/controller-gen | ||
else | ||
CONTROLLER_GEN=$(shell which controller-gen) | ||
endif | ||
|
||
kustomize: | ||
ifeq (, $(shell which kustomize)) | ||
@{ \ | ||
set -e ;\ | ||
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\ | ||
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
} | ||
KUSTOMIZE=$(GOBIN)/kustomize | ||
else | ||
KUSTOMIZE=$(shell which kustomize) | ||
endif | ||
|
||
all: generate check build | ||
|
||
generate: | ||
[[ ${OSDK_VERSION} == v0.19* ]] || ( echo "operator-sdk version 0.19 required" ; exit 1 ) | ||
operator-sdk generate crds --crd-version v1 | ||
env GOROOT=$(shell go env GOROOT) operator-sdk generate k8s | ||
controller-gen | ||
$(CONTROLLER_GEN) object paths="./..." | ||
$(CONTROLLER_GEN) crd paths=./api/... output:dir=./config/crd/bases schemapatch:manifests=./config/crd/bases | ||
# sync crd generated to helm-chart | ||
echo '{{- define "crd.openAPIV3Schema" }}' > charts/zookeeper-operator/templates/_crd_openapiv3schema.tpl | ||
echo 'openAPIV3Schema:' >> charts/zookeeper-operator/templates/_crd_openapiv3schema.tpl | ||
sed -e '1,/openAPIV3Schema/d' deploy/crds/zookeeper.pravega.io_zookeeperclusters_crd.yaml | sed -n '/served: true/!p;//q' >> charts/zookeeper-operator/templates/_crd_openapiv3schema.tpl | ||
sed -e '1,/openAPIV3Schema/d' config/crd/bases/zookeeper.pravega.io_zookeeperclusters_crd.yaml | sed -n '/served: true/!p;//q' >> charts/zookeeper-operator/templates/_crd_openapiv3schema.tpl | ||
echo '{{- end }}' >> charts/zookeeper-operator/templates/_crd_openapiv3schema.tpl | ||
|
||
|
||
|
@@ -77,19 +186,21 @@ test: | |
|
||
test-e2e: test-e2e-remote | ||
|
||
test-e2e-remote: test-login | ||
operator-sdk build $(TEST_IMAGE) | ||
test-e2e-remote: | ||
make test-login | ||
docker build . -t $(TEST_IMAGE) | ||
docker push $(TEST_IMAGE) | ||
operator-sdk test local ./test/e2e --operator-namespace default \ | ||
--namespaced-manifest ./test/e2e/resources/rbac-operator.yaml \ | ||
--global-manifest deploy/crds/zookeeper.pravega.io_zookeeperclusters_crd.yaml \ | ||
--image $(TEST_IMAGE) --go-test-flags "-v -timeout 0" | ||
make deploy | ||
RUN_LOCAL=false go test -timeout 1h ./test/e2e... | ||
make undeploy | ||
|
||
test-e2e-local: | ||
operator-sdk test local ./test/e2e --operator-namespace default --up-local --go-test-flags "-v -timeout 0" | ||
make deploy-test | ||
RUN_LOCAL=true go test -timeout 1h ./test/e2e... | ||
make undeploy-test | ||
|
||
run-local: | ||
operator-sdk run local | ||
go run ./main.go | ||
|
||
login: | ||
@docker login -u "$(DOCKER_USER)" -p "$(DOCKER_PASS)" | ||
|
@@ -124,3 +235,13 @@ check-license: | |
|
||
update-kube-version: | ||
./scripts/update_kube_version.sh ${KUBE_VERSION} | ||
# Generate bundle manifests and metadata, then validate generated files. | ||
bundle: manifests | ||
operator-sdk generate kustomize manifests -q | ||
kustomize build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) | ||
operator-sdk bundle validate ./bundle | ||
|
||
# Build the bundle image. | ||
bundle-build: | ||
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . | ||
|
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
domain: zookeeper.pravega.io | ||
layout: go.kubebuilder.io/v2 | ||
repo: github.com/pravega/zookeeper-operator | ||
resources: | ||
- group: zookeeper.pravega.io | ||
kind: ZookeeperCluster | ||
version: v1beta1 | ||
version: 3-alpha | ||
plugins: | ||
go.operator-sdk.io/v2-alpha: {} |
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package v1beta1 contains API Schema definitions for the zookeeper.pravega.io v1beta1 API group | ||
// +kubebuilder:object:generate=true | ||
// +groupName=zookeeper.pravega.io.zookeeper.pravega.io | ||
package v1beta1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects | ||
GroupVersion = schema.GroupVersion{Group: "zookeeper.pravega.io", Version: "v1beta1"} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) |
File renamed without changes.
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
File renamed without changes.
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
Oops, something went wrong.