Skip to content

Commit

Permalink
add kube-linter (#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroEsc authored Apr 16, 2024
1 parent 930eb22 commit 1b611a2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .kube-linter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Details on checks can be found on this page and the like: https://docs.kubelinter.io/#/generated/checks
checks:
addAllBuiltIn: true
exclude:
- "unset-cpu-requirements" # Not every pod requires this, for example hooks, we can change opinion later
- "unset-memory-requirements" # Not every pod requires this, for example hooks, we can change opinion later
- "no-read-only-root-fs" # Some volume mounts require writes
- "required-annotation-email" # Not a requirement for out deployments
- "no-node-affinity" # Not every pod requires this
21 changes: 21 additions & 0 deletions charts/redpanda/chart_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package redpanda_test

import (
"bytes"
"os"
"os/exec"
"testing"

"github.com/redpanda-data/helm-charts/charts/redpanda"
Expand Down Expand Up @@ -123,6 +125,25 @@ func TestTemplate(t *testing.T) {
})
require.NoError(t, err)

// kube-lint template file
var stdout bytes.Buffer
var stderr bytes.Buffer
inputYaml := bytes.NewBuffer(out)

cmd := exec.CommandContext(ctx, "kube-linter", "lint", "-", "--format", "json")
cmd.Stdin = inputYaml
cmd.Stdout = &stdout
cmd.Stderr = &stderr

errKubeLinter := cmd.Run()
if errKubeLinter != nil && len(stderr.String()) > 0 {
t.Logf("kube-linter error(s) found for %q: \n%s\nstderr:\n%s", v.Name(), stdout.String(), stderr.String())
} else if errKubeLinter != nil {
t.Logf("kube-linter error(s) found for %q: \n%s", v.Name(), errKubeLinter)
}
// TODO: remove comment below and the logging above once we agree to linter
//require.NoError(t, errKubeLinter)

testutil.AssertGolden(t, testutil.YAML, "./testdata/"+v.Name()+".golden", out)
})
}
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
pkgs.kubectl
pkgs.kubernetes-helm
pkgs.kustomize
pkgs.kube-linter
pkgs.yq # jq but for YAML
];
};
Expand Down

0 comments on commit 1b611a2

Please sign in to comment.