diff --git a/Makefile b/Makefile index f4b0d2a3..a67a6e4f 100644 --- a/Makefile +++ b/Makefile @@ -152,19 +152,19 @@ CURRENT_DIRECTORY := $(shell pwd) e2e: build docker-build ## Runs e2e tests, you can use EXTRA_ARGS @echo "+ $@" @echo "Docker image: $(DOCKER_REGISTRY):$(GITCOMMIT)" - kubectl config use-context $(ENVIRONMENT) + kubectl config use-context $(KUBECTL_CONTEXT) cp deploy/service_account.yaml deploy/namespace-init.yaml cat deploy/role.yaml >> deploy/namespace-init.yaml cat deploy/role_binding.yaml >> deploy/namespace-init.yaml cat deploy/operator.yaml >> deploy/namespace-init.yaml sed -i 's|\(image:\).*|\1 $(DOCKER_REGISTRY):$(GITCOMMIT)|g' deploy/namespace-init.yaml -ifeq ($(ENVIRONMENT),minikube) +ifeq ($(KUBECTL_CONTEXT),minikube) sed -i 's|\(imagePullPolicy\): IfNotPresent|\1: Never|g' deploy/namespace-init.yaml sed -i 's|\(args:\).*|\1\ ["--minikube"\]|' deploy/namespace-init.yaml endif @RUNNING_TESTS=1 go test -parallel=1 "./test/e2e/" -tags "$(BUILDTAGS) cgo" -v -timeout 30m -run "$(E2E_TEST_SELECTOR)" \ - -root=$(CURRENT_DIRECTORY) -kubeconfig=$(HOME)/.kube/config -globalMan deploy/crds/jenkins_v1alpha2_jenkins_crd.yaml -namespacedMan deploy/namespace-init.yaml $(EXTRA_ARGS) + -root=$(CURRENT_DIRECTORY) -kubeconfig=$(HOME)/.kube/config -globalMan deploy/crds/jenkins_$(API_VERSION)_jenkins_crd.yaml -namespacedMan deploy/namespace-init.yaml $(EXTRA_ARGS) .PHONY: vet vet: ## Verifies `go vet` passes @@ -204,10 +204,14 @@ install: ## Installs the executable go install -tags "$(BUILDTAGS)" ${GO_LDFLAGS} $(BUILD_PATH) .PHONY: run -run: ## Run the executable, you can use EXTRA_ARGS +run: export WATCH_NAMESPACE = $(NAMESPACE) +run: export OPERATOR_NAME = $(NAME) +run: build ## Run the executable, you can use EXTRA_ARGS @echo "+ $@" - kubectl config use-context $(ENVIRONMENT) - go run -tags "$(BUILDTAGS)" ${GO_LDFLAGS} $(BUILD_PATH)/main.go $(ARGS) + kubectl apply -f deploy/crds/jenkins_$(API_VERSION)_jenkins_crd.yaml + kubectl config use-context $(KUBECTL_CONTEXT) + @echo "Watching '$(WATCH_NAMESPACE)' namespace" + build/_output/bin/jenkins-operator $(EXTRA_ARGS) .PHONY: clean clean: ## Cleanup any build binaries or packages @@ -312,10 +316,10 @@ docker-run: ## Run the container in docker, you can use EXTRA_ARGS .PHONY: minikube-run minikube-run: export WATCH_NAMESPACE = $(NAMESPACE) minikube-run: export OPERATOR_NAME = $(NAME) -minikube-run: minikube-start ## Run the operator locally and use minikube as Kubernetes cluster, you can use EXTRA_ARGS +minikube-run: minikube-start build ## Run the operator locally and use minikube as Kubernetes cluster, you can use EXTRA_ARGS @echo "+ $@" kubectl config use-context minikube - kubectl apply -f deploy/crds/jenkins_v1alpha2_jenkins_crd.yaml + kubectl apply -f deploy/crds/jenkins_$(API_VERSION)_jenkins_crd.yaml @echo "Watching '$(WATCH_NAMESPACE)' namespace" build/_output/bin/jenkins-operator $(EXTRA_ARGS) diff --git a/config.env b/config.env index f042d356..d2cedd76 100644 --- a/config.env +++ b/config.env @@ -7,6 +7,6 @@ NAMESPACE=default API_VERSION=v1alpha2 MINIKUBE_KUBERNETES_VERSION=v1.12.9 MINIKUBE_DRIVER=virtualbox -ENVIRONMENT=minikube +KUBECTL_CONTEXT=minikube ALL_IN_ONE_DEPLOY_FILE_PREFIX=all-in-one GEN_CRD_API=gen-crd-api-reference-docs \ No newline at end of file diff --git a/docs/developer-guide.md b/docs/developer-guide.md index 2d5f9bb2..f3c3b819 100644 --- a/docs/developer-guide.md +++ b/docs/developer-guide.md @@ -21,12 +21,12 @@ cd kubernetes-operator make go-dependencies ``` -## Build and run +## Build and run with a minikube Build and run **jenkins-operator** locally: ```bash -make build && make minikube-run EXTRA_ARGS='--minikube --local' +make minikube-run EXTRA_ARGS='--minikube --local' ``` Once minikube and **jenkins-operator** are up and running, apply Jenkins custom resource: @@ -37,18 +37,20 @@ kubectl get jenkins -o yaml kubectl get po ``` -## Build and run with a remote cluster +## Build and run with a remote Kubernetes cluster + +You can also run the controller locally and make it listen to a remote Kubernetes server. -If you are using a Linux development environment, you can also run the controller locally and make it listen to a remote -server. ```bash -export KUBECONFIG=$HOME/.crc/cache/crc_libvirt_4.1.0/kubeconfig -kubectl apply -f deploy/crds/jenkins_v1alpha2_jenkins_crd.yaml +make run NAMESPACE=default KUBECTL_CONTEXT=remote-k8s EXTRA_ARGS='--kubeconfig ~/.kube/config' ``` -You can then build and run the controller locally and make it connect to your server: +Once minikube and **jenkins-operator** are up and running, apply Jenkins custom resource: + ```bash -make build && OPERATOR_NAME=jenkins-operator WATCH_NAMESPACE=default build/_output/bin/jenkins-operator --kubeconfig $KUBECONFIG +kubectl --context remote-k8s --namespace defaut apply -f deploy/crds/jenkins_v1alpha2_jenkins_cr.yaml +kubectl --context remote-k8s --namespace defaut get jenkins -o yaml +kubectl --context remote-k8s --namespace defaut get po ``` ## Testing diff --git a/docs/install_dev_tools.md b/docs/install_dev_tools.md index 166ef091..55725e7c 100644 --- a/docs/install_dev_tools.md +++ b/docs/install_dev_tools.md @@ -2,6 +2,14 @@ This document explains how to install the Go tools used by the development process. +## Configure environment variables + +```bash +export GOPATH=/home/go # example value +export GOROOT=/usr/lib/go-1.12 # example value +export PATH=$GOPATH/bin:$PATH +``` + ## goimports ```