Skip to content

Commit

Permalink
Use fullnameOverride to fix duplicate deployments and services
Browse files Browse the repository at this point in the history
Signed-off-by: Maël Valais <[email protected]>
  • Loading branch information
maelvls committed Mar 11, 2021
1 parent 489a57b commit 578e7a4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ metadata:
name: {{ template "cert-manager.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels:
app: {{ template "cert-manager.name" . }}
app.kubernetes.io/name: {{ template "cert-manager.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
Expand All @@ -28,7 +27,6 @@ spec:
template:
metadata:
labels:
app: {{ template "cert-manager.name" . }}
app.kubernetes.io/name: {{ template "cert-manager.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: "controller"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "google-cas-issuer.fullname" . }}-controller
name: {{ include "google-cas-issuer.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels:
{{- include "google-cas-issuer.labels" . | nindent 4 }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "preflight.fullname" . }}-agent
name: {{ include "preflight.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels:
{{- include "preflight.labels" . | nindent 4 }}
Expand Down
9 changes: 6 additions & 3 deletions chart/jetstack-secure-gcm/templates/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ spec:
# app.kubernetes.io/name: "{{ .Chart.Name }}" # Will be "jetstack-secure-gcm" due to the name override
# app.kubernetes.io/instance: "{{ .Release.Name }}" # Example: "jetstack-secure-for-cert-mana-2"
#
# Note that we had to set nameOverride for all the subcharts so that
# the app.kubernetes.io/name is correctly set on the cert-manager.
# In values.yaml [2], we have set:
# Note that we had to set nameOverride and fullnameOverrode for all
# the subcharts so that the app.kubernetes.io/name the same across all
# objects. In values.yaml [2], we have set:
#
# cert-manager:
# nameOverride: jetstack-secure-gcm
# fullnameOverride: jetstack-secure-gcm
# google-cas-issuer:
# nameOverride: jetstack-secure-gcm
# fullnameOverride: google-cas-issuer
# preflight:
# nameOverride: jetstack-secure-gcm
# fullnameOverride: preflight
#
# [1]: https://sigs.k8s.io/application/docs/api.md
# [2] ./chart/jetstack-secure-gcm/values.yaml
Expand Down
3 changes: 3 additions & 0 deletions chart/jetstack-secure-gcm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

cert-manager:
nameOverride: jetstack-secure-gcm
fullnameOverride: cert-manager
installCRDs: true
global:
rbac:
Expand Down Expand Up @@ -46,6 +47,7 @@ cert-manager:

google-cas-issuer:
nameOverride: jetstack-secure-gcm
fullnameOverride: google-cas-issuer
installCRDs: true
serviceAccount:
create: false # see note (1)
Expand All @@ -55,6 +57,7 @@ google-cas-issuer:

preflight:
nameOverride: jetstack-secure-gcm
fullnameOverride: preflight
serviceAccount:
# name: foo
create: false # see note (1)
Expand Down
13 changes: 12 additions & 1 deletion docs/TESTING-DEPLOYER.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,27 @@ spec:
app.kubernetes.io/instance: {{ .Release.Name }} # Example: "jetstack-secure-for-cert-mana-2"
```

First, we set the name override for all our charts:
Then, we use the `nameOverride` and `fullnameOverride`:
1. `nameOverride` makes sure that all the objects across all subcharts have
the following label:
```yaml
app.kubernetes.io/name: "jetstack-secure-gcm"
```
2. `fullnameOverride` makes sure that the object names actually make sense;
if we did not use this, we would end up with duplicate names in
deployments and services.

```yaml
# https://github.com/jetstack/jetstack-secure-gcm/blob/main/chart/jetstack-secure-gcm/values.yaml
cert-manager:
nameOverride: jetstack-secure-gcm
fullnameOverride: jetstack-secure-gcm
google-cas-issuer:
nameOverride: jetstack-secure-gcm
fullnameOverride: google-cas-issuer
preflight:
nameOverride: jetstack-secure-gcm
fullnameOverride: preflight
```

Then we make sure all the objects are set with the labels:
Expand Down

0 comments on commit 578e7a4

Please sign in to comment.