Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit 50414c3

Browse files
committed
feat: add namespaces chart
1 parent 3ce574d commit 50414c3

File tree

8 files changed

+224
-0
lines changed

8 files changed

+224
-0
lines changed

charts/namespaces/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

charts/namespaces/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
name: namespaces
3+
description: Deploy namespaces with (default) networkpolicies
4+
type: application
5+
version: 0.1.0

charts/namespaces/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# namespaces
2+
3+
Deploy namespaces with (default) networkpolicies
4+
5+
## Example
6+
7+
```yaml
8+
# Disable all NetworkPolicies
9+
disableNetworkPolicies: false
10+
11+
defaultNetworkPolicies:
12+
# Deny all egress traffic
13+
- name: default-policy
14+
spec:
15+
podSelector:
16+
matchLabels:
17+
role: db
18+
policyTypes:
19+
- Egress
20+
21+
namespaces:
22+
- name: test
23+
labels:
24+
meta.mor.re/testlabel: hallo
25+
networkPolicies:
26+
- name: testpolicy
27+
spec:
28+
podSelector:
29+
matchLabels:
30+
role: db
31+
32+
- name: no-policies
33+
disableDefaultNetworkPolicies: true
34+
```
35+
36+
## Values
37+
38+
| Key | Type | Default | Description |
39+
|-----|------|---------|-------------|
40+
| defaultNetworkPolicies | list | `[]` | NetworkPolicies that will be applied to all namespaces |
41+
| disableNetworkPolicies | bool | `false` | Switch to disable all NetworkPolicies |
42+
| namespaces | list | `[]` | List of namespaces to deploy |
43+

charts/namespaces/README.md.gotmpl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{{ template "chart.header" . }}
2+
{{ template "chart.description" . }}
3+
4+
{{ template "chart.sourcesSection" . }}
5+
6+
{{ template "chart.requirementsSection" . }}
7+
8+
## Example
9+
10+
```yaml
11+
# Disable all NetworkPolicies
12+
disableNetworkPolicies: false
13+
14+
defaultNetworkPolicies:
15+
# Deny all egress traffic
16+
- name: default-policy
17+
spec:
18+
podSelector:
19+
matchLabels:
20+
role: db
21+
policyTypes:
22+
- Egress
23+
24+
namespaces:
25+
- name: test
26+
labels:
27+
meta.mor.re/testlabel: hallo
28+
networkPolicies:
29+
- name: testpolicy
30+
spec:
31+
podSelector:
32+
matchLabels:
33+
role: db
34+
35+
- name: no-policies
36+
disableDefaultNetworkPolicies: true
37+
```
38+
39+
{{ template "chart.valuesSection" . }}
40+
41+
{{ template "chart.maintainersSection" . }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "namespaces.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "namespaces.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "namespaces.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "namespaces.labels" -}}
37+
helm.sh/chart: {{ include "namespaces.chart" . }}
38+
{{ include "namespaces.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "namespaces.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "namespaces.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "namespaces.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "namespaces.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- $labels := include "namespaces.labels" . -}}
2+
{{- range $.Values.namespaces }}
3+
---
4+
apiVersion: v1
5+
kind: Namespace
6+
metadata:
7+
name: {{ .name }}
8+
annotations:
9+
helm.sh/resource-policy: keep
10+
labels:
11+
{{- $labels | nindent 4 }}
12+
{{- with .labels }}
13+
{{- toYaml . | nindent 4 }}
14+
{{- end }}
15+
{{- end }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{{ if not .Values.disableNetworkPolicies }}
2+
{{- range $.Values.namespaces }}
3+
{{- $namespaceName := .name -}}
4+
{{- if not .disableDefaultNetworkPolicies -}}
5+
{{- range $.Values.defaultNetworkPolicies }}
6+
---
7+
apiVersion: networking.k8s.io/v1
8+
kind: NetworkPolicy
9+
metadata:
10+
name: {{ .name }}
11+
namespace: {{ $namespaceName }}
12+
spec:
13+
{{- toYaml .spec | nindent 2}}
14+
{{- end }}
15+
{{- end }}
16+
{{- range .networkPolicies }}
17+
---
18+
apiVersion: networking.k8s.io/v1
19+
kind: NetworkPolicy
20+
metadata:
21+
name: {{ .name }}
22+
namespace: {{ $namespaceName }}
23+
spec:
24+
{{- toYaml .spec | nindent 2}}
25+
{{- end -}}
26+
{{- end -}}
27+
{{- end -}}

charts/namespaces/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -- List of namespaces to deploy
2+
namespaces: []
3+
4+
# -- NetworkPolicies that will be applied to all namespaces
5+
defaultNetworkPolicies: []
6+
7+
# -- Switch to disable all NetworkPolicies
8+
disableNetworkPolicies: false

0 commit comments

Comments
 (0)