From 574609155ecad4ddf4ecdff599c33022260c0cb4 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Wed, 5 Jul 2023 12:29:02 +0200 Subject: [PATCH 1/5] feat: Support podOverrides --- rust/operator-binary/src/controller.rs | 18 +++-- .../kuttl/resources/02-assert.yaml.2 | 69 +++++++++++++++---- .../kuttl/resources/02-install-nifi.yaml.j2 | 27 +++++++- 3 files changed, 93 insertions(+), 21 deletions(-) diff --git a/rust/operator-binary/src/controller.rs b/rust/operator-binary/src/controller.rs index d210617d..4ebf1ce8 100644 --- a/rust/operator-binary/src/controller.rs +++ b/rust/operator-binary/src/controller.rs @@ -32,6 +32,7 @@ use stackable_operator::{ apimachinery::pkg::{ api::resource::Quantity, apis::meta::v1::LabelSelector, util::intstr::IntOrString, }, + DeepMerge, }, kube::{ api::ListParams, runtime::controller::Action, runtime::reflector::ObjectRef, Resource, @@ -710,6 +711,8 @@ async fn build_node_rolegroup_statefulset( sa_name: &str, ) -> Result { tracing::debug!("Building statefulset"); + let role_group = role.role_groups.get(&rolegroup_ref.role_group); + let zookeeper_host = "ZOOKEEPER_HOSTS"; let zookeeper_chroot = "ZOOKEEPER_CHROOT"; @@ -750,8 +753,6 @@ async fn build_node_rolegroup_statefulset( &nifi.spec.cluster_config.zookeeper_config_map_name, )); - let rolegroup = role.role_groups.get(&rolegroup_ref.role_group); - let node_address = format!( "$POD_NAME.{}-node-{}.{}.svc.cluster.local", rolegroup_ref.cluster.name, @@ -997,7 +998,7 @@ async fn build_node_rolegroup_statefulset( vec![&mut container_prepare, container_nifi], ); - let pod_template = pod_builder + pod_builder .metadata_builder(|m| { m.with_recommended_labels(build_recommended_labels( nifi, @@ -1063,8 +1064,7 @@ async fn build_node_rolegroup_statefulset( .run_as_group(0) .fs_group(1000) .build(), - ) - .build_template(); + ); let mut labels = BTreeMap::new(); labels.insert( @@ -1076,6 +1076,12 @@ async fn build_node_rolegroup_statefulset( .to_string(), ); + let mut pod_template = pod_builder.build_template(); + pod_template.merge_from(role.config.pod_overrides.clone()); + if let Some(role_group) = role_group { + pod_template.merge_from(role_group.config.pod_overrides.clone()); + } + Ok(StatefulSet { metadata: ObjectMetaBuilder::new() .name_and_namespace(nifi) @@ -1094,7 +1100,7 @@ async fn build_node_rolegroup_statefulset( replicas: if version_change_state == &VersionChangeState::BeginChange { Some(0) } else { - rolegroup.and_then(|rg| rg.replicas).map(i32::from) + role_group.and_then(|rg| rg.replicas).map(i32::from) }, selector: LabelSelector { match_labels: Some(role_group_selector_labels( diff --git a/tests/templates/kuttl/resources/02-assert.yaml.2 b/tests/templates/kuttl/resources/02-assert.yaml.2 index e3f32f65..654367d6 100644 --- a/tests/templates/kuttl/resources/02-assert.yaml.2 +++ b/tests/templates/kuttl/resources/02-assert.yaml.2 @@ -6,23 +6,68 @@ timeout: 600 apiVersion: apps/v1 kind: StatefulSet metadata: - name: test-nifi-node-default + name: test-nifi-node-resources-from-role +spec: + template: + spec: + containers: + - name: nifi + resources: + requests: + cpu: 500m + memory: 2Gi + limits: + cpu: "1" + memory: 2Gi +{% if lookup('env', 'VECTOR_AGGREGATOR') %} + - name: vector +{% endif %} +status: + readyReplicas: 1 + replicas: 1 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-nifi-node-resources-from-role-group +spec: + template: + spec: + containers: + - name: nifi + resources: + requests: + cpu: 500m + memory: 3Gi + limits: + cpu: "1" + memory: 3Gi +{% if lookup('env', 'VECTOR_AGGREGATOR') %} + - name: vector +{% endif %} status: readyReplicas: 1 replicas: 1 --- -apiVersion: v1 -kind: Pod +apiVersion: apps/v1 +kind: StatefulSet metadata: - name: test-nifi-node-default-0 + name: test-nifi-node-resources-from-pod-overrides spec: - containers: - - name: nifi - resources: - limits: - memory: 2Gi - requests: - memory: 2Gi + template: + spec: + containers: + - name: nifi + resources: + requests: + cpu: 600m + memory: 2Gi + limits: + cpu: 1100m + memory: 2Gi {% if lookup('env', 'VECTOR_AGGREGATOR') %} - - name: vector + - name: vector {% endif %} +status: + readyReplicas: 1 + replicas: 1 diff --git a/tests/templates/kuttl/resources/02-install-nifi.yaml.j2 b/tests/templates/kuttl/resources/02-install-nifi.yaml.j2 index 385e68a6..c64126cd 100644 --- a/tests/templates/kuttl/resources/02-install-nifi.yaml.j2 +++ b/tests/templates/kuttl/resources/02-install-nifi.yaml.j2 @@ -38,8 +38,11 @@ spec: logging: enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }} resources: + cpu: + min: 500m + max: "1" memory: - limit: "2Gi" + limit: 2Gi storage: flowfileRepo: capacity: 2Gi @@ -52,6 +55,24 @@ spec: stateRepo: capacity: 2Gi roleGroups: - default: - config: {} + resources-from-role: replicas: 1 + resources-from-role-group: + config: + resources: + cpu: + min: 600m + max: 1100m + memory: + limit: 3Gi + replicas: 1 + resources-from-pod-overrides: + podOverrides: + spec: + containers: + - name: hbase + resources: + requests: + cpu: 700m + limits: + cpu: 1200m From e41fd78aaa13fb2f013b727f619428f2bb781eee Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Wed, 5 Jul 2023 12:30:38 +0200 Subject: [PATCH 2/5] changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a985749..253d426c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ All notable changes to this project will be documented in this file. - Added support for NiFi versions 1.20.0 and 1.21.0 ([#464]). - Generate OLM bundle for Release 23.4.0 ([#467]). - Missing CRD defaults for `status.conditions` field ([#471]). -- Set explicit resources on all containers ([#476]) +- Set explicit resources on all containers ([#476]). +- Support podOverrides ([#483]). ### Changed @@ -31,6 +32,7 @@ All notable changes to this project will be documented in this file. [#471]: https://github.com/stackabletech/nifi-operator/pull/471 [#476]: https://github.com/stackabletech/nifi-operator/pull/476 [#480]: https://github.com/stackabletech/nifi-operator/pull/480 +[#483]: https://github.com/stackabletech/nifi-operator/pull/483 ## [23.4.0] - 2023-04-17 From daa3f8e23be0c89db73c51ffde2423297269a0b2 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Wed, 5 Jul 2023 12:34:04 +0200 Subject: [PATCH 3/5] Update test --- tests/templates/kuttl/resources/03-assert.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/templates/kuttl/resources/03-assert.yaml b/tests/templates/kuttl/resources/03-assert.yaml index 3f1c81d5..7a06b755 100644 --- a/tests/templates/kuttl/resources/03-assert.yaml +++ b/tests/templates/kuttl/resources/03-assert.yaml @@ -5,7 +5,7 @@ metadata: name: check-jvm-heap-args timeout: 600 commands: - - script: kubectl get cm -n $NAMESPACE test-nifi-node-default -o yaml | grep -E 'java.arg..=-Xmx1638m' | xargs test ! -z + - script: kubectl get cm -n $NAMESPACE test-nifi-node-resources-from-role -o yaml | grep -E 'java.arg..=-Xmx1638m' | xargs test ! -z --- apiVersion: kuttl.dev/v1beta1 kind: TestAssert @@ -13,4 +13,4 @@ metadata: name: check-jvm-heap-args timeout: 600 commands: - - script: kubectl get cm -n $NAMESPACE test-nifi-node-default -o yaml | grep -E 'java.arg..=-Xms1638m' | xargs test ! -z + - script: kubectl get cm -n $NAMESPACE test-nifi-node-resources-from-role-group -o yaml | grep -E 'java.arg..=-Xms2457m' | xargs test ! -z From 2c90312c114dbc27f3e131c152eebb1dd4688924 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Thu, 6 Jul 2023 10:11:11 +0200 Subject: [PATCH 4/5] Update tests/templates/kuttl/resources/02-install-nifi.yaml.j2 Co-authored-by: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> --- tests/templates/kuttl/resources/02-install-nifi.yaml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/templates/kuttl/resources/02-install-nifi.yaml.j2 b/tests/templates/kuttl/resources/02-install-nifi.yaml.j2 index c64126cd..457ae69e 100644 --- a/tests/templates/kuttl/resources/02-install-nifi.yaml.j2 +++ b/tests/templates/kuttl/resources/02-install-nifi.yaml.j2 @@ -70,7 +70,7 @@ spec: podOverrides: spec: containers: - - name: hbase + - name: nifi resources: requests: cpu: 700m From 33bbfc1c5cc32049620a57a52c8c20dfae9628cf Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Thu, 6 Jul 2023 10:21:35 +0200 Subject: [PATCH 5/5] fix test --- .../resources/{02-assert.yaml.2 => 02-assert.yaml.j2} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename tests/templates/kuttl/resources/{02-assert.yaml.2 => 02-assert.yaml.j2} (96%) diff --git a/tests/templates/kuttl/resources/02-assert.yaml.2 b/tests/templates/kuttl/resources/02-assert.yaml.j2 similarity index 96% rename from tests/templates/kuttl/resources/02-assert.yaml.2 rename to tests/templates/kuttl/resources/02-assert.yaml.j2 index 654367d6..122c4691 100644 --- a/tests/templates/kuttl/resources/02-assert.yaml.2 +++ b/tests/templates/kuttl/resources/02-assert.yaml.j2 @@ -37,10 +37,10 @@ spec: - name: nifi resources: requests: - cpu: 500m + cpu: 600m memory: 3Gi limits: - cpu: "1" + cpu: 1100m memory: 3Gi {% if lookup('env', 'VECTOR_AGGREGATOR') %} - name: vector @@ -60,10 +60,10 @@ spec: - name: nifi resources: requests: - cpu: 600m + cpu: 700m memory: 2Gi limits: - cpu: 1100m + cpu: 1200m memory: 2Gi {% if lookup('env', 'VECTOR_AGGREGATOR') %} - name: vector