diff --git a/cmd/version.go b/cmd/version.go index 9d00968a..607cd91b 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Popeye + package cmd import ( diff --git a/internal/alias.go b/internal/alias.go index da2d03ef..0bf8887d 100644 --- a/internal/alias.go +++ b/internal/alias.go @@ -16,6 +16,9 @@ import ( var ( ClusterGVR = types.NewGVR("cluster") + groups = map[R]string{ + NP: "networking.k8s.io", + } ) // ResourceMetas represents a collection of resource metadata. @@ -165,6 +168,10 @@ func (a *Aliases) loadPreferred(c types.Connection) error { continue } for _, r := range l.APIResources { + if g, ok := groups[R(r.Name)]; ok && g != gv.Group { + continue + } + gvr := types.NewGVRFromAPIRes(gv, r) if !a.cilium && strings.Contains(gvr.G(), "cilium.io") { a.cilium = true diff --git a/internal/gvr/types.go b/internal/gvr/types.go deleted file mode 100644 index e4a4ba6d..00000000 --- a/internal/gvr/types.go +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright Authors of Popeye - -package gvr - -// type GVR1 string - -// func (g GVR) String() string { -// return string(g) -// } - -// var ( -// CM GVR = "v1/configmaps" -// Pod GVR = "v1/pods" -// NS GVR = "v1/namespaces" -// Node GVR = "v1/nodes" -// SA GVR = "v1/serviceaccounts" -// PDB GVR = "policy/v1/poddisruptionbudgets" -// PV GVR = "v1/persistentvolumes" -// PVC GVR = "v1/persistentvolumeclaims" -// SEC GVR = "v1/secrets" -// ING GVR = "networking.k8s.io/v1/ingresses" -// NP GVR = "networking.k8s.io/v1/networkpolicies" -// SVC GVR = "v1/services" -// EP GVR = "v1/endpoints" -// RO GVR = "rbac.authorization.k8s.io/v1/roles" -// RB GVR = "rbac.authorization.k8s.io/v1/rolebindings" -// CR GVR = "rbac.authorization.k8s.io/v1/clusterroles" -// CRB GVR = "rbac.authorization.k8s.io/v1/clusterrolebindings" -// DP GVR = "apps/v1/deployments" -// DS GVR = "apps/v1/daemonsets" -// RS GVR = "apps/v1/replicasets" -// STS GVR = "apps/v1/statefulsets" -// HPA GVR = "autoscaling/v1/horizontalpodautoscalers" -// PMX GVR = "metrics.k8s.io/v1beta1/podmetrics" -// NMX GVR = "metrics.k8s.io/v1beta1/podmetrics" -// ) diff --git a/internal/report/writer.go b/internal/report/writer.go index 86c6bd68..1fabba04 100644 --- a/internal/report/writer.go +++ b/internal/report/writer.go @@ -99,7 +99,7 @@ func (s *ScanReport) Error(msg string, err error) { // Comment writes a comment line. func (s *ScanReport) Comment(msg string) { - fmt.Fprintf(s, " · "+msg+"\n") + fmt.Fprint(s, " · "+msg+"\n") } // Dump all errors to output. diff --git a/internal/report/writer_test.go b/internal/report/writer_test.go index 4d604801..eb9cfce4 100644 --- a/internal/report/writer_test.go +++ b/internal/report/writer_test.go @@ -5,6 +5,7 @@ package report import ( "bytes" + "errors" "fmt" "io" "strings" @@ -31,12 +32,12 @@ func TestError(t *testing.T) { e string }{ { - fmt.Errorf("crapola"), - "\n💥 \x1b[38;5;196mblee: crapola\x1b[0m\n", + err: fmt.Errorf("crapola"), + e: "\n💥 \x1b[38;5;196mblee: crapola\x1b[0m\n", }, { - fmt.Errorf(strings.Repeat("#", 200)), - "\n💥 \x1b[38;5;196mblee: " + strings.Repeat("#", Width-9) + "\x1b[0m\n\x1b[38;5;196m" + strings.Repeat("#", Width-3) + "\x1b[0m\n\x1b[38;5;196m" + strings.Repeat("#", Width-88) + "\x1b[0m\n", + err: errors.New(strings.Repeat("#", 200)), + e: "\n💥 \x1b[38;5;196mblee: " + strings.Repeat("#", Width-9) + "\x1b[0m\n\x1b[38;5;196m" + strings.Repeat("#", Width-3) + "\x1b[0m\n\x1b[38;5;196m" + strings.Repeat("#", Width-88) + "\x1b[0m\n", }, } diff --git a/internal/stringset_test.go b/internal/stringset_test.go index ced5c964..b52d20c5 100644 --- a/internal/stringset_test.go +++ b/internal/stringset_test.go @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Popeye + package internal_test import ( diff --git a/main.go b/main.go index 78ea911d..31fe7521 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Popeye + package main import ( diff --git a/pkg/popeye.go b/pkg/popeye.go index f5ff1d78..0ffa7464 100644 --- a/pkg/popeye.go +++ b/pkg/popeye.go @@ -263,10 +263,9 @@ func (p *Popeye) lint() (int, int, error) { if gvr == internal.Glossary[internal.NO] && p.client().ActiveNamespace() != client.AllNamespaces { continue } - if !p.aliases.IsNamespaced(gvr) { - ctx = context.WithValue(ctx, internal.KeyNamespace, client.ClusterScope) - } + runners[gvr] = fn(ctx, cache, codes) + } total, errCount := len(runners), 0 @@ -305,7 +304,12 @@ func (p *Popeye) runLinter(ctx context.Context, gvr types.GVR, l scrub.Linter, c } }() - if err := l.Lint(ctx); err != nil { + callCtx := ctx + if !p.aliases.IsNamespaced(gvr) { + callCtx = context.WithValue(ctx, internal.KeyNamespace, client.ClusterScope) + } + + if err := l.Lint(callCtx); err != nil { p.builder.AddError(err) } o := l.Outcome().Filter(rules.Level(p.config.LintLevel))