Skip to content

Commit

Permalink
Merge pull request #39 from cybozu-go/add-helm-chart
Browse files Browse the repository at this point in the history
Add helm chart
  • Loading branch information
zoetrope committed Jul 6, 2023
2 parents 2e1d50f + 58521d2 commit 76569b3
Show file tree
Hide file tree
Showing 20 changed files with 481 additions and 32 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
- uses: ./.github/actions/aqua
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- run: make install.yaml
- name: GoReleaser
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0
with:
Expand Down
56 changes: 52 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,63 @@ jobs:
- uses: ./.github/actions/aqua
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Set Tag
- name: Set previous release tag for GoReleaser
run: |
TAG=${GITHUB_REF#refs/tags/v}
sed -i "s/newTag: .*/newTag: $TAG/g" config/manager/kustomization.yaml
make install.yaml
export TAG=$(curl -s "https://api.github.com/repos/cybozu-go/pod-security-admission/releases/latest" | jq -r .tag_name)
echo "GORELEASER_PREVIOUS_TAG=${TAG}" >> $GITHUB_ENV
- name: GoReleaser
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
chart-release:
runs-on: ubuntu-22.04
needs: release
if: contains(needs.release.result, 'success')
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Helm
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5
- name: Set chart version
run: |
helm repo add pod-security-admission https://cybozu-go.github.io/pod-security-admission
helm repo update
# get the release tag version
tag_version=${GITHUB_REF##*/v}
# get the latest chart version
chart_version=$(helm search repo pod-security-admission -o json | jq -r 'sort_by(.version) | .[-1].version')
chart_patch_version=${chart_version##*.}
new_patch_version=$(($chart_patch_version+1))
# if minor or major version changed, reset new patch version
local_version=$(cat charts/pod-security-admission/Chart.yaml | yq .version | sed "s/0-chart-patch-version-placeholder/$chart_patch_version/g")
[ "$local_version" != "$chart_version" ] && new_patch_version=0
# replace placeholder with new version
sed --in-place "s/app-version-placeholder/$tag_version/g" charts/pod-security-admission/Chart.yaml
sed --in-place "s/0-chart-patch-version-placeholder/$new_patch_version/g" charts/pod-security-admission/Chart.yaml
sed --in-place "s/app-version-placeholder/$tag_version/g" charts/pod-security-admission/values.yaml
- name: Create release notes
run: |
tag_version=${GITHUB_REF##*/}
cat <<EOF > ./charts/pod-security-admission/RELEASE.md
Helm chart for pod-security-admission [$tag_version](https://github.com/cybozu-go/pod-security-admission/releases/tag/$tag_version)
EOF
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Run chart-releaser
uses: helm/chart-releaser-action@be16258da8010256c6e82849661221415f031968 # v1.5.0
with:
config: cr.yaml
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
/.idea
cover.out
/build
install.yaml
3 changes: 0 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ builds:
- amd64
ldflags:
- -X github.com/cybozu-go/pod-security-admission.Version={{.Version}}
archives:
- files:
- install.yaml
dockers:
- image_templates:
- "quay.io/cybozu/{{.ProjectName}}:{{ .Version }}-amd64"
Expand Down
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ ENVTEST_K8S_VERSION = 1.27.1
SHELL = /bin/bash
.SHELLFLAGS = -e -o pipefail -c
BIN_DIR := $(shell pwd)/bin
INSTALL_YAML = install.yaml

STATICCHECK = $(BIN_DIR)/staticcheck

Expand Down Expand Up @@ -67,10 +66,6 @@ test: setup-envtest manifests generate ## Run tests.
build: ## Build binary.
CGO_ENABLED=0 go build -o bin/pod-security-admission -ldflags="-w -s" ./cmd

$(INSTALL_YAML): setup
mkdir -p build
kustomize build ./config/default > $@

$(STATICCHECK):
$(call go-install-tool,$(STATICCHECK),honnef.co/go/tools/cmd/staticcheck@latest)

Expand Down
23 changes: 23 additions & 0 deletions charts/pod-security-admission/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
21 changes: 21 additions & 0 deletions charts/pod-security-admission/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: pod-security-admission
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0-chart-patch-version-placeholder
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: app-version-placeholder
62 changes: 62 additions & 0 deletions charts/pod-security-admission/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "pod-security-admission.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 "pod-security-admission.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 "pod-security-admission.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "pod-security-admission.labels" -}}
helm.sh/chart: {{ include "pod-security-admission.chart" . }}
{{ include "pod-security-admission.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "pod-security-admission.selectorLabels" -}}
app.kubernetes.io/name: {{ include "pod-security-admission.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "pod-security-admission.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "pod-security-admission.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions charts/pod-security-admission/templates/controller-manager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "pod-security-admission.fullname" . }}-controller-manager
labels:
{{- include "pod-security-admission.labels" . | nindent 4 }}
spec:
maxUnavailable: 1
selector:
matchLabels:
control-plane: controller-manager
76 changes: 76 additions & 0 deletions charts/pod-security-admission/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "pod-security-admission.fullname" . }}-controller-manager
labels:
control-plane: controller-manager
{{- include "pod-security-admission.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.controllerManager.replicas }}
selector:
matchLabels:
control-plane: controller-manager
{{- include "pod-security-admission.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
control-plane: controller-manager
{{- include "pod-security-admission.selectorLabels" . | nindent 8 }}
spec:
containers:
- args: {{- toYaml .Values.controllerManager.manager.args | nindent 8 }}
command:
- /pod-security-admission
env:
- name: KUBERNETES_CLUSTER_DOMAIN
value: {{ quote .Values.kubernetesClusterDomain }}
image: {{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag
| default .Chart.AppVersion }}
imagePullPolicy: {{ .Values.controllerManager.manager.imagePullPolicy }}
lifecycle:
preStop:
exec:
command:
- sleep
- "5"
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
name: manager
ports:
- containerPort: 8080
name: metrics
- containerPort: 8081
name: health
- containerPort: 9443
name: webhook
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources: {{- toYaml .Values.controllerManager.manager.resources | nindent 10
}}
securityContext: {{- toYaml .Values.controllerManager.manager.containerSecurityContext
| nindent 10 }}
volumeMounts:
- mountPath: /certs
name: cert
readOnly: true
- mountPath: /etc/pod-security-admission
name: config
securityContext:
runAsNonRoot: true
terminationGracePeriodSeconds: 10
volumes:
- name: cert
secret:
defaultMode: 420
secretName: webhook-server-cert
- configMap:
name: {{ include "pod-security-admission.fullname" . }}-pod-security-admission-config
name: config
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: {{ include "pod-security-admission.fullname" . }}-mutating-webhook-configuration
annotations:
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "pod-security-admission.fullname" . }}-serving-cert
labels:
{{- include "pod-security-admission.labels" . | nindent 4 }}
webhooks:
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: '{{ include "pod-security-admission.fullname" . }}-webhook-service'
namespace: '{{ .Release.Namespace }}'
path: /mutate-baseline
failurePolicy: Fail
name: baseline.mpod.kb.io
namespaceSelector:
matchExpressions:
- key: pod-security.cybozu.com/policy
operator: NotIn
values:
- privileged
reinvocationPolicy: IfNeeded
rules:
- apiGroups:
- ""
apiVersions:
- v1
operations:
- CREATE
resources:
- pods
- apiGroups:
- ""
apiVersions:
- v1
operations:
- UPDATE
resources:
- pods/ephemeralcontainers
sideEffects: None
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: '{{ include "pod-security-admission.fullname" . }}-webhook-service'
namespace: '{{ .Release.Namespace }}'
path: /mutate-restricted
failurePolicy: Fail
name: restricted.mpod.kb.io
namespaceSelector:
matchExpressions:
- key: pod-security.cybozu.com/policy
operator: In
values:
- restricted
reinvocationPolicy: IfNeeded
rules:
- apiGroups:
- ""
apiVersions:
- v1
operations:
- CREATE
resources:
- pods
- apiGroups:
- ""
apiVersions:
- v1
operations:
- UPDATE
resources:
- pods/ephemeralcontainers
sideEffects: None
Loading

0 comments on commit 76569b3

Please sign in to comment.