Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Dec 8, 2021
0 parents commit 19c20bd
Show file tree
Hide file tree
Showing 23 changed files with 711 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
max_line_length = 110
quote_type = single

[*.{yaml,md}]
indent_size = 2

[Makefile]
indent_style = tab
8 changes: 8 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: pip
directory: '/ci'
schedule:
interval: daily
ignore:
- dependency-name: none
20 changes: 20 additions & 0 deletions .github/workflows/dependabot-auto-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Auto merge Dependabot updates

on:
workflow_run:
workflows:
- Continuous integration
types:
- completed

jobs:
auto-merge:
name: Auto merge Dependabot updates
runs-on: ubuntu-20.04
timeout-minutes: 5
steps:
- name: Auto merge
uses: ridedott/dependabot-auto-merge-action@master
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50 changes: 50 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
name: Continuous integration

on:
push:
pull_request:

env:
HAS_SECRETS: ${{ secrets.HAS_SECRETS }}

jobs:
main:
runs-on: ubuntu-20.04
name: Continuous integration
timeout-minutes: 20
if: "!startsWith(github.event.head_commit.message, '[skip ci] ')"

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: camptocamp/initialise-gopass-summon-action@v2
with:
ci-gpg-private-key: ${{secrets.CI_GPG_PRIVATE_KEY}}
github-gopass-ci-token: ${{secrets.GOPASS_CI_GITHUB_TOKEN}}
if: env.HAS_SECRETS == 'HAS_SECRETS'

- run: echo "${HOME}/.local/bin" >> ${GITHUB_PATH}
- run: python3 -m pip install --user --requirement=ci/requirements.txt

- name: Checks
run: c2cciutils-checks

- name: Install helm
uses: azure/setup-helm@v1
- run: helm dependency update .
- run: helm lint .
- run: helm lint --values=tests/values.yaml .
- run: helm template --namespace=default --values=tests/values.yaml custom . > tests/actual.yaml
- run: diff --ignore-trailing-space tests/actual.yaml tests/expected.yaml

- name: Setup k3s/k3d
run: c2cciutils-k8s-install

- name: Apply
run: kubectl apply -f tests/expected.yaml

