Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PVC for agent #163

Merged
merged 23 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/davidanson/markdownlint-cli2
rev: v0.12.1
rev: v0.11.0
hooks:
- id: markdownlint-cli2
- repo: https://github.com/mrtazz/checkmake
Expand Down
2 changes: 1 addition & 1 deletion .woodpecker/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ steps:
- HELM_UNITTEST_VERSION=v0.4.1
commands:
- helm plugin install --version $HELM_UNITTEST_VERSION https://github.com/helm-unittest/helm-unittest > /dev/null
- helm unittest --strict -f 'unittests/**/*.yaml' ./charts/woodpecker/charts/server/
- helm unittest --strict -f 'unittests/**/*.yaml' ./charts/woodpecker/charts/server/ ./charts/woodpecker/charts/agent

test-chart:
image: quay.io/helmpack/chart-testing:v3.10.1
Expand Down
6 changes: 3 additions & 3 deletions charts/woodpecker/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ dependencies:
version: 1.0.0
- name: agent
repository: ""
version: 0.2.0
digest: sha256:289a2b8d226478642d244f6581215feb7bb142c608d5ceedb3a2aa8b58166688
generated: "2023-11-05T11:54:15.406187+01:00"
version: 0.3.0
digest: sha256:5f6be6fdc9fc5d2012bfa9f843f73faae901c8541fc07c713dff5ad2cc2dc75e
generated: "2024-02-15T20:14:00.795465+01:00"
2 changes: 1 addition & 1 deletion charts/woodpecker/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ dependencies:
version: 1.0.0
condition: server.enabled
- name: agent
version: 0.2.0
version: 0.3.0
condition: agent.enabled
8 changes: 7 additions & 1 deletion charts/woodpecker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resource "helm_release" "woodpecker" {

| Repository | Name | Version |
|------------|------|---------|
| | agent | 0.2.0 |
| | agent | 0.3.0 |
| | server | 1.0.0 |

## Values
Expand Down Expand Up @@ -81,6 +81,12 @@ resource "helm_release" "woodpecker" {
| agent.imagePullSecrets | list | `[]` | The image pull secrets |
| agent.nameOverride | string | `""` | Overrides the name of the chart of the agent component |
| agent.nodeSelector | object | `{}` | Specifies the labels of the nodes that the agent component must be running |
| agent.persistence.accessModes | list | `["ReadWriteOnce"]` | Defines the access mode of the persistent volume |
| agent.persistence.annotations | object | `{"helm.sh/resource-policy":"keep"}` | Defines annotations of the persistent volume |
| agent.persistence.enabled | bool | `true` | Enable the creation of the persistent volume |
| agent.persistence.mountPath | string | `"/etc/woodpecker"` | Defines the path where the volume should be mounted |
| agent.persistence.size | string | `"1Mi"` | Defines the size of the persistent volume |
| agent.persistence.storageClass | string | `""` | Defines the storageClass of the persistent volume |
| agent.podAnnotations | object | `{}` | Add pod annotations for the agent component |
| agent.podSecurityContext | object | `{}` | Add pod security context |
| agent.replicaCount | int | `2` | The number of replicas for the deployment |
Expand Down
2 changes: 1 addition & 1 deletion charts/woodpecker/charts/agent/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: agent
description: A Helm chart for the Woodpecker agent
type: application
version: 0.2.0
version: 0.3.0
# renovate: datasource=github-releases depName=woodpecker-ci/woodpecker extractVersion=^v(?<version>.*)$
appVersion: 2.3.0
home: https://woodpecker-ci.org/
Expand Down
9 changes: 8 additions & 1 deletion charts/woodpecker/charts/agent/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# agent

![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 2.3.0](https://img.shields.io/badge/AppVersion-2.3.0-informational?style=flat-square)
![Version: 0.3.0](https://img.shields.io/badge/Version-0.3.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 2.3.0](https://img.shields.io/badge/AppVersion-2.3.0-informational?style=flat-square)

A Helm chart for the Woodpecker agent

Expand Down Expand Up @@ -41,6 +41,13 @@ A Helm chart for the Woodpecker agent
| initContainers | list | `[]` | Add additional init containers to the pod (evaluated as a template) |
| nameOverride | string | `""` | Overrides the name of the chart of the agent component |
| nodeSelector | object | `{}` | Specifies the labels of the nodes that the agent component must be running |
| persistence.accessModes | list | `["ReadWriteOnce"]` | Defines the access mode of the persistent volume |
| persistence.annotations | object | `{"helm.sh/resource-policy":"keep"}` | Defines annotations of the persistent volume |
| persistence.enabled | bool | `true` | Enable the creation of the persistent volume |
| persistence.mountPath | string | `"/etc/woodpecker"` | |
| persistence.size | string | `"1Mi"` | Defines the size of the persistent volume |
| persistence.storageClass | string | `""` | Defines the storageClass of the persistent volume |
| persistence.subPath | string | `nil` | Defines the subPath of the persistent volume |
| podAnnotations | object | `{}` | Add pod annotations for the agent component |
| podSecurityContext | object | `{}` | Add pod security context |
| replicaCount | int | `2` | The number of replicas for the deployment |
Expand Down
10 changes: 10 additions & 0 deletions charts/woodpecker/charts/agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Storage Class
*/}}
{{- define "persistence.storageClass" -}}
{{- $storageClass := .Values.persistence.storageClass }}
{{- if $storageClass }}
storageClassName: {{ $storageClass | quote }}
{{- end }}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
pat-s marked this conversation as resolved.
Show resolved Hide resolved
metadata:
name: {{ include "woodpecker-agent.fullname" . }}
labels:
{{- include "woodpecker-agent.labels" . | nindent 4 }}
spec:
serviceName: {{ include "woodpecker-agent.fullname" . }}
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
Expand Down Expand Up @@ -55,9 +56,15 @@ spec:
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.extraVolumeMounts }}
{{- if or (.Values.persistence.enabled) (.Values.extraVolumeMounts) }}
volumeMounts:
{{- if .Values.persistence.enabled }}
- name: agent-config
mountPath: {{ .Values.persistence.mountPath }}
{{- end }}
{{- if .Values.extraVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
env:
{{- range $key, $value := .Values.env }}
Expand All @@ -81,11 +88,49 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.extraVolumes }}
{{- if or (.Values.persistence.enabled) (.Values.extraVolumeMounts) }}
volumes:
{{- toYaml . | nindent 6 }}
{{- if .Values.persistence.enabled }}
{{- if .Values.persistence.existingClaim }}
- name: agent-config
persistentVolumeClaim:
claimName: {{ .Values.persistence.existingClaim }}
{{- end }}
{{- end }}
{{- if .Values.extraVolumes }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end }}
{{- with .Values.dnsConfig }}
dnsConfig:
{{- toYaml . | nindent 8 }}
{{- end }}

