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 #368

Closed
wants to merge 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Generate OLM bundle for Release 23.4.0 ([#350]).
- Missing CRD defaults for `status.conditions` field ([#354]).
- Set explicit resources on all containers ([#359]).
- Support podOverrides ([#368]).

### Changed

Expand All @@ -27,6 +28,7 @@ All notable changes to this project will be documented in this file.
[#354]: https://github.com/stackabletech/hdfs-operator/pull/354
[#359]: https://github.com/stackabletech/hdfs-operator/pull/359
[#364]: https://github.com/stackabletech/hdfs-operator/pull/364
[#368]: https://github.com/stackabletech/hdfs-operator/pull/368

## [23.4.0] - 2023-04-17

Expand Down
43 changes: 42 additions & 1 deletion rust/crd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use stackable_operator::{
fragment::{Fragment, ValidationError},
merge::Merge,
},
k8s_openapi::apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::LabelSelector},
k8s_openapi::{
api::core::v1::PodTemplateSpec,
apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::LabelSelector},
},
kube::{runtime::reflector::ObjectRef, CustomResource, ResourceExt},
labels::role_group_selector_labels,
product_config::types::PropertyNameKind,
Expand Down Expand Up @@ -465,6 +468,44 @@ impl HdfsCluster {
.get(role_group)
}

pub fn pod_overrides_for_role(&self, role: &HdfsRole) -> Option<&PodTemplateSpec> {
match role {
HdfsRole::NameNode => self
.spec
.name_nodes
.as_ref()
.map(|n| &n.config.pod_overrides),
HdfsRole::DataNode => self
.spec
.data_nodes
.as_ref()
.map(|n| &n.config.pod_overrides),
HdfsRole::JournalNode => self
.spec
.journal_nodes
.as_ref()
.map(|n| &n.config.pod_overrides),
}
}

pub fn pod_overrides_for_role_group(
&self,
role: &HdfsRole,
role_group: &str,
) -> Option<&PodTemplateSpec> {
match role {
HdfsRole::NameNode => self
.namenode_rolegroup(role_group)
.map(|r| &r.config.pod_overrides),
HdfsRole::DataNode => self
.datanode_rolegroup(role_group)
.map(|r| &r.config.pod_overrides),
HdfsRole::JournalNode => self
.journalnode_rolegroup(role_group)
.map(|r| &r.config.pod_overrides),
}
}

pub fn rolegroup_ref(
&self,
role_name: impl Into<String>,
Expand Down
12 changes: 11 additions & 1 deletion rust/operator/src/hdfs_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use stackable_operator::{
core::v1::{ConfigMap, Service, ServicePort, ServiceSpec},
},
apimachinery::pkg::apis::meta::v1::LabelSelector,
DeepMerge,
},
kube::{
api::ObjectMeta,
Expand Down Expand Up @@ -620,6 +621,15 @@ fn rolegroup_statefulset(
)
.context(FailedToCreateContainerAndVolumeConfigurationSnafu)?;

let mut pod_template = pb.build_template();
if let Some(pod_overrides) = hdfs.pod_overrides_for_role(role) {
pod_template.merge_from(pod_overrides.clone());
}
if let Some(pod_overrides) = hdfs.pod_overrides_for_role_group(role, &rolegroup_ref.role_group)
{
pod_template.merge_from(pod_overrides.clone());
}

Ok(StatefulSet {
metadata: ObjectMetaBuilder::new()
.name_and_namespace(hdfs)
Expand Down Expand Up @@ -649,7 +659,7 @@ fn rolegroup_statefulset(
..LabelSelector::default()
},
service_name: object_name,
template: pb.build_template(),
template: pod_template,

volume_claim_templates: ContainerConfig::volume_claim_templates(role, merged_config),
..StatefulSetSpec::default()
Expand Down
46 changes: 46 additions & 0 deletions tests/templates/kuttl/smoke/30-assert.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: hdfs-namenode-default
spec:
template:
spec:
containers:
- name: namenode
resources:
requests:
cpu: 250m # From defaults
memory: 1Gi
limits:
cpu: "1" # From defaults
memory: 1Gi
- name: zkfc
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
- name: vector
{% endif %}
status:
readyReplicas: 2
replicas: 2
Expand All @@ -15,6 +31,21 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: hdfs-journalnode-default
spec:
template:
spec:
containers:
- name: journalnode
resources:
requests:
cpu: 110m # From podOverrides
memory: 512Mi
limits:
cpu: 410m # From podOverrides
memory: 512Mi
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
- name: vector
{% endif %}
status:
readyReplicas: 1
replicas: 1
Expand All @@ -23,6 +54,21 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: hdfs-datanode-default
spec:
template:
spec:
containers:
- name: datanode
resources:
requests:
cpu: 100m # From defaults
memory: 512Mi
limits:
cpu: 400m # From defaults
memory: 512Mi
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
- name: vector
{% endif %}
status:
readyReplicas: {{ test_scenario['values']['number-of-datanodes'] }}
replicas: {{ test_scenario['values']['number-of-datanodes'] }}
Expand Down
9 changes: 9 additions & 0 deletions tests/templates/kuttl/smoke/30-install-hdfs.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ spec:
roleGroups:
default:
replicas: 1
podOverrides:
spec:
containers:
- name: journalnode
resources:
requests:
cpu: 110m
limits:
cpu: 410m