Skip to content

Commit 8d294e4

Browse files
cappyzawamatheuscscp
authored andcommitted
Add .status.inventory to track managed objects
This adds the `.status.inventory` field to HelmRelease, similar to Kustomization, to expose managed Kubernetes objects. The inventory includes: - Objects from the release manifest (with namespace complement) - CRDs from the chart's crds/ directory Helm hooks are excluded as they are ephemeral resources deleted after execution. Signed-off-by: cappyzawa <[email protected]>
1 parent 7a78031 commit 8d294e4

File tree

17 files changed

+835
-4
lines changed

17 files changed

+835
-4
lines changed

.github/workflows/e2e.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ jobs:
6060
run: |
6161
kubectl -n helm-system apply -f config/testdata/podinfo
6262
kubectl -n helm-system wait helmreleases/podinfo --for=condition=ready --timeout=4m
63+
64+
# Inventory tracking enables drift detection and garbage collection.
65+
# Ensure it captures managed objects from the Helm release.
66+
INVENTORY=$(kubectl -n helm-system get helmrelease/podinfo -o jsonpath='{.status.inventory.entries}')
67+
INVENTORY_COUNT=$(echo "$INVENTORY" | jq 'length')
68+
if [ "$INVENTORY_COUNT" -lt 1 ]; then
69+
echo "Expected inventory entries, got $INVENTORY_COUNT"
70+
exit 1
71+
fi
72+
# Deployment is a primary workload resource; its presence confirms
73+
# that the inventory correctly tracks resources from the rendered manifests.
74+
if ! echo "$INVENTORY" | jq -e '.[] | select(.id | contains("_Deployment"))' > /dev/null; then
75+
echo "Expected Deployment in inventory"
76+
echo "Inventory: $INVENTORY"
77+
exit 1
78+
fi
79+
6380
kubectl -n helm-system wait helmreleases/podinfo-git --for=condition=ready --timeout=4m
6481
kubectl -n helm-system wait helmreleases/podinfo-oci --for=condition=ready --timeout=4m
6582
kubectl -n helm-system delete -f config/testdata/podinfo

