From 6d491b140a0eb7b7dd771d6b96d8dd8b3e301a17 Mon Sep 17 00:00:00 2001 From: Stefan Reimer Date: Fri, 3 Dec 2021 22:14:11 +0100 Subject: [PATCH] feat: add TeamCity to CI module --- charts/kubezero-ci/charts/teamcity/Chart.yaml | 18 ++++++ .../charts/teamcity/templates/_helpers.tpl | 62 ++++++++++++++++++ .../charts/teamcity/templates/agent.yaml | 50 +++++++++++++++ .../teamcity/templates/istio-service.yaml | 18 ++++++ .../charts/teamcity/templates/rbac.yaml | 28 +++++++++ .../charts/teamcity/templates/server-pvc.yaml | 33 ++++++++++ .../charts/teamcity/templates/server.yaml | 63 +++++++++++++++++++ .../charts/teamcity/templates/service.yaml | 16 +++++ .../teamcity/templates/serviceaccount.yaml | 12 ++++ .../kubezero-ci/charts/teamcity/values.yaml | 57 +++++++++++++++++ 10 files changed, 357 insertions(+) create mode 100644 charts/kubezero-ci/charts/teamcity/Chart.yaml create mode 100644 charts/kubezero-ci/charts/teamcity/templates/_helpers.tpl create mode 100644 charts/kubezero-ci/charts/teamcity/templates/agent.yaml create mode 100644 charts/kubezero-ci/charts/teamcity/templates/istio-service.yaml create mode 100644 charts/kubezero-ci/charts/teamcity/templates/rbac.yaml create mode 100644 charts/kubezero-ci/charts/teamcity/templates/server-pvc.yaml create mode 100644 charts/kubezero-ci/charts/teamcity/templates/server.yaml create mode 100644 charts/kubezero-ci/charts/teamcity/templates/service.yaml create mode 100644 charts/kubezero-ci/charts/teamcity/templates/serviceaccount.yaml create mode 100644 charts/kubezero-ci/charts/teamcity/values.yaml diff --git a/charts/kubezero-ci/charts/teamcity/Chart.yaml b/charts/kubezero-ci/charts/teamcity/Chart.yaml new file mode 100644 index 0000000..3d82877 --- /dev/null +++ b/charts/kubezero-ci/charts/teamcity/Chart.yaml @@ -0,0 +1,18 @@ +apiVersion: v2 +name: teamcity +description: A Helm chart to install a simple TeamCity installation +type: application +version: 0.1.0 +appVersion: "2021.2" +home: https://kubezero.com +icon: https://cdn.zero-downtime.net/assets/kubezero/logo-small-64.png +keywords: + - kubezero + - teamcity +maintainers: + - name: Quarky9 +dependencies: + - name: kubezero-lib + version: ">= 0.1.4" + repository: https://cdn.zero-downtime.net/charts/ +kubeVersion: ">= 1.18.0" diff --git a/charts/kubezero-ci/charts/teamcity/templates/_helpers.tpl b/charts/kubezero-ci/charts/teamcity/templates/_helpers.tpl new file mode 100644 index 0000000..9f76f68 --- /dev/null +++ b/charts/kubezero-ci/charts/teamcity/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "teamcity.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 "teamcity.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 "teamcity.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "teamcity.labels" -}} +helm.sh/chart: {{ include "teamcity.chart" . }} +{{ include "teamcity.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "teamcity.selectorLabels" -}} +app.kubernetes.io/name: {{ include "teamcity.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "teamcity.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "teamcity.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/kubezero-ci/charts/teamcity/templates/agent.yaml b/charts/kubezero-ci/charts/teamcity/templates/agent.yaml new file mode 100644 index 0000000..20d3b18 --- /dev/null +++ b/charts/kubezero-ci/charts/teamcity/templates/agent.yaml @@ -0,0 +1,50 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "teamcity.fullname" . }}-agent + labels: + {{- include "kubezero-lib.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.agentReplicaCount }} + selector: + matchLabels: + app.kubernetes.io/instance: teamcity-agent + app.kubernetes.io/name: teamcity + template: + metadata: + labels: + app.kubernetes.io/instance: teamcity-agent + app.kubernetes.io/name: teamcity + spec: + # serviceAccountName: {{ include "teamcity.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: "{{ .Chart.Name }}-agent" + securityContext: + {{- toYaml .Values.securityContext | nindent 10 }} + image: "{{ .Values.image.agent.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: SERVER_URL + value: "{{ include "teamcity.fullname" . }}:8111" + resources: + {{- toYaml .Values.resources | nindent 10 }} + volumeMounts: + - name: teamcity-config + mountPath: /data/teamcity_agent/conf + volumes: + - name: teamcity-config + emptyDir: {} + {{- 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/charts/kubezero-ci/charts/teamcity/templates/istio-service.yaml b/charts/kubezero-ci/charts/teamcity/templates/istio-service.yaml new file mode 100644 index 0000000..129d5c4 --- /dev/null +++ b/charts/kubezero-ci/charts/teamcity/templates/istio-service.yaml @@ -0,0 +1,18 @@ +{{- if .Values.istio.enabled }} +apiVersion: networking.istio.io/v1beta1 +kind: VirtualService +metadata: + name: {{ include "kubezero-lib.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "kubezero-lib.labels" . | nindent 4 }} +spec: + gateways: + - {{ .Values.istio.gateway }} + hosts: + - {{ .Values.istio.url }} + http: + - route: + - destination: + host: {{ include "teamcity.fullname" . }} +{{- end }} diff --git a/charts/kubezero-ci/charts/teamcity/templates/rbac.yaml b/charts/kubezero-ci/charts/teamcity/templates/rbac.yaml new file mode 100644 index 0000000..46bfc34 --- /dev/null +++ b/charts/kubezero-ci/charts/teamcity/templates/rbac.yaml @@ -0,0 +1,28 @@ +{{- if .Values.rbac.create }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "teamcity.fullname" . }}-manage-agents +rules: +- apiGroups: [""] + resources: ["namespaces"] + verbs: ["list", "get"] +- apiGroups: [""] + resources: ["pods"] + verbs: ["get", "create", "list", "delete"] +- apiGroups: ["extensions", "apps"] + resources: ["deployments"] + verbs: ["list", "get"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ include "teamcity.fullname" . }}-manage-agents +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ include "teamcity.fullname" . }}-manage-agents +subjects: + - kind: ServiceAccount + name: {{ include "teamcity.serviceAccountName" . }} +{{- end }} diff --git a/charts/kubezero-ci/charts/teamcity/templates/server-pvc.yaml b/charts/kubezero-ci/charts/teamcity/templates/server-pvc.yaml new file mode 100644 index 0000000..1e3cc3f --- /dev/null +++ b/charts/kubezero-ci/charts/teamcity/templates/server-pvc.yaml @@ -0,0 +1,33 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ include "teamcity.fullname" . }}-data + labels: + {{- include "kubezero-lib.labels" . | nindent 4 }} +spec: +{{- if .Values.pvc.data.storageClass }} + storageClassName: {{ .Values.pvc.data.storageClass }} +{{- end }} + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.pvc.data.storageSize }} + +--- + +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ include "teamcity.fullname" . }}-logs + labels: + {{- include "kubezero-lib.labels" . | nindent 4 }} +spec: +{{- if .Values.pvc.logs.storageClass }} + storageClassName: {{ .Values.pvc.logs.storageClass }} +{{- end }} + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.pvc.logs.storageSize }} diff --git a/charts/kubezero-ci/charts/teamcity/templates/server.yaml b/charts/kubezero-ci/charts/teamcity/templates/server.yaml new file mode 100644 index 0000000..28ad3db --- /dev/null +++ b/charts/kubezero-ci/charts/teamcity/templates/server.yaml @@ -0,0 +1,63 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "teamcity.fullname" . }} + labels: + {{- include "kubezero-lib.labels" . | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: + {{- include "kubezero-lib.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "kubezero-lib.labels" . | nindent 8 }} + spec: + serviceAccountName: {{ include "teamcity.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 10 }} + image: "{{ .Values.image.server.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: app + containerPort: 8111 + protocol: TCP + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: teamcity-data + mountPath: /data/teamcity_server/datadir + - name: teamcity-logs + mountPath: /opt/teamcity/logs + volumes: + - name: teamcity-data + {{- if .Values.pvc.data }} + persistentVolumeClaim: + claimName: {{ include "teamcity.fullname" . }}-data + {{- else }} + emptyDir: {} + {{- end }} + - name: teamcity-logs + {{- if .Values.pvc.logs }} + persistentVolumeClaim: + claimName: {{ include "teamcity.fullname" . }}-logs + {{- else }} + emptyDir: {} + {{- end -}} + {{- 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/charts/kubezero-ci/charts/teamcity/templates/service.yaml b/charts/kubezero-ci/charts/teamcity/templates/service.yaml new file mode 100644 index 0000000..6c104af --- /dev/null +++ b/charts/kubezero-ci/charts/teamcity/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: "{{ include "teamcity.fullname" . }}" + labels: + {{- include "kubezero-lib.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + protocol: TCP + targetPort: app + name: app + selector: + {{- include "kubezero-lib.selectorLabels" . | nindent 4 }} + sessionAffinity: None diff --git a/charts/kubezero-ci/charts/teamcity/templates/serviceaccount.yaml b/charts/kubezero-ci/charts/teamcity/templates/serviceaccount.yaml new file mode 100644 index 0000000..b8ff7f1 --- /dev/null +++ b/charts/kubezero-ci/charts/teamcity/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "teamcity.serviceAccountName" . }} + labels: + {{- include "kubezero-lib.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/kubezero-ci/charts/teamcity/values.yaml b/charts/kubezero-ci/charts/teamcity/values.yaml new file mode 100644 index 0000000..2b63c2c --- /dev/null +++ b/charts/kubezero-ci/charts/teamcity/values.yaml @@ -0,0 +1,57 @@ +# Default values for teamcity. + +agentReplicaCount: 0 + +image: + server: + repository: jetbrains/teamcity-server + agent: + repository: jetbrains/teamcity-agent + tag: "" + pullPolicy: IfNotPresent + +pvc: + data: + #storageClass: default + storageSize: 4Gi + logs: + #storageClass: default + storageSize: 1Gi + +serviceAccount: + create: true + annotations: {} + name: "" + +rbac: + create: true + +podAnnotations: {} + +podSecurityContext: + fsGroup: 1000 + +securityContext: {} + +service: + type: ClusterIP + port: 8111 + +istio: + enabled: false + gateway: istio-ingress/private-ingressgateway + url: "" # tc.example.com + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {}