@@ -16,7 +16,7 @@ use const_format::concatcp;
1616use snafu:: { ResultExt , Snafu } ;
1717use stackable_operator:: {
1818 cli:: OperatorEnvironmentOptions ,
19- cluster_resources:: { ClusterResourceApplyStrategy , ClusterResources } ,
19+ cluster_resources:: ClusterResourceApplyStrategy ,
2020 commons:: {
2121 networking:: DomainName , product_image_selection:: ResolvedProductImage ,
2222 rbac:: build_rbac_resources,
@@ -38,6 +38,7 @@ use stackable_operator::{
3838 } ,
3939 v2:: {
4040 HasName , HasUid , NameIsValidLabelValue ,
41+ cluster_resources:: cluster_resources_new,
4142 kvp:: label:: { recommended_labels, role_group_selector} ,
4243 role_group_utils:: ResourceNames ,
4344 types:: {
@@ -63,7 +64,7 @@ use crate::{
6364 properties:: listener:: get_kafka_listener_config,
6465 resource:: {
6566 listener:: build_broker_rolegroup_bootstrap_listener,
66- pdb:: add_pdbs ,
67+ pdb:: build_pdb ,
6768 service:: { build_rolegroup_headless_service, build_rolegroup_metrics_service} ,
6869 statefulset:: {
6970 build_broker_rolegroup_statefulset, build_controller_rolegroup_statefulset,
@@ -314,17 +315,17 @@ impl NameIsValidLabelValue for ValidatedCluster {
314315}
315316
316317/// The product name (`kafka`) as a type-safe label value.
317- fn product_name ( ) -> ProductName {
318+ pub ( crate ) fn product_name ( ) -> ProductName {
318319 ProductName :: from_str ( APP_NAME ) . expect ( "'kafka' is a valid product name" )
319320}
320321
321322/// The operator name as a type-safe label value.
322- fn operator_name ( ) -> OperatorName {
323+ pub ( crate ) fn operator_name ( ) -> OperatorName {
323324 OperatorName :: from_str ( OPERATOR_NAME ) . expect ( "the operator name is a valid label value" )
324325}
325326
326327/// The controller name as a type-safe label value.
327- fn controller_name ( ) -> ControllerName {
328+ pub ( crate ) fn controller_name ( ) -> ControllerName {
328329 ControllerName :: from_str ( KAFKA_CONTROLLER_NAME )
329330 . expect ( "the controller name is a valid label value" )
330331}
@@ -461,11 +462,6 @@ pub enum Error {
461462 source : stackable_operator:: cluster_resources:: Error ,
462463 } ,
463464
464- #[ snafu( display( "failed to create cluster resources" ) ) ]
465- CreateClusterResources {
466- source : stackable_operator:: cluster_resources:: Error ,
467- } ,
468-
469465 #[ snafu( display( "failed to patch service account" ) ) ]
470466 ApplyServiceAccount {
471467 source : stackable_operator:: cluster_resources:: Error ,
@@ -486,9 +482,9 @@ pub enum Error {
486482 source : stackable_operator:: commons:: rbac:: Error ,
487483 } ,
488484
489- #[ snafu( display( "failed to create PodDisruptionBudget" ) ) ]
490- FailedToCreatePdb {
491- source : crate :: controller :: build :: resource :: pdb :: Error ,
485+ #[ snafu( display( "failed to apply PodDisruptionBudget" ) ) ]
486+ ApplyPdb {
487+ source : stackable_operator :: cluster_resources :: Error ,
492488 } ,
493489
494490 #[ snafu( display( "failed to get required Labels" ) ) ]
@@ -530,12 +526,11 @@ impl ReconcilerError for Error {
530526 Error :: BuildDiscoveryConfig { .. } => None ,
531527 Error :: ApplyDiscoveryConfig { .. } => None ,
532528 Error :: DeleteOrphans { .. } => None ,
533- Error :: CreateClusterResources { .. } => None ,
534529 Error :: ApplyServiceAccount { .. } => None ,
535530 Error :: ApplyRoleBinding { .. } => None ,
536531 Error :: ApplyStatus { .. } => None ,
537532 Error :: BuildRbacResources { .. } => None ,
538- Error :: FailedToCreatePdb { .. } => None ,
533+ Error :: ApplyPdb { .. } => None ,
539534 Error :: GetRequiredLabels { .. } => None ,
540535 Error :: InvalidKafkaCluster { .. } => None ,
541536 Error :: BuildStatefulset { .. } => None ,
@@ -568,15 +563,16 @@ pub async fn reconcile_kafka(
568563 validate:: validate ( kafka, dereferenced_objects, & ctx. operator_environment )
569564 . context ( ValidateClusterSnafu ) ?;
570565
571- let mut cluster_resources = ClusterResources :: new (
572- APP_NAME ,
573- OPERATOR_NAME ,
574- KAFKA_CONTROLLER_NAME ,
575- & validated_cluster. object_ref ( & ( ) ) ,
566+ let mut cluster_resources = cluster_resources_new (
567+ & product_name ( ) ,
568+ & operator_name ( ) ,
569+ & controller_name ( ) ,
570+ & validated_cluster. name ,
571+ & validated_cluster. namespace ,
572+ & validated_cluster. uid ,
576573 ClusterResourceApplyStrategy :: from ( & kafka. spec . cluster_operation ) ,
577574 & kafka. spec . object_overrides ,
578- )
579- . context ( CreateClusterResourcesSnafu ) ?;
575+ ) ;
580576
581577 tracing:: debug!(
582578 kerberos_enabled = validated_cluster. cluster_config. kafka_security. has_kerberos_enabled( ) ,
@@ -718,10 +714,12 @@ pub async fn reconcile_kafka(
718714 if let Some ( GenericRoleConfig {
719715 pod_disruption_budget : pdb,
720716 } ) = role_cfg
717+ && let Some ( pdb) = build_pdb ( pdb, & validated_cluster, kafka_role)
721718 {
722- add_pdbs ( pdb, kafka, kafka_role, client, & mut cluster_resources)
719+ cluster_resources
720+ . add ( client, pdb)
723721 . await
724- . context ( FailedToCreatePdbSnafu ) ?;
722+ . context ( ApplyPdbSnafu ) ?;
725723 }
726724 }
727725
0 commit comments