Skip to content

Commit c0d62b9

Browse files
feat: add sidecar container (#389)
1 parent d8f5e4a commit c0d62b9

File tree

15 files changed

+231
-103
lines changed

15 files changed

+231
-103
lines changed

charts/cf-runtime/.ci/values-ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ monitor:
1717
enabled: true
1818
rbac:
1919
namespaced: true
20-
runner: {}
20+
runner:
21+
sidecar:
22+
enabled: true
2123
runtime:
2224
dind:
2325
image:

charts/cf-runtime/Chart.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v2
22
description: A Helm chart for Codefresh Runner
33
name: cf-runtime
4-
version: 6.0.1
4+
version: 6.1.0
55
keywords:
66
- codefresh
77
- runner
@@ -14,8 +14,8 @@ maintainers:
1414
url: https://codefresh-io.github.io/
1515
annotations:
1616
artifacthub.io/changes: |
17-
- kind: fixed
18-
description: Fix imageRegistry prefix for runtime images
17+
- kind: added
18+
description: Add optional sidecar container in runner to reconcile runtime-environment spec from Codefresh API
1919
dependencies:
2020
- name: cf-common
2121
repository: https://chartmuseum.codefresh.io/cf-common

charts/cf-runtime/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Codefresh Runner
22

3-
![Version: 6.0.1](https://img.shields.io/badge/Version-6.0.1-informational?style=flat-square)
3+
![Version: 6.1.0](https://img.shields.io/badge/Version-6.1.0-informational?style=flat-square)
44

55
Helm chart for deploying [Codefresh Runner](https://codefresh.io/docs/docs/installation/codefresh-runner/) to Kubernetes.
66

@@ -235,6 +235,16 @@ global:
235235
runtimeName: "my-cluster-name/my-namespace" # optional
236236
```
237237

238+
> **Note!** Though it's still possible to update runtime-environment via [get](https://codefresh-io.github.io/cli/runtime-environments/get-runtime-environments/) and [patch](https://codefresh-io.github.io/cli/runtime-environments/apply-runtime-environments/) commands, it's recommended to enable sidecar container to pull runtime spec from Codefresh API to detect any drift in configuration.
239+
240+
```yaml
241+
runner:
242+
# -- Sidecar container
243+
# Reconciles runtime spec from Codefresh API for drift detection
244+
sidecar:
245+
enabled: true
246+
```
247+
238248
## Architecture
239249

240250
[Codefresh Runner architecture](https://codefresh.io/docs/docs/installation/codefresh-runner/#codefresh-runner-architecture)
@@ -886,6 +896,7 @@ Go to [https://<YOUR_ONPREM_DOMAIN_HERE>/admin/runtime-environments/system](http
886896
| runner.enabled | bool | `true` | Enable the runner |
887897
| runner.env | object | `{}` | Add additional env vars |
888898
| runner.image | object | `{"registry":"quay.io","repository":"codefresh/venona","tag":"1.9.17"}` | Set image |
899+
| runner.init | object | `{"image":{"registry":"quay.io","repository":"codefresh/cli","tag":"0.85.0-rootless"},"resources":{"limits":{"cpu":"1","memory":"512Mi"},"requests":{"cpu":"0.2","memory":"256Mi"}}}` | Init container |
889900
| runner.nodeSelector | object | `{}` | Set node selector |
890901
| runner.podAnnotations | object | `{}` | Set pod annotations |
891902
| runner.podSecurityContext | object | See below | Set security context for the pod |
@@ -899,6 +910,7 @@ Go to [https://<YOUR_ONPREM_DOMAIN_HERE>/admin/runtime-environments/system](http
899910
| runner.serviceAccount.annotations | object | `{}` | Additional service account annotations |
900911
| runner.serviceAccount.create | bool | `true` | Create service account |
901912
| runner.serviceAccount.name | string | `""` | Override service account name |
913+
| runner.sidecar | object | `{"enabled":false,"env":{"RECONCILE_INTERVAL":300},"image":{"registry":"quay.io","repository":"codefresh/codefresh-shell","tag":"0.0.2"},"resources":{}}` | Sidecar container Reconciles runtime spec from Codefresh API for drift detection |
902914
| runner.tolerations | list | `[]` | Set tolerations |
903915
| runner.updateStrategy | object | `{"type":"RollingUpdate"}` | Upgrade strategy |
904916
| runtime | object | See below | Set runtime parameters |

charts/cf-runtime/README.md.gotmpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ global:
235235
runtimeName: "my-cluster-name/my-namespace" # optional
236236
```
237237

238+
> **Note!** Though it's still possible to update runtime-environment via [get](https://codefresh-io.github.io/cli/runtime-environments/get-runtime-environments/) and [patch](https://codefresh-io.github.io/cli/runtime-environments/apply-runtime-environments/) commands, it's recommended to enable sidecar container to pull runtime spec from Codefresh API to detect any drift in configuration.
239+
240+
```yaml
241+
runner:
242+
# -- Sidecar container
243+
# Reconciles runtime spec from Codefresh API for drift detection
244+
sidecar:
245+
enabled: true
246+
```
247+
238248
## Architecture
239249

240250
[Codefresh Runner architecture](https://codefresh.io/docs/docs/installation/codefresh-runner/#codefresh-runner-architecture)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
echo "-----"
4+
echo "API_HOST: ${API_HOST}"
5+
echo "KUBE_CONTEXT: ${KUBE_CONTEXT}"
6+
echo "KUBE_NAMESPACE: ${KUBE_NAMESPACE}"
7+
echo "OWNER_NAME: ${OWNER_NAME}"
8+
echo "RUNTIME_NAME: ${RUNTIME_NAME}"
9+
echo "CONFIGMAP_NAME: ${CONFIGMAP_NAME}"
10+
echo "RECONCILE_INTERVAL: ${RECONCILE_INTERVAL}"
11+
echo "-----"
12+
13+
msg() { echo -e "\e[32mINFO ---> $1\e[0m"; }
14+
err() { echo -e "\e[31mERR ---> $1\e[0m" ; return 1; }
15+
16+
17+
if [ -z "${USER_CODEFRESH_TOKEN}" ]; then
18+
err "missing codefresh user token. must supply \".global.codefreshToken\" if agent-codefresh-token does not exist"
19+
exit 1
20+
fi
21+
22+
codefresh auth create-context --api-key ${USER_CODEFRESH_TOKEN} --url ${API_HOST}
23+
24+
while true; do
25+
msg "Reconciling ${RUNTIME_NAME} runtime"
26+
27+
sleep $RECONCILE_INTERVAL
28+
29+
codefresh get re \
30+
--name ${RUNTIME_NAME} \
31+
-o yaml \
32+
| yq 'del(.version, .metadata.changedBy, .metadata.creationTime)' > /tmp/runtime.yaml
33+
34+
sed -i "s/'/\"/g" /tmp/runtime.yaml
35+
36+
kubectl get cm ${CONFIGMAP_NAME} -n ${KUBE_NAMESPACE} -o yaml \
37+
| yq 'del(.metadata.resourceVersion, .metadata.uid)' \
38+
| yq eval '.data["runtime.yaml"] = load_str("/tmp/runtime.yaml")' \
39+
| kubectl apply -f -
40+
done

charts/cf-runtime/templates/_components/runner/_deployment.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ spec:
6969
volumeMounts:
7070
{{- toYaml . | nindent 8 }}
7171
{{- end }}
72+
{{- if .Values.sidecar.enabled }}
73+
- name: reconcile-runtime
74+
image: {{ include (printf "%s.image.name" $cfCommonTplSemver ) (dict "image" .Values.sidecar.image "context" .) }}
75+
imagePullPolicy: {{ .Values.sidecar.image.pullPolicy | default "IfNotPresent" }}
76+
command:
77+
- /bin/bash
78+
args:
79+
- -ec
80+
- |
81+
{{ .Files.Get "files/reconcile-runtime.sh" | nindent 10 }}
82+
env:
83+
{{- include "runner-sidecar.environment-variables" . | nindent 8 }}
84+
{{- with .Values.sidecar.resources }}
85+
resources:
86+
{{- toYaml . | nindent 10 }}
87+
{{- end }}
88+
{{- end }}
7289
{{- with .Values.nodeSelector }}
7390
nodeSelector:
7491
{{- toYaml . | nindent 8 }}

charts/cf-runtime/templates/_components/runner/_rbac.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ rules:
2525
verbs: [ "get", "create", "delete" ]
2626
- apiGroups: [ "" ]
2727
resources: [ "configmaps", "secrets" ]
28-
verbs: [ "get", "create" ]
28+
verbs: [ "get", "create", "update", patch ]
2929
- apiGroups: [ "apps" ]
3030
resources: [ "deployments" ]
3131
verbs: [ "get" ]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{- define "runner-sidecar.environment-variables.defaults" }}
2+
HOME: /tmp
3+
{{- end }}
4+
5+
{{- define "runner-sidecar.environment-variables.calculated" }}
6+
API_HOST: {{ include "runtime.runtime-environment-spec.codefresh-host" . }}
7+
USER_CODEFRESH_TOKEN: {{ include "runtime.installation-token-env-var-value" . | nindent 2 }}
8+
KUBE_CONTEXT: {{ include "runtime.runtime-environment-spec.context-name" . }}
9+
KUBE_NAMESPACE: {{ .Release.Namespace }}
10+
OWNER_NAME: {{ include "runner.fullname" . }}
11+
RUNTIME_NAME: {{ include "runtime.runtime-environment-spec.runtime-name" . }}
12+
CONFIGMAP_NAME: {{ printf "%s-%s" (include "runtime.fullname" .) "spec" }}
13+
{{- end }}
14+
15+
{{- define "runner-sidecar.environment-variables" }}
16+
{{- $cfCommonTplSemver := printf "cf-common-%s" (index .Subcharts "cf-common").Chart.Version }}
17+
{{- $defaults := (include "runner-sidecar.environment-variables.defaults" . | fromYaml) }}
18+
{{- $calculated := (include "runner-sidecar.environment-variables.calculated" . | fromYaml) }}
19+
{{- $overrides := .Values.sidecar.env }}
20+
{{- $mergedValues := mergeOverwrite (merge $defaults $calculated) $overrides }}
21+
{{- include (printf "%s.env-vars" $cfCommonTplSemver) (dict "Values" $mergedValues "context" .) }}
22+
{{- end }}

charts/cf-runtime/templates/hooks/post-install/cm-update-runtime.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ metadata:
1313
{{- toYaml . | nindent 4 }}
1414
{{- end }}
1515
data:
16-
runtime.yaml: |-
17-
{{ include "runtime.runtime-environment-spec.template" . | nindent 4 }}
16+
runtime.yaml: |
17+
{{ include "runtime.runtime-environment-spec.template" . | nindent 4 | trim }}
1818
{{- end }}

charts/cf-runtime/templates/runtime/runtime-env-spec-tmpl.yaml

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,10 @@
88
metadata:
99
name: {{ include "runtime.runtime-environment-spec.runtime-name" . }}
1010
agent: {{ .Values.runtime.agent }}
11-
extends: {{- toYaml .Values.runtime.runtimeExtends | nindent 2 }}
12-
{{- with .Values.runtime.description }}
13-
description: {{ . }}
14-
{{- end }}
15-
{{- if not .Values.runtime.agent }}
16-
accounts: {{- toYaml .Values.runtime.accounts | nindent 2 }}
17-
{{- end }}
1811
runtimeScheduler:
1912
type: KubernetesPod
2013
{{- if $engineContext.image }}
21-
image: {{ include (printf "%s.image.name" $cfCommonTplSemver ) (dict "image" $engineContext.image "context" .) }}
14+
image: {{ include (printf "%s.image.name" $cfCommonTplSemver ) (dict "image" $engineContext.image "context" .) | quote }}
2215
{{- end }}
2316
{{- with $engineContext.command }}
2417
command: {{- toYaml . | nindent 4 }}
@@ -27,19 +20,19 @@ runtimeScheduler:
2720
{{- with $engineContext.env }}
2821
{{- toYaml . | nindent 4 }}
2922
{{- end }}
30-
COMPOSE_IMAGE: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.COMPOSE_IMAGE) }}'
31-
CONTAINER_LOGGER_IMAGE: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.CONTAINER_LOGGER_IMAGE) }}'
32-
DOCKER_BUILDER_IMAGE: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.DOCKER_BUILDER_IMAGE) }}'
33-
DOCKER_PULLER_IMAGE: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.DOCKER_PULLER_IMAGE) }}'
34-
DOCKER_PUSHER_IMAGE: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.DOCKER_PUSHER_IMAGE) }}'
35-
DOCKER_TAG_PUSHER_IMAGE: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.DOCKER_TAG_PUSHER_IMAGE) }}'
36-
FS_OPS_IMAGE: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.FS_OPS_IMAGE) }}'
37-
GIT_CLONE_IMAGE: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.GIT_CLONE_IMAGE) }}'
38-
KUBE_DEPLOY: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.KUBE_DEPLOY) }}'
39-
PIPELINE_DEBUGGER_IMAGE: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.PIPELINE_DEBUGGER_IMAGE) }}'
40-
TEMPLATE_ENGINE: '{{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.TEMPLATE_ENGINE) }}'
23+
COMPOSE_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.COMPOSE_IMAGE) | quote }}
24+
CONTAINER_LOGGER_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.CONTAINER_LOGGER_IMAGE) | quote }}
25+
DOCKER_BUILDER_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.DOCKER_BUILDER_IMAGE) | quote }}
26+
DOCKER_PULLER_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.DOCKER_PULLER_IMAGE) | quote }}
27+
DOCKER_PUSHER_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.DOCKER_PUSHER_IMAGE) | quote }}
28+
DOCKER_TAG_PUSHER_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.DOCKER_TAG_PUSHER_IMAGE) | quote }}
29+
FS_OPS_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.FS_OPS_IMAGE) | quote }}
30+
GIT_CLONE_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.GIT_CLONE_IMAGE) | quote }}
31+
KUBE_DEPLOY: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.KUBE_DEPLOY) | quote }}
32+
PIPELINE_DEBUGGER_IMAGE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.PIPELINE_DEBUGGER_IMAGE) | quote }}
33+
TEMPLATE_ENGINE: {{ include "runtime.runtimeImageName" (dict "registry" $imageRegistry "imageFullName" $engineContext.runtimeImages.TEMPLATE_ENGINE) | quote }}
4134
{{- with $engineContext.userEnvVars }}
42-
userEnvVars: {{- toYaml . | nindent 2 }}
35+
userEnvVars: {{- toYaml . | nindent 4 }}
4336
{{- end }}
4437
{{- with $engineContext.workflowLimits }}
4538
workflowLimits: {{ toYaml . | nindent 4 }}
@@ -82,7 +75,7 @@ runtimeScheduler:
8275
dockerDaemonScheduler:
8376
type: DindKubernetesPod
8477
{{- if $dindContext.image }}
85-
dindImage: {{ include (printf "%s.image.name" $cfCommonTplSemver ) (dict "image" $dindContext.image "context" .) }}
78+
dindImage: {{ include (printf "%s.image.name" $cfCommonTplSemver ) (dict "image" $dindContext.image "context" .) | quote }}
8679
{{- end }}
8780
{{- with $dindContext.userAccess }}
8881
userAccess: {{ . }}
@@ -125,7 +118,10 @@ dockerDaemonScheduler:
125118
pvcs:
126119
{{- range $index, $pvc := $dindContext.pvcs }}
127120
- name: {{ $pvc.name }}
128-
{{- include (printf "%v.tplrender" $cfCommonTplSemver) (dict "Values" (omit $pvc "name" ) "context" $) | nindent 6 }}
121+
reuseVolumeSelector: {{ $pvc.reuseVolumeSelector | quote }}
122+
reuseVolumeSortOrder: {{ $pvc.reuseVolumeSortOrder }}
123+
storageClassName: {{ include (printf "%v.tplrender" $cfCommonTplSemver) (dict "Values" $pvc.storageClassName "context" $) }}
124+
volumeSize: {{ $pvc.volumeSize }}
129125
{{- end }}
130126
{{- end }}
131127
defaultDindResources:
@@ -159,4 +155,16 @@ dockerDaemonScheduler:
159155
secret:
160156
secretName: codefresh-certs-server
161157
{{- end }}
158+
extends: {{- toYaml .Values.runtime.runtimeExtends | nindent 2 }}
159+
{{- if .Values.runtime.description }}
160+
description: {{ .Values.runtime.description }}
161+
{{- else }}
162+
description: null
163+
{{- end }}
164+
{{- if .Values.global.accountId }}
165+
accountId: {{ .Values.global.accountId }}
166+
{{- end }}
167+
{{- if not .Values.runtime.agent }}
168+
accounts: {{- toYaml .Values.runtime.accounts | nindent 2 }}
169+
{{- end }}
162170
{{- end }}

0 commit comments

Comments
 (0)