Skip to content

Commit

Permalink
[helm] add lint checks for renderExamples (#6060)
Browse files Browse the repository at this point in the history
* fix: add lint checks for renderExamples

* fix: helm linting errors
  • Loading branch information
pkoutsovasilis authored Nov 20, 2024
1 parent 2a46509 commit 0097d21
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{- if or ($presetVal).clusterRole.create ($presetVal).clusterRole.name -}}
{{- if or ($presetVal).serviceAccount.create ($presetVal).serviceAccount.name -}}
{{/* cluster role binding is not namespace bound so let's try to give it a unique enough name */}}
{{- $clusterRoleName := printf "agent-%s-%s-%s" $presetName $.Release.Name $.Release.Namespace -}}
{{- $clusterRoleName := printf "agent-%s-%s-%s" $presetName $.Release.Name $.Release.Namespace }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- range $presetName, $presetVal := $.Values.agent.presets -}}
{{- if eq $presetVal.clusterRole.create true -}}
{{/* cluster role binding is not namespace bound so let's try to give it a unique enough name */}}
{{- $clusterRoleName := printf "agent-%s-%s-%s" $presetName $.Release.Name $.Release.Namespace -}}
{{- $clusterRoleName := printf "agent-%s-%s-%s" $presetName $.Release.Name $.Release.Namespace }}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- range $presetName, $presetVal := $.Values.agent.presets -}}
{{- if and (eq ($presetVal).mode "daemonset") (eq $.Values.agent.engine "eck") -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) -}}
{{- $podTemplateResource := include "elasticagent.engine.eck.podTemplate" (list $ $presetVal $agentName) | fromYaml -}}
{{- $podTemplateResource := include "elasticagent.engine.eck.podTemplate" (list $ $presetVal $agentName) | fromYaml }}
apiVersion: agent.k8s.elastic.co/v1alpha1
kind: Agent
metadata:
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/elastic-agent/templates/agent/eck/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- include "elasticagent.init" $ -}}
{{- range $presetName, $presetVal := $.Values.agent.presets }}
{{- if (eq $.Values.agent.engine "eck") -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) }}
apiVersion: v1
kind: Secret
metadata:
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/elastic-agent/templates/agent/k8s/_secret.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{- . | toYaml | nindent 6}}
{{- end }}
inputs:
{{- with ($presetVal)._inputs -}}
{{- with ($presetVal)._inputs }}
{{- . | toYaml | nindent 6 }}
{{- end }}
{{- else }}
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/elastic-agent/templates/agent/k8s/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- include "elasticagent.init" $ -}}
{{- range $presetName, $presetVal := $.Values.agent.presets }}
{{- if (eq $.Values.agent.engine "k8s") -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) }}
apiVersion: v1
kind: Secret
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- include "elasticagent.init" $ -}}
{{- range $presetName, $presetVal := $.Values.agent.presets -}}
{{- if eq $presetVal.serviceAccount.create true -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) -}}
{{- $agentName := include "elasticagent.preset.fullname" (list $ $presetName) }}
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down
6 changes: 6 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3446,6 +3446,12 @@ func (Helm) RenderExamples() error {
maps.Copy(helmValues, data)
}

lintAction := action.NewLint()
lintResult := lintAction.Run([]string{helmChartPath}, helmValues)
if len(lintResult.Errors) > 0 {
return fmt.Errorf("failed to lint helm chart for example %s: %w", exampleFullPath, errors.Join(lintResult.Errors...))
}

installAction := action.NewInstall(actionConfig)
installAction.Namespace = "default"
installAction.ReleaseName = "example"
Expand Down

0 comments on commit 0097d21

Please sign in to comment.