Skip to content

Commit

Permalink
remove selector and extend common.labels with teh component label
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Baryshev <dennybaa@gmail.com>
  • Loading branch information
dennybaa committed Jul 25, 2023
1 parent 4704846 commit 0a95e3b
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 79 deletions.
31 changes: 15 additions & 16 deletions dysnix/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,21 @@ containers:
### App chart parameters
| Name | Description | Value |
| ---------------------- | -------------------------------------------------------------------------------------------------- | ------------ |
| `workload` | Specifies the workload type (deployment/statefulset) for the component | `deployment` |
| `app.name` | Specifies the chart/application name (app.kubernetes.io/name), since this is a generic chart | `app` |
| `app.components` | Enable/disable the components. For example `{"": false, "foo": true, "bar": "custom"}`. | `{}` |
| `selector.matchLabels` | Specifies additional selector labels for the workload resources and services | `{}` |
| `reuse` | Enables reuse/merge of the upper-level component values (applicable for containers/initContainers) | `false` |
| `containers` | Specify a map of additional pod containers | `{}` |
| `initContainers` | Specifies initContainers **(use, values map for order and data)** | `{}` |
| `env` | Name Map of environment variables for the main container | `{}` |
| `envFrom` | Configures of envFrom to include into the main container | `[]` |
| `volumes` | Specify volumes for the main pod | `{}` |
| `volumeMounts` | Specify volumeMounts for the main container | `{}` |
| `configMaps` | Creates application сonfigMaps (note the name is prefixed with the app name) | `{}` |
| `secrets` | Creates application secrets (note the name is prefixed with the app name) | `{}` |
| `templateChecksums` | Specifies list of template files to add as an annotation checksum into the pod. | `[]` |
| Name | Description | Value |
| ------------------- | -------------------------------------------------------------------------------------------------- | ------------ |
| `workload` | Specifies the workload type (deployment/statefulset) for the component | `deployment` |
| `app.name` | Specifies the chart/application name (app.kubernetes.io/name), since this is a generic chart | `app` |
| `app.components` | Enable/disable the components. For example `{"": false, "foo": true, "bar": "custom"}`. | `{}` |
| `reuse` | Enables reuse/merge of the upper-level component values (applicable for containers/initContainers) | `false` |
| `containers` | Specify a map of additional pod containers | `{}` |
| `initContainers` | Specifies initContainers **(use, values map for order and data)** | `{}` |
| `env` | Name Map of environment variables for the main container | `{}` |
| `envFrom` | Configures of envFrom to include into the main container | `[]` |
| `volumes` | Specify volumes for the main pod | `{}` |
| `volumeMounts` | Specify volumeMounts for the main container | `{}` |
| `configMaps` | Creates application сonfigMaps (note the name is prefixed with the app name) | `{}` |
| `secrets` | Creates application secrets (note the name is prefixed with the app name) | `{}` |
| `templateChecksums` | Specifies list of template files to add as an annotation checksum into the pod. | `[]` |


### Global parameters
Expand Down
20 changes: 0 additions & 20 deletions dysnix/app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
{{- ternary ._include.top.Values.app.name .Chart.Name (eq "direct" (include "app.chart.mode" .)) -}}
{{- end -}}

{{/*
Component label
*/}}
{{- define "app.labels.component" -}}
{{- if ._include.component -}}
app.kubernetes.io/component: {{ ._include.component }}
{{- end -}}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
Expand Down Expand Up @@ -114,14 +105,3 @@ targetPort: {{ .value.targetPort }}
targetPort: {{ .value.targetPort | int }}
{{- end -}}
{{- end -}}

