kube-client 4.0.0

Kubernetes client
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
use super::parse::{self, GroupVersionData};
use crate::{Client, Error, Result, error::DiscoveryError};
use k8s_openapi::apimachinery::pkg::apis::meta::v1::{APIGroup, APIVersions};
pub use kube_core::discovery::{ApiCapabilities, ApiResource};
use kube_core::{
    Version,
    discovery::v2::APIGroupDiscovery,
    gvk::{GroupVersion, GroupVersionKind, ParseGroupVersionError},
};
use std::{cmp::Reverse, collections::HashMap, iter::Iterator};

/// Describes one API groups collected resources and capabilities.
///
/// Each `ApiGroup` contains all data pinned to a each version.
/// In particular, one data set within the `ApiGroup` for `"apiregistration.k8s.io"`
/// is the subset pinned to `"v1"`; commonly referred to as `"apiregistration.k8s.io/v1"`.
///
/// If you know the version of the discovered group, you can fetch it directly:
/// ```no_run
/// use kube::{Client, api::{Api, DynamicObject}, discovery, ResourceExt};
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
///     let client = Client::try_default().await?;
///     let apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
///      for (apiresource, caps) in apigroup.versioned_resources("v1") {
///          println!("Found ApiResource {}", apiresource.kind);
///      }
///     Ok(())
/// }
/// ```
///
/// But if you do not know this information, you can use [`ApiGroup::preferred_version_or_latest`].
///
/// Whichever way you choose the end result is something describing a resource and its abilities:
/// - `Vec<(ApiResource, `ApiCapabilities)>` :: for all resources in a versioned ApiGroup
/// - `(ApiResource, ApiCapabilities)` :: for a single kind under a versioned ApiGroud
///
/// These two types: [`ApiResource`], and [`ApiCapabilities`]
/// should contain the information needed to construct an [`Api`](crate::Api) and start querying the kubernetes API.
/// You will likely need to use [`DynamicObject`] as the generic type for Api to do this,
/// as well as the [`ApiResource`] for the `DynamicType` for the [`Resource`] trait.
///
/// ```no_run
/// use kube::{Client, api::{Api, DynamicObject}, discovery, ResourceExt};
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
///     let client = Client::try_default().await?;
///     let apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
///     let (ar, caps) = apigroup.recommended_kind("APIService").unwrap();
///     let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
///     for service in api.list(&Default::default()).await? {
///         println!("Found APIService: {}", service.name_any());
///     }
///     Ok(())
/// }
/// ```
///
/// This type represents an abstraction over the native [`APIGroup`] to provide easier access to underlying group resources.
///
/// ### Common Pitfall
/// Version preference and recommendations shown herein is a **group concept**, not a resource-wide concept.
/// A common mistake is have different stored versions for resources within a group, and then receive confusing results from this module.
/// Resources in a shared group should share versions - and transition together - to minimize confusion.
/// See <https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-groups-and-versioning> for more info.
///
/// [`ApiResource`]: crate::discovery::ApiResource
/// [`ApiCapabilities`]: crate::discovery::ApiCapabilities
/// [`DynamicObject`]: crate::api::DynamicObject
/// [`Resource`]: crate::Resource
/// [`ApiGroup::preferred_version_or_latest`]: crate::discovery::ApiGroup::preferred_version_or_latest
/// [`ApiGroup::versioned_resources`]: crate::discovery::ApiGroup::versioned_resources
/// [`ApiGroup::recommended_resources`]: crate::discovery::ApiGroup::recommended_resources
/// [`ApiGroup::recommended_kind`]: crate::discovery::ApiGroup::recommended_kind
pub struct ApiGroup {
    /// Name of the group e.g. apiregistration.k8s.io
    name: String,
    /// List of resource information, capabilities at particular versions
    data: Vec<GroupVersionData>,
    /// Preferred version if exported by the `APIGroup`
    preferred: Option<String>,
}

