diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..79c1371e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,52 @@ +FROM docker:18.09 + +ARG GO_VERSION +ARG OPERATOR_SDK_VERSION +ARG MINIKUBE_VERSION + +ARG GOPATH="/go" + +RUN mkdir -p /go + +# Stage 1 - Install dependencies +RUN apk update && \ + apk add --no-cache \ + curl \ + python \ + py-crcmod \ + bash \ + libc6-compat \ + openssh-client \ + git \ + make \ + gcc \ + libc-dev \ + git + +RUN curl -O https://storage.googleapis.com/golang/go$GO_VERSION.linux-amd64.tar.gz && tar -xvf go$GO_VERSION.linux-amd64.tar.gz + +# Stage 2 - Install operator-sdk +RUN echo $GOPATH/bin/operator-sdk +RUN curl -L https://github.com/operator-framework/operator-sdk/releases/download/v$OPERATOR_SDK_VERSION/operator-sdk-v$OPERATOR_SDK_VERSION-x86_64-linux-gnu -o $GOPATH/bin/operator-sdk \ + && chmod +x $GOPATH/bin/operator-sdk + +RUN curl -Lo minikube https://storage.googleapis.com/minikube/releases/v$MINIKUBE_VERSION/minikube-linux-amd64 \ + && chmod +x minikube \ + && cp minikube /usr/local/bin/ \ + && rm minikube + +RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl \ + && chmod +x ./kubectl \ + && mv ./kubectl /usr/local/bin/kubectl + +RUN export GO111MODULE=auto + +RUN mkdir -p $GOPATH/src/github.com/jenkinsci/kubernetes-operator +WORKDIR $GOPATH/src/github.com/jenkinsci/kubernetes-operator + +RUN mkdir -p /home/builder + +ENV DOCKER_TLS_VERIFY 1 +ENV DOCKER_CERT_PATH /minikube/certs + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/Makefile b/Makefile index ad889fe3..61b0bf0f 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,19 @@ SHELL := /bin/sh PATH := $(GOPATH)/bin:$(PATH) +OSFLAG := +ifeq ($(OS),Windows_NT) + OSFLAG = WIN32 +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + OSFLAG = LINUX + endif + ifeq ($(UNAME_S),Darwin) + OSFLAG = OSX + endif +endif + # Import config # You can change the default config with `make config="config_special.env" build` config ?= config.env @@ -149,7 +162,7 @@ prepare-all-in-one-deploy-file: ## Prepares all in one deploy file .PHONY: e2e CURRENT_DIRECTORY := $(shell pwd) -e2e: build docker-build ## Runs e2e tests, you can use EXTRA_ARGS +e2e: docker-build ## Runs e2e tests, you can use EXTRA_ARGS @echo "+ $@" @echo "Docker image: $(DOCKER_REGISTRY):$(GITCOMMIT)" kubectl config use-context $(KUBECTL_CONTEXT) @@ -157,10 +170,20 @@ e2e: build docker-build ## Runs e2e tests, you can use EXTRA_ARGS 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) sed -i 's|\(image:\).*|\1 $(DOCKER_REGISTRY):$(GITCOMMIT)|g' deploy/namespace-init.yaml 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 +endif + +ifeq ($(OSFLAG), OSX) + sed -i '' 's|\(image:\).*|\1 $(DOCKER_REGISTRY):$(GITCOMMIT)|g' deploy/namespace-init.yaml +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 endif @RUNNING_TESTS=1 go test -parallel=1 "./test/e2e/" -tags "$(BUILDTAGS) cgo" -v -timeout 30m -run "$(E2E_TEST_SELECTOR)" \ @@ -173,13 +196,14 @@ vet: ## Verifies `go vet` passes .PHONY: staticcheck HAS_STATICCHECK := $(shell which staticcheck) +PLATFORM = $(shell echo $(UNAME_S) | tr A-Z a-z) staticcheck: ## Verifies `staticcheck` passes @echo "+ $@" ifndef HAS_STATICCHECK - wget https://github.com/dominikh/go-tools/releases/download/2019.1.1/staticcheck_linux_amd64 - chmod +x staticcheck_linux_amd64 - mkdir -p $(HOME)/bin - mv staticcheck_linux_amd64 $(HOME)/bin/staticcheck + wget https://github.com/dominikh/go-tools/releases/download/2019.1.1/staticcheck_$(PLATFORM)_amd64 + chmod +x staticcheck_$(PLATFORM)_amd64 + mkdir -p $(GOPATH)/bin + mv staticcheck_$(PLATFORM)_amd64 $(GOPATH)/bin/staticcheck endif @staticcheck $(PACKAGES) @@ -267,7 +291,7 @@ docker-login: ## Log in into the Docker repository @echo "+ $@" .PHONY: docker-build -docker-build: check-env build ## Build the container +docker-build: check-env ## Build the container @echo "+ $@" docker build . -t $(DOCKER_REGISTRY):$(GITCOMMIT) --file build/Dockerfile @@ -316,7 +340,7 @@ 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 build ## Run the operator locally and use minikube as Kubernetes cluster, you can use EXTRA_ARGS +minikube-run: minikube-start ## 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_$(API_VERSION)_jenkins_crd.yaml @@ -390,3 +414,27 @@ endif @echo "Dependencies:" go mod vendor -v @echo + +.PHONY: image +image: ## Create the docker image from the Dockerfile. This image is used to build linux binary regardless of the system on the host + @echo "+ $@" + docker build --rm --force-rm --no-cache \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg MINIKUBE_VERSION=$(MINIKUBE_VERSION) \ + --build-arg OPERATOR_SDK_VERSION=$(OPERATOR_SDK_VERSION) \ + -t jenkins-operator/runner . + +.PHONY: indocker +PWD := $(shell pwd) +DOCKER_HOST_IP := $(shell minikube docker-env | grep DOCKER_HOST | cut -d '"' -f 2) +MINIKUBE_IP := $(shell minikube ip) +indocker: minikube-start image ## Run make in a docker container + @echo "+ $@" + docker run --rm -it $(DOCKER_FLAGS) \ + -v /var/run/docker.sock:/var/run/docker.sock \ + --mount type=bind,source=$(PWD),target=/go/src/github.com/jenkinsci/kubernetes-operator \ + --mount type=bind,source=$(HOME)/.minikube,target=/minikube \ + --mount type=bind,source=$(HOME)/.kube,target=/home/builder/.kube \ + -e DOCKER_HOST=$(DOCKER_HOST_IP) \ + -e MINIKUBE_IP=$(MINIKUBE_IP) \ + jenkins-operator/runner diff --git a/config.env b/config.env index d2cedd76..f0052c0a 100644 --- a/config.env +++ b/config.env @@ -1,5 +1,7 @@ # Setup variables for the Makefile NAME=kubernetes-operator +OPERATOR_SDK_VERSION=0.8.1 +GO_VERSION=1.12.6 PKG=github.com/jenkinsci/kubernetes-operator DOCKER_ORGANIZATION=virtuslab DOCKER_REGISTRY=jenkins-operator @@ -7,6 +9,7 @@ NAMESPACE=default API_VERSION=v1alpha2 MINIKUBE_KUBERNETES_VERSION=v1.12.9 MINIKUBE_DRIVER=virtualbox +MINIKUBE_VERSION=1.2.0 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/deploy/operator.yaml b/deploy/operator.yaml index 64890cee..0245cfbe 100644 --- a/deploy/operator.yaml +++ b/deploy/operator.yaml @@ -32,3 +32,4 @@ spec: fieldPath: metadata.name - name: OPERATOR_NAME value: "jenkins-operator" + diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..ef742ebb --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +export GOPATH=/go +export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin +export GO111MODULE=on + +kubectl config set-cluster minikube --server=https://$MINIKUBE_IP:8443 \ + --certificate-authority=/minikube/ca.crt && \ + kubectl config set-credentials minikube --certificate-authority=/root/.minikube/ca.crt \ + --client-key=/minikube/client.key \ + --client-certificate=/minikube/client.crt && \ + kubectl config set-context minikube --cluster=minikube --user=minikube && \ + kubectl config use-context minikube + +make go-dependencies +ln -s $GOPATH/src/github.com/jenkinsci/kubernetes-operator/vendor/k8s.io $GOPATH/src/k8s.i +ln -s $GOPATH/src/github.com/jenkinsci/kubernetes-operator/vendor/sigs.k8s.io $GOPATH/src/sigs.k8s.io + +bash \ No newline at end of file diff --git a/go.mod b/go.mod index 5690bdc1..7c5a3bdd 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,12 @@ require ( go.uber.org/atomic v1.3.2 // indirect go.uber.org/multierr v1.1.0 // indirect go.uber.org/zap v1.9.1 + golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect + golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect + golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect + golang.org/x/text v0.3.2 // indirect golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect + golang.org/x/tools v0.0.0-20190708203411-c8855242db9c // indirect k8s.io/api v0.0.0-20190222213804-5cb15d344471 k8s.io/apimachinery v0.0.0-20190221213512-86fb29eff628 k8s.io/client-go v2.0.0-alpha.0.0.20181126152608-d082d5923d3c+incompatible @@ -62,3 +67,5 @@ replace ( sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.1.10 sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde ) + +replace github.com/golang/lint v0.0.0-20190409202823-959b441ac422 => golang.org/x/lint v0.0.0-20190409202823-959b441ac422 diff --git a/go.sum b/go.sum index 6a041cfd..5cee9964 100644 --- a/go.sum +++ b/go.sum @@ -194,12 +194,17 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= +golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f h1:hX65Cu3JDlGH3uEdK7I99Ii+9kjD6mvnnpfLdEAH0x4= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -213,6 +218,10 @@ golang.org/x/net v0.0.0-20190206173232-65e2d4e15006/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI= @@ -222,6 +231,8 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -232,18 +243,27 @@ golang.org/x/sys v0.0.0-20181218192612-074acd46bca6/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k= +golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 h1:+DCIGbF/swA92ohVg0//6X2IVY3KZs6p9mix0ziNYJM= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181219222714-6e267b5cc78e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190213015956-f7e1b50d2251/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138 h1:H3uGjxCR/6Ds0Mjgyp7LMK81+LvmbvWWEnJhzk1Pi9E= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190708203411-c8855242db9c h1:rRFNgkkT7zOyWlroLBmsrKYtBNhox8WtulQlOr3jIDk= +golang.org/x/tools v0.0.0-20190708203411-c8855242db9c/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.2.0 h1:B5VXkdjt7K2Gm6fGBC9C9a1OAKJDT95cTqwet+2zib0= google.golang.org/api v0.2.0/go.mod h1:IfRCZScioGtypHNTlz3gFk67J8uePVW7uDTBzXuIkhU= diff --git a/pkg/apis/jenkins/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/jenkins/v1alpha2/zz_generated.deepcopy.go index cf8da24f..ab88bd8c 100644 --- a/pkg/apis/jenkins/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/jenkins/v1alpha2/zz_generated.deepcopy.go @@ -9,6 +9,22 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AppliedGroovyScript) DeepCopyInto(out *AppliedGroovyScript) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AppliedGroovyScript. +func (in *AppliedGroovyScript) DeepCopy() *AppliedGroovyScript { + if in == nil { + return nil + } + out := new(AppliedGroovyScript) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Backup) DeepCopyInto(out *Backup) { *out = *in @@ -50,6 +66,39 @@ func (in *Build) DeepCopy() *Build { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConfigMapRef) DeepCopyInto(out *ConfigMapRef) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigMapRef. +func (in *ConfigMapRef) DeepCopy() *ConfigMapRef { + if in == nil { + return nil + } + out := new(ConfigMapRef) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConfigurationAsCode) DeepCopyInto(out *ConfigurationAsCode) { + *out = *in + in.Customization.DeepCopyInto(&out.Customization) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigurationAsCode. +func (in *ConfigurationAsCode) DeepCopy() *ConfigurationAsCode { + if in == nil { + return nil + } + out := new(ConfigurationAsCode) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Container) DeepCopyInto(out *Container) { *out = *in @@ -123,6 +172,45 @@ func (in *Container) DeepCopy() *Container { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Customization) DeepCopyInto(out *Customization) { + *out = *in + out.Secret = in.Secret + if in.Configurations != nil { + in, out := &in.Configurations, &out.Configurations + *out = make([]ConfigMapRef, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Customization. +func (in *Customization) DeepCopy() *Customization { + if in == nil { + return nil + } + out := new(Customization) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *GroovyScripts) DeepCopyInto(out *GroovyScripts) { + *out = *in + in.Customization.DeepCopyInto(&out.Customization) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GroovyScripts. +func (in *GroovyScripts) DeepCopy() *GroovyScripts { + if in == nil { + return nil + } + out := new(GroovyScripts) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Handler) DeepCopyInto(out *Handler) { *out = *in @@ -277,6 +365,8 @@ func (in *JenkinsSpec) DeepCopyInto(out *JenkinsSpec) { in.SlaveService.DeepCopyInto(&out.SlaveService) in.Backup.DeepCopyInto(&out.Backup) in.Restore.DeepCopyInto(&out.Restore) + in.GroovyScripts.DeepCopyInto(&out.GroovyScripts) + in.ConfigurationAsCode.DeepCopyInto(&out.ConfigurationAsCode) return } @@ -317,6 +407,11 @@ func (in *JenkinsStatus) DeepCopyInto(out *JenkinsStatus) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.AppliedGroovyScripts != nil { + in, out := &in.AppliedGroovyScripts, &out.AppliedGroovyScripts + *out = make([]AppliedGroovyScript, len(*in)) + copy(*out, *in) + } return } @@ -363,6 +458,22 @@ func (in *Restore) DeepCopy() *Restore { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SecretRef) DeepCopyInto(out *SecretRef) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretRef. +func (in *SecretRef) DeepCopy() *SecretRef { + if in == nil { + return nil + } + out := new(SecretRef) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SeedJob) DeepCopyInto(out *SeedJob) { *out = *in diff --git a/test/e2e/configuration_test.go b/test/e2e/configuration_test.go index e80384eb..44d641b8 100644 --- a/test/e2e/configuration_test.go +++ b/test/e2e/configuration_test.go @@ -40,31 +40,36 @@ func TestConfiguration(t *testing.T) { RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", }, } - volumes := []corev1.Volume{ - { - Name: "test-configmap", - VolumeSource: corev1.VolumeSource{ - ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: userConfigurationConfigMapName, - }, + groovyScripts := v1alpha2.GroovyScripts{ + Customization: v1alpha2.Customization{ + Configurations: []v1alpha2.ConfigMapRef{ + { + Name: userConfigurationConfigMapName, }, }, + Secret: v1alpha2.SecretRef{ + Name: userConfigurationSecretName, + }, }, - { - Name: "test-secret", - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: userConfigurationSecretName, + } + + casc := v1alpha2.ConfigurationAsCode{ + Customization: v1alpha2.Customization{ + Configurations: []v1alpha2.ConfigMapRef{ + { + Name: userConfigurationConfigMapName, }, }, + Secret: v1alpha2.SecretRef{ + Name: userConfigurationSecretName, + }, }, } // base createUserConfigurationSecret(t, namespace, systemMessageEnvName, systemMessage) createUserConfigurationConfigMap(t, namespace, numberOfExecutors, fmt.Sprintf("${%s}", systemMessageEnvName)) - jenkins := createJenkinsCR(t, jenkinsCRName, namespace, &[]v1alpha2.SeedJob{mySeedJob.SeedJob}, volumes) + jenkins := createJenkinsCR(t, jenkinsCRName, namespace, &[]v1alpha2.SeedJob{mySeedJob.SeedJob}, groovyScripts, casc) createDefaultLimitsForContainersInNamespace(t, namespace) createKubernetesCredentialsProviderSecret(t, namespace, mySeedJob) waitForJenkinsBaseConfigurationToComplete(t, jenkins) @@ -162,6 +167,9 @@ func verifyJenkinsMasterPodAttributes(t *testing.T, jenkins *v1alpha2.Jenkins) { assert.Equal(t, resources.JenkinsMasterContainerName, jenkinsPod.Spec.Containers[0].Name) assert.Equal(t, len(jenkins.Spec.Master.Containers), len(jenkinsPod.Spec.Containers)) + + assert.Equal(t, jenkins.Spec.Master.SecurityContext, jenkinsPod.Spec.SecurityContext) + assert.Equal(t, jenkins.Spec.Master.Containers[0].Command, jenkinsPod.Spec.Containers[0].Command) for _, actualContainer := range jenkinsPod.Spec.Containers { if actualContainer.Name == resources.JenkinsMasterContainerName { diff --git a/test/e2e/jenkins.go b/test/e2e/jenkins.go index 580b1cb9..f6e91176 100644 --- a/test/e2e/jenkins.go +++ b/test/e2e/jenkins.go @@ -65,7 +65,7 @@ func createJenkinsAPIClient(jenkins *v1alpha2.Jenkins) (jenkinsclient.Jenkins, e ) } -func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha2.SeedJob, volumes []corev1.Volume) *v1alpha2.Jenkins { +func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha2.SeedJob, groovyScripts v1alpha2.GroovyScripts, casc v1alpha2.ConfigurationAsCode) *v1alpha2.Jenkins { var seedJobs []v1alpha2.SeedJob if seedJob != nil { seedJobs = append(seedJobs, *seedJob...) @@ -78,6 +78,8 @@ func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha2.S Namespace: namespace, }, Spec: v1alpha2.JenkinsSpec{ + GroovyScripts: groovyScripts, + ConfigurationAsCode: casc, Master: v1alpha2.JenkinsMaster{ Annotations: map[string]string{"test": "label"}, Containers: []v1alpha2.Container{ @@ -124,7 +126,6 @@ func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha2.S {Name: "simple-theme-plugin", Version: "0.5.1"}, }, NodeSelector: map[string]string{"kubernetes.io/hostname": "minikube"}, - Volumes: volumes, }, SeedJobs: seedJobs, }, diff --git a/test/e2e/restart_test.go b/test/e2e/restart_test.go index 0dce822d..fab56c46 100644 --- a/test/e2e/restart_test.go +++ b/test/e2e/restart_test.go @@ -20,7 +20,7 @@ func TestJenkinsMasterPodRestart(t *testing.T) { // Deletes test namespace defer ctx.Cleanup() - jenkins := createJenkinsCR(t, "e2e", namespace, nil, []corev1.Volume{}) + jenkins := createJenkinsCR(t, "e2e", namespace, nil, v1alpha2.GroovyScripts{}, v1alpha2.ConfigurationAsCode{}) waitForJenkinsBaseConfigurationToComplete(t, jenkins) restartJenkinsMasterPod(t, jenkins) waitForRecreateJenkinsMasterPod(t, jenkins) @@ -36,7 +36,7 @@ func TestSafeRestart(t *testing.T) { jenkinsCRName := "e2e" configureAuthorizationToUnSecure(t, namespace) - jenkins := createJenkinsCR(t, jenkinsCRName, namespace, nil, []corev1.Volume{}) + jenkins := createJenkinsCR(t, jenkinsCRName, namespace, nil, v1alpha2.GroovyScripts{}, v1alpha2.ConfigurationAsCode{}) waitForJenkinsBaseConfigurationToComplete(t, jenkins) waitForJenkinsUserConfigurationToComplete(t, jenkins) jenkinsClient := verifyJenkinsAPIConnection(t, jenkins) diff --git a/test/e2e/seedjobs_test.go b/test/e2e/seedjobs_test.go index b32da366..8e3d5421 100644 --- a/test/e2e/seedjobs_test.go +++ b/test/e2e/seedjobs_test.go @@ -51,7 +51,7 @@ func TestSeedJobs(t *testing.T) { createKubernetesCredentialsProviderSecret(t, namespace, seedJobConfig) seedJobs = append(seedJobs, seedJobConfig.SeedJob) } - jenkins := createJenkinsCR(t, jenkinsCRName, namespace, &seedJobs, []corev1.Volume{}) + jenkins := createJenkinsCR(t, jenkinsCRName, namespace, &seedJobs, v1alpha2.GroovyScripts{}, v1alpha2.ConfigurationAsCode{}) waitForJenkinsBaseConfigurationToComplete(t, jenkins) verifyJenkinsMasterPodAttributes(t, jenkins)