analyzers

package
v0.0.0-...-1a63a6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PkgControllerRuntimeClient    = "sigs.k8s.io/controller-runtime/pkg/client"
	PkgControllerRuntimeReconcile = "sigs.k8s.io/controller-runtime/pkg/reconcile"
	PkgClientGoDynamic            = "k8s.io/client-go/dynamic"
	PkgClientGoKubernetes         = "k8s.io/client-go/kubernetes"
	PkgClientGoRest               = "k8s.io/client-go/rest"
	PkgMetaV1                     = "k8s.io/apimachinery/pkg/apis/meta/v1"
	PkgClientGoDiscovery          = "k8s.io/client-go/discovery"
	PkgClientGoRestMapper         = "k8s.io/client-go/restmapper"
)

Common Kubernetes package paths

Variables

View Source
var AnalyzerClientReuse = &analysis.Analyzer{
	Name:     "clientreuse",
	Doc:      "flags client construction inside loops or hot paths; clients should be reused",
	Run:      runClientReuse,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerClientReuse flags creating Kubernetes clients in hot paths or inside loops.

View Source
var AnalyzerDiscoveryFlood = &analysis.Analyzer{
	Name:     "discoveryflood",
	Doc:      "flags repeated discovery or RESTMapper rebuilds",
	Run:      runDiscoveryFlood,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerDiscoveryFlood flags repeated discovery client creations or RESTMapper resets in loops, which can flood the API server.

View Source
var AnalyzerDynamicOveruse = &analysis.Analyzer{
	Name:     "dynamicoveruse",
	Doc:      "flags overuse of dynamic/unstructured when typed clients exist",
	Run:      runDynamicOveruse,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerDynamicOveruse flags creation of dynamic/unstructured clients when typed clients appear to be available in the same package (heuristic).

View Source
var AnalyzerExcessiveClusterScope = &analysis.Analyzer{
	Name:     "excessiveclusterscope",
	Doc:      "flags cluster-scoped RBAC where namespace scope may suffice",
	Run:      runExcessiveClusterScope,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerExcessiveClusterScope flags ClusterRole/ClusterRoleBinding composite literals when Role/RoleBinding would suffice (heuristic).

View Source
var AnalyzerExcessiveConfig = &analysis.Analyzer{
	Name:     "excessiveconfig",
	Doc:      "flags repeated rest.Config or client creation in loops or hot paths",
	Run:      runExcessiveConfig,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerExcessiveConfig flags repeated creation of rest.Config/clients in hot paths.

View Source
var AnalyzerIgnoring429 = &analysis.Analyzer{
	Name:     "ignoring429",
	Doc:      "flags handling of 429 without backoff",
	Run:      runIgnoring429,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerIgnoring429 flags code that checks for HTTP 429 or throttling but does not back off (e.g., immediately retries with no sleep/backoff).

View Source
var AnalyzerLargePageSizes = &analysis.Analyzer{
	Name:     "largepages",
	Doc:      "flags excessively large page sizes in list calls",
	Run:      runLargePages,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerLargePageSizes flags ListOptions with very large Limit values.

View Source
var AnalyzerLeakyWatch = &analysis.Analyzer{
	Name:     "leakywatch",
	Doc:      "flags potential leaky watch channels without stop",
	Run:      runLeakyWatch,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerLeakyWatch flags Watch calls whose ResultChan is obtained but not stopped/drained. Heuristic: if a call to Stop/Cancel is not found.

View Source
var AnalyzerListInLoop = &analysis.Analyzer{
	Name:     "listinloop",
	Doc:      "flags List/Watch calls inside loops (prefer informers/cache)",
	Run:      runListInLoop,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerListInLoop flags List/Watch calls inside loops.

View Source
var AnalyzerManualPolling = &analysis.Analyzer{
	Name:     "manualpolling",
	Doc:      "flags manual polling loops using List with sleep/ticker",
	Run:      runManualPolling,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerManualPolling flags loops that poll with List + sleep/ticker instead of using watches/informers.

View Source
var AnalyzerMissingContext = &analysis.Analyzer{
	Name:     "missingcontext",
	Doc:      "flags client calls using context.Background/TODO instead of propagated context",
	Run:      runMissingContext,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerMissingContext flags client calls that pass context.Background/TODO instead of a propagated context.

View Source
var AnalyzerMissingInformer = &analysis.Analyzer{
	Name:     "missinginformer",
	Doc:      "flags direct Watch calls when no SharedInformer is used",
	Run:      runMissingInformer,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerMissingInformer flags direct client-go Watch calls in packages that do not appear to use shared informers/caches. Prefer shared informers to reduce API server load and improve efficiency.

View Source
var AnalyzerNoResync = &analysis.Analyzer{
	Name:     "noresync",
	Doc:      "flags informer creation with zero resync period",
	Run:      runNoResync,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerNoResync flags informer creations with resync period set to 0 where a positive resync might be desirable. Heuristic only.

View Source
var AnalyzerNoRetryTransient = &analysis.Analyzer{
	Name:     "noretrytransient",
	Doc:      "flags transient errors handled without retry",
	Run:      runNoRetryTransient,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerNoRetryTransient flags error handling that detects transient network issues but returns immediately without any retry/backoff.

View Source
var AnalyzerNoSelectors = &analysis.Analyzer{
	Name: "noselectors",
	Doc:  "flags List calls without label/field selectors",
	Run:  runNoSelectors,
}

AnalyzerNoSelectors flags List calls without label/field selectors or options.

View Source
var AnalyzerQPSBurst = &analysis.Analyzer{
	Name:     "qpsburst",
	Doc:      "flags rest.Config QPS/Burst zero or extreme values",
	Run:      runQPSBurst,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerQPSBurst flags rest.Config.QPS/Burst that are zero/unlimited or extreme.

View Source
var AnalyzerRESTMapperNotCached = &analysis.Analyzer{
	Name:     "restmapper_not_cached",
	Doc:      "flags RESTMapper without caching",
	Run:      runRESTMapperNotCached,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerRESTMapperNotCached flags use of discovery-based RESTMapper without caching wrapper. Heuristic: direct NewDiscoveryRESTMapper or NewDeferredDiscoveryRESTMapper without surrounding NewShortcutExpander or cached wrapper elsewhere in package.

View Source
var AnalyzerRequeueBackoff = &analysis.Analyzer{
	Name:     "requeuebackoff",
	Doc:      "flags requeue without backoff in Reconcile",
	Run:      runRequeueBackoff,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerRequeueBackoff flags controller-runtime Reconcile paths that requeue immediately without a backoff (e.g., returning requeue=true without RequeueAfter).

View Source
var AnalyzerRestConfigDefaults = &analysis.Analyzer{
	Name:     "restconfigdefaults",
	Doc:      "flags rest.Config initialization without timeouts or UserAgent",
	Run:      runRestConfigDefaults,
	Requires: []*analysis.Analyzer{inspect.Analyzer},
}

AnalyzerRestConfigDefaults flags rest.Config creations missing timeouts or user-agent.

View Source
var AnalyzerTightErrorLoops = &analysis.Analyzer{
	Name:     "tighterrorloops",
	Doc:      "flags tight loops retrying on errors around Kubernetes API calls without backoff",
	Run:      runTightErrorLoops,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerTightErrorLoops flags tight retry loops on errors that call the Kubernetes API without any backoff/sleep.

View Source
var AnalyzerUnboundedQueue = &analysis.Analyzer{
	Name:     "unboundedqueue",
	Doc:      "flags unbounded workqueue usage without rate limiting",
	Run:      runUnboundedQueue,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerUnboundedQueue flags usage of workqueue without rate limiting or without max-depth guards.

View Source
var AnalyzerUnstructuredEverywhere = &analysis.Analyzer{
	Name:     "unstructuredeverywhere",
	Doc:      "flags pervasive use of unstructured objects instead of typed",
	Run:      runUnstructuredEverywhere,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerUnstructuredEverywhere flags heavy use of unstructured.Unstructured in functions that could use typed objects. Heuristic: many composite literals or declarations of Unstructured within a file.

View Source
var AnalyzerWideNamespace = &analysis.Analyzer{
	Name:     "widenamespace",
	Doc:      "flags cluster-wide scans when namespace-scoped suffices",
	Run:      runWideNamespace,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerWideNamespace flags all-namespaces listing heuristics like InNamespace("") or typed Pods("").List.

View Source
var AnalyzerWildcardVerbs = &analysis.Analyzer{
	Name:     "wildcardverbs",
	Doc:      "flags wildcard verbs in RBAC rules",
	Run:      runWildcardVerbs,
	Requires: []*analysis.Analyzer{insppass.Analyzer},
}

AnalyzerWildcardVerbs flags RBAC policy rules with verbs ["*"]

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL