@@ -18,6 +18,37 @@ pub struct ResourceInfo {
1818 pub ready : Option < bool > ,
1919 pub message : Option < String > ,
2020 pub revision : Option < String > ,
21+ // Cached metadata for filtering
22+ pub labels : HashMap < String , String > ,
23+ pub annotations : HashMap < String , String > ,
24+ }
25+
26+ /// Extract labels from a Kubernetes resource JSON object
27+ pub fn extract_labels ( obj : & serde_json:: Value ) -> HashMap < String , String > {
28+ obj. get ( "metadata" )
29+ . and_then ( |m| m. get ( "labels" ) )
30+ . and_then ( |l| l. as_object ( ) )
31+ . map ( |labels| {
32+ labels
33+ . iter ( )
34+ . filter_map ( |( k, v) | v. as_str ( ) . map ( |s| ( k. clone ( ) , s. to_string ( ) ) ) )
35+ . collect ( )
36+ } )
37+ . unwrap_or_default ( )
38+ }
39+
40+ /// Extract annotations from a Kubernetes resource JSON object
41+ pub fn extract_annotations ( obj : & serde_json:: Value ) -> HashMap < String , String > {
42+ obj. get ( "metadata" )
43+ . and_then ( |m| m. get ( "annotations" ) )
44+ . and_then ( |a| a. as_object ( ) )
45+ . map ( |annotations| {
46+ annotations
47+ . iter ( )
48+ . filter_map ( |( k, v) | v. as_str ( ) . map ( |s| ( k. clone ( ) , s. to_string ( ) ) ) )
49+ . collect ( )
50+ } )
51+ . unwrap_or_default ( )
2152}
2253
2354/// Thread-safe resource state store
@@ -135,6 +166,8 @@ mod tests {
135166 ready : Some ( true ) ,
136167 message : Some ( "Ready" . to_string ( ) ) ,
137168 revision : None ,
169+ labels : HashMap :: new ( ) ,
170+ annotations : HashMap :: new ( ) ,
138171 } ;
139172
140173 use crate :: models:: FluxResourceKind ;
@@ -168,6 +201,8 @@ mod tests {
168201 ready : None ,
169202 message : None ,
170203 revision : None ,
204+ labels : HashMap :: new ( ) ,
205+ annotations : HashMap :: new ( ) ,
171206 } ;
172207 let key = resource_key (
173208 "default" ,
@@ -197,6 +232,8 @@ mod tests {
197232 ready : None ,
198233 message : None ,
199234 revision : None ,
235+ labels : HashMap :: new ( ) ,
236+ annotations : HashMap :: new ( ) ,
200237 } ;
201238
202239 let gitrepo = ResourceInfo {
@@ -208,6 +245,8 @@ mod tests {
208245 ready : None ,
209246 message : None ,
210247 revision : None ,
248+ labels : HashMap :: new ( ) ,
249+ annotations : HashMap :: new ( ) ,
211250 } ;
212251
213252 let kustomization2 = ResourceInfo {
@@ -219,6 +258,8 @@ mod tests {
219258 ready : None ,
220259 message : None ,
221260 revision : None ,
261+ labels : HashMap :: new ( ) ,
262+ annotations : HashMap :: new ( ) ,
222263 } ;
223264
224265 state. upsert (
@@ -258,6 +299,8 @@ mod tests {
258299 ready : None ,
259300 message : None ,
260301 revision : None ,
302+ labels : HashMap :: new ( ) ,
303+ annotations : HashMap :: new ( ) ,
261304 } ,
262305 ) ;
263306
@@ -272,6 +315,8 @@ mod tests {
272315 ready : None ,
273316 message : None ,
274317 revision : None ,
318+ labels : HashMap :: new ( ) ,
319+ annotations : HashMap :: new ( ) ,
275320 } ,
276321 ) ;
277322
@@ -286,6 +331,8 @@ mod tests {
286331 ready : None ,
287332 message : None ,
288333 revision : None ,
334+ labels : HashMap :: new ( ) ,
335+ annotations : HashMap :: new ( ) ,
289336 } ,
290337 ) ;
291338
@@ -317,6 +364,8 @@ mod tests {
317364 ready : None ,
318365 message : None ,
319366 revision : None ,
367+ labels : HashMap :: new ( ) ,
368+ annotations : HashMap :: new ( ) ,
320369 } ,
321370 ) ;
322371
0 commit comments