Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/linters/container/rules/mount_points.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const (
)

type mountPointsFile struct {
Dirs []string `yaml:"dirs"`
Dirs []string `yaml:"dirs"`
Files []string `yaml:"files"`
}

func NewMountPointsRule(excludeRules []pkg.StringRuleExclude, modulePath string) *MountPointsRule {
Expand Down Expand Up @@ -133,6 +134,10 @@ func collectMountPointsDirs(modulePath string) map[string]bool {
dirs[strings.TrimRight(dir, "/")] = true
}

for _, file := range mpf.Files {
dirs[strings.TrimRight(file, "/")] = true
}

return nil
})

Expand Down
26 changes: 26 additions & 0 deletions pkg/linters/container/rules/mount_points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,32 @@ func TestMountPointsContainerRule_TrailingSlash(t *testing.T) {
assert.Len(t, errorList.GetErrors(), 0)
}

func TestMountPointsContainerRule_FilesDeclared(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "mpcr-test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir)

writeMountPointsFile(t, tmpDir, `dirs:
- /etc/app
files:
- /etc/app/config.yaml
- /var/run/app.sock
`)

obj := objectWithMounts("Deployment", "app", "/etc/app", "/etc/app/config.yaml", "/var/run/app.sock")

containers, err := obj.GetAllContainers()
assert.NoError(t, err)

errorList := errors.NewLintRuleErrorsList()
rule := NewMountPointsRule(nil, tmpDir)
rule.CheckMountPaths(obj, containers, errorList)

assert.Len(t, errorList.GetErrors(), 0)
}

func TestMountPointsContainerRule_DaemonSetAndStatefulSet(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "mpcr-test")
if err != nil {
Expand Down
Loading