From be8c4c8d17a69a6e279a105686ac9f005417f9df Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 24 Feb 2023 15:32:30 -0500 Subject: [PATCH] feat: Add support for `ReplicaSet` without duplicating whats created by `Deployment` --- eksup/src/k8s/resources.rs | 41 +++++++++++++++------------- examples/test-mixed_v1.24_upgrade.md | 5 ++++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/eksup/src/k8s/resources.rs b/eksup/src/k8s/resources.rs index 5aaddc6..973d3d5 100644 --- a/eksup/src/k8s/resources.rs +++ b/eksup/src/k8s/resources.rs @@ -100,32 +100,35 @@ async fn get_deployments(client: &Client) -> Result> { Ok(deployments) } -async fn _get_replicasets(client: &Client) -> Result> { +async fn get_replicasets(client: &Client) -> Result> { let api: Api = Api::all(client.to_owned()); let replicaset_list = api.list(&Default::default()).await?; let replicasets = replicaset_list .items .iter() - .map(|repl| { - let objmeta = repl.metadata.clone(); - let spec = repl.spec.clone().unwrap(); + .filter_map(|repl| match repl.metadata.owner_references { + None => { + let objmeta = repl.metadata.clone(); + let spec = repl.spec.clone().unwrap(); - let metadata = StdMetadata { - name: objmeta.name.unwrap(), - namespace: objmeta.namespace.unwrap(), - kind: Kind::ReplicaSet, - labels: objmeta.labels.unwrap_or_default(), - annotations: objmeta.annotations.unwrap_or_default(), - }; + let metadata = StdMetadata { + name: objmeta.name.unwrap(), + namespace: objmeta.namespace.unwrap(), + kind: Kind::ReplicaSet, + labels: objmeta.labels.unwrap_or_default(), + annotations: objmeta.annotations.unwrap_or_default(), + }; - let spec = StdSpec { - min_ready_seconds: spec.min_ready_seconds, - replicas: spec.replicas, - template: spec.template, - }; + let spec = StdSpec { + min_ready_seconds: spec.min_ready_seconds, + replicas: spec.replicas, + template: spec.template, + }; - StdResource { metadata, spec } + Some(StdResource { metadata, spec }) + } + Some(_) => None, }) .collect(); @@ -587,7 +590,7 @@ pub async fn get_resources(client: &Client) -> Result> { let daemonsets = get_daemonsets(client).await?; let deployments = get_deployments(client).await?; let jobs = get_jobs(client).await?; - // let replicasets = get_replicasets(client).await?; + let replicasets = get_replicasets(client).await?; let statefulsets = get_statefulsets(client).await?; let mut resources = Vec::new(); @@ -595,7 +598,7 @@ pub async fn get_resources(client: &Client) -> Result> { resources.extend(daemonsets); resources.extend(deployments); resources.extend(jobs); - // resources.extend(replicasets); + resources.extend(replicasets); resources.extend(statefulsets); Ok(resources) diff --git a/examples/test-mixed_v1.24_upgrade.md b/examples/test-mixed_v1.24_upgrade.md index dd16f34..673ffc2 100644 --- a/examples/test-mixed_v1.24_upgrade.md +++ b/examples/test-mixed_v1.24_upgrade.md @@ -215,6 +215,7 @@ When upgrading the control plane, Amazon EKS performs standard infrastructure an |----|---------|-------------|-------------|----------| | ❌ | bad-dpl | deployment | Deployment | 1 | | ❌ | coredns | kube-system | Deployment | 2 | + | ❌ | bad-rs | replicaset | ReplicaSet | 1 | | ❌ | bad-ss | statefulset | StatefulSet | 1 | @@ -223,6 +224,7 @@ When upgrading the control plane, Amazon EKS performs standard infrastructure an |----|---------|-------------|-------------|---------| | ⚠️ | bad-dpl | deployment | Deployment | 0 | | ⚠️ | coredns | kube-system | Deployment | 0 | + | ⚠️ | bad-rs | replicaset | ReplicaSet | 0 | | ❌ | bad-ss | statefulset | StatefulSet | 0 | @@ -233,6 +235,7 @@ When upgrading the control plane, Amazon EKS performs standard infrastructure an | | NAME | NAMESPACE | KIND | ANTIAFFINITY | TOPOLOGYSPREADCONSTRAINTS | |----|---------|-------------|-------------|--------------|---------------------------| | ❌ | bad-dpl | deployment | Deployment | false | false | + | ❌ | bad-rs | replicaset | ReplicaSet | false | false | | ❌ | bad-ss | statefulset | StatefulSet | false | false | @@ -240,6 +243,7 @@ When upgrading the control plane, Amazon EKS performs standard infrastructure an | | NAME | NAMESPACE | KIND | READINESS PROBE | |----|---------|-------------|-------------|-----------------| | ❌ | bad-dpl | deployment | Deployment | false | + | ❌ | bad-rs | replicaset | ReplicaSet | false | | ❌ | bad-ss | statefulset | StatefulSet | false | @@ -257,6 +261,7 @@ When upgrading the control plane, Amazon EKS performs standard infrastructure an | ❌ | aws-node | kube-system | DaemonSet | true | | ❌ | bad-dpl | deployment | Deployment | true | | ❌ | bad-job | job | Job | true | + | ❌ | bad-rs | replicaset | ReplicaSet | true | | ❌ | bad-ss | statefulset | StatefulSet | true |