/// Internal queriers to convert from an APIGroup (or APIVersions for core) to our ApiGroup
///
/// These queriers ignore groups with empty versions.
/// This ensures that `ApiGroup::preferred_version_or_latest` always have an answer.
/// On construction, they also sort the internal vec of GroupVersionData according to `Version`.
impl ApiGroup {
    pub(crate) async fn query_apis(client: &Client, g: APIGroup) -> Result<Self> {
        tracing::debug!(name = g.name.as_str(), "Listing group versions");
        let key = g.name;
        if g.versions.is_empty() {
            return Err(Error::Discovery(DiscoveryError::EmptyApiGroup(key)));
        }
        let mut data = vec![];
        for vers in &g.versions {
            let resources = client.list_api_group_resources(&vers.group_version).await?;
            data.push(GroupVersionData::new(vers.version.clone(), resources)?);
        }
        let mut group = ApiGroup {
            name: key,
            data,
            preferred: g.preferred_version.map(|v| v.version),
        };
        group.sort_versions();
        Ok(group)
    }

    pub(crate) async fn query_core(client: &Client, coreapis: APIVersions) -> Result<Self> {
        let mut data = vec![];
        let key = ApiGroup::CORE_GROUP.to_string();
        if coreapis.versions.is_empty() {
            return Err(Error::Discovery(DiscoveryError::EmptyApiGroup(key)));
        }
        for v in coreapis.versions {
            let resources = client.list_core_api_resources(&v).await?;
            data.push(GroupVersionData::new(v, resources)?);
        }
        let mut group = ApiGroup {
            name: ApiGroup::CORE_GROUP.to_string(),
            data,
            preferred: Some("v1".to_string()),
        };
        group.sort_versions();
        Ok(group)
    }

    /// Create an ApiGroup from aggregated discovery v2 types
    ///
    /// This is used by `Discovery::run_aggregated()` to convert the aggregated
    /// discovery response into the same format used by regular discovery.
    /// Takes ownership to avoid cloning internal data.
    pub(crate) fn from_v2(ag: APIGroupDiscovery) -> Result<Self> {
        let name = ag.metadata.and_then(|m| m.name).unwrap_or_default();

        if ag.versions.is_empty() {
            return Err(Error::Discovery(DiscoveryError::EmptyApiGroup(name)));
        }

        // Preferred version is the first one in the list (they're sorted by preference)
        let preferred = ag.versions.first().and_then(|v| v.version.clone());

        let data: Vec<GroupVersionData> = ag
            .versions
            .into_iter()
            .map(|ver| GroupVersionData::from_v2(&name, ver))
            .collect();

        let mut group = ApiGroup {
            name,
            data,
            preferred,
        };
        group.sort_versions();
        Ok(group)
    }

    fn sort_versions(&mut self) {
        self.data
            .sort_by_cached_key(|gvd| Reverse(Version::parse(gvd.version.as_str()).priority()))
    }

    // shortcut method to give cheapest return for a single GVK
    pub(crate) async fn query_gvk(
        client: &Client,
        gvk: &GroupVersionKind,
    ) -> Result<(ApiResource, ApiCapabilities)> {
        let apiver = gvk.api_version();
        let list = if gvk.group.is_empty() {
            client.list_core_api_resources(&apiver).await?
        } else {
            client.list_api_group_resources(&apiver).await?
        };
        for res in &list.resources {
            if res.kind == gvk.kind && !res.name.contains('/') {
                let ar = parse::parse_apiresource(res, &list.group_version).map_err(
                    |ParseGroupVersionError(s)| Error::Discovery(DiscoveryError::InvalidGroupVersion(s)),
                )?;
                let caps = parse::parse_apicapabilities(&list, &res.name)?;
                return Ok((ar, caps));
            }
        }
        Err(Error::Discovery(DiscoveryError::MissingKind(format!("{gvk:?}"))))
    }

    // shortcut method to give cheapest return for a pinned group
    pub(crate) async fn query_gv(client: &Client, gv: &GroupVersion) -> Result<Self> {
        let apiver = gv.api_version();
        let list = if gv.group.is_empty() {
            client.list_core_api_resources(&apiver).await?
        } else {
            client.list_api_group_resources(&apiver).await?
        };
        let data = GroupVersionData::new(gv.version.clone(), list)?;
        let group = ApiGroup {
            name: gv.group.clone(),
            data: vec![data],
            preferred: Some(gv.version.clone()), // you preferred what you asked for
        };
        Ok(group)
    }
}

/// Public ApiGroup interface
impl ApiGroup {
    /// Core group name
    pub const CORE_GROUP: &'static str = "";

    /// Returns the name of this group.
    pub fn name(&self) -> &str {
        &self.name
    }

