Skip to content

Commit

Permalink
Optimize deploying experience and adapt to a newer version of K8s(1.2…
Browse files Browse the repository at this point in the history
…2+) (#9)

* Fix that horizon-core could not launch successfully if gitlab has been restarted && Bump Tekton trigger verson to 0.17.0 to fix the issue that EventListener cannot be deleted in helm uninstallation && Fix that some resources cannot be applied to v1.22+ K8s because some v1beta resource versions are unavailable in v1.22+
  • Loading branch information
iamyeka authored Feb 27, 2023
1 parent edcb4ca commit 4927df9
Show file tree
Hide file tree
Showing 123 changed files with 4,409 additions and 3,004 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea
.vscode
Chart.lock
*.tgz
7 changes: 6 additions & 1 deletion charts/gitlab/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: gitlab
apiVersion: v2
version: 2.0.1
version: 2.0.2
appVersion: 15.5.1
description: GitLab Community Edition
keywords:
Expand All @@ -11,3 +11,8 @@ keywords:
- code review
- wiki
home: https://about.gitlab.com

dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
version: 2.x.x
30 changes: 21 additions & 9 deletions charts/gitlab/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@ data:
GITLAB_TIMEZONE: {{ .Values.config.GITLAB_TIMEZONE | quote }}
{{- end }}
init.sh: |
while true
do
CHECK_STATUS="$(curl -s -o /dev/null -w "%{http_code}" http://localhost/help)"
[[ "$CHECK_STATUS" == 20* ]] && {
gitlab-rails runner "token = User.find_by_username('root').personal_access_tokens.create(scopes: [:api], name: 'Automation token'); token.set_token('{{ .Values.config.GITLAB_ROOT_ACCESS_TOKEN }}'); token.save!"
exit 0
}
sleep 10
done
while true
do
CHECK_STATUS="$(curl -s -o /dev/null -w "%{http_code}" http://localhost/help)"
[[ "$CHECK_STATUS" == 20* ]] && {
gitlab-rails runner /tmp/script.rb
exit 0
}
sleep 10
done
script.rb: |
# clear token to solve 500 error, refer: https://gitlab.com/gitlab-org/gitlab-foss/-/issues/59623,
# https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/26829/diffs
Project.update(runners_token: nil, runners_token_encrypted: nil)
Namespace.update(runners_token: nil, runners_token_encrypted: nil)
# create personal access token
token = User.find_by_username('root').personal_access_tokens.find_by_name('Automation token')
token.delete if token
token = User.find_by_username('root').personal_access_tokens.create(scopes: [:api], name: 'Automation token')
token.set_token('{{ .Values.config.GITLAB_ROOT_ACCESS_TOKEN }}')
token.save!
11 changes: 6 additions & 5 deletions charts/gitlab/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- $releaseName := .Release.Name -}}
{{- $servicePort := .Values.httpPort -}}
apiVersion: extensions/v1beta1
apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }}
kind: Ingress
metadata:
annotations:
Expand All @@ -18,7 +18,8 @@ spec:
http:
paths:
- path: /
backend:
serviceName: {{ printf "%s-%s" $releaseName "gitlab" | trunc 63 }}
servicePort: {{ $servicePort }}
{{- end }}
{{- if eq "true" (include "common.ingress.supportsPathType" $) }}
pathType: ImplementationSpecific
{{- end }}
backend: {{- include "common.ingress.backend" (dict "serviceName" (printf "%s-%s" $releaseName "gitlab" | trunc 63) "servicePort" $servicePort "context" $) | nindent 14 }}
{{- end }}
17 changes: 0 additions & 17 deletions charts/gitlab/templates/pvc.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: apps/v1
kind: Deployment
apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
kind: StatefulSet
metadata:
name: {{ template "fullname" . }}
namespace: {{ .Release.Namespace }}
Expand All @@ -10,6 +10,7 @@ spec:
selector:
matchLabels:
app: {{ template "fullname" . }}
serviceName: {{ template "fullname" . }}
template:
metadata:
labels:
Expand All @@ -31,7 +32,7 @@ spec:
- name: GITLAB_OMNIBUS_CONFIG
value: |
external_url 'http://{{ .Values.config.GITLAB_HOST }}'
# Smtp
gitlab_rails['smtp_enable'] = false
gitlab_rails['gitlab_email_enabled'] = false
Expand Down Expand Up @@ -142,16 +143,35 @@ spec:
- name: init
mountPath: /tmp/init.sh
subPath: init.sh
- name: init
mountPath: /tmp/script.rb
subPath: script.rb
resources:
{{ toYaml .Values.resources | indent 10 }}
volumes:
- name: gitlab-data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ template "fullname" . }}-data
{{- else }}
emptyDir: {}
{{- end }}
- name: init
configMap:
name: {{ template "fullname" . }}
- name: init
configMap:
name: {{ template "fullname" . }}
{{- if and .Values.persistence.enabled .Values.persistence.existingClaim }}
- name: gitlab-data
persistentVolumeClaim:
claimName: {{ .Values.persistence.existingClaim }}
{{- else if not .Values.persistence.enabled }}
emptyDir: {}
{{- else if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
volumeClaimTemplates:
- metadata:
name: gitlab-data
annotations:
{{- if .Values.persistence.storageClass }}
volume.beta.kubernetes.io/storage-class: {{ .Values.persistence.storageClass | quote }}
{{- else }}
volume.alpha.kubernetes.io/storage-class: default
{{- end }}
spec:
accessModes:
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- end }}
1 change: 1 addition & 0 deletions charts/gitlab/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ingress:

