5.7 KiB
| title | linkTitle | weight | date | description |
|---|---|---|---|---|
| Developer Guide | Developer Guide | 60 | 2019-08-05 | Jenkins Operator for developers |
{{% pageinfo %}} This document explains how to setup your development environment. {{% /pageinfo %}}
Prerequisites
- operator_sdk version v0.8.1
- git
- go version v1.12+
- goimports, golint, checkmake and staticcheck
- minikube version v1.1.0+ (preferred Hypervisor - virtualbox)
- docker version 17.03+
Clone repository and download dependencies
mkdir -p $GOPATH/src/github.com/jenkinsci
cd $GOPATH/src/github.com/jenkinsci/
git clone git@github.com:jenkinsci/kubernetes-operator.git
cd kubernetes-operator
make go-dependencies
Build and run with a minikube
Build and run Jenkins Operator locally:
make build minikube-run OPERATOR_EXTRA_ARGS='--jenkins-api-hostname=$(eval minikube ip) --jenkins-api-use-nodeport=true'
Once minikube and Jenkins Operator are up and running, apply Jenkins custom resource:
kubectl apply -f deploy/crds/jenkins_v1alpha2_jenkins_cr.yaml
kubectl get jenkins -o yaml
kubectl get po
Build and run with a remote Kubernetes cluster
You can also run the controller locally and make it listen to a remote Kubernetes server.
make run NAMESPACE=default KUBECTL_CONTEXT=remote-k8s OPERATOR_EXTRA_ARGS='--kubeconfig ~/.kube/config'
Once minikube and Jenkins Operator are up and running, apply Jenkins custom resource:
kubectl --context remote-k8s --namespace default apply -f deploy/crds/jenkins_v1alpha2_jenkins_cr.yaml
kubectl --context remote-k8s --namespace default get jenkins -o yaml
kubectl --context remote-k8s --namespace default get po
Testing
Run unit tests:
make test
Running E2E tests on Linux
Run e2e tests with minikube:
make minikube-start
eval $(minikube docker-env)
make build e2e config=config.minikube.env CONTAINER_RUNTIME=podman
config.minikube.env is the E2E test profile which provides all connection info to operator to run on minikube.
Run the specific e2e test:
make build e2e E2E_TEST_SELECTOR='^TestConfiguration$' config=config.minikube.env CONTAINER_RUNTIME=podman
If you want to run E2E tests on CRC (Code Ready Containers by OpenShift), you should use config.crc.env profile instead of config.minikube.env.
If you have some trouble with podman (for example building) then check how to use docker instead of podman.
Running E2E tests on macOS
At first, you need to start minikube:
$ make minikube-start
$ eval $(minikube docker-env)
Build a Docker image inside the provided Linux container by:
$ make indocker
Build Jenkins Operator inside a container using:
$ make build
Then exit the container and run:
make e2e config=config.minikube.env
or using crc as cluster software:
make e2e config=config.crc.env
Using Docker instead of podman
If you have trouble with building image using the podman, you can set additional flag IMAGE_PULL_MODE to pull image from the organization.
At first, you need to edit config.base.env and change the DOCKER_ORGANIZATION to your Docker Hub account/organization.
After this change the IMAGE_PULL_MODE to remote. It will setup the Makefile goal to pull Docker image from registry.
Then you need to pull image from your repository:
$ make container-runtime-build container-runtime-snapshot-push
When image will be uploaded to repository, you can now write this command to run E2E tests:
$ make e2e E2E_TEST_SELECTOR='^TestConfiguration$' config=config.crc.env
Tips & Tricks
Building docker image on minikube (for e2e tests)
To be able to work with the docker daemon on minikube machine run the following command before building an image:
eval $(minikube docker-env)
When pkg/apis/jenkinsio/*/jenkins_types.go has changed
Run:
make deepcopy-gen
Getting the Jenkins URL and basic credentials
minikube service jenkins-operator-http-<cr_name> --url
kubectl get secret jenkins-operator-credentials-<cr_name> -o 'jsonpath={.data.user}' | base64 -d
kubectl get secret jenkins-operator-credentials-<cr_name> -o 'jsonpath={.data.password}' | base64 -d
Tools
Configure environment variables
export GOPATH=/home/go # example value
export GOROOT=/usr/lib/go-1.12 # example value
export PATH=$GOPATH/bin:$PATH
goimports
go get golang.org/x/tools/cmd/goimports
cd $GOPATH/src/golang.org/x/tools/cmd/goimports
go build
go install
golint
go get -u golang.org/x/lint/golint
cd $GOPATH/src/golang.org/x/lint/golint
go build
go install
checkmake
go get github.com/mrtazz/checkmake
cd $GOPATH/src/github.com/mrtazz/checkmake
go build
go install
staticcheck
mkdir -p $GOPATH/src/github.com/dominikh/
cd $GOPATH/src/github.com/dominikh/
git clone https://github.com/dominikh/go-tools.git
cd $GOPATH/src/github.com/dominikh/go-tools/staticcheck
go build
go install