Skip to content

Commit 8c63fcb

Browse files
committed
✨ feat(api): add Target collection filtering (ADR-0207)
Ship Option 1 phased filters: namespace intent on Target/ClusterTarget, Scope ceiling with deniedNamespaces, resourceRules OR-union, CEL matchPolicy, KollectClusterScope CRD, admission webhooks, engine pre-store gates, status fields, Helm default include/exclude namespaces, docs and tests.
1 parent e538490 commit 8c63fcb

56 files changed

Lines changed: 3138 additions & 228 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2026 Konrad Heimel
3+
4+
package v1alpha1
5+
6+
import (
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
// CollectionFilterSpec holds target-side collection intent (ADR-0207).
11+
// Namespace fields combine with AND semantics: includedNamespaces (when set) ∩ namespaceSelector.
12+
type CollectionFilterSpec struct {
13+
// includedNamespaces is a static namespace allowlist. Empty means no extra restriction
14+
// beyond namespaceSelector.
15+
// +listType=set
16+
// +optional
17+
IncludedNamespaces []string `json:"includedNamespaces,omitempty"`
18+
19+
// excludedNamespaces is a static namespace denylist applied after include logic.
20+
// +listType=set
21+
// +optional
22+
ExcludedNamespaces []string `json:"excludedNamespaces,omitempty"`
23+
24+
// namespaceExcludeSelector excludes namespaces whose labels match the selector.
25+
// +optional
26+
NamespaceExcludeSelector *metav1.LabelSelector `json:"namespaceExcludeSelector,omitempty"`
27+
28+
// resourceRules declares GVK-scoped collection rules. When empty, collection falls back to
29+
// Profile targetGVK plus legacy labelSelector/names on the Target.
30+
// +listType=atomic
31+
// +optional
32+
ResourceRules []ResourceRule `json:"resourceRules,omitempty"`
33+
}
34+
35+
// ResourceRule selects objects of a GVK within optional namespace and resource label constraints.
36+
// Multiple rules are OR-unioned (D7). Optional matchPolicy is a CEL expression evaluated pre-store.
37+
type ResourceRule struct {
38+
// gvk is the API group, version, and kind this rule applies to.
39+
// +required
40+
GVK GroupVersionKind `json:"gvk"`
41+
42+
// namespaceSelector further restricts this rule to namespaces matching the selector.
43+
// +optional
44+
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
45+
46+
// matchLabels requires resource metadata labels to match (AND with matchExpressions).
47+
// +optional
48+
MatchLabels map[string]string `json:"matchLabels,omitempty"`
49+
50+
// matchExpressions requires resource metadata labels to match.
51+
// +optional
52+
MatchExpressions []metav1.LabelSelectorRequirement `json:"matchExpressions,omitempty"`
53+
54+
// matchPolicy is an optional CEL expression with `object` bound to the resource.
55+
// Evaluated after label/GVK/namespace gates, before store insert (ADR-0207 Phase 3).
56+
// +optional
57+
MatchPolicy string `json:"matchPolicy,omitempty"`
58+
}
59+
60+
// CollectionFilterStatus summarizes applied namespace and rule filters on a Target.
61+
type CollectionFilterStatus struct {
62+
// matchedNamespaces lists workload namespaces matched by Target intent (before Scope ceiling).
63+
// +listType=set
64+
// +optional
65+
MatchedNamespaces []string `json:"matchedNamespaces,omitempty"`
66+
67+
// effectiveNamespaces lists namespaces after intersecting Scope allowedNamespaces and subtracting
68+
// Target/Scope deny lists.
69+
// +listType=set
70+
// +optional
71+
EffectiveNamespaces []string `json:"effectiveNamespaces,omitempty"`
72+
73+
// activeResourceRules is the number of compiled resourceRules entries (0 when using legacy fallback).
74+
// +optional
75+
ActiveResourceRules int `json:"activeResourceRules,omitempty"`
76+
}
77+
78+
// ScopeCeilingSpec is the tenancy guardrail subset shared by KollectScope and KollectClusterScope.
79+
type ScopeCeilingSpec struct {
80+
// allowedGVKs restricts which target resource kinds may be collected in this scope.
81+
// +listType=atomic
82+
// +optional
83+
AllowedGVKs []GroupVersionKind `json:"allowedGVKs,omitempty"`
84+
85+
// allowedNamespaces restricts which workload namespaces may be collected.
86+
// Empty means any namespace allowed by targets in the scope namespace.
87+
// +listType=set
88+
// +optional
89+
AllowedNamespaces []string `json:"allowedNamespaces,omitempty"`
90+
91+
// deniedNamespaces is a platform blacklist; Target intent cannot override (D8).
92+
// +listType=set
93+
// +optional
94+
DeniedNamespaces []string `json:"deniedNamespaces,omitempty"`
95+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2026 Konrad Heimel
3+
4+
package v1alpha1
5+
6+
import (
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
// KollectClusterScopeSpec defines a cluster-scoped tenancy ceiling (ADR-0207).
11+
type KollectClusterScopeSpec struct {
12+
ScopeCeilingSpec `json:",inline"`
13+
14+
// sinkRefs lists cluster-scoped KollectSink names permitted for export from this scope.
15+
// +listType=set
16+
// +optional
17+
SinkRefs []string `json:"sinkRefs,omitempty"`
18+
}
19+
20+
// +kubebuilder:object:root=true
21+
// +kubebuilder:resource:scope=Cluster,shortName=kcscope
22+
23+
// KollectClusterScope is a cluster governance boundary for cluster targets and inventories.
24+
// Static config only — no controller or status subresource (ADR-0202).
25+
type KollectClusterScope struct {
26+
metav1.TypeMeta `json:",inline"`
27+
metav1.ObjectMeta `json:"metadata,omitzero"`
28+
29+
Spec KollectClusterScopeSpec `json:"spec"`
30+
}
31+
32+
// +kubebuilder:object:root=true
33+
34+
// KollectClusterScopeList contains a list of KollectClusterScope.
35+
type KollectClusterScopeList struct {
36+
metav1.TypeMeta `json:",inline"`
37+
metav1.ListMeta `json:"metadata,omitzero"`
38+
Items []KollectClusterScope `json:"items"`
39+
}
40+
41+
func init() {
42+
SchemeBuilder.Register(&KollectClusterScope{}, &KollectClusterScopeList{})
43+
}

‎api/v1alpha1/kollectclustertarget_types.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type KollectClusterTargetSpec struct {
1818
// +optional
1919
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
2020

21+
CollectionFilterSpec `json:",inline"`
22+
2123
// suspend pauses reconciliation when set to true (reserved for future controller).
2224
// +optional
2325
Suspend bool `json:"suspend,omitempty"`
@@ -34,6 +36,8 @@ type KollectClusterTargetStatus struct {
3436
// observedGeneration is the most recent generation observed by a controller.
3537
// +optional
3638
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
39+
40+
CollectionFilterStatus `json:",inline"`
3741
}
3842

3943
// +kubebuilder:object:root=true

‎api/v1alpha1/kollectscope_types.go‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@ import (
99

1010
// KollectScopeSpec defines a namespaced tenancy boundary for collection and sinks.
1111
type KollectScopeSpec struct {
12-
// allowedGVKs restricts which target resource kinds may be collected in this scope.
13-
// +listType=atomic
14-
// +optional
15-
AllowedGVKs []GroupVersionKind `json:"allowedGVKs,omitempty"`
16-
17-
// allowedNamespaces restricts which workload namespaces may be collected.
18-
// Empty means any namespace allowed by targets in the scope namespace.
19-
// +listType=set
20-
// +optional
21-
AllowedNamespaces []string `json:"allowedNamespaces,omitempty"`
12+
ScopeCeilingSpec `json:",inline"`
2213

2314
// sinkRefs lists namespaced KollectSink names permitted for export from this scope.
2415
// +listType=set

‎api/v1alpha1/kollecttarget_types.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type KollectTargetSpec struct {
2020
// +optional
2121
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
2222

23+
CollectionFilterSpec `json:",inline"`
24+
2325
// labelSelector restricts collection to resources matching the selector.
2426
// +optional
2527
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
@@ -66,6 +68,8 @@ type KollectTargetStatus struct {
6668
// observedGeneration is the most recent generation observed by the controller.
6769
// +optional
6870
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
71+
72+
CollectionFilterStatus `json:",inline"`
6973
}
7074

7175
// +kubebuilder:object:root=true

0 commit comments

Comments
 (0)