Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Apr 11, 2019
1 parent 689da2a commit 00871e3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion internal/linter/cm.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (*CM) checkEnv(poFQN string, co v1.Container, refs References) {
continue
}
refs[key] = map[string]*Reference{
"env": &Reference{
"env": {
name: kref.Name,
keys: map[string]struct{}{
kref.Key: blank,
Expand Down
4 changes: 2 additions & 2 deletions internal/linter/cm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestCMCheckContainerRefs(t *testing.T) {
{makePodEnv("p1", "cm1", "fred", false), "env", true, &Reference{
name: "cm1",
keys: map[string]struct{}{
"fred": struct{}{},
"fred": {},
},
}},
{makePodEnv("p1", "cm1", "fred", true), "env", false, nil},
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestCMCheckVolumes(t *testing.T) {
true,
&Reference{
name: "default/p1:v1",
keys: map[string]struct{}{"fred": struct{}{}},
keys: map[string]struct{}{"fred": {}},
},
},
// Pod with a volume referencing an optional cm.
Expand Down
28 changes: 16 additions & 12 deletions internal/linter/sec.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,7 @@ func (s *Secret) Lint(ctx context.Context) error {
return nil
}

func (s *Secret) lint(secs map[string]v1.Secret, pods map[string]v1.Pod, sas map[string]v1.ServiceAccount) {
refs := make(References, len(pods)+len(sas))

for fqn, po := range pods {
s.checkVolumes(fqn, po.Spec.Volumes, refs)
s.checkContainerRefs(fqn, po.Spec.InitContainers, refs)
s.checkContainerRefs(fqn, po.Spec.Containers, refs)
s.checkPullImageSecrets(po, refs)
}

func checkServiceAccountRef(sas map[string]v1.ServiceAccount, refs References) {
for _, sa := range sas {
Reference := Reference{name: sa.Name}
for _, s := range sa.Secrets {
Expand All @@ -83,9 +74,22 @@ func (s *Secret) lint(secs map[string]v1.Secret, pods map[string]v1.Pod, sas map
}
}
}
}

func (s *Secret) lint(secs map[string]v1.Secret, pods map[string]v1.Pod, sas map[string]v1.ServiceAccount) {
refs := make(References, len(pods)+len(sas))

for fqn, po := range pods {
s.checkVolumes(fqn, po.Spec.Volumes, refs)
s.checkContainerRefs(fqn, po.Spec.InitContainers, refs)
s.checkContainerRefs(fqn, po.Spec.Containers, refs)
s.checkPullImageSecrets(po, refs)
}
checkServiceAccountRef(sas, refs)

for fqn, sec := range secs {
s.initIssues(fqn)

ref, ok := refs[fqn]
if !ok {
s.addIssuef(fqn, InfoLevel, "Reference?")
Expand Down Expand Up @@ -176,10 +180,10 @@ func (*Secret) checkContainerRefs(poFQN string, cos []v1.Container, refs map[str
}

refs[fqn] = map[string]*Reference{
"env": &Reference{
"env": {
name: kref.Name,
keys: map[string]struct{}{
kref.Key: struct{}{},
kref.Key: {},
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/linter/sec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestSecCheckContainerRefs(t *testing.T) {
{makePodSecEnv("p1", "s1", "fred", false), "env", true, &Reference{
name: "s1",
keys: map[string]struct{}{
"fred": struct{}{},
"fred": {},
},
}},
{makePodEnv("p1", "s1", "fred", true), "env", false, nil},
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestSecCheckVolumes(t *testing.T) {
{
makePodSecVol("p1", "s1", "fred", false), "volume", true, &Reference{
name: "default/p1:v1",
keys: map[string]struct{}{"fred": struct{}{}},
keys: map[string]struct{}{"fred": {}},
},
},
{
Expand Down

0 comments on commit 00871e3

Please sign in to comment.