    /// Returns served versions (e.g. `["v1", "v2beta1"]`) of this group.
    ///
    /// This [`Iterator`] is never empty, and returns elements in descending order of [`Version`](kube_core::Version):
    /// - Stable versions (with the last being the first)
    /// - Beta versions (with the last being the first)
    /// - Alpha versions (with the last being the first)
    /// - Other versions, alphabetically
    pub fn versions(&self) -> impl Iterator<Item = &str> {
        self.data.as_slice().iter().map(|gvd| gvd.version.as_str())
    }

    /// Returns preferred version for working with given group.
    ///
    /// Please note the [ApiGroup Common Pitfall](ApiGroup#common-pitfall).
    pub fn preferred_version(&self) -> Option<&str> {
        self.preferred.as_deref()
    }

    /// Returns the preferred version or latest version for working with given group.
    ///
    /// If the server does not recommend a version, we pick the "most stable and most recent" version
    /// in accordance with [kubernetes version priority](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#version-priority)
    /// via the descending sort order from [`Version`](kube_core::Version).
    ///
    /// Please note the [ApiGroup Common Pitfall](ApiGroup#common-pitfall).
    pub fn preferred_version_or_latest(&self) -> &str {
        // NB: self.versions is non-empty by construction in ApiGroup
        self.preferred
            .as_deref()
            .unwrap_or_else(|| self.versions().next().unwrap())
    }

    /// Returns the resources in the group at an arbitrary version string.
    ///
    /// If the group does not support this version, the returned vector is empty.
    ///
    /// If you are looking for the api recommended list of resources, or just on particular kind
    /// consider [`ApiGroup::recommended_resources`] or [`ApiGroup::recommended_kind`] instead.
    pub fn versioned_resources(&self, ver: &str) -> Vec<(ApiResource, ApiCapabilities)> {
        self.data
            .iter()
            .find(|gvd| gvd.version == ver)
            .map(|gvd| gvd.resources.clone())
            .unwrap_or_default()
    }

    /// Returns the recommended (preferred or latest) versioned resources in the group
    ///
    /// ```no_run
    /// use kube::{Client, api::{Api, DynamicObject}, discovery::{self, verbs}, ResourceExt};
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let client = Client::try_default().await?;
    ///     let apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
    ///     for (ar, caps) in apigroup.recommended_resources() {
    ///         if !caps.supports_operation(verbs::LIST) {
    ///             continue;
    ///         }
    ///         let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
    ///         for inst in api.list(&Default::default()).await? {
    ///             println!("Found {}: {}", ar.kind, inst.name_any());
    ///         }
    ///     }
    ///     Ok(())
    /// }
    /// ```
    ///
    /// This is equivalent to taking the [`ApiGroup::versioned_resources`] at the [`ApiGroup::preferred_version_or_latest`].
    ///
    /// Please note the [ApiGroup Common Pitfall](ApiGroup#common-pitfall).
    pub fn recommended_resources(&self) -> Vec<(ApiResource, ApiCapabilities)> {
        let ver = self.preferred_version_or_latest();
        self.versioned_resources(ver)
    }

    ///  Returns all resources in the group at their the most stable respective version
    ///
    /// ```no_run
    /// use kube::{Client, api::{Api, DynamicObject}, discovery::{self, verbs}, ResourceExt};
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let client = Client::try_default().await?;
    ///     let apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
    ///     for (ar, caps) in apigroup.resources_by_stability() {
    ///         if !caps.supports_operation(verbs::LIST) {
    ///             continue;
    ///         }
    ///         let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
    ///         for inst in api.list(&Default::default()).await? {
    ///             println!("Found {}: {}", ar.kind, inst.name_any());
    ///         }
    ///     }
    ///     Ok(())
    /// }
    /// ```
    /// See an example in [examples/kubectl.rs](https://github.com/kube-rs/kube/blob/main/examples/kubectl.rs)
    pub fn resources_by_stability(&self) -> Vec<(ApiResource, ApiCapabilities)> {
        let mut lookup = HashMap::new();
        self.data.iter().for_each(|gvd| {
            gvd.resources.iter().for_each(|resource| {
                lookup
                    .entry(resource.0.kind.clone())
                    .or_insert_with(Vec::new)
                    .push(resource);
            })
        });
        lookup
            .into_values()
            .map(|mut v| {
                v.sort_by_cached_key(|(ar, _)| Reverse(Version::parse(ar.version.as_str()).priority()));
                v[0].to_owned()
            })
            .collect()
    }

