Skip to content

Commit 190ca21

Browse files
committed
move listenerClass to roleConfig
1 parent 41819bb commit 190ca21

30 files changed

Lines changed: 191 additions & 194 deletions

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,6 @@ spec:
362362
description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details.
363363
nullable: true
364364
type: string
365-
listenerClass:
366-
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose the nodes.
367-
nullable: true
368-
type: string
369365
logging:
370366
default:
371367
containers: {}
@@ -780,11 +776,15 @@ spec:
780776
x-kubernetes-preserve-unknown-fields: true
781777
roleConfig:
782778
default:
779+
listenerClass: cluster-internal
783780
podDisruptionBudget:
784781
enabled: true
785782
maxUnavailable: null
786783
description: This is a product-agnostic RoleConfig, which is sufficient for most of the products.
787784
properties:
785+
listenerClass:
786+
default: cluster-internal
787+
type: string
788788
podDisruptionBudget:
789789
default:
790790
enabled: true
@@ -853,10 +853,6 @@ spec:
853853
description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details.
854854
nullable: true
855855
type: string
856-
listenerClass:
857-
description: This field controls which [ListenerClass](https://docs.stackable.tech/home/nightly/listener-operator/listenerclass.html) is used to expose the nodes.
858-
nullable: true
859-
type: string
860856
logging:
861857
default:
862858
containers: {}

docs/modules/nifi/examples/getting_started/getting_started.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ spec:
148148
autoGenerate: true
149149
zookeeperConfigMapName: simple-nifi-znode
150150
nodes:
151-
config:
151+
roleConfig:
152152
listenerClass: external-unstable
153153
roleGroups:
154154
default:

docs/modules/nifi/examples/getting_started/getting_started.sh.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ spec:
148148
autoGenerate: true
149149
zookeeperConfigMapName: simple-nifi-znode
150150
nodes:
151-
config:
151+
roleConfig:
152152
listenerClass: external-unstable
153153
roleGroups:
154154
default:

docs/modules/nifi/pages/usage_guide/custom-components.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ spec:
167167
autoGenerate: true
168168
zookeeperConfigMapName: simple-nifi-znode
169169
nodes:
170-
config:
170+
roleConfig:
171171
listenerClass: external-unstable
172172
configOverrides:
173173
nifi.properties:
@@ -287,7 +287,7 @@ spec:
287287
autoGenerate: true
288288
zookeeperConfigMapName: simple-nifi-znode
289289
nodes:
290-
config:
290+
roleConfig:
291291
listenerClass: external-unstable
292292
configOverrides:
293293
nifi.properties:

docs/modules/nifi/pages/usage_guide/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ spec:
3030
keySecret: nifi-sensitive-property-key
3131
autoGenerate: true
3232
nodes:
33-
config:
33+
roleConfig:
3434
listenerClass: external-unstable
3535
roleGroups:
3636
default:

docs/modules/nifi/pages/usage_guide/listenerclass.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
:description: Configure Apache NiFi service exposure with cluster-internal or external-unstable listener classes.
33

44
The operator deploys a xref:listener-operator:listener.adoc[Listener] for the Node pod.
5-
The listener defaults to only being accessible from within the Kubernetes cluster, but this can be changed by setting `.spec.nodes.config.listenerClass`:
5+
The listener defaults to only being accessible from within the Kubernetes cluster, but this can be changed by setting `.spec.nodes.roleConfig.listenerClass`:
66

77
[source,yaml]
88
----
99
spec:
1010
nodes:
11-
config:
11+
roleConfig:
1212
listenerClass: external-unstable # <1>
1313
----
1414
<1> Specify one of `external-stable`, `external-unstable`, `cluster-internal` (the default setting is `cluster-internal`).

examples/simple-nifi-cluster.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ spec:
5656
autoGenerate: true
5757
zookeeperConfigMapName: simple-nifi-znode
5858
nodes:
59-
config:
59+
roleConfig:
6060
listenerClass: external-unstable
6161
roleGroups:
6262
default:

rust/operator-binary/src/config/jvm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use snafu::{OptionExt, ResultExt, Snafu};
22
use stackable_operator::{
33
memory::{BinaryMultiple, MemoryQuantity},
4-
role_utils::{self, GenericRoleConfig, JavaCommonConfig, JvmArgumentOverrides, Role},
4+
role_utils::{self, JavaCommonConfig, JvmArgumentOverrides, Role},
55
};
66

77
use crate::{
88
config::{JVM_SECURITY_PROPERTIES_FILE, NIFI_CONFIG_DIRECTORY},
9-
crd::{NifiConfig, NifiConfigFragment},
9+
crd::{NifiConfig, NifiConfigFragment, NifiNodeRoleConfig},
1010
};
1111

1212
// Part of memory resources allocated for Java heap
@@ -29,7 +29,7 @@ pub enum Error {
2929
/// Create the NiFi bootstrap.conf
3030
pub fn build_merged_jvm_config(
3131
merged_config: &NifiConfig,
32-
role: &Role<NifiConfigFragment, GenericRoleConfig, JavaCommonConfig>,
32+
role: &Role<NifiConfigFragment, NifiNodeRoleConfig, JavaCommonConfig>,
3333
role_group: &str,
3434
) -> Result<JvmArgumentOverrides, Error> {
3535
let heap_size = MemoryQuantity::try_from(

rust/operator-binary/src/config/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ use stackable_operator::{
1414
ValidatedRoleConfigByPropertyKind, transform_all_roles_to_config,
1515
validate_all_roles_and_groups_config,
1616
},
17-
role_utils::{GenericRoleConfig, JavaCommonConfig, Role},
17+
role_utils::{JavaCommonConfig, Role},
1818
};
1919
use strum::{Display, EnumIter};
2020

2121
use crate::{
2222
crd::{
23-
HTTPS_PORT, NifiConfig, NifiConfigFragment, NifiRole, NifiStorageConfig, PROTOCOL_PORT,
24-
sensitive_properties, v1alpha1, v1alpha1::NifiClusteringBackend,
23+
HTTPS_PORT, NifiConfig, NifiConfigFragment, NifiNodeRoleConfig, NifiRole,
24+
NifiStorageConfig, PROTOCOL_PORT, sensitive_properties,
25+
v1alpha1::{self, NifiClusteringBackend},
2526
},
2627
operations::graceful_shutdown::graceful_shutdown_config_properties,
2728
security::{
@@ -112,7 +113,7 @@ pub enum Error {
112113
pub fn build_bootstrap_conf(
113114
merged_config: &NifiConfig,
114115
overrides: BTreeMap<String, String>,
115-
role: &Role<NifiConfigFragment, GenericRoleConfig, JavaCommonConfig>,
116+
role: &Role<NifiConfigFragment, NifiNodeRoleConfig, JavaCommonConfig>,
116117
role_group: &str,
117118
) -> Result<String, Error> {
118119
let mut bootstrap = BTreeMap::new();
@@ -736,7 +737,7 @@ pub fn build_state_management_xml(clustering_backend: &NifiClusteringBackend) ->
736737
pub fn validated_product_config(
737738
resource: &v1alpha1::NifiCluster,
738739
version: &str,
739-
role: &Role<NifiConfigFragment, GenericRoleConfig, JavaCommonConfig>,
740+
role: &Role<NifiConfigFragment, NifiNodeRoleConfig, JavaCommonConfig>,
740741
product_config: &ProductConfigManager,
741742
) -> Result<ValidatedRoleConfigByPropertyKind, Error> {
742743
let mut roles = HashMap::new();

rust/operator-binary/src/controller.rs

Lines changed: 34 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,13 @@ use stackable_operator::{
2424
container::ContainerBuilder,
2525
resources::ResourceRequirementsBuilder,
2626
security::PodSecurityContextBuilder,
27-
volume::{
28-
ListenerOperatorVolumeSourceBuilder, ListenerOperatorVolumeSourceBuilderError,
29-
ListenerReference, SecretFormat,
30-
},
27+
volume::{ListenerOperatorVolumeSourceBuilderError, SecretFormat},
3128
},
3229
},
3330
client::Client,
3431
cluster_resources::{ClusterResourceApplyStrategy, ClusterResources},
3532
commons::{product_image_selection::ResolvedProductImage, rbac::build_rbac_resources},
36-
crd::{
37-
authentication::oidc::v1alpha1::AuthenticationProvider,
38-
git_sync,
39-
listener::v1alpha1::{Listener, ListenerPort, ListenerSpec},
40-
},
33+
crd::{authentication::oidc::v1alpha1::AuthenticationProvider, git_sync},
4134
k8s_openapi::{
4235
DeepMerge,
4336
api::{
@@ -91,10 +84,11 @@ use crate::{
9184
crd::{
9285
APP_NAME, BALANCE_PORT, BALANCE_PORT_NAME, Container, HTTPS_PORT, HTTPS_PORT_NAME,
9386
LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME, METRICS_PORT, METRICS_PORT_NAME, NifiConfig,
94-
NifiConfigFragment, NifiRole, NifiStatus, PROTOCOL_PORT, PROTOCOL_PORT_NAME,
95-
STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR, authentication::AuthenticationClassResolved,
96-
v1alpha1,
87+
NifiConfigFragment, NifiNodeRoleConfig, NifiRole, NifiStatus, PROTOCOL_PORT,
88+
PROTOCOL_PORT_NAME, STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR,
89+
authentication::AuthenticationClassResolved, v1alpha1,
9790
},
91+
listener::{build_group_listener, build_group_listener_pvc, group_listener_name},
9892
operations::{
9993
graceful_shutdown::add_graceful_shutdown_config,
10094
pdb::add_pdbs,
@@ -343,12 +337,13 @@ pub enum Error {
343337
BuildListenerVolume {
344338
source: ListenerOperatorVolumeSourceBuilderError,
345339
},
346-
347-
#[snafu(display("failed to apply group listener for {rolegroup}"))]
340+
#[snafu(display("failed to apply group listener"))]
348341
ApplyGroupListener {
349342
source: stackable_operator::cluster_resources::Error,
350-
rolegroup: RoleGroupRef<v1alpha1::NifiCluster>,
351343
},
344+
345+
#[snafu(display("failed to configure listener"))]
346+
ListenerConfiguration { source: crate::listener::Error },
352347
}
353348

354349
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -542,19 +537,6 @@ pub async fn reconcile_nifi(
542537
)
543538
.await?;
544539

545-
let rg_group_listener = build_group_listener(
546-
nifi,
547-
&resolved_product_image,
548-
&rolegroup,
549-
merged_config.listener_class,
550-
)?;
551-
552-
cluster_resources
553-
.add(client, rg_group_listener)
554-
.await
555-
.with_context(|_| ApplyGroupListenerSnafu {
556-
rolegroup: rolegroup.clone(),
557-
})?;
558540
cluster_resources
559541
.add(client, rg_service)
560542
.await
@@ -583,13 +565,29 @@ pub async fn reconcile_nifi(
583565
}
584566

585567
let role_config = nifi.role_config(&nifi_role);
586-
if let Some(GenericRoleConfig {
587-
pod_disruption_budget: pdb,
568+
if let Some(NifiNodeRoleConfig {
569+
common: GenericRoleConfig {
570+
pod_disruption_budget: pdb,
571+
},
572+
listener_class,
588573
}) = role_config
589574
{
590575
add_pdbs(pdb, nifi, &nifi_role, client, &mut cluster_resources)
591576
.await
592577
.context(FailedToCreatePdbSnafu)?;
578+
579+
let role_group_listener = build_group_listener(
580+
nifi,
581+
build_recommended_labels(nifi, NIFI_CONTROLLER_NAME, "node", "none"),
582+
listener_class.to_owned(),
583+
group_listener_name(nifi),
584+
)
585+
.context(ListenerConfigurationSnafu)?;
586+
587+
cluster_resources
588+
.add(client, role_group_listener)
589+
.await
590+
.with_context(|_| ApplyGroupListenerSnafu)?;
593591
}
594592

595593
// Only add the reporting task in case it is enabled.
@@ -662,7 +660,7 @@ async fn build_node_rolegroup_config_map(
662660
resolved_product_image: &ResolvedProductImage,
663661
authentication_config: &NifiAuthenticationConfig,
664662
authorization_config: &NifiAuthorizationConfig,
665-
role: &Role<NifiConfigFragment, GenericRoleConfig, JavaCommonConfig>,
663+
role: &Role<NifiConfigFragment, NifiNodeRoleConfig, JavaCommonConfig>,
666664
rolegroup: &RoleGroupRef<v1alpha1::NifiCluster>,
667665
rolegroup_config: &HashMap<PropertyNameKind, BTreeMap<String, String>>,
668666
merged_config: &NifiConfig,
@@ -837,49 +835,6 @@ fn build_node_rolegroup_service(
837835
Ok(service)
838836
}
839837

840-
pub fn build_group_listener(
841-
nifi: &v1alpha1::NifiCluster,
842-
resolved_product_image: &ResolvedProductImage,
843-
rolegroup: &RoleGroupRef<v1alpha1::NifiCluster>,
844-
listener_class: String,
845-
) -> Result<Listener> {
846-
let metadata = ObjectMetaBuilder::new()
847-
.name_and_namespace(nifi)
848-
.name(nifi.group_listener_name(rolegroup))
849-
.ownerreference_from_resource(nifi, None, Some(true))
850-
.context(ObjectMissingMetadataForOwnerRefSnafu)?
851-
.with_recommended_labels(build_recommended_labels(
852-
nifi,
853-
&resolved_product_image.app_version_label,
854-
&rolegroup.role,
855-
&rolegroup.role_group,
856-
))
857-
.context(MetadataBuildSnafu)?
858-
.build();
859-
860-
let spec = ListenerSpec {
861-
class_name: Some(listener_class),
862-
ports: Some(listener_ports()),
863-
..Default::default()
864-
};
865-
866-
let listener = Listener {
867-
metadata,
868-
spec,
869-
status: None,
870-
};
871-
872-
Ok(listener)
873-
}
874-
875-
fn listener_ports() -> Vec<ListenerPort> {
876-
vec![ListenerPort {
877-
name: HTTPS_PORT_NAME.to_owned(),
878-
port: HTTPS_PORT.into(),
879-
protocol: Some("TCP".to_owned()),
880-
}]
881-
}
882-
883838
const USERDATA_MOUNTPOINT: &str = "/stackable/userdata";
884839

885840
/// The rolegroup [`StatefulSet`] runs the rolegroup, as configured by the administrator.
@@ -892,7 +847,7 @@ async fn build_node_rolegroup_statefulset(
892847
resolved_product_image: &ResolvedProductImage,
893848
cluster_info: &KubernetesClusterInfo,
894849
rolegroup_ref: &RoleGroupRef<v1alpha1::NifiCluster>,
895-
role: &Role<NifiConfigFragment, GenericRoleConfig, JavaCommonConfig>,
850+
role: &Role<NifiConfigFragment, NifiNodeRoleConfig, JavaCommonConfig>,
896851
rolegroup_config: &HashMap<PropertyNameKind, BTreeMap<String, String>>,
897852
merged_config: &NifiConfig,
898853
authentication_config: &NifiAuthenticationConfig,
@@ -976,7 +931,7 @@ async fn build_node_rolegroup_statefulset(
976931
env_vars.extend(authorization_config.get_env_vars());
977932

978933
let node_address = format!(
979-
"$POD_NAME.{}-node-{}.{}.svc.{}",
934+
"$POD_NAME.{}-node-{}-metrics.{}.svc.{}",
980935
rolegroup_ref.cluster.name,
981936
rolegroup_ref.role_group,
982937
&nifi
@@ -1235,13 +1190,9 @@ async fn build_node_rolegroup_statefulset(
12351190
// listener endpoints will use persistent volumes
12361191
// so that load balancers can hard-code the target addresses and
12371192
// that it is possible to connect to a consistent address
1238-
let listener_pvc = ListenerOperatorVolumeSourceBuilder::new(
1239-
&ListenerReference::ListenerName(nifi.group_listener_name(rolegroup_ref)),
1240-
&unversioned_recommended_labels,
1241-
)
1242-
.context(BuildListenerVolumeSnafu)?
1243-
.build_pvc(LISTENER_VOLUME_NAME.to_owned())
1244-
.context(BuildListenerVolumeSnafu)?;
1193+
let listener_pvc =
1194+
build_group_listener_pvc(&group_listener_name(nifi), &unversioned_recommended_labels)
1195+
.context(ListenerConfigurationSnafu)?;
12451196

12461197
add_graceful_shutdown_config(merged_config, &mut pod_builder).context(GracefulShutdownSnafu)?;
12471198

0 commit comments

Comments
 (0)