- name: Publish
run: c2cciutils-publish
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/Chart.lock
/charts/
/tests/*actual.yaml
*/__pycache__/*
24 changes: 24 additions & 0 deletions .helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/

tests/
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
templates/**/*.yaml
tests/*expected.yaml
9 changes: 9 additions & 0 deletions Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v2
appVersion: '1.0'
description: A custom pod with everything needed
name: custom-pod
version: 0.1.0
dependencies:
- name: common
repository: https://camptocamp.github.io/helm-common
version: 0.1.1
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HELM != helm3

gen-expected:
${HELM} template --namespace=default --values=tests/values.yaml custom . > tests/expected.yaml
sed -i 's/[[:blank:]]\+$$//g' tests/expected.yaml
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# [Kubernetes](https://kubernetes.io/) [HELM chart](https://helm.sh/) for a simple custom application

With this chart you can easily deploy a simple custom application on Kubernetes, with only configuration.

[See as example](./tests/values.yaml).
11 changes: 11 additions & 0 deletions ci/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/camptocamp/c2cciutils/master/c2cciutils/schema.json

checks:
required_workflows:
clean.yaml: false
audit.yaml: false
backport.yaml: false
codeql.yaml: false
black:
ignore_patterns_re:
- .*\.yaml
1 change: 1 addition & 0 deletions ci/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c2cciutils==1.1.dev20211021112135
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.black]
line-length = 110
target-version = ['py38']
21 changes: 21 additions & 0 deletions templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "common.fullname" ( dict "root" . "service" .Values ) }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "common.fullname" ( dict "root" . "service" .Values ) }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "common.fullname" ( dict "root" . "service" .Values ) }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "common.name" ( dict "root" . "service" .Values ) }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
68 changes: 68 additions & 0 deletions templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "common.fullname" ( dict "root" . "service" .Values ) }}
labels: {{ include "common.labels" ( dict "root" . "service" .Values ) | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
strategy:
type: RollingUpdate
selector:
matchLabels: {{- include "common.selectorLabels" ( dict "root" . "service" .Values ) | nindent 6 }}
template:
metadata:
labels: {{- include "common.selectorLabels" ( dict "root" . "service" .Values ) | nindent 8 }}
spec: {{- include "common.podConfig" ( dict "root" . "service" .Values ) | indent 6 }}
{{- if .Values.initContainers }}
initContainers:
{{- range $name, $config := .Values.initContainers }}
- name: {{ $name }}
{{- include "common.containerConfig" ( dict "root" $ "container" $config ) | nindent 10 }}
{{- with $config.command }}
command: {{ $config.command | toYaml | nindent 12 }}
{{- end }}
{{- with $config.args }}
args: {{ $config.args | toYaml | nindent 12 }}
{{- end }}
{{- with $config.volumeMounts }}
volumeMounts: {{ $config.volumeMounts | toYaml | nindent 12 }}
{{- end }}
{{- end }}
{{- end }}
containers:
{{- range $name, $config := .Values.containers }}
- name: {{ $name }}
{{- include "common.containerConfig" ( dict "root" $ "container" $config ) | nindent 10 }}
{{- with $config.command }}
command:
{{- . | toYaml | nindent 12 }}
{{- end }}
{{- with $config.args }}
args:
{{- . | toYaml | nindent 12 }}
{{- end }}
{{- with $config.volumeMounts }}
volumeMounts:
{{- . | toYaml | nindent 12 }}
{{- end }}
{{- with $config.ports }}
ports:
{{- $config.ports | toYaml | nindent 12 }}
{{- end }}
{{- with $config.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $config.readinessProbe }}
readinessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $config.readinessProbe }}
startupProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
53 changes: 53 additions & 0 deletions templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "common.fullname" ( dict "root" . "service" .Values ) -}}
{{- $svcPort := $.Values.ingress.servicePort -}}
{{- range $ingress_host := .Values.ingress.hosts }}
---
{{- if semverCompare ">=1.19.0" ( trimPrefix "v" $.Capabilities.KubeVersion.Version ) }}
apiVersion: networking.k8s.io/v1
{{- else -}}
{{- if semverCompare ">=1.14-0" $.Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}-{{ $ingress_host.name }}
labels: {{ include "common.labels" ( dict "root" $ "service" $.Values ) | nindent 4 }}
{{- with $.Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if $ingress_host.tls }}
tls:
{{- range $ingress_host.tls }}
- hosts:
- {{ $ingress_host.host }}
secretName: {{ $ingress_host.tls.secretName }}
{{- end }}
{{- end }}
rules:
- host: {{ $ingress_host.host }}
http:
paths:
{{- range $.Values.ingress.paths }}
- path: {{ . }}
{{- if semverCompare ">=1.14-0" $.Capabilities.KubeVersion.GitVersion }}
pathType: Prefix
{{- end }}
backend:
{{- if semverCompare ">=1.14-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end -}}
{{- end }}
{{- end }}
{{- end }}
9 changes: 9 additions & 0 deletions templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: {{ include "common.fullname" ( dict "root" . "service" .Values ) }}
labels: {{- include "common.selectorLabels" ( dict "root" . "service" .Values ) | nindent 4 }}
spec:
maxUnavailable: 1
selector:
matchLabels: {{- include "common.selectorLabels" ( dict "root" . "service" .Values ) | nindent 6 }}
13 changes: 13 additions & 0 deletions templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "common.fullname" ( dict "root" . "service" .Values ) }}
labels: {{ include "common.labels" ( dict "root" . "service" .Values ) | nindent 4 }}
prometheus: "true"
spec:
type: {{ .Values.service.type }}
{{- with .Values.service.ports }}
ports:
{{- . | toYaml | nindent 4 }}
{{- end }}
selector: {{- include "common.selectorLabels" ( dict "root" . "service" .Values ) | nindent 4 }}
7 changes: 7 additions & 0 deletions templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "common.serviceAccountName" ( dict "root" . "service" .Values ) }}
labels: {{ include "common.labels" ( dict "root" . "service" .Values ) | nindent 4 }}
{{- end }}
Loading

0 comments on commit 19c20bd

Please sign in to comment.