72 lines
2.8 KiB
Plaintext
72 lines
2.8 KiB
Plaintext
In Helm, it's important to follow certain naming conventions for variables to ensure code readability and maintainability. One such widely accepted convention is the use of camelCase for variable names. By adhering to this convention, it can be ensured that Helm charts are consistent, readable, and easier to maintain, thereby improving overall code quality.
|
|
|
|
== Why is this an issue?
|
|
Adhering to a naming convention is crucial for maintaining readability and consistency in code. It ensures that code is easy to read and understand, which is vital for maintaining and debugging the code in the future. When variable names in Helm charts do not follow the camelCase convention, it can lead to several issues:
|
|
|
|
1. **Readability**: Inconsistent naming conventions can make the code harder to read. Developers often expect variables to be in camelCase in Helm charts. When they encounter a variable that doesn't follow this convention, it can disrupt their reading flow, making it harder to understand the code.
|
|
2. **Maintainability**: Not following accepted conventions can introduce inconsistent naming, especially when multiple developers work on the same project, leading to technical debt. If a developer needs to update the code, they might have to spend extra time understanding the purpose of each variable. This can lead to slower updates and a higher chance of introducing bugs.
|
|
|
|
By adhering to the camelCase naming convention, these issues can be avoided and Helm charts will be more efficient and easier to work with.
|
|
|
|
== How to fix it in Helm
|
|
Change the variable's name to adhere to the naming conventions. Names should be camelCased and start with a lowercase letter, for example, `myVariable`.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,text,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
{{- $my_Variable := .Values.myVariableValue -}} # Noncompliant
|
|
----
|
|
|
|
[source,text,diff-id=2,diff-type=noncompliant]
|
|
----
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: {{ .Release.Name }}-configmap
|
|
data:
|
|
myvalue: "Hello World"
|
|
{{- range $KeyNc, $val-nc := .Values.favorite }} # Noncompliant
|
|
{{ $key }}: {{ $val | quote }}
|
|
{{- end }}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,text,diff-id=1,diff-type=compliant]
|
|
----
|
|
{{- $myVariable := .Values.myVariableValue -}}
|
|
----
|
|
|
|
[source,text,diff-id=2,diff-type=compliant]
|
|
----
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: {{ .Release.Name }}-configmap
|
|
data:
|
|
myvalue: "Hello World"
|
|
{{- range $keyC, $valC := .Values.favorite }}
|
|
{{ $key }}: {{ $val | quote }}
|
|
{{- end }}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Rename XXX to be compliant with the camelCase naming convention.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
* Highlight the non-compliant variable.
|
|
|
|
|
|
endif::env-github,rspecator-view[] |