From 950b00b03cb48b51f95f979e1a2e8cd62ea445c2 Mon Sep 17 00:00:00 2001 From: Rob Kernick Date: Mon, 16 Oct 2017 16:16:46 -0400 Subject: [PATCH] Add chart for sonarqube (#2374) --- stable/sonarqube/.helmignore | 21 +++++ stable/sonarqube/Chart.yaml | 16 ++++ stable/sonarqube/README.md | 58 ++++++++++++++ stable/sonarqube/requirements.lock | 6 ++ stable/sonarqube/requirements.yaml | 4 + stable/sonarqube/templates/NOTES.txt | 19 +++++ stable/sonarqube/templates/_helpers.tpl | 24 ++++++ stable/sonarqube/templates/deployment.yaml | 76 +++++++++++++++++++ stable/sonarqube/templates/ingress.yaml | 32 ++++++++ stable/sonarqube/templates/pvc-conf.yaml | 24 ++++++ stable/sonarqube/templates/pvc-data.yaml | 24 ++++++ .../sonarqube/templates/pvc-extensions.yaml | 24 ++++++ stable/sonarqube/templates/service.yaml | 19 +++++ .../sonarqube/templates/sonarqube-test.yaml | 42 ++++++++++ stable/sonarqube/templates/test-config.yaml | 14 ++++ stable/sonarqube/values.yaml | 57 ++++++++++++++ stable/sonatype-nexus/templates/pvc.yaml | 2 +- 17 files changed, 461 insertions(+), 1 deletion(-) create mode 100644 stable/sonarqube/.helmignore create mode 100644 stable/sonarqube/Chart.yaml create mode 100644 stable/sonarqube/README.md create mode 100644 stable/sonarqube/requirements.lock create mode 100644 stable/sonarqube/requirements.yaml create mode 100644 stable/sonarqube/templates/NOTES.txt create mode 100644 stable/sonarqube/templates/_helpers.tpl create mode 100644 stable/sonarqube/templates/deployment.yaml create mode 100644 stable/sonarqube/templates/ingress.yaml create mode 100644 stable/sonarqube/templates/pvc-conf.yaml create mode 100644 stable/sonarqube/templates/pvc-data.yaml create mode 100644 stable/sonarqube/templates/pvc-extensions.yaml create mode 100644 stable/sonarqube/templates/service.yaml create mode 100644 stable/sonarqube/templates/sonarqube-test.yaml create mode 100644 stable/sonarqube/templates/test-config.yaml create mode 100644 stable/sonarqube/values.yaml diff --git a/stable/sonarqube/.helmignore b/stable/sonarqube/.helmignore new file mode 100644 index 0000000000..f0c1319444 --- /dev/null +++ b/stable/sonarqube/.helmignore @@ -0,0 +1,21 @@ +# 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 diff --git a/stable/sonarqube/Chart.yaml b/stable/sonarqube/Chart.yaml new file mode 100644 index 0000000000..ef1f080c46 --- /dev/null +++ b/stable/sonarqube/Chart.yaml @@ -0,0 +1,16 @@ +name: sonarqube +description: Sonarqube is an open sourced code quality scanning tool +version: 0.1.0 +appVersion: 6.5 +keywords: + - coverage + - security + - code + - quality +home: https://www.sonarqube.org/ +icon: https://www.sonarqube.org/assets/logo-31ad3115b1b4b120f3d1efd63e6b13ac9f1f89437f0cf6881cc4d8b5603a52b4.svg +sources: + - https://github.com/SonarSource/docker-sonarqube +maintainers: + - name: rjkernick + email: rjkernick@gmail.com diff --git a/stable/sonarqube/README.md b/stable/sonarqube/README.md new file mode 100644 index 0000000000..830d60ef04 --- /dev/null +++ b/stable/sonarqube/README.md @@ -0,0 +1,58 @@ +# SonarQube + +[SonarQube](https://www.sonarqube.org/) is an open sourced code quality scanning tool + +## Introduction + +This chart bootstraps a SonarQube instance with a PostgreSQL database + +## Prerequisites + +- Kubernetes 1.6+ + +## Installing the chart: + +To install the chart : + +```bash +$ helm install stable/sonarqube +``` + +The above command deploys Sonarqube on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation + +The default login is admin/admin + +## Uninstalling the chart + +To uninstall/delete the deployment: + +```bash +$ helm list +NAME REVISION UPDATED STATUS CHART NAMESPACE +kindly-newt 1 Mon Oct 2 15:05:44 2017 DEPLOYED sonarqube-0.1.0 default +$ helm delete kindly-newt +``` + +## Configuration + +The following table lists the configurable parameters of the Sonarqube chart and their default values. + +| Parameter | Description | Default | +| ------------------------------------------ | ---------------------------------- | -------------------------------------------| +| `imageTag` | `sonarqube` image tag. | 6.5 | +| `imagePullPolicy` | Image pull policy | `IfNotPresent` | +| `ingress.enabled` | Flag for enabling ingress | false | +| `service.type` | Kubernetes service type | `LoadBalancer` | +| `persistence.enabled` | Flag for enabling persistent storage| false | +| `persistence.storageClass` | Storage class to be used | "-" | +| `persistence.accessMode` | Volumes access mode to be set | `ReadWriteOnce` | +| `persistence.dataVolumeSize` | Size of the data volume | `8Gi` | +| `persistence.confVolumeSize` | Size of the conf volume | `1Gi` | +| `persistence.extensionsVolumeSize` | Size of the extension volume | `2Gi` | +| `postgresql.postgresUser` | Postgresql database user | `sonarUser` | +| `postgresql.postgresPassword` | Postgresql database password | `sonarPass` | +| `postgresql.postgresDatabase` | Postgresql database name | `sonarDB` | + +You can also configure values for the PostgreSQL database via the Postgresql [README.md](https://github.com/kubernetes/charts/blob/master/stable/postgresql/README.md) + +For overriding variables see: [Customizing the chart](https://docs.helm.sh/using_helm/#customizing-the-chart-before-installing) diff --git a/stable/sonarqube/requirements.lock b/stable/sonarqube/requirements.lock new file mode 100644 index 0000000000..081470b7c9 --- /dev/null +++ b/stable/sonarqube/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: postgresql + repository: https://kubernetes-charts.storage.googleapis.com/ + version: 0.8.3 +digest: sha256:b67c843d95aa0a2e7684abb787b22913e54baa92f45a450a3c3bcb7f3e068748 +generated: 2017-10-02T11:44:34.540107846-04:00 diff --git a/stable/sonarqube/requirements.yaml b/stable/sonarqube/requirements.yaml new file mode 100644 index 0000000000..98765c61de --- /dev/null +++ b/stable/sonarqube/requirements.yaml @@ -0,0 +1,4 @@ +dependencies: + - name: postgresql + version: 0.8.3 + repository: https://kubernetes-charts.storage.googleapis.com/ diff --git a/stable/sonarqube/templates/NOTES.txt b/stable/sonarqube/templates/NOTES.txt new file mode 100644 index 0000000000..5b503239b7 --- /dev/null +++ b/stable/sonarqube/templates/NOTES.txt @@ -0,0 +1,19 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range .Values.ingress.hosts }} + http://{{ . }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "sonarqube.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get svc -w {{ template "sonarqube.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "sonarqube.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.externalPort }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "sonarqube.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:{{ .Values.service.externalPort }} +{{- end }} diff --git a/stable/sonarqube/templates/_helpers.tpl b/stable/sonarqube/templates/_helpers.tpl new file mode 100644 index 0000000000..45ce1abb51 --- /dev/null +++ b/stable/sonarqube/templates/_helpers.tpl @@ -0,0 +1,24 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "sonarqube.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). +*/}} +{{- define "sonarqube.fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* + Create a default fully qualified postgresql name. + We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "postgresql.fullname" -}} +{{- printf "%s-%s" .Release.Name "postgresql" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/stable/sonarqube/templates/deployment.yaml b/stable/sonarqube/templates/deployment.yaml new file mode 100644 index 0000000000..542c53bd01 --- /dev/null +++ b/stable/sonarqube/templates/deployment.yaml @@ -0,0 +1,76 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "sonarqube.fullname" . }} + labels: + app: {{ template "sonarqube.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + app: {{ template "sonarqube.name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.internalPort }} + env: + - name: SONARQUBE_JDBC_USERNAME + value: {{.Values.postgresql.postgresUser | quote }} + - name: SONARQUBE_JDBC_PASSWORD + valueFrom: + secretKeyRef: + name: {{ template "postgresql.fullname" .}} + key: postgres-password + - name: SONARQUBE_JDBC_URL + value: "jdbc:postgresql://{{ template "postgresql.fullname" .}}:5432/{{.Values.postgresql.postgresDatabase}}" + livenessProbe: + httpGet: + path: / + port: {{ .Values.service.internalPort }} + readinessProbe: + httpGet: + path: / + port: {{ .Values.service.internalPort }} + volumeMounts: + - mountPath: /opt/sonarqube/conf + name: sonarqube-conf + - mountPath: /opt/sonarqube/data + name: sonarqube-data + - mountPath: /opt/sonarqube/extensions + name: sonarqube-extensions + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} + volumes: + - name: sonarqube-conf + {{- if .Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ template "sonarqube.fullname" . }}-conf + {{- else }} + emptyDir: {} + {{- end }} + - name: sonarqube-data + {{- if .Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ template "sonarqube.fullname" . }}-data + {{- else }} + emptyDir: {} + {{- end }} + - name: sonarqube-extensions + {{- if .Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ template "sonarqube.fullname" . }}-extensions + {{- else }} + emptyDir: {} + {{- end -}} diff --git a/stable/sonarqube/templates/ingress.yaml b/stable/sonarqube/templates/ingress.yaml new file mode 100644 index 0000000000..2c4853837a --- /dev/null +++ b/stable/sonarqube/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if .Values.ingress.enabled -}} +{{- $serviceName := include "sonarqube.fullname" . -}} +{{- $servicePort := .Values.service.externalPort -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "sonarqube.fullname" . }} + labels: + app: {{ template "sonarqube.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + annotations: + {{- range $key, $value := .Values.ingress.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + rules: + {{- range $host := .Values.ingress.hosts }} + - host: {{ $host }} + http: + paths: + - path: / + backend: + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: +{{ toYaml .Values.ingress.tls | indent 4 }} + {{- end -}} +{{- end -}} diff --git a/stable/sonarqube/templates/pvc-conf.yaml b/stable/sonarqube/templates/pvc-conf.yaml new file mode 100644 index 0000000000..89042949ef --- /dev/null +++ b/stable/sonarqube/templates/pvc-conf.yaml @@ -0,0 +1,24 @@ +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ template "sonarqube.fullname" . }}-conf + labels: + app: {{ template "sonarqube.name" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +spec: + accessModes: + - {{ .Values.persistence.accessMode | quote }} + resources: + requests: + storage: {{ .Values.persistence.confVolumeSize | quote }} +{{- if .Values.persistence.storageClass }} +{{- if (eq "-" .Values.persistence.storageClass) }} + storageClassName: "" +{{- else }} + storageClassName: "{{ .Values.persistence.storageClass }}" +{{- end }} +{{- end }} +{{- end }} diff --git a/stable/sonarqube/templates/pvc-data.yaml b/stable/sonarqube/templates/pvc-data.yaml new file mode 100644 index 0000000000..fe1214e319 --- /dev/null +++ b/stable/sonarqube/templates/pvc-data.yaml @@ -0,0 +1,24 @@ +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ template "sonarqube.fullname" . }}-data + labels: + app: {{ template "sonarqube.name" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +spec: + accessModes: + - {{ .Values.persistence.accessMode | quote }} + resources: + requests: + storage: {{ .Values.persistence.dataVolumeSize | quote }} +{{- if .Values.persistence.storageClass }} +{{- if (eq "-" .Values.persistence.storageClass) }} + storageClassName: "" +{{- else }} + storageClassName: "{{ .Values.persistence.storageClass }}" +{{- end }} +{{- end }} +{{- end }} diff --git a/stable/sonarqube/templates/pvc-extensions.yaml b/stable/sonarqube/templates/pvc-extensions.yaml new file mode 100644 index 0000000000..de7fbe0ca9 --- /dev/null +++ b/stable/sonarqube/templates/pvc-extensions.yaml @@ -0,0 +1,24 @@ +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ template "sonarqube.fullname" . }}-extensions + labels: + app: {{ template "sonarqube.name" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +spec: + accessModes: + - {{ .Values.persistence.accessMode | quote }} + resources: + requests: + storage: {{ .Values.persistence.extensionsVolumeSize | quote }} +{{- if .Values.persistence.storageClass }} +{{- if (eq "-" .Values.persistence.storageClass) }} + storageClassName: "" +{{- else }} + storageClassName: "{{ .Values.persistence.storageClass }}" +{{- end }} +{{- end }} +{{- end }} diff --git a/stable/sonarqube/templates/service.yaml b/stable/sonarqube/templates/service.yaml new file mode 100644 index 0000000000..9be9babde9 --- /dev/null +++ b/stable/sonarqube/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "sonarqube.fullname" . }} + labels: + app: {{ template "sonarqube.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "sonarqube.name" . }} + release: {{ .Release.Name }} diff --git a/stable/sonarqube/templates/sonarqube-test.yaml b/stable/sonarqube/templates/sonarqube-test.yaml new file mode 100644 index 0000000000..b6eda68e40 --- /dev/null +++ b/stable/sonarqube/templates/sonarqube-test.yaml @@ -0,0 +1,42 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ .Release.Name }}-ui-test-{{ randAlphaNum 5 | lower }}" + annotations: + "helm.sh/hook": test-success + labels: + app: {{ template "sonarqube.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + initContainers: + - name: "test-framework" + image: "dduportal/bats:0.4.0" + command: + - "bash" + - "-c" + - | + set -ex + # copy bats to tools dir + cp -R /usr/local/libexec/ /tools/bats/ + volumeMounts: + - mountPath: /tools + name: tools + containers: + - name: {{ .Release.Name }}-ui-test + image: {{ .Values.image.repository }}:{{ .Values.image.tag }} + command: ["/tools/bats/bats", "-t", "/tests/run.sh"] + volumeMounts: + - mountPath: /tests + name: tests + readOnly: true + - mountPath: /tools + name: tools + volumes: + - name: tests + configMap: + name: {{ template "sonarqube.fullname" . }}-tests + - name: tools + emptyDir: {} + restartPolicy: Never diff --git a/stable/sonarqube/templates/test-config.yaml b/stable/sonarqube/templates/test-config.yaml new file mode 100644 index 0000000000..7c9ea9f313 --- /dev/null +++ b/stable/sonarqube/templates/test-config.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "sonarqube.fullname" . }}-tests + labels: + app: {{ template "sonarqube.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +data: + run.sh: |- + @test "Testing Sonarqube UI is accessible" { + curl --connect-timeout 5 --retry 12 --retry-delay 1 --retry-max-time 60 {{ .Release.Name }}-sonarqube:9000 + } diff --git a/stable/sonarqube/values.yaml b/stable/sonarqube/values.yaml new file mode 100644 index 0000000000..d3c4ea7c71 --- /dev/null +++ b/stable/sonarqube/values.yaml @@ -0,0 +1,57 @@ +# Default values for sonarqube. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +image: + repository: sonarqube + tag: 6.5 +service: + name: sonarqube + type: LoadBalancer + externalPort: 9000 + internalPort: 9000 +ingress: + enabled: false + # Used to create an Ingress record. + hosts: + - sonar.organization.com + annotations: + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + tls: + # Secrets must be manually created in the namespace. + # - secretName: chart-example-tls + # hosts: + # - chart-example.local +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 +persistence: + enabled: false + ## If defined, storageClassName: + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. (gp2 on AWS, standard on + ## GKE, AWS & OpenStack) + ## + # storageClass: "-" + # accessMode: ReadWriteOnce + # dataVolumeSize: 8Gi + # confVolumeSize: 1Gi + # extensionsVolumeSize: 2Gi + +## Configuration values for the postgresql dependency +## ref: https://github.com/kubernetes/charts/blob/master/stable/postgressql/README.md +## +postgresql: + postgresUser: "sonarUser" + postgresPassword: "sonarPass" + postgresDatabase: "sonarDB" diff --git a/stable/sonatype-nexus/templates/pvc.yaml b/stable/sonatype-nexus/templates/pvc.yaml index 439abccbaf..dba7f4e3a5 100644 --- a/stable/sonatype-nexus/templates/pvc.yaml +++ b/stable/sonatype-nexus/templates/pvc.yaml @@ -4,7 +4,7 @@ apiVersion: v1 metadata: name: {{ template "fullname" . }} labels: - app: {{ template "fullname" . }} + app: {{ template "name" . }} chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}"