{{/*
Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector
*/}}
{{- define "common.labels.matchLabels" -}}
app.kubernetes.io/name: {{ include "common.names.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- range $key, $value := ._include.top.Values.selector.matchLabels }}
{{ $key }}: {{ ternary $value ($value | toString) (kindIs "string" $value) }}
{{- end }}
{{- end -}}
25 changes: 25 additions & 0 deletions dysnix/app/templates/_labels.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{/* vim: set filetype=mustache: */}}

{{/*
Kubernetes standard labels
*/}}
{{- define "common.labels.standard" -}}
app.kubernetes.io/name: {{ include "common.names.name" . }}
helm.sh/chart: {{ include "common.names.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if ._include.component }}
app.kubernetes.io/component: {{ ._include.component }}
{{- end }}
{{- end -}}

{{/*
Labels to use on deploy.spec.selector.matchLabels and svc.spec.selector
*/}}
{{- define "common.labels.matchLabels" -}}
app.kubernetes.io/name: {{ include "common.names.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if ._include.component }}
app.kubernetes.io/component: {{ ._include.component }}
{{- end }}
{{- end -}}
1 change: 0 additions & 1 deletion dysnix/app/templates/configmaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ metadata:
{{- end }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
Expand Down
5 changes: 1 addition & 4 deletions dysnix/app/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ metadata:
namespace: {{ include "common.names.namespace" . | quote }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
Expand All @@ -28,7 +27,6 @@ spec:
selector:
matchLabels:
{{- include "common.labels.matchLabels" . | nindent 6 }}
{{- include "app.labels.component" . | nindent 6 }}
template:
metadata:
annotations:
Expand All @@ -38,7 +36,6 @@ spec:
{{- end }}
labels:
{{- include "common.labels.standard" . | nindent 8 }}
{{- include "app.labels.component" . | nindent 8 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -116,7 +113,7 @@ spec:
{{- include "common.tplvalues.render" (dict "value" .Values.extraInitContainers "context" $) | nindent 8 }}
{{- end }}
containers:
- name: {{ .Values.app.name }}
- name: {{ template "app.chart.name" . }}
image: {{ include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.containerSecurityContext.enabled }}
Expand Down
1 change: 0 additions & 1 deletion dysnix/app/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
name: {{ include "common.names.fullname" . }}
namespace: {{ include "common.names.namespace" . | quote }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
Expand Down
1 change: 0 additions & 1 deletion dysnix/app/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ metadata:
namespace: {{ .Values.ingress.namespace | default (include "common.names.namespace" .) | quote }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
Expand Down
1 change: 0 additions & 1 deletion dysnix/app/templates/pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ metadata:
namespace: {{ include "common.names.namespace" . | quote }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
Expand Down
1 change: 0 additions & 1 deletion dysnix/app/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ metadata:
{{- end }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
Expand Down
1 change: 0 additions & 1 deletion dysnix/app/templates/service-account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
name: {{ include "app.serviceAccountName" . }}
namespace: {{ include "common.names.namespace" . | quote }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
Expand Down
1 change: 0 additions & 1 deletion dysnix/app/templates/service-monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ metadata:
namespace: {{ default (include "common.names.namespace" .) .Values.metrics.serviceMonitor.namespace | quote }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- if .Values.metrics.serviceMonitor.labels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.metrics.serviceMonitor.labels "context" $ ) | nindent 4 }}
{{- end }}
Expand Down
2 changes: 0 additions & 2 deletions dysnix/app/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ metadata:
namespace: {{ include "common.names.namespace" . | quote }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
Expand Down Expand Up @@ -49,7 +48,6 @@ spec:
{{- end }}
selector:
{{- include "common.labels.matchLabels" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- end }}
{{- end -}}

Expand Down
2 changes: 0 additions & 2 deletions dysnix/app/templates/tls-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ metadata:
namespace: {{ include "common.names.namespace" $ | quote }}
labels:
{{- include "common.labels.standard" $ | nindent 4 }}
{{- include "app.labels.component" $ | nindent 4 }}
{{- if $.Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" $.Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
Expand All @@ -34,7 +33,6 @@ metadata:
namespace: {{ include "common.names.namespace" . | quote }}
labels:
{{- include "common.labels.standard" . | nindent 4 }}
{{- include "app.labels.component" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
Expand Down
9 changes: 0 additions & 9 deletions dysnix/app/tests/deployment-common_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ tests:
- equal:
path: spec.template.spec.containers[0].image
value: foo/alpine:bar
-
it: selector matchLabels
values:
- ./values/common.yaml
asserts:
- isSubset:
path: spec.selector.matchLabels
content:
tenant: foo
-
it: deployment labels
values:
Expand Down
4 changes: 0 additions & 4 deletions dysnix/app/tests/service_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ tests:
path: spec.ports
content:
name: zdisabled
- isSubset:
path: spec.selector
content:
tenant: foo
-
it: check extended port configuration
values:
Expand Down
4 changes: 0 additions & 4 deletions dysnix/app/tests/values/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ image:
repository: alpine
tag: bar

selector:
matchLabels:
tenant: foo

commonLabels:
common: label

Expand Down
12 changes: 1 addition & 11 deletions dysnix/app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,7 @@ app:
# components:
# foo: true # foo is enabled, .Values.foo
# bar: myPath # bar is enabled, .Values.myPath
# not-enabled: false # component is disabled

## @param selector.matchLabels Specifies additional selector labels for the workload resources and services
## ref: https://kubernetes.io/docs/concepts/services-networking/service/#service-resource
##
## eg.
## selector:
## matchLabels:
## tenant: foo
selector:
matchLabels: {}
# not-enabled: false # component is disabled

## @param reuse Enables reuse/merge of the upper-level component values (applicable for containers/initContainers)
##
Expand Down

0 comments on commit 0a95e3b

Please sign in to comment.