Skip to content

Commit

Permalink
Add namespace chart
Browse files Browse the repository at this point in the history
  • Loading branch information
posquit0 committed Sep 18, 2023
1 parent f1fc20d commit 3b5b0ff
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/namespace/.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/namespace/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: namespace
description: A Helm chart to manage Kubernetes namespace.
home: https://github.com/tedilabs/helm-charts
# icon:
sources:
- https://github.com/tedilabs/helm-charts
type: application
version: "0.1.0"
appVersion: "0.1.0"
kubeVersion: ">=1.23.0-0"
keywords:
- cluster
maintainers:
- name: Byungjin Park
email: posquit0.bj@gmail.com
annotations:
"artifacthub.io/license": Apache-2.0
"artifacthub.io/links": |
- name: Chart Source
url: https://github.com/tedilabs/helm-charts
Empty file.
62 changes: 62 additions & 0 deletions charts/namespace/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "namespace.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 "namespace.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 "namespace.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "namespace.selectorLabels" -}}
app.kubernetes.io/name: {{ include "namespace.name" . | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "namespace.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "namespace.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
31 changes: 31 additions & 0 deletions charts/namespace/templates/limit-range.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- if .Values.limitRange.enabled }}

Check failure on line 1 in charts/namespace/templates/limit-range.yaml

View workflow job for this annotation

GitHub Actions / Lint (yamllint) / yamllint - Lint YAML files

1:3 syntax error: expected the node content, but found '-' (syntax)
{{- $commonLabels := default (dict) .Values.commonLabels }}
{{- $commonAnnotations := default (dict) .Values.commonAnnotations }}
{{- $limitRangeLabels := default (dict) .Values.limitRange.labels }}
{{- $limitRangeAnnotations := default (dict) .Values.limitRange.annotations }}
{{- $labels := merge (dict) $commonLabels $limitRangeLabels }}
{{- $annotations := merge (dict) $commonAnnotations $limitRangeAnnotations }}
apiVersion: v1
kind: LimitRange
metadata:
name: {{ .Values.name | quote }}
namespace: {{ .Values.name | quote }}
{{- if $labels }}
labels:
{{- include "namespace.labels" . | nindent 4 }}
{{- range $key, $val := $labels }}
{{- $key | nindent 4 }}: {{ $val | quote }}
{{- end }}
{{- end }}
{{- if $annotations }}
annotations:
{{- range $key, $val := $annotations }}
{{- $key | nindent 4 }}: {{ $val | quote }}
{{- end }}
{{- end }}
spec:
{{- with .Values.limitRange.limits }}
limits:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end }}
23 changes: 23 additions & 0 deletions charts/namespace/templates/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- $commonLabels := default (dict) .Values.commonLabels }}

Check failure on line 1 in charts/namespace/templates/namespace.yaml

View workflow job for this annotation

GitHub Actions / Lint (yamllint) / yamllint - Lint YAML files

1:3 syntax error: expected the node content, but found '-' (syntax)
{{- $commonAnnotations := default (dict) .Values.commonAnnotations }}
{{- $namespaceLabels := default (dict) .Values.labels }}
{{- $namespaceAnnotations := default (dict) .Values.annotations }}
{{- $labels := merge (dict) $commonLabels $namespaceLabels }}
{{- $annotations := merge (dict) $commonAnnotations $namespaceAnnotations }}
apiVersion: v1
kind: Namespace
metadata:
name: {{ required "A valid `.Values.name` is required." .Values.name | quote }}
{{- if $labels }}
labels:
{{- include "namespace.labels" . | nindent 4 }}
{{- range $key, $val := $labels }}
{{- $key | nindent 4 }}: {{ $val | quote }}
{{- end }}
{{- end }}
{{- if $annotations }}
annotations:
{{- range $key, $val := $annotations }}
{{- $key | nindent 4 }}: {{ $val | quote }}
{{- end }}
{{- end }}
44 changes: 44 additions & 0 deletions charts/namespace/templates/resource-quotas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{- if .Values.resourceQuotas }}

Check failure on line 1 in charts/namespace/templates/resource-quotas.yaml

View workflow job for this annotation

GitHub Actions / Lint (yamllint) / yamllint - Lint YAML files

1:3 syntax error: expected the node content, but found '-' (syntax)
{{- $root := . }}
{{- $commonLabels := default (dict) .Values.commonLabels }}
{{- $commonAnnotations := default (dict) .Values.commonAnnotations }}
apiVersion: v1
kind: List
items:
{{- range $quota := .Values.resourceQuotas }}
{{- $resourceQuotaLabels := default (dict) $quota.labels }}
{{- $resourceQuotaAnnotations := default (dict) $quota.annotations }}
{{- $labels := merge (dict) $commonLabels $resourceQuotaLabels }}
{{- $annotations := merge (dict) $commonAnnotations $resourceQuotaAnnotations }}
- apiVersion: v1
kind: ResourceQuota
metadata:
name: {{ required "A valid `name` is required." $quota.name | quote }}
{{- if $labels }}
labels:
{{- include "namespace.labels" $root | nindent 6 }}
{{- range $key, $val := $labels }}
{{- $key | nindent 6 }}: {{ $val | quote }}
{{- end }}
{{- end }}
{{- if $annotations }}
annotations:
{{- range $key, $val := $annotations }}
{{- $key | nindent 6 }}: {{ $val | quote }}
{{- end }}
{{- end }}
spec:
hard:
{{- range $key, $val := $quota.hard }}
{{- $key | nindent 6 }}: {{ $val }}
{{- end }}
{{- if $quota.scopeSelector }}
scopeSelector:
{{- toYaml $quota.scopeSelector | nindent 6 }}
{{- end }}
{{- if $quota.scopes }}
scopes:
{{- toYaml $quota.scopes | nindent 6 }}
{{- end }}
{{- end }}
{{- end }}
36 changes: 36 additions & 0 deletions charts/namespace/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Default values for namespace.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

name: default

labels: {}
annotations: {}

commonLabels: {}
commonAnnotations: {}

limitRange:
enabled: false
limits: {}
# limits:
# - type: Container
# - type: Pod
# - type: PersistentVolumeClaim
# min:
# storage: 100Mi
# max:
# storage: 100Gi

resourceQuotas: []
# resourceQuota:
# - name: object-count-quota
# hard:
# count/pods: 0
# scopeSelector:
# matchExpressions:
# - operator: In
# scopeName: PriorityClass
# values:
# - system-node-critical
# - system-cluster-critical

0 comments on commit 3b5b0ff

Please sign in to comment.