Skip to content

Commit 313a3b2

Browse files
committed
Allow mounting extra volumes into NiFi pods that processors may depend on (#434)
# Description Add option to specify extra Volumes that will be mounted into the NiFi containern to allow providing files that processors may need. This could be certificates, scheml files, configuration files for services to connect to .... Co-authored-by: Sönke Liebau <soenke.liebau@stackable.de>
1 parent b0c9308 commit 313a3b2

File tree

7 files changed

+1147
-34
lines changed

7 files changed

+1147
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88

99
- Enabled logging and log aggregation ([#418])
1010
- Deploy default and support custom affinities ([#436]).
11+
- Added the ability to mount extra volumes for files that may be needed for NiFi processors to work ([#434])
1112

1213
### Changed
1314

@@ -17,6 +18,7 @@ All notable changes to this project will be documented in this file.
1718

1819
[#417]: https://github.com/stackabletech/nifi-operator/pull/417
1920
[#418]: https://github.com/stackabletech/nifi-operator/pull/418
21+
[#434]: https://github.com/stackabletech/nifi-operator/pull/434
2022
[#436]: https://github.com/stackabletech/nifi-operator/pull/436
2123

2224
## [23.1.0] - 2023-01-23

deploy/helm/nifi-operator/crds/crds.yaml

Lines changed: 1076 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
= Adding External Files to the NiFi Servers
2+
3+
Since Apache NiFi allows executing pretty much arbitrary workflows depending on which processors are used, it may become necessary to add external files to the pods.
4+
These could for example be client certificates used to configure a `PollHTTP` processor, a keytab to obtain a Kerberos ticket, or similar things.
5+
6+
In order to make these files available the operator allows specifying extra volumes that will be added to the NiFi pods.
7+
8+
[source,yaml]
9+
----
10+
spec:
11+
clusterConfig:
12+
extraVolumes:
13+
- name: nifi-client-certs
14+
secret:
15+
secretName: nifi-client-certs
16+
----
17+
18+
All `Volumes` specified in this section will be made available under `/stackable/userdata/{volumename}`.

docs/modules/nifi/partials/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* xref:nifi:usage_guide/index.adoc[]
77
** xref:nifi:usage_guide/security.adoc[]
88
** xref:nifi:usage_guide/resource-configuration.adoc[]
9+
** xref:nifi:usage_guide/extra_volumes.adoc[]
910
** xref:nifi:usage_guide/monitoring.adoc[]
1011
** xref:nifi:usage_guide/log-aggregation.adoc[]
1112
** xref:nifi:usage_guide/configuration-environment-overrides.adoc[]

examples/simple-nifi-cluster.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
# Deploy a NiFi cluster, a user secret amd a ZooKeeper cluster and a respective
22
# ZNode `simple-nifi-znode` which will be referenced
3-
---
4-
apiVersion: zookeeper.stackable.tech/v1alpha1
5-
kind: ZookeeperCluster
6-
metadata:
7-
name: simple-zk
8-
spec:
9-
image:
10-
productVersion: 3.8.0
11-
stackableVersion: "23.4.0-rc1"
12-
servers:
13-
roleGroups:
14-
default:
15-
replicas: 3
3+
164
---
175
apiVersion: zookeeper.stackable.tech/v1alpha1
186
kind: ZookeeperZnode

rust/crd/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ pub mod affinity;
22
pub mod authentication;
33

44
use crate::authentication::NifiAuthenticationConfig;
5+
use std::collections::BTreeMap;
56

67
use affinity::get_affinity;
78
use serde::{Deserialize, Serialize};
89
use snafu::{OptionExt, ResultExt, Snafu};
10+
use stackable_operator::k8s_openapi::api::core::v1::Volume;
911
use stackable_operator::{
1012
commons::{
1113
affinity::StackableAffinity,
@@ -27,7 +29,6 @@ use stackable_operator::{
2729
role_utils::{Role, RoleGroup, RoleGroupRef},
2830
schemars::{self, JsonSchema},
2931
};
30-
use std::collections::BTreeMap;
3132

3233
pub const APP_NAME: &str = "nifi";
3334

@@ -90,7 +91,7 @@ pub struct NifiSpec {
9091
pub stopped: Option<bool>,
9192
}
9293

93-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
94+
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
9495
#[serde(rename_all = "camelCase")]
9596
pub struct NifiClusterConfig {
9697
/// A reference to a Secret containing username/password for the initial admin user
@@ -103,6 +104,11 @@ pub struct NifiClusterConfig {
103104
pub vector_aggregator_config_map_name: Option<String>,
104105
/// The reference to the ZooKeeper cluster
105106
pub zookeeper_config_map_name: String,
107+
/// Extra volumes to mount into every container, this can be useful to for example make client
108+
/// certificates, keytabs or similar things available to processors
109+
/// These volumes will be mounted below `/stackable/userdata/{volumename}`
110+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
111+
pub extra_volumes: Vec<Volume>,
106112
}
107113

108114
#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]

rust/operator-binary/src/controller.rs

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
//! Ensures that `Pod`s are configured and running for each [`NifiCluster`]
2-
use crate::config::{
3-
build_bootstrap_conf, build_nifi_properties, build_state_management_xml,
4-
validated_product_config, NifiRepository, NIFI_BOOTSTRAP_CONF, NIFI_PROPERTIES,
5-
NIFI_STATE_MANAGEMENT_XML,
2+
use std::{
3+
borrow::Cow,
4+
collections::{BTreeMap, HashMap},
5+
ops::Deref,
6+
sync::Arc,
7+
time::Duration,
68
};
7-
use crate::product_logging::{extend_role_group_config_map, resolve_vector_aggregator_address};
8-
use crate::{config, OPERATOR_NAME};
99

1010
use rand::{distributions::Alphanumeric, Rng};
1111
use snafu::{OptionExt, ResultExt, Snafu};
12-
use stackable_nifi_crd::{
13-
authentication::ResolvedAuthenticationMethod, Container, NifiCluster, NifiConfig,
14-
NifiConfigFragment, NifiRole, NifiStatus, APP_NAME, BALANCE_PORT, BALANCE_PORT_NAME,
15-
HTTPS_PORT, HTTPS_PORT_NAME, LOG_VOLUME_SIZE_IN_MIB, METRICS_PORT, METRICS_PORT_NAME,
16-
PROTOCOL_PORT, PROTOCOL_PORT_NAME, STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR,
17-
};
1812
use stackable_operator::{
1913
builder::{
2014
ConfigMapBuilder, ContainerBuilder, ObjectMetaBuilder, PodBuilder,
@@ -52,16 +46,24 @@ use stackable_operator::{
5246
},
5347
role_utils::{Role, RoleGroupRef},
5448
};
55-
use std::{
56-
borrow::Cow,
57-
collections::{BTreeMap, HashMap},
58-
ops::Deref,
59-
sync::Arc,
60-
time::Duration,
61-
};
6249
use strum::{EnumDiscriminants, IntoStaticStr};
6350
use tracing::Instrument;
6451

52+
use stackable_nifi_crd::{
53+
authentication::ResolvedAuthenticationMethod, Container, NifiCluster, NifiConfig,
54+
NifiConfigFragment, NifiRole, NifiStatus, APP_NAME, BALANCE_PORT, BALANCE_PORT_NAME,
55+
HTTPS_PORT, HTTPS_PORT_NAME, LOG_VOLUME_SIZE_IN_MIB, METRICS_PORT, METRICS_PORT_NAME,
56+
PROTOCOL_PORT, PROTOCOL_PORT_NAME, STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR,
57+
};
58+
59+
use crate::config::{
60+
build_bootstrap_conf, build_nifi_properties, build_state_management_xml,
61+
validated_product_config, NifiRepository, NIFI_BOOTSTRAP_CONF, NIFI_PROPERTIES,
62+
NIFI_STATE_MANAGEMENT_XML,
63+
};
64+
use crate::product_logging::{extend_role_group_config_map, resolve_vector_aggregator_address};
65+
use crate::{config, OPERATOR_NAME};
66+
6567
pub const CONTROLLER_NAME: &str = "nificluster";
6668

6769
const KEYSTORE_VOLUME_NAME: &str = "keystore";
@@ -629,6 +631,8 @@ fn build_node_rolegroup_service(
629631
})
630632
}
631633

634+
const USERDATA_MOUNTPOINT: &str = "/stackable/userdata";
635+
632636
/// The rolegroup [`StatefulSet`] runs the rolegroup, as configured by the administrator.
633637
///
634638
/// The [`Pod`](`stackable_operator::k8s_openapi::api::core::v1::Pod`)s are accessible through the
@@ -857,6 +861,24 @@ async fn build_node_rolegroup_statefulset(
857861
.resources(merged_config.resources.clone().into());
858862

859863
let mut pod_builder = PodBuilder::new();
864+
865+
// Add user configured extra volumes if any are specified
866+
for volume in &nifi.spec.cluster_config.extra_volumes {
867+
// Extract values into vars so we make it impossible to log something other than
868+
// what we actually use to create the mounts - maybe paranoid, but hey ..
869+
let volume_name = &volume.name;
870+
let mount_point = format!("{USERDATA_MOUNTPOINT}/{}", volume.name);
871+
872+
tracing::info!(
873+
?volume_name,
874+
?mount_point,
875+
?role,
876+
"Adding user specified extra volume",
877+
);
878+
pod_builder.add_volume(volume.clone());
879+
container_nifi.add_volume_mount(volume_name, mount_point);
880+
}
881+
860882
// We want to add nifi container first for easier defaulting into this container
861883
pod_builder.add_container(container_nifi.build());
862884

0 commit comments

Comments
 (0)