Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add disablesuffixes option for backwards compat #84

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

aarlaud
Copy link
Contributor

@aarlaud aarlaud commented Oct 17, 2023

Adding --set disableSuffixes=true value will avoid adding suffixes to objects, reverting to old behavior where one can have only one broker per namespace, mainly for backward compatibility.

@aarlaud aarlaud requested review from a team as code owners October 17, 2023 12:22
@aarlaud aarlaud requested a review from iuliams October 17, 2023 12:22
Copy link

@ahmed-agabani-snyk ahmed-agabani-snyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General practice:

  • I do not recommend changing names using boolean flags (disableSuffixes=true).
  • I recommend allowing the consumer to specify the name of the resource using ./helm/values.yaml

Suggestion:

  • consolidate the if statements into the _helpers.tpl and use {{ include "snyk-broker.************Name" . }} in templates.

Example demonstrating general practice and suggestion:

# ./helm/templates/_helpers.tpl

{{/*
Expand the name of the chart.
*/}}
{{- define "tor-operator.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 "snyk-broker.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 the name of the broker deployment to use
*/}}
{{- define "snyk-broker.brokerDeploymentName" -}}
{{- if .Values.brokerDeployment.create }}
{{- default (include "snyk-broker.fullname" .) .Values.brokerDeployment.name }}
{{- else }}
{{- default "default" .Values.brokerDeployment.name }}
{{- end }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "snyk-broker.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "snyk-broker.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
# ./helm/values.yaml

nameOverride: ""
fullnameOverride: ""

brokerDeployment:
  # Specifies whether a broker deployment should be created
  create: true
  # Annotations to add to the broker deployment
  annotations: {}
  # The name of the broker deployment to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""

serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Annotations to add to the service account
  annotations: {}
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""
# ./helm/templates/brokerdeployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "snyk-broker.brokerDeploymentName" . }}
  {{- with .Values.brokerDeployment.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  template:
    metadata:
    spec:
      serviceAccountName: {{ include "snyk-broker.serviceAccountName" . }}

@aarlaud
Copy link
Contributor Author

aarlaud commented Oct 18, 2023

General practice:

  • I do not recommend changing names using boolean flags (disableSuffixes=true).
  • I recommend allowing the consumer to specify the name of the resource using ./helm/values.yaml

Suggestion:

  • consolidate the if statements into the _helpers.tpl and use {{ include "snyk-broker.************Name" . }} in templates.

Example demonstrating general practice and suggestion:

# ./helm/templates/_helpers.tpl

{{/*
Expand the name of the chart.
*/}}
{{- define "tor-operator.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 "snyk-broker.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 the name of the broker deployment to use
*/}}
{{- define "snyk-broker.brokerDeploymentName" -}}
{{- if .Values.brokerDeployment.create }}
{{- default (include "snyk-broker.fullname" .) .Values.brokerDeployment.name }}
{{- else }}
{{- default "default" .Values.brokerDeployment.name }}
{{- end }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "snyk-broker.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "snyk-broker.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
# ./helm/values.yaml

nameOverride: ""
fullnameOverride: ""

brokerDeployment:
  # Specifies whether a broker deployment should be created
  create: true
  # Annotations to add to the broker deployment
  annotations: {}
  # The name of the broker deployment to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""

serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Annotations to add to the service account
  annotations: {}
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""
# ./helm/templates/brokerdeployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "snyk-broker.brokerDeploymentName" . }}
  {{- with .Values.brokerDeployment.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  template:
    metadata:
    spec:
      serviceAccountName: {{ include "snyk-broker.serviceAccountName" . }}

Agreed on the recommendations and best practices. Will merge this in for now and will look at refactoring this the suggested way at a later time.

@aarlaud aarlaud closed this Oct 18, 2023
@aarlaud aarlaud reopened this Oct 18, 2023
@aarlaud aarlaud merged commit bb3550f into main Oct 18, 2023
2 checks passed
@aarlaud aarlaud deleted the fix/add-optout-for-suffix-in-object-names branch October 18, 2023 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants