Skip to content

Commit

Permalink
Require version for helm chart (#183)
Browse files Browse the repository at this point in the history
* Require version for helm chart
  • Loading branch information
jdewinne authored Jun 25, 2024
1 parent e021f28 commit d951311
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pkg/kots/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3196,6 +3196,57 @@ spec:
},
},
},
{
name: "missing required version for Helm extension in embedded cluster config",
specFiles: domain.SpecFiles{
validPreflightSpec,
validConfigSpec,
validSupportBundleSpec,
validKotsAppSpec,
{
Name: "ec-config.yaml",
Path: "ec-config.yaml",
Content: `apiVersion: embeddedcluster.replicated.com/v1beta1
kind: Config
spec:
version: "v1.2.2+k8s-1.29"
roles:
controller:
name: management
labels:
management: "true"
custom:
- name: app
labels:
app: "true"
extensions:
helm:
repositories:
- name: ingress-nginx
url: https://kubernetes.github.io/ingress-nginx
charts:
- name: ingress-nginx
chartname: ingress-nginx/ingress-nginx
namespace: ingress-nginx
`,
},
},
expect: []domain.LintExpression{
{
Rule: "ec-helm-extension-version-required",
Path: "ec-config.yaml",
Type: "error",
Message: "Missing version for Helm Chart extension",
Positions: []domain.LintExpressionItemPosition{
{
Start: domain.LintExpressionItemLinePosition{
Line: 20,
},
},
},
},
},
},
{
name: "duplicate kots kinds in release",
specFiles: domain.SpecFiles{
Expand Down
19 changes: 19 additions & 0 deletions pkg/kots/rego/kots-spec-opa-nonrendered.rego
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,25 @@ lint[output] {
}
}

# Check if helm charts in the embedded cluster config contain a version
lint[output] {
rule_name := "ec-helm-extension-version-required"
rule_config := lint_rule_config(rule_name, "error")
not rule_config.off
spec := specs[_]
chart := spec.spec.extensions.helm.charts[index]
not chart.version
field := concat(".", [spec.field, "extensions.helm.charts", string(index)])
output := {
"rule": rule_name,
"type": rule_config.level,
"message": "Missing version for Helm Chart extension",
"path": spec.path,
"field": field,
"docIndex": spec.docIndex
}
}

# Check if the kubernetes installer addons versions are valid
is_kubernetes_installer(file) {
is_kubernetes_installer_api_version(file.content.apiVersion)
Expand Down

0 comments on commit d951311

Please sign in to comment.