@@ -37,6 +37,7 @@ use stackable_operator::{
37
37
time:: Duration ,
38
38
utils:: cluster_info:: KubernetesClusterInfo ,
39
39
} ;
40
+ use stackable_versioned:: versioned;
40
41
use strum:: { Display , EnumIter , EnumString , IntoEnumIterator } ;
41
42
42
43
use crate :: crd:: { authorization:: KafkaAuthorization , tls:: KafkaTls } ;
@@ -76,7 +77,7 @@ pub enum Error {
76
77
77
78
#[ snafu( display( "failed to validate config of rolegroup {rolegroup}" ) ) ]
78
79
RoleGroupValidation {
79
- rolegroup : RoleGroupRef < KafkaCluster > ,
80
+ rolegroup : RoleGroupRef < v1alpha1 :: KafkaCluster > ,
80
81
source : ValidationError ,
81
82
} ,
82
83
@@ -103,39 +104,41 @@ pub enum Error {
103
104
FragmentValidationFailure { source : ValidationError } ,
104
105
}
105
106
106
- /// A Kafka cluster stacklet. This resource is managed by the Stackable operator for Apache Kafka.
107
- /// Find more information on how to use it and the resources that the operator generates in the
108
- /// [operator documentation](DOCS_BASE_URL_PLACEHOLDER/kafka/).
109
- #[ derive( Clone , CustomResource , Debug , Deserialize , JsonSchema , Serialize ) ]
110
- #[ kube(
111
- group = "kafka.stackable.tech" ,
112
- version = "v1alpha1" ,
113
- kind = "KafkaCluster" ,
114
- plural = "kafkaclusters" ,
115
- status = "KafkaClusterStatus" ,
116
- shortname = "kafka" ,
117
- namespaced,
118
- crates(
119
- kube_core = "stackable_operator::kube::core" ,
120
- k8s_openapi = "stackable_operator::k8s_openapi" ,
121
- schemars = "stackable_operator::schemars"
122
- )
123
- ) ]
124
- #[ serde( rename_all = "camelCase" ) ]
125
- pub struct KafkaClusterSpec {
126
- // no doc - docs in ProductImage struct.
127
- pub image : ProductImage ,
128
-
129
- // no doc - docs in Role struct.
130
- pub brokers : Option < Role < KafkaConfigFragment , GenericRoleConfig , JavaCommonConfig > > ,
131
-
132
- /// Kafka settings that affect all roles and role groups.
133
- /// The settings in the `clusterConfig` are cluster wide settings that do not need to be configurable at role or role group level.
134
- pub cluster_config : KafkaClusterConfig ,
135
-
136
- // no doc - docs in ClusterOperation struct.
137
- #[ serde( default ) ]
138
- pub cluster_operation : ClusterOperation ,
107
+ #[ versioned( version( name = "v1alpha1" ) ) ]
108
+ pub mod versioned {
109
+ /// A Kafka cluster stacklet. This resource is managed by the Stackable operator for Apache Kafka.
110
+ /// Find more information on how to use it and the resources that the operator generates in the
111
+ /// [operator documentation](DOCS_BASE_URL_PLACEHOLDER/kafka/).
112
+ #[ versioned( k8s(
113
+ group = "kafka.stackable.tech" ,
114
+ kind = "KafkaCluster" ,
115
+ plural = "kafkaclusters" ,
116
+ status = "KafkaClusterStatus" ,
117
+ shortname = "kafka" ,
118
+ namespaced,
119
+ crates(
120
+ kube_core = "stackable_operator::kube::core" ,
121
+ k8s_openapi = "stackable_operator::k8s_openapi" ,
122
+ schemars = "stackable_operator::schemars"
123
+ )
124
+ ) ) ]
125
+ #[ derive( Clone , CustomResource , Debug , Deserialize , JsonSchema , Serialize ) ]
126
+ #[ serde( rename_all = "camelCase" ) ]
127
+ pub struct KafkaClusterSpec {
128
+ // no doc - docs in ProductImage struct.
129
+ pub image : ProductImage ,
130
+
131
+ // no doc - docs in Role struct.
132
+ pub brokers : Option < Role < KafkaConfigFragment , GenericRoleConfig , JavaCommonConfig > > ,
133
+
134
+ /// Kafka settings that affect all roles and role groups.
135
+ /// The settings in the `clusterConfig` are cluster wide settings that do not need to be configurable at role or role group level.
136
+ pub cluster_config : KafkaClusterConfig ,
137
+
138
+ // no doc - docs in ClusterOperation struct.
139
+ #[ serde( default ) ]
140
+ pub cluster_operation : ClusterOperation ,
141
+ }
139
142
}
140
143
141
144
#[ derive( Clone , Deserialize , Debug , Eq , JsonSchema , PartialEq , Serialize ) ]
@@ -170,18 +173,15 @@ pub struct KafkaClusterConfig {
170
173
pub zookeeper_config_map_name : String ,
171
174
}
172
175
173
- impl KafkaCluster {
176
+ impl v1alpha1 :: KafkaCluster {
174
177
/// The name of the load-balanced Kubernetes Service providing the bootstrap address. Kafka clients will use this
175
178
/// to get a list of broker addresses and will use those to transmit data to the correct broker.
176
179
pub fn bootstrap_service_name ( & self , rolegroup : & RoleGroupRef < Self > ) -> String {
177
180
format ! ( "{}-bootstrap" , rolegroup. object_name( ) )
178
181
}
179
182
180
183
/// Metadata about a broker rolegroup
181
- pub fn broker_rolegroup_ref (
182
- & self ,
183
- group_name : impl Into < String > ,
184
- ) -> RoleGroupRef < KafkaCluster > {
184
+ pub fn broker_rolegroup_ref ( & self , group_name : impl Into < String > ) -> RoleGroupRef < Self > {
185
185
RoleGroupRef {
186
186
cluster : ObjectRef :: from_obj ( self ) ,
187
187
role : KafkaRole :: Broker . to_string ( ) ,
@@ -203,7 +203,7 @@ impl KafkaCluster {
203
203
204
204
pub fn rolegroup (
205
205
& self ,
206
- rolegroup_ref : & RoleGroupRef < KafkaCluster > ,
206
+ rolegroup_ref : & RoleGroupRef < Self > ,
207
207
) -> Result < & RoleGroup < KafkaConfigFragment , JavaCommonConfig > , Error > {
208
208
let role_variant =
209
209
KafkaRole :: from_str ( & rolegroup_ref. role ) . with_context ( |_| UnknownKafkaRoleSnafu {
@@ -324,9 +324,9 @@ impl KafkaRole {
324
324
/// Metadata about a rolegroup
325
325
pub fn rolegroup_ref (
326
326
& self ,
327
- kafka : & KafkaCluster ,
327
+ kafka : & v1alpha1 :: KafkaCluster ,
328
328
group_name : impl Into < String > ,
329
- ) -> RoleGroupRef < KafkaCluster > {
329
+ ) -> RoleGroupRef < v1alpha1 :: KafkaCluster > {
330
330
RoleGroupRef {
331
331
cluster : ObjectRef :: from_obj ( kafka) ,
332
332
role : self . to_string ( ) ,
@@ -474,7 +474,7 @@ impl KafkaConfig {
474
474
}
475
475
476
476
impl Configuration for KafkaConfigFragment {
477
- type Configurable = KafkaCluster ;
477
+ type Configurable = v1alpha1 :: KafkaCluster ;
478
478
479
479
fn compute_env (
480
480
& self ,
@@ -528,7 +528,7 @@ pub struct KafkaClusterStatus {
528
528
pub conditions : Vec < ClusterCondition > ,
529
529
}
530
530
531
- impl HasStatusCondition for KafkaCluster {
531
+ impl HasStatusCondition for v1alpha1 :: KafkaCluster {
532
532
fn conditions ( & self ) -> Vec < ClusterCondition > {
533
533
match & self . status {
534
534
Some ( status) => status. conditions . clone ( ) ,
@@ -541,7 +541,7 @@ impl HasStatusCondition for KafkaCluster {
541
541
mod tests {
542
542
use super :: * ;
543
543
544
- fn get_server_secret_class ( kafka : & KafkaCluster ) -> Option < String > {
544
+ fn get_server_secret_class ( kafka : & v1alpha1 :: KafkaCluster ) -> Option < String > {
545
545
kafka
546
546
. spec
547
547
. cluster_config
@@ -550,7 +550,7 @@ mod tests {
550
550
. and_then ( |tls| tls. server_secret_class . clone ( ) )
551
551
}
552
552
553
- fn get_internal_secret_class ( kafka : & KafkaCluster ) -> String {
553
+ fn get_internal_secret_class ( kafka : & v1alpha1 :: KafkaCluster ) -> String {
554
554
kafka
555
555
. spec
556
556
. cluster_config
@@ -574,7 +574,8 @@ mod tests {
574
574
clusterConfig:
575
575
zookeeperConfigMapName: xyz
576
576
"# ;
577
- let kafka: KafkaCluster = serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
577
+ let kafka: v1alpha1:: KafkaCluster =
578
+ serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
578
579
assert_eq ! ( get_server_secret_class( & kafka) , tls:: server_tls_default( ) ) ;
579
580
assert_eq ! (
580
581
get_internal_secret_class( & kafka) ,
@@ -595,7 +596,8 @@ mod tests {
595
596
zookeeperConfigMapName: xyz
596
597
597
598
"# ;
598
- let kafka: KafkaCluster = serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
599
+ let kafka: v1alpha1:: KafkaCluster =
600
+ serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
599
601
assert_eq ! (
600
602
get_server_secret_class( & kafka) . unwrap( ) ,
601
603
"simple-kafka-server-tls" . to_string( )
@@ -618,7 +620,8 @@ mod tests {
618
620
serverSecretClass: null
619
621
zookeeperConfigMapName: xyz
620
622
"# ;
621
- let kafka: KafkaCluster = serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
623
+ let kafka: v1alpha1:: KafkaCluster =
624
+ serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
622
625
assert_eq ! ( get_server_secret_class( & kafka) , None ) ;
623
626
assert_eq ! (
624
627
get_internal_secret_class( & kafka) ,
@@ -639,7 +642,8 @@ mod tests {
639
642
internalSecretClass: simple-kafka-internal-tls
640
643
zookeeperConfigMapName: xyz
641
644
"# ;
642
- let kafka: KafkaCluster = serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
645
+ let kafka: v1alpha1:: KafkaCluster =
646
+ serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
643
647
assert_eq ! ( get_server_secret_class( & kafka) , tls:: server_tls_default( ) ) ;
644
648
assert_eq ! (
645
649
get_internal_secret_class( & kafka) ,
@@ -660,7 +664,8 @@ mod tests {
660
664
clusterConfig:
661
665
zookeeperConfigMapName: xyz
662
666
"# ;
663
- let kafka: KafkaCluster = serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
667
+ let kafka: v1alpha1:: KafkaCluster =
668
+ serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
664
669
assert_eq ! ( get_server_secret_class( & kafka) , tls:: server_tls_default( ) ) ;
665
670
assert_eq ! (
666
671
get_internal_secret_class( & kafka) ,
@@ -680,7 +685,8 @@ mod tests {
680
685
internalSecretClass: simple-kafka-internal-tls
681
686
zookeeperConfigMapName: xyz
682
687
"# ;
683
- let kafka: KafkaCluster = serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
688
+ let kafka: v1alpha1:: KafkaCluster =
689
+ serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
684
690
assert_eq ! ( get_server_secret_class( & kafka) , tls:: server_tls_default( ) ) ;
685
691
assert_eq ! (
686
692
get_internal_secret_class( & kafka) ,
@@ -700,7 +706,8 @@ mod tests {
700
706
serverSecretClass: simple-kafka-server-tls
701
707
zookeeperConfigMapName: xyz
702
708
"# ;
703
- let kafka: KafkaCluster = serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
709
+ let kafka: v1alpha1:: KafkaCluster =
710
+ serde_yaml:: from_str ( input) . expect ( "illegal test input" ) ;
704
711
assert_eq ! (
705
712
get_server_secret_class( & kafka) ,
706
713
Some ( "simple-kafka-server-tls" . to_string( ) )
0 commit comments