api/v2/helmrelease_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,11 @@ type HelmReleaseStatus struct {
11821182
// +optional
11831183
History Snapshots `json:"history,omitempty"`
11841184

1185+
// Inventory contains the list of Kubernetes resource object references
1186+
// that have been applied for this release.
1187+
// +optional
1188+
Inventory *ResourceInventory `json:"inventory,omitempty"`
1189+
11851190
// LastAttemptedReleaseAction is the last release action performed for this
11861191
// HelmRelease. It is used to determine the active retry or remediation
11871192
// strategy.

api/v2/inventory_types.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2026 The Flux authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v2
18+
19+
const (
20+
// InventoryBuildFailedReason represents the fact that the inventory
21+
// build failed.
22+
InventoryBuildFailedReason string = "InventoryBuildFailed"
23+
24+
// NamespaceCheckSkippedReason represents the fact that namespace
25+
// scope check was skipped due to RESTMapper error.
26+
NamespaceCheckSkippedReason string = "NamespaceCheckSkipped"
27+
)
28+
29+
// ResourceInventory contains a list of Kubernetes resource object references
30+
// that have been applied by a HelmRelease.
31+
type ResourceInventory struct {
32+
// Entries of Kubernetes resource object references.
33+
Entries []ResourceRef `json:"entries"`
34+
}
35+
36+
// ResourceRef contains the information necessary to locate a resource within a cluster.
37+
type ResourceRef struct {
38+
// ID is the string representation of the Kubernetes resource object's metadata,
39+
// in the format '<namespace>_<name>_<group>_<kind>'.
40+
ID string `json:"id"`
41+
42+
// Version is the API version of the Kubernetes resource object's kind.
43+
Version string `json:"v"`
44+
}

api/v2/zz_generated.deepcopy.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,34 @@ spec:
12481248
state. It is reset after a successful reconciliation.
12491249
format: int64
12501250
type: integer
1251+
inventory:
1252+
description: |-
1253+
Inventory contains the list of Kubernetes resource object references
1254+
that have been applied for this release.
1255+
properties:
1256+
entries:
1257+
description: Entries of Kubernetes resource object references.
1258+
items:
1259+
description: ResourceRef contains the information necessary
1260+
to locate a resource within a cluster.
1261+
properties:
1262+
id:
1263+
description: |-
1264+
ID is the string representation of the Kubernetes resource object's metadata,
1265+
in the format '<namespace>_<name>_<group>_<kind>'.
1266+
type: string
1267+
v:
1268+
description: Version is the API version of the Kubernetes
1269+
resource object's kind.
1270+
type: string
1271+
required:
1272+
- id
1273+
- v
1274+
type: object
1275+
type: array
1276+
required:
1277+
- entries
1278+
type: object
12511279
lastAttemptedConfigDigest:
12521280
description: |-
12531281
LastAttemptedConfigDigest is the digest for the config (better known as

docs/api/v2/helm.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,21 @@ up to the last successfully completed release.</p>
16691669
</tr>
16701670
<tr>
16711671
<td>
1672+
<code>inventory</code><br>
1673+
<em>
1674+
<a href="#helm.toolkit.fluxcd.io/v2.ResourceInventory">
1675+
ResourceInventory
1676+
</a>
1677+
</em>
1678+
</td>
1679+
<td>
1680+
<em>(Optional)</em>
1681+
<p>Inventory contains the list of Kubernetes resource object references
1682+
that have been applied for this release.</p>
1683+
</td>
1684+
</tr>
1685+
<tr>
1686+
<td>
16721687
<code>lastAttemptedReleaseAction</code><br>
16731688
<em>
16741689
<a href="#helm.toolkit.fluxcd.io/v2.ReleaseAction">
@@ -2342,6 +2357,85 @@ UpgradeRemediation.</p>
23422357
</p>
23432358
<p>RemediationStrategy returns the strategy to use to remediate a failed install
23442359
or upgrade.</p>
2360+
<h3 id="helm.toolkit.fluxcd.io/v2.ResourceInventory">ResourceInventory
2361+
</h3>
2362+
<p>
2363+
(<em>Appears on:</em>
2364+
<a href="#helm.toolkit.fluxcd.io/v2.HelmReleaseStatus">HelmReleaseStatus</a>)
2365+
</p>
2366+
<p>ResourceInventory contains a list of Kubernetes resource object references
2367+
that have been applied by a HelmRelease.</p>
2368+
<div class="md-typeset__scrollwrap">
2369+
<div class="md-typeset__table">
2370+
<table>
2371+
<thead>
2372+
<tr>
2373+
<th>Field</th>
2374+
<th>Description</th>
2375+
</tr>
2376+
</thead>
2377+
<tbody>
2378+
<tr>
2379+
<td>
2380+
<code>entries</code><br>
2381+
<em>
2382+
<a href="#helm.toolkit.fluxcd.io/v2.ResourceRef">
2383+
[]ResourceRef
2384+
</a>
2385+
</em>
2386+
</td>
2387+
<td>
2388+
<p>Entries of Kubernetes resource object references.</p>
2389+
</td>
2390+
</tr>
2391+
</tbody>
2392+
</table>
2393+
</div>
2394+
</div>
2395+
<h3 id="helm.toolkit.fluxcd.io/v2.ResourceRef">ResourceRef
2396+
</h3>
2397+
<p>
2398+
(<em>Appears on:</em>
2399+
<a href="#helm.toolkit.fluxcd.io/v2.ResourceInventory">ResourceInventory</a>)
2400+
</p>
2401+
<p>ResourceRef contains the information necessary to locate a resource within a cluster.</p>
2402+
<div class="md-typeset__scrollwrap">
2403+
<div class="md-typeset__table">
2404+
<table>
2405+
<thead>
2406+
<tr>
2407+
<th>Field</th>
2408+
<th>Description</th>
2409+
</tr>
2410+
</thead>
2411+
<tbody>
2412+
<tr>
2413+
<td>
2414+
<code>id</code><br>
2415+
<em>
2416+
string
2417+
</em>
2418+
</td>
2419+
<td>
2420+
<p>ID is the string representation of the Kubernetes resource object&rsquo;s metadata,
2421+
in the format &lsquo;<namespace><em><name></em><group>_<kind>&rsquo;.</p>
2422+
</td>
2423+
</tr>
2424+
<tr>
2425+
<td>
2426+
<code>v</code><br>
2427+
<em>
2428+
string
2429+
</em>
2430+
</td>
2431+
<td>
2432+
<p>Version is the API version of the Kubernetes resource object&rsquo;s kind.</p>
2433+
</td>
2434+
</tr>
2435+
</tbody>
2436+
</table>
2437+
</div>
2438+
</div>
23452439
<h3 id="helm.toolkit.fluxcd.io/v2.Retry">Retry
23462440
</h3>
23472441
<p>Retry defines a consistent interface for retry strategies from

docs/spec/v2/helmreleases.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,36 @@ status:
18841884
version: 1
18851885
```
18861886

1887+
### Inventory
1888+
1889+
The HelmRelease reports the list of Kubernetes resource objects that have been
1890+
applied by the Helm release in `.status.inventory`. This can be used to
1891+
identify which objects are managed by the HelmRelease. The inventory records
1892+
are in the format `<namespace>_<name>_<group>_<kind>`.
1893+
1894+
The inventory includes all resources from the rendered manifests, as well as
1895+
CRDs from the chart's `crds/` directory. Helm hooks are not included in the
1896+
inventory, as they are not considered part of the release by Helm.
1897+
1898+
#### Inventory example
1899+
1900+
```yaml
1901+
---
1902+
apiVersion: helm.toolkit.fluxcd.io/v2
1903+
kind: HelmRelease
1904+
metadata:
1905+
name: <release-name>
1906+
status:
1907+
inventory:
1908+
entries:
1909+
- id: default_podinfo__Service
1910+
v: v1
1911+
- id: default_podinfo_apps_Deployment
1912+
v: v1
1913+
- id: default_podinfo_autoscaling_HorizontalPodAutoscaler
1914+
v: v2
1915+
```
1916+
18871917
### Conditions
18881918

18891919
A HelmRelease enters various states during its lifecycle, reflected as

0 commit comments

Comments
 (0)