persistence:
enabled: false
existingClaim: ""
size: 2Gi
accessMode: ReadWriteOnce
storageClass: ""
Expand Down
3 changes: 3 additions & 0 deletions charts/horizon/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ version: 2.0.4
appVersion: v2.0.5

dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
version: 2.x.x
- name: gitlab
version: 2.0.1
repository: https://horizoncd.github.io/helm-charts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ secrets:
- name: git-secret{{ $i }}
{{- end }}
- name: git-token
- name: harbor-secret
- name: harbor-secret
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ spec:
{{- with .Values.horizon.buildTask.timeout.imageStep }}
timeout: {{.}}
{{- end}}
env:
- name: DOCKER_CONFIG
value: /tekton/home/.docker/
script:
{{ toYaml (tpl .Values.horizon.script.image .) | nindent 8 }}
{{ if .Values.extraVolumeMounts -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,33 @@ metadata:
spec:
params:
- name: token
type: string
- name: application
type: string
- name: cluster
type: string
- name: clusterID
type: string
- name: environment
type: string
- name: gitRepositoryUrl
type: string
- name: gitSubfolder
type: string
- name: gitCommit
type: string
- name: gitBranch
type: string
- name: gitTag
type: string
- name: pipelineJSONBlob
type: string
- name: imageURL
type: string
- name: pipelinerunID
type: string
- name: requestID
type: string
workspaces:
- name: buildinfo
tasks:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{- if .Values.enableV1betaEventListener }}
apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
name: horizon-listener
spec:
serviceAccountName: tekton-triggers-sa
resources:
kubernetesResource:
replicas: {{ .Values.eventListener.replicas }}
spec:
template:
spec:
containers:
- resources:
requests:
memory: 32Mi
cpu: 1m
limits:
memory: 256Mi
cpu: 100m
triggers:
- bindings:
- ref: horizon-taskbinding
template:
ref: horizon-triggertemplate
interceptors:
- ref:
name: "cel"
params:
- name: "overlays"
value:
- key: pipelineJSONBlob
expression: "body.pipelineJSONBlob.marshalJSON()"
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if not .Values.enableV1betaEventListener }}
apiVersion: triggers.tekton.dev/v1alpha1
kind: EventListener
metadata:
Expand Down Expand Up @@ -30,3 +31,4 @@ spec:
overlays:
- key: pipelineJSONBlob
expression: "body.pipelineJSONBlob.marshalJSON()"
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{{- if .Values.horizon.ingress.hosts }}
apiVersion: extensions/v1beta1
apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }}
kind: Ingress
metadata:
name: horizon-listener
spec:
rules:
{{- range .Values.horizon.ingress.hosts }}
- host: {{ . }}
http:
paths:
- backend:
serviceName: el-horizon-listener
servicePort: 8080
path: /
{{- end }}
{{- end }}
{{- range .Values.horizon.ingress.hosts }}
- host: {{ . }}
http:
paths:
- path: /
{{- if eq "true" (include "common.ingress.supportsPathType" $) }}
pathType: ImplementationSpecific
{{- end }}
backend: {{- include "common.ingress.backend" (dict "serviceName" "el-horizon-listener" "servicePort" 8080 "context" $) | nindent 14 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ rules:
# EventListeners need to be able to fetch any clustertriggerbindings
- apiGroups: ["triggers.tekton.dev"]
resources: ["clustertriggerbindings"]
verbs: ["get", "list", "watch"]
verbs: ["get", "list", "watch"]
{{- if .Values.enableV1betaEventListener }}
- apiGroups: ["triggers.tekton.dev"]
resources: ["clusterinterceptors"]
verbs: ["get", "list", "watch"]
{{- end }}
4 changes: 3 additions & 1 deletion charts/horizon/charts/tektonci-resources/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ horizon:
image: |
#!/bin/bash
set -e
export BUILD_TYPE="$(cat $(workspaces.buildinfo.path)/build-type)"
export APPLICATION="$(params.application)"
Expand All @@ -154,6 +153,7 @@ horizon:
echo -e "\nstart building: $DOCKER_IMAGE"
export DOCKER_CONFIG=~/.docker
CMD_KANIKO="time /kaniko/executor --skip-tls-verify --context=${CONTEXT} \
--snapshotMode=redo \
--use-new-run \
Expand Down Expand Up @@ -329,3 +329,5 @@ gitRepos:
eventListener:
replicas: 1
extraVolumeMounts: []
# When set true, custom resources of tekton triggers like EventListener are rendered based on tekton triggers whose version is above v0.17.0.
enableV1betaEventListener: true
27 changes: 7 additions & 20 deletions charts/horizon/templates/core/core-cloudevent-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{{- if .Values.core.cloudEventIngress.enabled -}}
{{- $fullName := printf "%v-%v" (include "horizon.core" .) "cloudevent" -}}
{{- $svcPort := .Values.core.cloudEventService.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }}
kind: Ingress
metadata:
name: {{ $fullName }}
Expand All @@ -16,26 +12,17 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.core.cloudEventIngress.tls }}
tls:
{{- range .Values.core.cloudEventIngress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.core.cloudEventIngress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- if eq "true" (include "common.ingress.supportsPathType" $) }}
pathType: {{ $.Values.core.cloudEventIngress.pathType}}
{{- end }}
backend: {{- include "common.ingress.backend" (dict "serviceName" $fullName "servicePort" $svcPort "context" $) | nindent 14 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Loading

0 comments on commit 4927df9

Please sign in to comment.