diff --git a/Makefile b/Makefile index a429d6ff..303b4591 100644 --- a/Makefile +++ b/Makefile @@ -453,4 +453,14 @@ else touch $(KUBECONFIG) sudo minikube start --vm-driver=none --kubernetes-version=$(MINIKUBE_KUBERNETES_VERSION) sudo chown -R travis: /home/travis/.minikube/ -endif \ No newline at end of file +endif + +.PHONY: helm-package +helm-package: + @echo "+ $@" + cd chart/ && helm package jenkins-operator + +.PHONY: helm-deploy +helm-deploy: helm-package + @echo "+ $@" + helm repo index chart/ --url https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/chart/jenkins-operator/ \ No newline at end of file diff --git a/chart/index.yaml b/chart/index.yaml new file mode 100644 index 00000000..1d558217 --- /dev/null +++ b/chart/index.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +entries: + jenkins-operator: + - apiVersion: v1 + appVersion: 0.2.0 + created: "2019-09-18T12:05:07.80241+02:00" + description: Kubernetes native operator which fully manages Jenkins on Kubernetes + digest: 17d48e5da2a77975cc5d9c4db3d28f003d578759f8538bf58ac3977534feb42f + name: jenkins-operator + urls: + - https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/chart/jenkins-operator/jenkins-operator-0.0.1.tgz + version: 0.0.1 +generated: "2019-09-18T12:05:07.801225+02:00" diff --git a/chart/jenkins-operator-0.0.1.tgz b/chart/jenkins-operator-0.0.1.tgz new file mode 100644 index 00000000..cba505b8 Binary files /dev/null and b/chart/jenkins-operator-0.0.1.tgz differ diff --git a/chart/jenkins-operator/.helmignore b/chart/jenkins-operator/.helmignore new file mode 100644 index 00000000..50af0317 --- /dev/null +++ b/chart/jenkins-operator/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/chart/jenkins-operator/Chart.yaml b/chart/jenkins-operator/Chart.yaml new file mode 100644 index 00000000..e902af9a --- /dev/null +++ b/chart/jenkins-operator/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "0.2.0" +description: Kubernetes native operator which fully manages Jenkins on Kubernetes +name: jenkins-operator +version: 0.0.1 diff --git a/chart/jenkins-operator/templates/NOTES.txt b/chart/jenkins-operator/templates/NOTES.txt new file mode 100644 index 00000000..897c5f95 --- /dev/null +++ b/chart/jenkins-operator/templates/NOTES.txt @@ -0,0 +1,11 @@ +1. Watch Jenkins instance being created: +$ kubectl --namespace {{ .Release.Namespace }} get pods -w + +2. Get Jenkins credentials: +$ kubectl --namespace {{ .Release.Namespace }} get secret jenkins-operator-credentials-{{ .Values.jenkins.name }} -o 'jsonpath={.data.user}' | base64 -d +$ kubectl --namespace {{ .Release.Namespace }} get secret jenkins-operator-credentials-{{ .Values.jenkins.name }} -o 'jsonpath={.data.password}' | base64 -d + +3. Connect to Jenkins (actual Kubernetes cluster): +$ kubectl --namespace {{ .Release.Namespace }} port-forward jenkins-{{ .Values.jenkins.name }} 8080:8080 + +Now open the browser and enter http://localhost:8080 \ No newline at end of file diff --git a/chart/jenkins-operator/templates/_helpers.tpl b/chart/jenkins-operator/templates/_helpers.tpl new file mode 100644 index 00000000..df05cf14 --- /dev/null +++ b/chart/jenkins-operator/templates/_helpers.tpl @@ -0,0 +1,45 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "jenkins-operator.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "jenkins-operator.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "jenkins-operator.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "jenkins-operator.labels" -}} +app.kubernetes.io/name: {{ include "jenkins-operator.name" . }} +helm.sh/chart: {{ include "jenkins-operator.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} diff --git a/chart/jenkins-operator/templates/deployment.yaml b/chart/jenkins-operator/templates/deployment.yaml new file mode 100644 index 00000000..40070b81 --- /dev/null +++ b/chart/jenkins-operator/templates/deployment.yaml @@ -0,0 +1,59 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "jenkins-operator.fullname" . }} + labels: +{{ include "jenkins-operator.labels" . | indent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "jenkins-operator.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "jenkins-operator.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + serviceAccountName: jenkins-operator + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + command: + - jenkins-operator + args: [] + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: OPERATOR_NAME + value: "jenkins-operator" + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/chart/jenkins-operator/templates/jenkins-cr.yaml b/chart/jenkins-operator/templates/jenkins-cr.yaml new file mode 100644 index 00000000..83dda313 --- /dev/null +++ b/chart/jenkins-operator/templates/jenkins-cr.yaml @@ -0,0 +1,6 @@ +apiVersion: {{ .Values.jenkins.apiVersion }} +kind: Jenkins +metadata: + name: {{ .Values.jenkins.name }} +spec: + {{- toYaml .Values.jenkins.spec | nindent 4 }} diff --git a/chart/jenkins-operator/templates/jenkins-crd.yaml b/chart/jenkins-operator/templates/jenkins-crd.yaml new file mode 100644 index 00000000..db376ab2 --- /dev/null +++ b/chart/jenkins-operator/templates/jenkins-crd.yaml @@ -0,0 +1,19 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: jenkins.jenkins.io +spec: + group: jenkins.io + names: + kind: Jenkins + listKind: JenkinsList + plural: jenkins + singular: jenkins + scope: Namespaced + versions: + - name : v1alpha2 + served: true + storage: true + - name : v1alpha1 + served: true + storage: false diff --git a/chart/jenkins-operator/templates/role.yaml b/chart/jenkins-operator/templates/role.yaml new file mode 100644 index 00000000..d6e7aaa1 --- /dev/null +++ b/chart/jenkins-operator/templates/role.yaml @@ -0,0 +1,93 @@ +--- +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: jenkins-operator +rules: + - apiGroups: + - "" + resources: + - services + - configmaps + - secrets + verbs: + - get + - create + - update + - list + - watch + - apiGroups: + - apps + resources: + - deployments + - daemonsets + - replicasets + - statefulsets + verbs: + - '*' + - apiGroups: + - "" + resources: + - serviceaccounts + verbs: + - create + - apiGroups: + - rbac.authorization.k8s.io + resources: + - roles + - rolebindings + verbs: + - create + - update + - apiGroups: + - "" + resources: + - pods/portforward + verbs: + - create + - apiGroups: + - "" + resources: + - pods/log + verbs: + - get + - list + - watch + - apiGroups: + - "" + resources: + - pods + - pods/exec + verbs: + - "*" + - apiGroups: + - "" + resources: + - events + verbs: + - watch + - list + - create + - patch + - apiGroups: + - apps + resourceNames: + - jenkins-operator + resources: + - deployments/finalizers + verbs: + - update + - apiGroups: + - jenkins.io + resources: + - '*' + verbs: + - '*' + - apiGroups: + - "" + resources: + - persistentvolumeclaims + verbs: + - get + - list + - watch diff --git a/chart/jenkins-operator/templates/role_binding.yaml b/chart/jenkins-operator/templates/role_binding.yaml new file mode 100644 index 00000000..8224b7c1 --- /dev/null +++ b/chart/jenkins-operator/templates/role_binding.yaml @@ -0,0 +1,12 @@ +--- +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: jenkins-operator +subjects: +- kind: ServiceAccount + name: jenkins-operator +roleRef: + kind: Role + name: jenkins-operator + apiGroup: rbac.authorization.k8s.io diff --git a/chart/jenkins-operator/templates/service_account.yaml b/chart/jenkins-operator/templates/service_account.yaml new file mode 100644 index 00000000..21b293ce --- /dev/null +++ b/chart/jenkins-operator/templates/service_account.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jenkins-operator diff --git a/chart/jenkins-operator/values.yaml b/chart/jenkins-operator/values.yaml new file mode 100644 index 00000000..528577fe --- /dev/null +++ b/chart/jenkins-operator/values.yaml @@ -0,0 +1,69 @@ +# Default values for jenkins-operator. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: virtuslab/jenkins-operator + tag: v0.2.0 + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +jenkins: + apiVersion: jenkins.io/v1alpha2 + name: example + spec: + master: + containers: + - name: jenkins-master + image: jenkins/jenkins:lts + imagePullPolicy: Always + livenessProbe: + failureThreshold: 12 + httpGet: + path: /login + port: http + scheme: HTTP + initialDelaySeconds: 80 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + readinessProbe: + failureThreshold: 3 + httpGet: + path: /login + port: http + scheme: HTTP + initialDelaySeconds: 30 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + resources: + limits: + cpu: 1500m + memory: 3Gi + requests: + cpu: "1" + memory: 500Mi + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/jenkins-operator-0.0.1.tgz b/jenkins-operator-0.0.1.tgz new file mode 100644 index 00000000..cba505b8 Binary files /dev/null and b/jenkins-operator-0.0.1.tgz differ