Skip to content

Commit

Permalink
fix issue #111 #112
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Jul 4, 2020
1 parent e1a1d7b commit 87b694a
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 31 deletions.
15 changes: 13 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
README.md
/execs
*_test.go
k8s
*.yml
*.yml
/krew
/notes
/junit
/dist
/change_logs
/assets
/.github
/.idea
/.vscode
/aa_dead
/k8s
/k8s1
19 changes: 7 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
# -----------------------------------------------------------------------------
# Build...
FROM golang:1.13.5-alpine AS build
FROM golang:1.14.4-alpine AS build

ENV VERSION=v0.8.0 GO111MODULE=on PACKAGE=github.com/derailed/popeye
WORKDIR /popeye

WORKDIR /go/src/$PACKAGE

COPY go.mod go.sum main.go ./
COPY go.mod go.sum main.go Makefile ./
COPY internal internal
COPY cmd cmd
COPY types types
COPY pkg pkg
COPY cmd cmd

RUN apk update && apk upgrade ;\
apk --no-cache add git ca-certificates ;\
CGO_ENABLED=0 GOOS=linux go build -o /go/bin/popeye \
-trimpath -ldflags="-w -s -X $PACKAGE/cmd.version=$VERSION" *.go
RUN apk --no-cache add make git gcc libc-dev curl ca-certificates && make build

# -----------------------------------------------------------------------------
# Image...
FROM alpine:3.11.2
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=build /go/bin/popeye /bin/popeye
COPY --from=build /popeye/execs/popeye /bin/popeye

ENTRYPOINT [ "/bin/popeye" ]
1 change: 1 addition & 0 deletions internal/issues/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (c *Collector) AddCode(ctx context.Context, code config.ID, args ...interfa
panic(fmt.Errorf("No code with ID %d", code))
}
if !c.ShouldExclude(run.SectionGVR.String(), run.FQN, code) {
fmt.Println("ADD Issue", run.FQN, code)
c.addIssue(run.FQN, New(run.SectionGVR, Root, co.Severity, co.Format(code, args...)))
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/dp.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (d *Deployment) Sanitize(ctx context.Context) error {
podsMetrics(d, pmx)
d.checkUtilization(ctx, over, dp, pmx)

if d.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if d.NoConcerns(fqn) && d.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
d.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (d *DaemonSet) Sanitize(ctx context.Context) error {
podsMetrics(d, pmx)
d.checkUtilization(ctx, over, ds, pmx)

if d.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if d.NoConcerns(fqn) && d.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
d.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (h *HorizontalPodAutoscaler) Sanitize(ctx context.Context) error {
tcpu.Add(*list.Cpu())
tmem.Add(*list.Memory())

if h.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if h.NoConcerns(fqn) && h.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
h.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/ing.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (i *Ingress) Sanitize(ctx context.Context) error {

i.checkDeprecation(ctx, ing)

if i.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if i.NoConcerns(fqn) && i.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
i.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (n *Node) Sanitize(ctx context.Context) error {
n.checkUtilization(ctx, nmx[fqn])
}

if n.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if n.NoConcerns(fqn) && n.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
n.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/np.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (n *NetworkPolicy) Sanitize(ctx context.Context) error {
n.checkDeprecation(ctx, np)
n.checkRefs(ctx, np)

if n.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if n.NoConcerns(fqn) && n.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
n.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/pdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (p *PodDisruptionBudget) Sanitize(ctx context.Context) error {

p.checkInUse(ctx, pdb)

if p.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if p.NoConcerns(fqn) && p.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
p.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (p *Pod) Sanitize(ctx context.Context) error {
containerMetrics(pmx, cmx)
p.checkUtilization(ctx, po, cmx)

if p.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if p.NoConcerns(fqn) && p.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
p.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/psp.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (p *PodSecurityPolicy) Sanitize(ctx context.Context) error {

p.checkDeprecation(ctx, psp)

if p.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if p.NoConcerns(fqn) && p.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
p.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/pv.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (p *PersistentVolume) Sanitize(ctx context.Context) error {

p.checkBound(ctx, pv.Status.Phase)

if p.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if p.NoConcerns(fqn) && p.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
p.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (p *PersistentVolumeClaim) Sanitize(ctx context.Context) error {
p.InitOutcome(fqn)
ctx = internal.WithFQN(ctx, fqn)
defer func(fqn string, ctx context.Context) {
if p.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if p.NoConcerns(fqn) && p.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
p.ClearOutcome(fqn)
}
}(fqn, ctx)
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/rb.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (r *RoleBinding) Sanitize(ctx context.Context) error {
}
}

if r.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if r.NoConcerns(fqn) && r.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
r.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/ro.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (r *Role) checkInUse(ctx context.Context, refs *sync.Map) {
r.AddCode(ctx, 400)
}

if r.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if r.NoConcerns(fqn) && r.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
r.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/rs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *ReplicaSet) Sanitize(ctx context.Context) error {
r.checkHealth(ctx, rs)
r.checkDeprecation(ctx, rs)

if r.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if r.NoConcerns(fqn) && r.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
r.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/sa.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *ServiceAccount) Sanitize(ctx context.Context) error {
s.AddCode(ctx, 400)
}

if s.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if s.NoConcerns(fqn) && s.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
s.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *StatefulSet) Sanitize(ctx context.Context) error {
s.checkContainers(ctx, st)
s.checkUtilization(ctx, over, st, pmx)

if s.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if s.NoConcerns(fqn) && s.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
s.ClearOutcome(fqn)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sanitize/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *Service) Sanitize(ctx context.Context) error {
s.checkEndpoints(ctx, svc.Spec.Selector, svc.Spec.Type)
s.checkType(ctx, svc.Spec.Type)

if s.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
if s.NoConcerns(fqn) && s.Config.ExcludeFQN(internal.MustExtractSectionGVR(ctx), fqn) {
s.ClearOutcome(fqn)
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/excludes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"fmt"
"regexp"
"strings"

Expand Down Expand Up @@ -64,8 +65,10 @@ func (e Excludes) ShouldExclude(section, fqn string, code ID) bool {

// Match checks if a given named should be excluded.
func (e Exclusions) Match(resource string, code ID) bool {
fmt.Printf("Match %q -- %v\n", resource, code)
for _, exclude := range e {
if exclude.Match(resource) && hasCode(exclude.Codes, code) {
fmt.Println(" MATCHED!!")
return true
}
}
Expand Down

0 comments on commit 87b694a

Please sign in to comment.