Add support for podman & fix crc e2e tests (#214)

#203 Add support for podman - container runtime
This commit is contained in:
Jakub Al-Khalili 2019-11-28 16:26:40 +01:00 committed by Paweł Prażak
parent b75e8de596
commit eea28a42a3
4 changed files with 72 additions and 35 deletions

View File

@ -43,6 +43,9 @@ BUILD_TAG := $(GITBRANCH)-$(GITCOMMIT)
BUILD_PATH := ./cmd/manager
# CONTAINER_RUNTIME_COMMAND is Container Runtime - it could be docker or podman
CONTAINER_RUNTIME_COMMAND := docker
# Set any default go build tags
BUILDTAGS :=
@ -62,12 +65,13 @@ PACKAGES_FOR_UNIT_TESTS = $(shell go list -f '{{.ImportPath}}/' ./... | grep -v
# Run all the e2e tests by default
E2E_TEST_SELECTOR ?= .*
ARGS ?= /usr/bin/jenkins-operator --local --namespace=$(NAMESPACE) $(EXTRA_ARGS)
JENKINS_API_HOSTNAME := $(shell $(JENKINS_API_HOSTNAME_COMMAND))
OPERATOR_ARGS ?= --jenkins-api-hostname=$(JENKINS_API_HOSTNAME) --jenkins-api-port=$(JENKINS_API_PORT) --jenkins-api-use-nodeport=$(JENKINS_API_USE_NODEPORT) --namespace=$(NAMESPACE) $(OPERATOR_EXTRA_ARGS)
.DEFAULT_GOAL := help
.PHONY: all
all: status checkmake clean build verify install docker-build docker-images ## Build the image
all: status checkmake clean build verify install container-runtime-build container-runtime-images ## Build the image
@echo "+ $@"
.PHONY: check-env
@ -156,24 +160,38 @@ test: ## Runs the go tests
.PHONY: e2e
CURRENT_DIRECTORY := $(shell pwd)
JENKINS_API_HOSTNAME := $(shell $(JENKINS_API_HOSTNAME_COMMAND))
e2e: docker-build ## Runs e2e tests, you can use EXTRA_ARGS
e2e: container-runtime-build ## Runs e2e tests, you can use EXTRA_ARGS
@echo "+ $@"
@echo "Docker image: $(DOCKER_REGISTRY):$(GITCOMMIT)"
ifeq ($(KUBERNETES_PROVIDER),minikube)
kubectl config use-context $(KUBECTL_CONTEXT)
endif
ifeq ($(KUBERNETES_PROVIDER),crc)
oc project $(CRC_OC_PROJECT)
endif
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
ifeq ($(OSFLAG), LINUX)
ifeq ($(IMAGE_PULL_MODE), remote)
sed -i 's|\(image:\).*|\1 $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(GITCOMMIT)|g' deploy/namespace-init.yaml
sed -i 's|\(imagePullPolicy\): IfNotPresent|\1: Always|g' deploy/namespace-init.yaml
else
sed -i 's|\(image:\).*|\1 $(DOCKER_REGISTRY):$(GITCOMMIT)|g' deploy/namespace-init.yaml
endif
ifeq ($(KUBERNETES_PROVIDER),minikube)
sed -i 's|\(imagePullPolicy\): IfNotPresent|\1: Never|g' deploy/namespace-init.yaml
endif
endif
ifeq ($(OSFLAG), OSX)
ifeq ($(IMAGE_PULL_MODE), remote)
sed -i '' 's|\(image:\).*|\1 $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(GITCOMMIT)|g' deploy/namespace-init.yaml
sed -i '' 's|\(imagePullPolicy\): IfNotPresent|\1: Always|g' deploy/namespace-init.yaml
else
sed -i '' 's|\(image:\).*|\1 $(DOCKER_REGISTRY):$(GITCOMMIT)|g' deploy/namespace-init.yaml
endif
ifeq ($(KUBERNETES_PROVIDER),minikube)
sed -i '' 's|\(imagePullPolicy\): IfNotPresent|\1: Never|g' deploy/namespace-init.yaml
endif
@ -182,7 +200,7 @@ endif
@RUNNING_TESTS=1 go test -parallel=1 "./test/e2e/" -tags "$(BUILDTAGS) cgo" -v -timeout 45m -run "$(E2E_TEST_SELECTOR)" \
-root=$(CURRENT_DIRECTORY) -kubeconfig=$(HOME)/.kube/config -globalMan deploy/crds/jenkins_$(API_VERSION)_jenkins_crd.yaml \
-jenkins-api-hostname=$(JENKINS_API_HOSTNAME) -jenkins-api-port=$(JENKINS_API_PORT) -jenkins-api-use-nodeport=$(JENKINS_API_USE_NODEPORT) \
-namespacedMan deploy/namespace-init.yaml $(EXTRA_ARGS)
-namespacedMan deploy/namespace-init.yaml $(TEST_ARGS)
.PHONY: vet
vet: ## Verifies `go vet` passes
@ -227,10 +245,15 @@ run: export WATCH_NAMESPACE = $(NAMESPACE)
run: export OPERATOR_NAME = $(NAME)
run: build ## Run the executable, you can use EXTRA_ARGS
@echo "+ $@"
ifeq ($(KUBERNETES_PROVIDER),minikube)
kubectl config use-context $(KUBECTL_CONTEXT)
endif
ifeq ($(KUBERNETES_PROVIDER),crc)
oc project $(CRC_OC_PROJECT)
endif
kubectl apply -f deploy/crds/jenkins_$(API_VERSION)_jenkins_crd.yaml
@echo "Watching '$(WATCH_NAMESPACE)' namespace"
build/_output/bin/jenkins-operator --local $(EXTRA_ARGS)
build/_output/bin/jenkins-operator $(OPERATOR_ARGS)
.PHONY: clean
clean: ## Cleanup any build binaries or packages
@ -281,44 +304,50 @@ ifndef HAS_CHECKMAKE
endif
@checkmake Makefile
.PHONY: docker-login
docker-login: ## Log in into the Docker repository
.PHONY: container-runtime-login
container-runtime-login: ## Log in into the Docker repository
@echo "+ $@"
.PHONY: docker-build
docker-build: check-env ## Build the container
.PHONY: container-runtime-build
container-runtime-build: check-env ## Build the container
@echo "+ $@"
docker build \
$(CONTAINER_RUNTIME_COMMAND) build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg OPERATOR_SDK_VERSION=$(OPERATOR_SDK_VERSION) \
-t $(DOCKER_REGISTRY):$(GITCOMMIT) . \
--file build/Dockerfile
--file build/Dockerfile $(CONTAINER_RUNTIME_EXTRA_ARGS)
.PHONY: docker-images
docker-images: ## List all local containers
.PHONY: container-runtime-images
container-runtime-images: ## List all local containers
@echo "+ $@"
docker images
$(CONTAINER_RUNTIME_COMMAND) images $(CONTAINER_RUNTIME_EXTRA_ARGS)
.PHONY: docker-push
docker-push: ## Push the container
.PHONY: container-runtime-push
container-runtime-push: ## Push the container
@echo "+ $@"
docker tag $(DOCKER_REGISTRY):$(GITCOMMIT) $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(BUILD_TAG)
docker push $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(BUILD_TAG)
$(CONTAINER_RUNTIME_COMMAND) tag $(DOCKER_REGISTRY):$(GITCOMMIT) $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(BUILD_TAG) $(CONTAINER_RUNTIME_EXTRA_ARGS)
$(CONTAINER_RUNTIME_COMMAND) push $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(BUILD_TAG) $(CONTAINER_RUNTIME_EXTRA_ARGS)
.PHONY: docker-release-version
docker-release-version: ## Release image with version tag (in addition to build tag)
.PHONY: container-runtime-snapshot-push
container-runtime-snapshot-push:
@echo "+ $@"
docker tag $(DOCKER_REGISTRY):$(GITCOMMIT) $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(VERSION_TAG)
docker push $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(VERSION_TAG)
$(CONTAINER_RUNTIME_COMMAND) tag $(DOCKER_REGISTRY):$(GITCOMMIT) $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(GITCOMMIT) $(CONTAINER_RUNTIME_EXTRA_ARGS)
$(CONTAINER_RUNTIME_COMMAND) push $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(GITCOMMIT) $(CONTAINER_RUNTIME_EXTRA_ARGS)
.PHONY: docker-release-latest
docker-release-latest: ## Release image with latest tags (in addition to build tag)
.PHONY: container-runtime-release-version
container-runtime-release-version: ## Release image with version tag (in addition to build tag)
@echo "+ $@"
docker tag $(DOCKER_REGISTRY):$(GITCOMMIT) $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(LATEST_TAG)
docker push $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(LATEST_TAG)
$(CONTAINER_RUNTIME_COMMAND) tag $(DOCKER_REGISTRY):$(GITCOMMIT) $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(VERSION_TAG) $(CONTAINER_RUNTIME_EXTRA_ARGS)
$(CONTAINER_RUNTIME_COMMAND) push $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(VERSION_TAG) $(CONTAINER_RUNTIME_EXTRA_ARGS)
.PHONY: docker-release
docker-release: docker-build docker-release-version docker-release-latest ## Release image with version and latest tags (in addition to build tag)
.PHONY: container-runtime-release-latest
container-runtime-release-latest: ## Release image with latest tags (in addition to build tag)
@echo "+ $@"
$(CONTAINER_RUNTIME_COMMAND) tag $(DOCKER_REGISTRY):$(GITCOMMIT) $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(LATEST_TAG) $(CONTAINER_RUNTIME_EXTRA_ARGS)
$(CONTAINER_RUNTIME_COMMAND) push $(DOCKER_ORGANIZATION)/$(DOCKER_REGISTRY):$(LATEST_TAG) $(CONTAINER_RUNTIME_EXTRA_ARGS)
.PHONY: container-runtime-release
container-runtime-release: container-runtime-build container-runtime-release-version container-runtime-release-latest ## Release image with version and latest tags (in addition to build tag)
@echo "+ $@"
# if this session isn't interactive, then we don't want to allocate a
@ -329,12 +358,12 @@ ifeq ($(INTERACTIVE), 1)
DOCKER_FLAGS += -t
endif
.PHONY: docker-run
docker-run: ## Run the container in docker, you can use EXTRA_ARGS
.PHONY: container-runtime-run
container-runtime-run: ## Run the container in docker, you can use EXTRA_ARGS
@echo "+ $@"
docker run --rm -i $(DOCKER_FLAGS) \
$(CONTAINER_RUNTIME_COMMAND) run $(CONTAINER_RUNTIME_EXTRA_ARGS) --rm -i $(DOCKER_FLAGS) \
--volume $(HOME)/.kube/config:/home/jenkins-operator/.kube/config \
$(DOCKER_REGISTRY):$(GITCOMMIT) $(ARGS)
$(DOCKER_REGISTRY):$(GITCOMMIT) /usr/bin/jenkins-operator $(OPERATOR_ARGS)
.PHONY: minikube-run
minikube-run: export WATCH_NAMESPACE = $(NAMESPACE)
@ -344,7 +373,7 @@ minikube-run: minikube-start ## Run the operator locally and use minikube as Kub
kubectl config use-context minikube
kubectl apply -f deploy/crds/jenkins_$(API_VERSION)_jenkins_crd.yaml
@echo "Watching '$(WATCH_NAMESPACE)' namespace"
build/_output/bin/jenkins-operator $(EXTRA_ARGS)
build/_output/bin/jenkins-operator $(OPERATOR_ARGS)
.PHONY: deepcopy-gen
deepcopy-gen: ## Generate deepcopy golang code

View File

@ -9,3 +9,4 @@ NAMESPACE=default
API_VERSION=v1alpha2
ALL_IN_ONE_DEPLOY_FILE_PREFIX=all-in-one
GEN_CRD_API=gen-crd-api-reference-docs
IMAGE_PULL_MODE=local

7
config.crc.env Normal file
View File

@ -0,0 +1,7 @@
KUBERNETES_PROVIDER=crc
JENKINS_API_HOSTNAME_COMMAND=crc ip
JENKINS_API_PORT=0
JENKINS_API_USE_NODEPORT=true
CRC_OC_PROJECT=default

View File

@ -6,5 +6,5 @@ MINIKUBE_VERSION=1.4.0
KUBECTL_CONTEXT=minikube
JENKINS_API_HOSTNAME_COMMAND=minikube ip
JENKINS_API_PORT=-1
JENKINS_API_PORT=0
JENKINS_API_USE_NODEPORT=true