-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmod.rs
More file actions
724 lines (653 loc) · 23.7 KB
/
Copy pathmod.rs
File metadata and controls
724 lines (653 loc) · 23.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
pub mod affinity;
pub mod authentication;
pub mod authorization;
pub mod listener;
pub mod security;
pub mod tls;
use std::{collections::BTreeMap, str::FromStr};
use affinity::get_affinity;
use authentication::KafkaAuthentication;
use serde::{Deserialize, Serialize};
use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::{
commons::{
affinity::StackableAffinity,
cluster_operation::ClusterOperation,
product_image_selection::ProductImage,
resources::{
CpuLimitsFragment, MemoryLimitsFragment, NoRuntimeLimits, NoRuntimeLimitsFragment,
PvcConfig, PvcConfigFragment, Resources, ResourcesFragment,
},
},
config::{
fragment::{self, Fragment, ValidationError},
merge::Merge,
},
k8s_openapi::{
api::core::v1::PersistentVolumeClaim, apimachinery::pkg::api::resource::Quantity,
},
kube::{CustomResource, ResourceExt, runtime::reflector::ObjectRef},
product_config_utils::Configuration,
product_logging::{self, spec::Logging},
role_utils::{GenericRoleConfig, JavaCommonConfig, Role, RoleGroup, RoleGroupRef},
schemars::{self, JsonSchema},
shared::time::Duration,
status::condition::{ClusterCondition, HasStatusCondition},
utils::cluster_info::KubernetesClusterInfo,
versioned::versioned,
};
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
use crate::crd::{authorization::KafkaAuthorization, tls::KafkaTls};
pub const DOCKER_IMAGE_BASE_NAME: &str = "kafka";
pub const APP_NAME: &str = "kafka";
pub const OPERATOR_NAME: &str = "kafka.stackable.tech";
// metrics
pub const METRICS_PORT_NAME: &str = "metrics";
pub const METRICS_PORT: u16 = 9606;
// config files
pub const SERVER_PROPERTIES_FILE: &str = "server.properties";
pub const JVM_SECURITY_PROPERTIES_FILE: &str = "security.properties";
// env vars
pub const KAFKA_HEAP_OPTS: &str = "KAFKA_HEAP_OPTS";
// server_properties
pub const LOG_DIRS_VOLUME_NAME: &str = "log-dirs";
// directories
pub const LISTENER_BROKER_VOLUME_NAME: &str = "listener-broker";
pub const LISTENER_BOOTSTRAP_VOLUME_NAME: &str = "listener-bootstrap";
pub const STACKABLE_LISTENER_BROKER_DIR: &str = "/stackable/listener-broker";
pub const STACKABLE_LISTENER_BOOTSTRAP_DIR: &str = "/stackable/listener-bootstrap";
pub const STACKABLE_DATA_DIR: &str = "/stackable/data";
pub const STACKABLE_CONFIG_DIR: &str = "/stackable/config";
pub const STACKABLE_LOG_CONFIG_DIR: &str = "/stackable/log_config";
pub const STACKABLE_LOG_DIR: &str = "/stackable/log";
// kerberos
pub const STACKABLE_KERBEROS_DIR: &str = "/stackable/kerberos";
pub const STACKABLE_KERBEROS_KRB5_PATH: &str = "/stackable/kerberos/krb5.conf";
const DEFAULT_BROKER_GRACEFUL_SHUTDOWN_TIMEOUT: Duration = Duration::from_minutes_unchecked(30);
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("object has no namespace associated"))]
NoNamespace,
#[snafu(display("failed to validate config of rolegroup {rolegroup}"))]
RoleGroupValidation {
rolegroup: RoleGroupRef<v1alpha1::KafkaCluster>,
source: ValidationError,
},
#[snafu(display("the Kafka role [{role}] is missing from spec"))]
MissingKafkaRole { role: String },
#[snafu(display("the role {role} is not defined"))]
CannotRetrieveKafkaRole { role: String },
#[snafu(display("the Kafka node role group [{role_group}] is missing from spec"))]
MissingKafkaRoleGroup { role_group: String },
#[snafu(display("the role group {role_group} is not defined"))]
CannotRetrieveKafkaRoleGroup { role_group: String },
#[snafu(display("unknown role {role}. Should be one of {roles:?}"))]
UnknownKafkaRole {
source: strum::ParseError,
role: String,
roles: Vec<String>,
},
#[snafu(display("fragment validation failure"))]
FragmentValidationFailure { source: ValidationError },
}
#[versioned(
version(name = "v1alpha1"),
crates(
kube_core = "stackable_operator::kube::core",
kube_client = "stackable_operator::kube::client",
k8s_openapi = "stackable_operator::k8s_openapi",
schemars = "stackable_operator::schemars",
versioned = "stackable_operator::versioned"
)
)]
pub mod versioned {
/// A Kafka cluster stacklet. This resource is managed by the Stackable operator for Apache Kafka.
/// Find more information on how to use it and the resources that the operator generates in the
/// [operator documentation](DOCS_BASE_URL_PLACEHOLDER/kafka/).
#[versioned(crd(
group = "kafka.stackable.tech",
plural = "kafkaclusters",
status = "KafkaClusterStatus",
shortname = "kafka",
namespaced
))]
#[derive(Clone, CustomResource, Debug, Deserialize, JsonSchema, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct KafkaClusterSpec {
// no doc - docs in ProductImage struct.
pub image: ProductImage,
// no doc - docs in Role struct.
pub brokers: Option<Role<KafkaConfigFragment, GenericRoleConfig, JavaCommonConfig>>,
/// Kafka settings that affect all roles and role groups.
///
/// The settings in the `clusterConfig` are cluster wide settings that do not need to be configurable at role or role group level.
pub cluster_config: v1alpha1::KafkaClusterConfig,
// no doc - docs in ClusterOperation struct.
#[serde(default)]
pub cluster_operation: ClusterOperation,
}
#[derive(Clone, Deserialize, Debug, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct KafkaClusterConfig {
/// Authentication class settings for Kafka like mTLS authentication.
#[serde(default)]
pub authentication: Vec<KafkaAuthentication>,
/// Authorization settings for Kafka like OPA.
#[serde(default)]
pub authorization: KafkaAuthorization,
/// TLS encryption settings for Kafka (server, internal).
#[serde(
default = "tls::default_kafka_tls",
skip_serializing_if = "Option::is_none"
)]
pub tls: Option<KafkaTls>,
/// Name of the Vector aggregator [discovery ConfigMap](DOCS_BASE_URL_PLACEHOLDER/concepts/service_discovery).
/// It must contain the key `ADDRESS` with the address of the Vector aggregator.
/// Follow the [logging tutorial](DOCS_BASE_URL_PLACEHOLDER/tutorials/logging-vector-aggregator)
/// to learn how to configure log aggregation with Vector.
#[serde(skip_serializing_if = "Option::is_none")]
pub vector_aggregator_config_map_name: Option<String>,
/// Kafka requires a ZooKeeper cluster connection to run.
/// Provide the name of the ZooKeeper [discovery ConfigMap](DOCS_BASE_URL_PLACEHOLDER/concepts/service_discovery)
/// here. When using the [Stackable operator for Apache ZooKeeper](DOCS_BASE_URL_PLACEHOLDER/zookeeper/)
/// to deploy a ZooKeeper cluster, this will simply be the name of your ZookeeperCluster resource.
pub zookeeper_config_map_name: String,
}
}
impl HasStatusCondition for v1alpha1::KafkaCluster {
fn conditions(&self) -> Vec<ClusterCondition> {
match &self.status {
Some(status) => status.conditions.clone(),
None => vec![],
}
}
}
impl v1alpha1::KafkaCluster {
/// The name of the load-balanced Kubernetes Service providing the bootstrap address. Kafka clients will use this
/// to get a list of broker addresses and will use those to transmit data to the correct broker.
pub fn bootstrap_service_name(&self, rolegroup: &RoleGroupRef<Self>) -> String {
format!("{}-bootstrap", rolegroup.object_name())
}
/// Metadata about a broker rolegroup
pub fn broker_rolegroup_ref(&self, group_name: impl Into<String>) -> RoleGroupRef<Self> {
RoleGroupRef {
cluster: ObjectRef::from_obj(self),
role: KafkaRole::Broker.to_string(),
role_group: group_name.into(),
}
}
pub fn role(
&self,
role_variant: &KafkaRole,
) -> Result<&Role<KafkaConfigFragment, GenericRoleConfig, JavaCommonConfig>, Error> {
match role_variant {
KafkaRole::Broker => self.spec.brokers.as_ref(),
}
.with_context(|| CannotRetrieveKafkaRoleSnafu {
role: role_variant.to_string(),
})
}
pub fn rolegroup(
&self,
rolegroup_ref: &RoleGroupRef<Self>,
) -> Result<&RoleGroup<KafkaConfigFragment, JavaCommonConfig>, Error> {
let role_variant =
KafkaRole::from_str(&rolegroup_ref.role).with_context(|_| UnknownKafkaRoleSnafu {
role: rolegroup_ref.role.to_owned(),
roles: KafkaRole::roles(),
})?;
let role = self.role(&role_variant)?;
role.role_groups
.get(&rolegroup_ref.role_group)
.with_context(|| CannotRetrieveKafkaRoleGroupSnafu {
role_group: rolegroup_ref.role_group.to_owned(),
})
}
pub fn role_config(&self, role: &KafkaRole) -> Option<&GenericRoleConfig> {
match role {
KafkaRole::Broker => self.spec.brokers.as_ref().map(|b| &b.role_config),
}
}
/// List all pods expected to form the cluster
///
/// We try to predict the pods here rather than looking at the current cluster state in order to
/// avoid instance churn.
pub fn pods(&self) -> Result<impl Iterator<Item = KafkaPodRef> + '_, Error> {
let ns = self.metadata.namespace.clone().context(NoNamespaceSnafu)?;
Ok(self
.spec
.brokers
.iter()
.flat_map(|role| &role.role_groups)
// Order rolegroups consistently, to avoid spurious downstream rewrites
.collect::<BTreeMap<_, _>>()
.into_iter()
.flat_map(move |(rolegroup_name, rolegroup)| {
let rolegroup_ref = self.broker_rolegroup_ref(rolegroup_name);
let ns = ns.clone();
(0..rolegroup.replicas.unwrap_or(0)).map(move |i| KafkaPodRef {
namespace: ns.clone(),
role_group_service_name: rolegroup_ref.object_name(),
pod_name: format!("{}-{}", rolegroup_ref.object_name(), i),
})
}))
}
/// Retrieve and merge resource configs for role and role groups
pub fn merged_config(
&self,
role: &KafkaRole,
rolegroup_ref: &RoleGroupRef<Self>,
) -> Result<KafkaConfig, Error> {
// Initialize the result with all default values as baseline
let conf_defaults = KafkaConfig::default_config(&self.name_any(), role);
// Retrieve role resource config
let role = self.role(role)?;
let mut conf_role = role.config.config.to_owned();
// Retrieve rolegroup specific resource config
let role_group = self.rolegroup(rolegroup_ref)?;
let mut conf_role_group = role_group.config.config.to_owned();
// Merge more specific configs into default config
// Hierarchy is:
// 1. RoleGroup
// 2. Role
// 3. Default
conf_role.merge(&conf_defaults);
conf_role_group.merge(&conf_role);
tracing::debug!("Merged config: {:?}", conf_role_group);
fragment::validate(conf_role_group).context(FragmentValidationFailureSnafu)
}
}
/// Reference to a single `Pod` that is a component of a [`KafkaCluster`]
///
/// Used for service discovery.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct KafkaPodRef {
pub namespace: String,
pub role_group_service_name: String,
pub pod_name: String,
}
impl KafkaPodRef {
pub fn fqdn(&self, cluster_info: &KubernetesClusterInfo) -> String {
format!(
"{pod_name}.{service_name}.{namespace}.svc.{cluster_domain}",
pod_name = self.pod_name,
service_name = self.role_group_service_name,
namespace = self.namespace,
cluster_domain = cluster_info.cluster_domain
)
}
}
#[derive(
Clone,
Debug,
Deserialize,
Display,
EnumIter,
Eq,
Hash,
JsonSchema,
PartialEq,
Serialize,
EnumString,
)]
pub enum KafkaRole {
#[strum(serialize = "broker")]
Broker,
}
impl KafkaRole {
/// Metadata about a rolegroup
pub fn rolegroup_ref(
&self,
kafka: &v1alpha1::KafkaCluster,
group_name: impl Into<String>,
) -> RoleGroupRef<v1alpha1::KafkaCluster> {
RoleGroupRef {
cluster: ObjectRef::from_obj(kafka),
role: self.to_string(),
role_group: group_name.into(),
}
}
pub fn roles() -> Vec<String> {
let mut roles = vec![];
for role in Self::iter() {
roles.push(role.to_string())
}
roles
}
/// A Kerberos principal has three parts, with the form username/fully.qualified.domain.name@YOUR-REALM.COM.
/// We only have one role and will use "kafka" everywhere (which e.g. differs from the current hdfs implementation,
/// but is similar to HBase).
pub fn kerberos_service_name(&self) -> &'static str {
"kafka"
}
}
#[derive(Clone, Debug, Default, PartialEq, Fragment, JsonSchema)]
#[fragment_attrs(
derive(
Clone,
Debug,
Default,
Deserialize,
JsonSchema,
Merge,
PartialEq,
Serialize
),
serde(rename_all = "camelCase")
)]
pub struct Storage {
#[fragment_attrs(serde(default))]
pub log_dirs: PvcConfig,
}
impl Storage {
pub fn build_pvcs(&self) -> Vec<PersistentVolumeClaim> {
let data_pvc = self
.log_dirs
.build_pvc(LOG_DIRS_VOLUME_NAME, Some(vec!["ReadWriteOnce"]));
vec![data_pvc]
}
}
#[derive(
Clone,
Debug,
Deserialize,
Display,
Eq,
EnumIter,
JsonSchema,
Ord,
PartialEq,
PartialOrd,
Serialize,
)]
#[serde(rename_all = "kebab-case")]
#[strum(serialize_all = "kebab-case")]
pub enum Container {
Vector,
KcatProber,
GetService,
Kafka,
}
#[derive(Debug, Default, PartialEq, Fragment, JsonSchema)]
#[fragment_attrs(
derive(
Clone,
Debug,
Default,
Deserialize,
JsonSchema,
Merge,
PartialEq,
Serialize
),
serde(rename_all = "camelCase")
)]
pub struct KafkaConfig {
#[fragment_attrs(serde(default))]
pub logging: Logging<Container>,
#[fragment_attrs(serde(default))]
pub resources: Resources<Storage, NoRuntimeLimits>,
#[fragment_attrs(serde(default))]
pub affinity: StackableAffinity,
/// Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details.
#[fragment_attrs(serde(default))]
pub graceful_shutdown_timeout: Option<Duration>,
/// The ListenerClass used for bootstrapping new clients. Should use a stable ListenerClass to avoid unnecessary client restarts (such as `cluster-internal` or `external-stable`).
pub bootstrap_listener_class: String,
/// The ListenerClass used for connecting to brokers. Should use a direct connection ListenerClass to minimize cost and minimize performance overhead (such as `cluster-internal` or `external-unstable`).
pub broker_listener_class: String,
/// Request secret (currently only autoTls certificates) lifetime from the secret operator, e.g. `7d`, or `30d`.
/// Please note that this can be shortened by the `maxCertificateLifetime` setting on the SecretClass issuing the TLS certificate.
#[fragment_attrs(serde(default))]
pub requested_secret_lifetime: Option<Duration>,
}
impl KafkaConfig {
// Auto TLS certificate lifetime
const DEFAULT_BROKER_SECRET_LIFETIME: Duration = Duration::from_days_unchecked(1);
pub fn default_config(cluster_name: &str, role: &KafkaRole) -> KafkaConfigFragment {
KafkaConfigFragment {
logging: product_logging::spec::default_logging(),
resources: ResourcesFragment {
cpu: CpuLimitsFragment {
min: Some(Quantity("250m".to_owned())),
max: Some(Quantity("1000m".to_owned())),
},
memory: MemoryLimitsFragment {
limit: Some(Quantity("1Gi".to_owned())),
runtime_limits: NoRuntimeLimitsFragment {},
},
storage: StorageFragment {
log_dirs: PvcConfigFragment {
capacity: Some(Quantity("2Gi".to_owned())),
storage_class: None,
selectors: None,
},
},
},
affinity: get_affinity(cluster_name, role),
graceful_shutdown_timeout: Some(DEFAULT_BROKER_GRACEFUL_SHUTDOWN_TIMEOUT),
bootstrap_listener_class: Some("cluster-internal".to_string()),
broker_listener_class: Some("cluster-internal".to_string()),
requested_secret_lifetime: Some(Self::DEFAULT_BROKER_SECRET_LIFETIME),
}
}
}
impl Configuration for KafkaConfigFragment {
type Configurable = v1alpha1::KafkaCluster;
fn compute_env(
&self,
_resource: &Self::Configurable,
_role_name: &str,
) -> Result<BTreeMap<String, Option<String>>, stackable_operator::product_config_utils::Error>
{
Ok(BTreeMap::new())
}
fn compute_cli(
&self,
_resource: &Self::Configurable,
_role_name: &str,
) -> Result<BTreeMap<String, Option<String>>, stackable_operator::product_config_utils::Error>
{
Ok(BTreeMap::new())
}
fn compute_files(
&self,
resource: &Self::Configurable,
_role_name: &str,
file: &str,
) -> Result<BTreeMap<String, Option<String>>, stackable_operator::product_config_utils::Error>
{
let mut config = BTreeMap::new();
if file == SERVER_PROPERTIES_FILE {
// OPA
if resource.spec.cluster_config.authorization.opa.is_some() {
config.insert(
"authorizer.class.name".to_string(),
Some("org.openpolicyagent.kafka.OpaAuthorizer".to_string()),
);
config.insert(
"opa.authorizer.metrics.enabled".to_string(),
Some("true".to_string()),
);
}
}
Ok(config)
}
}
#[derive(Clone, Default, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct KafkaClusterStatus {
#[serde(default)]
pub conditions: Vec<ClusterCondition>,
}
#[cfg(test)]
mod tests {
use super::*;
fn get_server_secret_class(kafka: &v1alpha1::KafkaCluster) -> Option<String> {
kafka
.spec
.cluster_config
.tls
.as_ref()
.and_then(|tls| tls.server_secret_class.clone())
}
fn get_internal_secret_class(kafka: &v1alpha1::KafkaCluster) -> String {
kafka
.spec
.cluster_config
.tls
.as_ref()
.unwrap()
.internal_secret_class
.clone()
}
#[test]
fn test_client_tls() {
let input = r#"
apiVersion: kafka.stackable.tech/v1alpha1
kind: KafkaCluster
metadata:
name: simple-kafka
spec:
image:
productVersion: 3.7.2
clusterConfig:
zookeeperConfigMapName: xyz
"#;
let kafka: v1alpha1::KafkaCluster =
serde_yaml::from_str(input).expect("illegal test input");
assert_eq!(get_server_secret_class(&kafka), tls::server_tls_default());
assert_eq!(
get_internal_secret_class(&kafka),
tls::internal_tls_default()
);
let input = r#"
apiVersion: kafka.stackable.tech/v1alpha1
kind: KafkaCluster
metadata:
name: simple-kafka
spec:
image:
productVersion: 3.7.2
clusterConfig:
tls:
serverSecretClass: simple-kafka-server-tls
zookeeperConfigMapName: xyz
"#;
let kafka: v1alpha1::KafkaCluster =
serde_yaml::from_str(input).expect("illegal test input");
assert_eq!(
get_server_secret_class(&kafka).unwrap(),
"simple-kafka-server-tls".to_string()
);
assert_eq!(
get_internal_secret_class(&kafka),
tls::internal_tls_default()
);
let input = r#"
apiVersion: kafka.stackable.tech/v1alpha1
kind: KafkaCluster
metadata:
name: simple-kafka
spec:
image:
productVersion: 3.7.2
clusterConfig:
tls:
serverSecretClass: null
zookeeperConfigMapName: xyz
"#;
let kafka: v1alpha1::KafkaCluster =
serde_yaml::from_str(input).expect("illegal test input");
assert_eq!(get_server_secret_class(&kafka), None);
assert_eq!(
get_internal_secret_class(&kafka),
tls::internal_tls_default()
);
let input = r#"
apiVersion: kafka.stackable.tech/v1alpha1
kind: KafkaCluster
metadata:
name: simple-kafka
spec:
image:
productVersion: 3.7.2
zookeeperConfigMapName: xyz
clusterConfig:
tls:
internalSecretClass: simple-kafka-internal-tls
zookeeperConfigMapName: xyz
"#;
let kafka: v1alpha1::KafkaCluster =
serde_yaml::from_str(input).expect("illegal test input");
assert_eq!(get_server_secret_class(&kafka), tls::server_tls_default());
assert_eq!(
get_internal_secret_class(&kafka),
"simple-kafka-internal-tls".to_string()
);
}
#[test]
fn test_internal_tls() {
let input = r#"
apiVersion: kafka.stackable.tech/v1alpha1
kind: KafkaCluster
metadata:
name: simple-kafka
spec:
image:
productVersion: 3.7.2
clusterConfig:
zookeeperConfigMapName: xyz
"#;
let kafka: v1alpha1::KafkaCluster =
serde_yaml::from_str(input).expect("illegal test input");
assert_eq!(get_server_secret_class(&kafka), tls::server_tls_default());
assert_eq!(
get_internal_secret_class(&kafka),
tls::internal_tls_default()
);
let input = r#"
apiVersion: kafka.stackable.tech/v1alpha1
kind: KafkaCluster
metadata:
name: simple-kafka
spec:
image:
productVersion: 3.7.2
clusterConfig:
tls:
internalSecretClass: simple-kafka-internal-tls
zookeeperConfigMapName: xyz
"#;
let kafka: v1alpha1::KafkaCluster =
serde_yaml::from_str(input).expect("illegal test input");
assert_eq!(get_server_secret_class(&kafka), tls::server_tls_default());
assert_eq!(
get_internal_secret_class(&kafka),
"simple-kafka-internal-tls".to_string()
);
let input = r#"
apiVersion: kafka.stackable.tech/v1alpha1
kind: KafkaCluster
metadata:
name: simple-kafka
spec:
image:
productVersion: 3.7.2
clusterConfig:
tls:
serverSecretClass: simple-kafka-server-tls
zookeeperConfigMapName: xyz
"#;
let kafka: v1alpha1::KafkaCluster =
serde_yaml::from_str(input).expect("illegal test input");
assert_eq!(
get_server_secret_class(&kafka),
Some("simple-kafka-server-tls".to_string())
);
assert_eq!(
get_internal_secret_class(&kafka),
tls::internal_tls_default()
);
}
}