-
-
Notifications
You must be signed in to change notification settings - Fork 184
Improved Helm Chart Templates #215
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
base: main
Are you sure you want to change the base?
Changes from all commits
453373f
8ba619b
3b9a9d4
399e30c
b93783e
13da6ce
f681266
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| {{- range $value := .Values.beelzebubServiceConfigs }} | ||
| {{- $trimmed := trimSuffix ".yaml" $value.name }} | ||
| {{- $safeName := regexReplaceAll "[^a-z0-9-]" (lower $trimmed) "-" | trimAll "-" | trunc 63 }} | ||
| --- | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: "beelzebub-services" | ||
| labels: | ||
| {{- include "beelzebub-chart.labels" . | nindent 4 }} | ||
| name: beelzebub-services-cm-{{ $safeName }} | ||
| data: | ||
| service.yaml: | ||
| {{- toYaml .Values.beelsebubServiceConfigs | nindent 12 }} | ||
| {{ $value.name }}: |- | ||
| {{- toYaml $value.config | nindent 4 }} | ||
| {{- end }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,11 @@ metadata: | |
| spec: | ||
| type: {{ .Values.service.type }} | ||
| ports: | ||
| - port: {{ .Values.service.port }} | ||
| targetPort: http | ||
| {{- range $value := .Values.beelzebubServiceConfigs }} | ||
| - port: {{ trimPrefix ":" $value.config.address }} | ||
| targetPort: {{ trimPrefix ":" $value.config.address }} | ||
| protocol: TCP | ||
| name: http | ||
| name: {{ trimSuffix ".yaml" $value.name }} | ||
| {{- end }} | ||
|
Comment on lines
+10
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Address parsing is brittle; Use a regex to extract the trailing port. Current rendering will break if Included in the diff above via 🧰 Tools🪛 YAMLlint (1.37.1)[warning] 11-11: wrong indentation: expected 2 but found 4 (indentation) 🤖 Prompt for AI AgentsPort name may violate IANA_SVC_NAME (length ≤15, lowercase, a-z start); sanitize and ensure uniqueness.
Apply: - ports:
- {{- range $value := .Values.beelzebubServiceConfigs }}
- - port: {{ trimPrefix ":" $value.config.address }}
- targetPort: {{ trimPrefix ":" $value.config.address }}
- protocol: TCP
- name: {{ trimSuffix ".yaml" $value.name }}
- {{- end }}
+ ports:
+ {{- range $i, $value := .Values.beelzebubServiceConfigs }}
+ {{- $trimmed := trimSuffix ".yaml" $value.name -}}
+ {{- $base := (regexReplaceAll "[^a-z0-9-]" (lower $trimmed) "-" ) | trimAll "-" -}}
+ {{- $portName := trunc 15 $base -}}
+ - port: {{ (regexFind "[0-9]{2,5}$" (toString $value.config.address)) | default (toString .Values.service.port) }}
+ targetPort: {{ (regexFind "[0-9]{2,5}$" (toString $value.config.address)) | default (toString .Values.service.port) }}
+ protocol: TCP
+ name: {{ $portName }}-{{ $i }}
+ {{- end }}Note: If you want to strictly enforce starting with a letter, prefix with 🧰 Tools🪛 YAMLlint (1.37.1)[warning] 11-11: wrong indentation: expected 2 but found 4 (indentation) |
||
| selector: | ||
| {{- include "beelzebub-chart.selectorLabels" . | nindent 4 }} | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,8 +8,10 @@ metadata: | |||||||||||||||||||||||||||||||||||
| "helm.sh/hook": test | ||||||||||||||||||||||||||||||||||||
| spec: | ||||||||||||||||||||||||||||||||||||
| containers: | ||||||||||||||||||||||||||||||||||||
| {{- range $value := .Values.beelzebubServiceConfigs }} | ||||||||||||||||||||||||||||||||||||
| - name: wget | ||||||||||||||||||||||||||||||||||||
| image: busybox | ||||||||||||||||||||||||||||||||||||
| command: ['wget'] | ||||||||||||||||||||||||||||||||||||
| args: ['{{ include "beelzebub-chart.fullname" . }}:{{ .Values.service.port }}'] | ||||||||||||||||||||||||||||||||||||
| args: ['{{ include "beelzebub-chart.fullname" . }}:{{ trimPrefix ":" $value.config.address }}'] | ||||||||||||||||||||||||||||||||||||
| {{- end }} | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate container names and wrong template scope inside range.
Apply: - containers:
- {{- range $value := .Values.beelzebubServiceConfigs }}
- - name: wget
+ containers:
+ {{- range $i, $value := .Values.beelzebubServiceConfigs }}
+ {{- $trimmed := trimSuffix ".yaml" $value.name -}}
+ {{- $safeName := (regexReplaceAll "[^a-z0-9-]" (lower $trimmed) "-" ) | trimAll "-" | trunc 63 -}}
+ {{- $port := (regexFind "[0-9]{2,5}$" (toString $value.config.address)) | default (toString .Values.service.port) -}}
+ - name: wget-{{ $safeName }}-{{ $i }}
image: busybox
command: ['wget']
- args: ['{{ include "beelzebub-chart.fullname" . }}:{{ trimPrefix ":" $value.config.address }}']
+ args: ['{{ include "beelzebub-chart.fullname" $ }}:{{ $port }}']
{{- end }}📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[warning] 12-12: wrong indentation: expected 2 but found 4 (indentation) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| restartPolicy: Never | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Robustly parse containerPort and sanitize port names.
Handle host:port and missing address; ensure containerPort is numeric; sanitize the name.
📝 Committable suggestion
🤖 Prompt for AI Agents