    /// Returns the recommended version of the `kind` in the recommended resources (if found)
    ///
    /// ```no_run
    /// use kube::{Client, api::{Api, DynamicObject}, discovery, ResourceExt};
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
    ///     let client = Client::try_default().await?;
    ///     let apigroup = discovery::group(&client, "apiregistration.k8s.io").await?;
    ///     let (ar, caps) = apigroup.recommended_kind("APIService").unwrap();
    ///     let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
    ///     for service in api.list(&Default::default()).await? {
    ///         println!("Found APIService: {}", service.name_any());
    ///     }
    ///     Ok(())
    /// }
    /// ```
    ///
    /// This is equivalent to filtering the [`ApiGroup::versioned_resources`] at [`ApiGroup::preferred_version_or_latest`] against a chosen `kind`.
    pub fn recommended_kind(&self, kind: &str) -> Option<(ApiResource, ApiCapabilities)> {
        let ver = self.preferred_version_or_latest();
        for (ar, caps) in self.versioned_resources(ver) {
            if ar.kind == kind {
                return Some((ar, caps));
            }
        }
        None
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    use kube_core::discovery::{
        Scope,
        v2::{APIGroupDiscovery, APIResourceDiscovery, APIVersionDiscovery, GroupVersionKind},
    };

    fn make_v2_resource(resource: &str, kind: &str, scope: &str, verbs: Vec<&str>) -> APIResourceDiscovery {
        APIResourceDiscovery {
            resource: Some(resource.to_string()),
            response_kind: Some(GroupVersionKind {
                group: None,
                version: None,
                kind: Some(kind.to_string()),
            }),
            scope: Some(scope.to_string()),
            verbs: verbs.into_iter().map(String::from).collect(),
            ..Default::default()
        }
    }

    #[test]
    fn test_api_group_from_v2_apps() {
        let ag = APIGroupDiscovery {
            metadata: Some(ObjectMeta {
                name: Some("apps".to_string()),
                ..Default::default()
            }),
            versions: vec![APIVersionDiscovery {
                version: Some("v1".to_string()),
                resources: vec![
                    make_v2_resource("deployments", "Deployment", "Namespaced", vec![
                        "get", "list", "create",
                    ]),
                    make_v2_resource("replicasets", "ReplicaSet", "Namespaced", vec!["get", "list"]),
                ],
                freshness: Some("Current".to_string()),
            }],
        };

        let group = ApiGroup::from_v2(ag).unwrap();

        assert_eq!(group.name(), "apps");
        assert_eq!(group.preferred_version(), Some("v1"));
        assert_eq!(group.versions().collect::<Vec<_>>(), vec!["v1"]);

        let resources = group.recommended_resources();
        assert_eq!(resources.len(), 2);

        let (deploy_ar, deploy_caps) = group.recommended_kind("Deployment").unwrap();
        assert_eq!(deploy_ar.group, "apps");
        assert_eq!(deploy_ar.version, "v1");
        assert_eq!(deploy_ar.api_version, "apps/v1");
        assert_eq!(deploy_ar.kind, "Deployment");
        assert_eq!(deploy_caps.scope, Scope::Namespaced);
    }

    #[test]
    fn test_api_group_from_v2_core() {
        let ag = APIGroupDiscovery {
            metadata: Some(ObjectMeta {
                name: Some("".to_string()), // core group has empty name
                ..Default::default()
            }),
            versions: vec![APIVersionDiscovery {
                version: Some("v1".to_string()),
                resources: vec![
                    make_v2_resource("pods", "Pod", "Namespaced", vec!["get", "list", "watch"]),
                    make_v2_resource("nodes", "Node", "Cluster", vec!["get", "list"]),
                ],
                freshness: Some("Current".to_string()),
            }],
        };

        let group = ApiGroup::from_v2(ag).unwrap();

        assert_eq!(group.name(), "");
        assert_eq!(group.preferred_version(), Some("v1"));

        let (pod_ar, pod_caps) = group.recommended_kind("Pod").unwrap();
        assert_eq!(pod_ar.group, "");
        assert_eq!(pod_ar.api_version, "v1"); // core group: no prefix
        assert_eq!(pod_caps.scope, Scope::Namespaced);

        let (node_ar, node_caps) = group.recommended_kind("Node").unwrap();
        assert_eq!(node_ar.kind, "Node");
        assert_eq!(node_caps.scope, Scope::Cluster);
    }

    #[test]
    fn test_api_group_from_v2_multiple_versions() {
        // Use autoscaling group which has multiple major versions (v1, v2)
        // Major versions are never removed per deprecation policy Rule #4a
        let ag = APIGroupDiscovery {
            metadata: Some(ObjectMeta {
                name: Some("autoscaling".to_string()),
                ..Default::default()
            }),
            versions: vec![
                // First version is preferred
                APIVersionDiscovery {
                    version: Some("v2".to_string()),
                    resources: vec![make_v2_resource(
                        "horizontalpodautoscalers",
                        "HorizontalPodAutoscaler",
                        "Namespaced",
                        vec!["get", "list"],
                    )],
                    freshness: Some("Current".to_string()),
                },
                APIVersionDiscovery {
                    version: Some("v1".to_string()),
                    resources: vec![make_v2_resource(
                        "horizontalpodautoscalers",
                        "HorizontalPodAutoscaler",
                        "Namespaced",
                        vec!["get"],
                    )],
                    freshness: Some("Current".to_string()),
                },
            ],
        };

        let group = ApiGroup::from_v2(ag).unwrap();

        assert_eq!(group.name(), "autoscaling");
        assert_eq!(group.preferred_version(), Some("v2"));
        assert_eq!(group.versions().collect::<Vec<_>>(), vec!["v2", "v1"]);

        // Recommended should be v2
        let (ar, _) = group.recommended_kind("HorizontalPodAutoscaler").unwrap();
        assert_eq!(ar.version, "v2");

        // Can also get v1 explicitly
        let v1_resources = group.versioned_resources("v1");
        assert_eq!(v1_resources.len(), 1);
        assert_eq!(v1_resources[0].0.version, "v1");
    }

    #[test]
    fn test_api_group_from_v2_empty_versions_error() {
        let ag = APIGroupDiscovery {
            metadata: Some(ObjectMeta {
                name: Some("empty".to_string()),
                ..Default::default()
            }),
            versions: vec![], // empty!
        };

        let result = ApiGroup::from_v2(ag);
        assert!(result.is_err());
    }

    #[test]
    fn test_resources_by_stability() {
        let ac = ApiCapabilities {
            scope: Scope::Namespaced,
            subresources: vec![],
            operations: vec![],
        };

        let testlowversioncr_v1alpha1 = ApiResource {
            group: String::from("kube.rs"),
            version: String::from("v1alpha1"),
            kind: String::from("TestLowVersionCr"),
            api_version: String::from("kube.rs/v1alpha1"),
            plural: String::from("testlowversioncrs"),
        };

        let testcr_v1 = ApiResource {
            group: String::from("kube.rs"),
            version: String::from("v1"),
            kind: String::from("TestCr"),
            api_version: String::from("kube.rs/v1"),
            plural: String::from("testcrs"),
        };

        let testcr_v2alpha1 = ApiResource {
            group: String::from("kube.rs"),
            version: String::from("v2alpha1"),
            kind: String::from("TestCr"),
            api_version: String::from("kube.rs/v2alpha1"),
            plural: String::from("testcrs"),
        };

        let group = ApiGroup {
            name: "kube.rs".to_string(),
            data: vec![
                GroupVersionData {
                    version: "v1alpha1".to_string(),
                    resources: vec![(testlowversioncr_v1alpha1, ac.clone())],
                },
                GroupVersionData {
                    version: "v1".to_string(),
                    resources: vec![(testcr_v1, ac.clone())],
                },
                GroupVersionData {
                    version: "v2alpha1".to_string(),
                    resources: vec![(testcr_v2alpha1, ac)],
                },
            ],
            preferred: Some(String::from("v1")),
        };

        let resources = group.resources_by_stability();
        assert!(
            resources
                .iter()
                .any(|(ar, _)| ar.kind == "TestCr" && ar.version == "v1"),
            "wrong stable version"
        );
        assert!(
            resources
                .iter()
                .any(|(ar, _)| ar.kind == "TestLowVersionCr" && ar.version == "v1alpha1"),
            "lost low version resource"
        );
    }
}