Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat: Support podOverrides #483

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
18 changes: 12 additions & 6 deletions rust/operator-binary/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -710,6 +711,8 @@ async fn build_node_rolegroup_statefulset(
sa_name: &str,
) -> Result<StatefulSet> {
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";

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -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(
Expand Down
28 changes: 0 additions & 28 deletions tests/templates/kuttl/resources/02-assert.yaml.2

This file was deleted.

73 changes: 73 additions & 0 deletions tests/templates/kuttl/resources/02-assert.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 600
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
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: 600m
memory: 3Gi
limits:
cpu: 1100m
memory: 3Gi
{% 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-pod-overrides
spec:
template:
spec:
containers:
- name: nifi
resources:
requests:
cpu: 700m
memory: 2Gi
limits:
cpu: 1200m
memory: 2Gi
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
- name: vector
{% endif %}
status:
readyReplicas: 1
replicas: 1
27 changes: 24 additions & 3 deletions tests/templates/kuttl/resources/02-install-nifi.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: nifi
resources:
requests:
cpu: 700m
limits:
cpu: 1200m
4 changes: 2 additions & 2 deletions tests/templates/kuttl/resources/03-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ 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
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