1- use std:: { collections:: BTreeMap , str:: FromStr } ;
2-
31use databases:: MetadataDatabaseConnection ;
42use security:: AuthenticationConfig ;
53use serde:: { Deserialize , Serialize } ;
6- use snafu:: { OptionExt , ResultExt , Snafu } ;
4+ use snafu:: Snafu ;
75use stackable_operator:: {
86 commons:: {
97 affinity:: StackableAffinity ,
@@ -22,17 +20,16 @@ use stackable_operator::{
2220 crd:: s3,
2321 deep_merger:: ObjectOverrides ,
2422 k8s_openapi:: apimachinery:: pkg:: api:: resource:: Quantity ,
25- kube:: { CustomResource , ResourceExt , runtime:: reflector:: ObjectRef } ,
23+ kube:: { CustomResource , runtime:: reflector:: ObjectRef } ,
2624 product_logging:: { self , spec:: Logging } ,
2725 role_utils:: { GenericRoleConfig , Role , RoleGroup , RoleGroupRef } ,
2826 schemars:: { self , JsonSchema } ,
2927 shared:: time:: Duration ,
3028 status:: condition:: { ClusterCondition , HasStatusCondition } ,
31- utils:: cluster_info:: KubernetesClusterInfo ,
3229 v2:: { config_overrides:: KeyValueConfigOverrides , role_utils:: JavaCommonConfig } ,
3330 versioned:: versioned,
3431} ;
35- use strum:: { Display , EnumIter , EnumString , IntoEnumIterator } ;
32+ use strum:: { Display , EnumIter , EnumString } ;
3633use v1alpha1:: HiveMetastoreRoleConfig ;
3734
3835use crate :: { crd:: affinity:: get_affinity, listener:: metastore_default_listener_class} ;
@@ -83,16 +80,6 @@ pub enum Error {
8380
8481 #[ snafu( display( "the role {role} is not defined" ) ) ]
8582 CannotRetrieveHiveRole { role : String } ,
86-
87- #[ snafu( display( "the role group {role_group} is not defined" ) ) ]
88- CannotRetrieveHiveRoleGroup { role_group : String } ,
89-
90- #[ snafu( display( "unknown role {role}. Should be one of {roles:?}" ) ) ]
91- UnknownHiveRole {
92- source : strum:: ParseError ,
93- role : String ,
94- roles : Vec < String > ,
95- } ,
9683}
9784
9885#[ versioned(
@@ -221,65 +208,6 @@ impl v1alpha1::HiveCluster {
221208 }
222209 }
223210
224- /// List all pods expected to form the cluster
225- ///
226- /// We try to predict the pods here rather than looking at the current cluster state in order to
227- /// avoid instance churn.
228- pub fn pods ( & self ) -> Result < impl Iterator < Item = PodRef > + ' _ , NoNamespaceError > {
229- let ns = self . metadata . namespace . clone ( ) . context ( NoNamespaceSnafu ) ?;
230- Ok ( self
231- . spec
232- . metastore
233- . iter ( )
234- . flat_map ( |role| & role. role_groups )
235- // Order rolegroups consistently, to avoid spurious downstream rewrites
236- . collect :: < BTreeMap < _ , _ > > ( )
237- . into_iter ( )
238- . flat_map ( move |( rolegroup_name, rolegroup) | {
239- let rolegroup_ref = self . metastore_rolegroup_ref ( rolegroup_name) ;
240- let ns = ns. clone ( ) ;
241- ( 0 ..rolegroup. replicas . unwrap_or ( 0 ) ) . map ( move |i| PodRef {
242- namespace : ns. clone ( ) ,
243- role_group_service_name : rolegroup_ref. object_name ( ) ,
244- pod_name : format ! ( "{}-{}" , rolegroup_ref. object_name( ) , i) ,
245- } )
246- } ) )
247- }
248-
249- pub fn role ( & self , role_variant : & HiveRole ) -> Result < & HiveRoleType , Error > {
250- match role_variant {
251- HiveRole :: MetaStore => self . spec . metastore . as_ref ( ) ,
252- }
253- . with_context ( || CannotRetrieveHiveRoleSnafu {
254- role : role_variant. to_string ( ) ,
255- } )
256- }
257-
258- /// The name of the role-listener provided for a specific role.
259- /// returns a name `<cluster>-<role>`
260- pub fn role_listener_name ( & self , hive_role : & HiveRole ) -> String {
261- format ! ( "{name}-{role}" , name = self . name_any( ) , role = hive_role)
262- }
263-
264- pub fn rolegroup (
265- & self ,
266- rolegroup_ref : & RoleGroupRef < Self > ,
267- ) -> Result < HiveRoleGroupType , Error > {
268- let role_variant =
269- HiveRole :: from_str ( & rolegroup_ref. role ) . with_context ( |_| UnknownHiveRoleSnafu {
270- role : rolegroup_ref. role . to_owned ( ) ,
271- roles : HiveRole :: roles ( ) ,
272- } ) ?;
273-
274- let role = self . role ( & role_variant) ?;
275- role. role_groups
276- . get ( & rolegroup_ref. role_group )
277- . with_context ( || CannotRetrieveHiveRoleGroupSnafu {
278- role_group : rolegroup_ref. role_group . to_owned ( ) ,
279- } )
280- . cloned ( )
281- }
282-
283211 pub fn role_config ( & self , role : & HiveRole ) -> Option < & HiveMetastoreRoleConfig > {
284212 match role {
285213 HiveRole :: MetaStore => self . spec . metastore . as_ref ( ) . map ( |m| & m. role_config ) ,
@@ -326,27 +254,6 @@ pub enum HiveRole {
326254}
327255
328256impl HiveRole {
329- /// Metadata about a rolegroup
330- pub fn rolegroup_ref (
331- & self ,
332- hive : & v1alpha1:: HiveCluster ,
333- group_name : impl Into < String > ,
334- ) -> RoleGroupRef < v1alpha1:: HiveCluster > {
335- RoleGroupRef {
336- cluster : ObjectRef :: from_obj ( hive) ,
337- role : self . to_string ( ) ,
338- role_group : group_name. into ( ) ,
339- }
340- }
341-
342- pub fn roles ( ) -> Vec < String > {
343- let mut roles = vec ! [ ] ;
344- for role in Self :: iter ( ) {
345- roles. push ( role. to_string ( ) )
346- }
347- roles
348- }
349-
350257 /// A Kerberos principal has three parts, with the form username/fully.qualified.domain.name@YOUR-REALM.COM.
351258 /// We only have one role and will use "hive" everywhere (which e.g. differs from the current hdfs implementation).
352259 pub fn kerberos_service_name ( & self ) -> & ' static str {
@@ -466,30 +373,6 @@ pub struct HiveClusterStatus {
466373 pub conditions : Vec < ClusterCondition > ,
467374}
468375
469- #[ derive( Debug , Snafu ) ]
470- #[ snafu( display( "object has no namespace associated" ) ) ]
471- pub struct NoNamespaceError ;
472-
473- /// Reference to a single `Pod` that is a component of a [`HiveCluster`]
474- /// Used for service discovery.
475- pub struct PodRef {
476- pub namespace : String ,
477- pub role_group_service_name : String ,
478- pub pod_name : String ,
479- }
480-
481- impl PodRef {
482- pub fn fqdn ( & self , cluster_info : & KubernetesClusterInfo ) -> String {
483- format ! (
484- "{pod_name}.{service_name}.{namespace}.svc.{cluster_domain}" ,
485- pod_name = self . pod_name,
486- service_name = self . role_group_service_name,
487- namespace = self . namespace,
488- cluster_domain = cluster_info. cluster_domain
489- )
490- }
491- }
492-
493376#[ cfg( test) ]
494377mod tests {
495378 use stackable_operator:: versioned:: test_utils:: RoundtripTestData ;
0 commit comments