{{- if and (not .Values.persistence.existingClaim) .Values.persistence.enabled }}
volumeClaimTemplates:
- metadata:
name: agent-config
namespace: {{ $.namespace }}
annotations:
{{- range $key, $value := .Values.persistence.annotations }}
{{ $key }}: {{ $value }}
{{- end }}
spec:
accessModes:
{{- range .Values.persistence.accessModes }}
- {{ . | quote }}
{{- end }}
{{- if .Values.persistence.storageClass }}
{{- if (eq "-" .Values.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistence.storageClass }}"
{{- end }}
resources:
requests:
storage: {{ .Values.persistence.size }}
{{- end }}
pat-s marked this conversation as resolved.
Show resolved Hide resolved
{{- else if (not .Values.persistence.enabled) }}
- name: data
emptyDir: {}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
suite: test deployment
templates:
- deployment.yaml
- templates/statefulset.yaml
tests:
- it: should have initContainers when .Values.initContainers is set
set:
Expand All @@ -11,7 +11,7 @@ tests:
- hasDocuments:
count: 1
- isKind:
of: Deployment
of: StatefulSet
- isNotEmpty:
path: spec.template.spec.initContainers
- equal:
Expand Down
28 changes: 28 additions & 0 deletions charts/woodpecker/charts/agent/unittests/statefulset/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
suite: test deployment
templates:
- templates/statefulset.yaml
tests:
- it: persistence is enabled
set:
persistence:
enabled: true
asserts:
- equal:
path: spec.volumeClaimTemplates[0].spec.accessModes[0]
value: 'ReadWriteOnce'
# this should only exist with existingClaim and is otherwise taken care of automatically
- equal:
path: spec.template.spec.volumes
value: null
- it: persistence with existingClaim
set:
persistence:
enabled: true
existingClaim: foo
asserts:
- equal:
path: spec.template.spec.volumes
value:
- persistentVolumeClaim:
claimName: foo
name: agent-config
39 changes: 28 additions & 11 deletions charts/woodpecker/charts/agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ image:
# -- The pull policy for the image
pullPolicy: IfNotPresent
# -- Overrides the image tag whose default is the chart appVersion.
tag: ""
tag: ''

# -- Defines a custom command to start the container
command: []
Expand All @@ -19,15 +19,15 @@ args: []

env:
# -- Add the environment variables for the agent component
WOODPECKER_SERVER: "woodpecker-server:9000"
WOODPECKER_SERVER: 'woodpecker-server:9000'
WOODPECKER_BACKEND: kubernetes
WOODPECKER_BACKEND_K8S_NAMESPACE: woodpecker
WOODPECKER_BACKEND_K8S_STORAGE_CLASS: ""
WOODPECKER_BACKEND_K8S_STORAGE_CLASS: ''
WOODPECKER_BACKEND_K8S_VOLUME_SIZE: 10G
WOODPECKER_BACKEND_K8S_STORAGE_RWX: true
WOODPECKER_BACKEND_K8S_POD_LABELS: ""
WOODPECKER_BACKEND_K8S_POD_ANNOTATIONS: ""
WOODPECKER_CONNECT_RETRY_COUNT: "1"
WOODPECKER_BACKEND_K8S_POD_LABELS: ''
WOODPECKER_BACKEND_K8S_POD_ANNOTATIONS: ''
WOODPECKER_CONNECT_RETRY_COUNT: '1'

# -- Add extra secret that is contains environment variables
extraSecretNamesForEnvFrom:
Expand All @@ -40,7 +40,8 @@ secrets: {}
# WOODPECKER_AGENT_SECRET: ${WOODPECKER_AGENT_SECRET}

# -- Additional volumes that can be mounted in containers
extraVolumes: []
extraVolumes:
[]
pat-s marked this conversation as resolved.
Show resolved Hide resolved
# - name: docker-config
# configMap:
# name: docker-config
Expand All @@ -49,19 +50,35 @@ extraVolumes: []
# claimName: example

# -- Additional volumes that will be attached to the agent container
extraVolumeMounts: []
extraVolumeMounts:
[]
pat-s marked this conversation as resolved.
Show resolved Hide resolved
# - name: ca-certs
# mountPath: /etc/ssl/certs/ca-certificates.crt

# -- Add additional init containers to the pod (evaluated as a template)
initContainers: []

persistence:
# -- Enable the creation of the persistent volume
enabled: true
# -- Defines an existing claim to use
existingClaim:
# -- Defines the size of the persistent volume
size: 1Gi
# -- Defines the path where the volume should be mounted
mountPath: '/etc/woodpecker'
# -- Defines the storageClass of the persistent volume
storageClass: ""
pat-s marked this conversation as resolved.
Show resolved Hide resolved
# -- Defines the access mode of the persistent volume
accessModes:
- ReadWriteOnce

# -- The image pull secrets
imagePullSecrets: []
# -- Overrides the name of the chart of the agent component
nameOverride: ""
nameOverride: ''
# -- Overrides the full name of the chart of the agent component
fullnameOverride: ""
fullnameOverride: ''

serviceAccount:
# -- Specifies whether a service account should be created (also see RBAC subsection)
Expand All @@ -70,7 +87,7 @@ serviceAccount:
annotations: {}
# -- The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
name: ''
rbac:
# -- If your cluster has RBAC enabled and you're using the Kubernetes agent-
# backend you'll need this. (this is true for almost all production clusters)
Expand Down
10 changes: 10 additions & 0 deletions charts/woodpecker/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Storage Class
*/}}
{{- define "persistence.storageClass" -}}
{{- $storageClass := .Values.persistence.storageClass | default .Values.global.storageClass }}
{{- if $storageClass }}
storageClassName: {{ $storageClass | quote }}
{{- end }}
{{- end -}}
15 changes: 15 additions & 0 deletions charts/woodpecker/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ agent:
extraSecretNamesForEnvFrom:
- woodpecker-secret

persistence:
# -- Enable the creation of the persistent volume
enabled: true
# -- Defines an existing claim to use
existingClaim:
# -- Defines the size of the persistent volume
size: 1Mi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to be 1Gi?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? The volume just holds the agent configuration (text file). 1Mi should be more than enough as default.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's 1Gi in the agent subchart values (https://github.com/woodpecker-ci/helm/pull/163/files#diff-afab925868b45a9b5ea72b370133adf7a55e74652cfd7695bbeca6b7e2c30658R65) and i think 1Mi is below the minimum of some csi provisioners

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok yes, missed that. Good point in that case we should fix it.

# -- Defines the path where the volume should be mounted
mountPath: '/etc/woodpecker'
# -- Defines the storageClass of the persistent volume
storageClass: ""
# -- Defines the access mode of the persistent volume
accessModes:
- ReadWriteOnce

# -- Additional volumes that can be mounted in containers
extraVolumes:
[]
Expand Down