Skip to content

Commit

Permalink
Add helm chart.
Browse files Browse the repository at this point in the history
  • Loading branch information
mneverov committed Oct 25, 2024
1 parent 4320aa9 commit 0e7bde6
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/kube-network-policies/.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/
6 changes: 6 additions & 0 deletions charts/kube-network-policies/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: kube-network-policies
description: A Helm chart for Kubernetes Network Policies
type: application
version: 0.0.1
appVersion: "0.0.1"
63 changes: 63 additions & 0 deletions charts/kube-network-policies/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "kube-network-policies.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 "kube-network-policies.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 "kube-network-policies.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "kube-network-policies.labels" -}}
helm.sh/chart: {{ include "kube-network-policies.chart" . }}
{{ include "kube-network-policies.selectorLabels" . }}
k8s-app: {{ include "kube-network-policies.name" . }}
tier: node
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "kube-network-policies.selectorLabels" -}}
app: {{ include "kube-network-policies.name" . }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "kube-network-policies.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "kube-network-policies.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
75 changes: 75 additions & 0 deletions charts/kube-network-policies/templates/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: {{ template "kube-network-policies.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "kube-network-policies.labels" . | nindent 4 }}
{{- with .Values.daemonset.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.daemonset.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
selector:
matchLabels:
{{- include "kube-network-policies.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "kube-network-policies.labels" . | nindent 8 }}
{{- with .Values.daemonset.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
hostNetwork: true
dnsPolicy: ClusterFirst
{{- with .Values.daemonset.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.daemonset.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "kube-network-policies.serviceAccountName" . }}
containers:
- name: kube-network-policies
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
args:
- /bin/netpol
- --hostname-override=$(MY_NODE_NAME)
- --v=2
{{- if .Values.baselineAdminNetworkPolicy }}
- --nfqueue-id=99
- --admin-network-policy=true
- --baseline-admin-network-policy=true
{{- else }}
- --nfqueue-id=98
{{- end }}
{{- with .Values.daemonset.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.daemonset.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
{{- with .Values.daemonset.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: lib-modules
mountPath: /lib/modules
readOnly: true
volumes:
- name: lib-modules
hostPath:
path: /lib/modules
62 changes: 62 additions & 0 deletions charts/kube-network-policies/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "kube-network-policies.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "kube-network-policies.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "kube-network-policies.serviceAccountName" . }}
labels:
{{- include "kube-network-policies.labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
resources:
- pods
- namespaces
{{- if .Values.baselineAdminNetworkPolicy }}
- nodes
{{- end }}
verbs:
- list
- watch
- apiGroups:
- "networking.k8s.io"
resources:
- networkpolicies
verbs:
- list
- watch
{{- if .Values.baselineAdminNetworkPolicy }}
- apiGroups:
- "policy.networking.k8s.io"
resources:
- adminnetworkpolicies
- baselineadminnetworkpolicies
verbs:
- list
- watch
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "kube-network-policies.serviceAccountName" . }}
labels:
{{- include "kube-network-policies.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "kube-network-policies.serviceAccountName" . }}
subjects:
- kind: ServiceAccount
name: {{ include "kube-network-policies.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
31 changes: 31 additions & 0 deletions charts/kube-network-policies/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
image:
repository: registry.k8s.io/networking/kube-network-policies
pullPolicy: IfNotPresent
tag: "v0.6.0"

nameOverride: ""
fullnameOverride: ""

baselineAdminNetworkPolicy: true

serviceAccount:
annotations: {}
name: kube-network-policies

daemonset:
annotations: {}
labels: {}
nodeSelector:
kubernetes.io/os: linux
tolerations:
- operator: Exists
effect: NoSchedule
extraEnv: []
securityContext:
privileged: true
capabilities:
add: ["NET_ADMIN"]
resources:
requests:
cpu: "100m"
memory: "50Mi"

0 comments on commit 0e7bde6

Please sign in to comment.