Commit 7a106fb
🧹 resource watcher improvements (#1369)
* 🧹 Changed the Resource Watcher to use inventory-based K8s API scanning
This makes sure we properly identifies scanned resources as live K8s cluster resources.
* ⭐️ batch scan specific resources instead of all resources by type
Instead of scanning all resources of changed types, now scans only the
specific resources that changed using cnspec's k8s-resources filter.
- Added K8sResourceIdentifier to track type, namespace, and name
- Updated debouncer to collect full resource identifiers
- Scanner generates inventory with k8s-resources option for targeted scanning
- More efficient: scans only changed resources, not all of a type
Fixes #1366
* 🐛 fix resource type pluralization for ingresses
Use explicit mapping between plural and singular resource type names
instead of naive string manipulation. This fixes scanning for ingresses
(ingresses → ingress, not ingresse) and other irregular plurals.
- Add resourceTypePluralization map and ToSingular() function
- Store plural form in K8sResourceIdentifier.Type
- Convert to singular only in String() for cnspec k8s-resources filter
- Add tests for pluralization logic
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* 🐛 fix inventory namespace options, ToSingular fallback, and test key consistency
Avoid emitting empty namespace/namespaces-exclude in inventory options,
return unknown resource types as-is instead of naively stripping trailing 's',
and fix plural key format in debouncer test.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* 🐛 fix empty ClusterUID producing trailing hyphen in ManagedBy field
When ClusterUID is not provided, ManagedBy was set to "mondoo-operator-"
(with trailing hyphen). Now defaults to "mondoo-operator" and only appends
the hyphen and UID when present. Also extracts IIFEs into plain variables
for readability.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* 🧹 remove logger side-effect from ToSingular and modernize watcher.go
Make ToSingular a pure function by removing the watcherLogger call.
Also apply Go modernize lints: use slices.Contains for namespace
filtering and replace interface{} with any.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* 🧹 move K8sResourceIdentifier and ToSingular to types.go
These shared types were defined in scanner.go but used across
debouncer.go, watcher.go, and their tests. Moving them to a
dedicated types.go improves discoverability.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* 🐛 make cluster UID and integration MRN lookups best-effort
Previously, failures to fetch the cluster UID or integration MRN
would abort the entire deployment sync. These are optional metadata
for asset labeling and should not block the resource watcher from
being deployed, e.g. in RBAC-restricted environments.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* 🧹 remove dead fields, fix scan rate limiting, and sort discovery targets
- Remove unused `scheme` field from ResourceWatcher and `gvk` from
resourceEventHandler (leftover from YAML serialization approach)
- Move lastScanTime update to after scan completion so the rate limit
interval is measured between scan completions, not scan starts
- Sort discovery targets for deterministic inventory YAML output
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* 🐛 fix missing integrationMRN/clusterUID args in TestDeployment_WithAnnotations
The rebase conflict resolution missed updating this test call to include
the new integrationMRN and clusterUID parameters.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* ✅ add integration test for resource watcher
Add TestReconcile_ResourceWatcher to verify the resource watcher detects
K8s resource changes and scans them via cnspec. The test enables the
resource watcher with short debounce/scan intervals, waits for the
deployment to become ready, creates a test deployment to trigger a scan,
and polls until assets appear upstream and are scored.
Also fix the resource watcher deployment to use MondooOperatorImage
instead of CnspecImage, since the deployment runs /mondoo-operator
(not cnspec).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent a00fa19 commit 7a106fb
12 files changed
Lines changed: 568 additions & 213 deletions
File tree
- cmd/mondoo-operator/resource_watcher
- controllers/resource_watcher
- tests/integration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
167 | 169 | | |
168 | 170 | | |
169 | 171 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
174 | 180 | | |
175 | 181 | | |
176 | 182 | | |
177 | | - | |
| 183 | + | |
178 | 184 | | |
179 | 185 | | |
180 | 186 | | |
181 | 187 | | |
182 | 188 | | |
183 | 189 | | |
184 | 190 | | |
185 | | - | |
| 191 | + | |
186 | 192 | | |
187 | 193 | | |
188 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
50 | | - | |
51 | | - | |
| 49 | + | |
| 50 | + | |
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
| |||
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
85 | | - | |
| 83 | + | |
| 84 | + | |
86 | 85 | | |
87 | 86 | | |
88 | 87 | | |
| |||
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | | - | |
106 | | - | |
| 104 | + | |
| 105 | + | |
107 | 106 | | |
108 | | - | |
109 | | - | |
| 107 | + | |
| 108 | + | |
110 | 109 | | |
111 | 110 | | |
112 | 111 | | |
113 | | - | |
114 | | - | |
115 | | - | |
| 112 | + | |
| 113 | + | |
116 | 114 | | |
117 | 115 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 116 | + | |
122 | 117 | | |
123 | 118 | | |
124 | 119 | | |
125 | 120 | | |
126 | 121 | | |
127 | 122 | | |
128 | 123 | | |
129 | | - | |
| 124 | + | |
130 | 125 | | |
131 | 126 | | |
132 | 127 | | |
133 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
0 commit comments