Skip to content

Commit 9f50fa5

Browse files
committed
make the broker role required in the CRD
1 parent 3bc8d5d commit 9f50fa5

4 files changed

Lines changed: 36 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ All notable changes to this project will be documented in this file.
1111
- Bump stackable-operator to 0.114.0 ([#994]).
1212
- The RBAC ServiceAccount and RoleBinding are now built with the operator-rs `v2::rbac`
1313
functions and carry the full set of recommended labels ([#990]).
14+
- BREAKING: The `brokers` role is now required by the CRD; a KafkaCluster without it was
15+
previously accepted by the API server but failed reconciliation ([#990]).
1416

1517
[#985]: https://github.com/stackabletech/kafka-operator/pull/985
1618
[#990]: https://github.com/stackabletech/kafka-operator/pull/990

extra/crds.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ spec:
3535
at role level, the `roleConfig`.
3636
You can learn more about this in the
3737
[Roles and role group concept documentation](https://docs.stackable.tech/home/nightly/concepts/roles-and-role-groups).
38-
nullable: true
3938
properties:
4039
cliOverrides:
4140
additionalProperties:
@@ -2260,6 +2259,7 @@ spec:
22602259
x-kubernetes-preserve-unknown-fields: true
22612260
type: array
22622261
required:
2262+
- brokers
22632263
- image
22642264
type: object
22652265
status:

rust/operator-binary/src/controller/validate.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::{
3535
security::{self, ValidatedKafkaSecurity},
3636
},
3737
crd::{
38-
self, CONTAINER_IMAGE_BASE_NAME,
38+
CONTAINER_IMAGE_BASE_NAME,
3939
authentication::{self},
4040
role::{
4141
AnyConfig, AnyConfigOverrides, KafkaRole,
@@ -62,9 +62,6 @@ pub enum Error {
6262
#[snafu(display("failed to validate authentication method"))]
6363
FailedToValidateAuthenticationMethod { source: security::Error },
6464

65-
#[snafu(display("cluster object defines no '{role}' role"))]
66-
MissingKafkaRole { source: crd::Error, role: KafkaRole },
67-
6865
#[snafu(display("failed to merge and validate the role group config"))]
6966
ValidateRoleGroupConfig {
7067
source: stackable_operator::config::fragment::ValidationError,
@@ -249,10 +246,8 @@ pub fn validate(
249246
BTreeMap<RoleGroupName, ValidatedRoleGroupConfig>,
250247
> = BTreeMap::new();
251248

252-
// Brokers always exist.
253-
let broker_role = kafka.broker_role().context(MissingKafkaRoleSnafu {
254-
role: KafkaRole::Broker,
255-
})?;
249+
// The broker role is required by the CRD.
250+
let broker_role = &kafka.spec.brokers;
256251
let broker_groups = validate_role_group_configs(
257252
broker_role,
258253
BrokerConfig::default_config(&kafka.name_any(), &KafkaRole::Broker.to_string()),

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod tls;
77

88
use authentication::KafkaAuthentication;
99
use serde::{Deserialize, Serialize};
10-
use snafu::{OptionExt, Snafu};
10+
use snafu::Snafu;
1111
use stackable_operator::{
1212
commons::{
1313
cluster_operation::ClusterOperation, networking::DomainName,
@@ -73,9 +73,6 @@ pub enum Error {
7373
))]
7474
Kafka4RequiresKraftMetadataManager,
7575

76-
#[snafu(display("The Kafka role [{role}] is missing from spec"))]
77-
MissingRole { role: String },
78-
7976
#[snafu(display(
8077
"Kafka version 4 and higher requires a Kraft controller (configured via `spec.controller`)"
8178
))]
@@ -130,7 +127,7 @@ pub mod versioned {
130127
pub image: ProductImage,
131128

132129
// no doc - docs in Role struct.
133-
pub brokers: Option<BrokerRole>,
130+
pub brokers: BrokerRole,
134131

135132
// no doc - docs in Role struct.
136133
pub controllers: Option<ControllerRole>,
@@ -320,12 +317,6 @@ impl v1alpha1::KafkaCluster {
320317
_ => None,
321318
})
322319
}
323-
324-
pub fn broker_role(&self) -> Result<&BrokerRole, Error> {
325-
self.spec.brokers.as_ref().context(MissingRoleSnafu {
326-
role: KafkaRole::Broker.to_string(),
327-
})
328-
}
329320
}
330321

331322
/// Reference to a single `Pod` that is a component of a [`KafkaCluster`]
@@ -444,6 +435,10 @@ mod tests {
444435
spec:
445436
image:
446437
productVersion: 3.9.2
438+
brokers:
439+
roleGroups:
440+
default:
441+
replicas: 1
447442
clusterConfig:
448443
zookeeperConfigMapName: xyz
449444
"#;
@@ -463,6 +458,10 @@ mod tests {
463458
spec:
464459
image:
465460
productVersion: 3.9.2
461+
brokers:
462+
roleGroups:
463+
default:
464+
replicas: 1
466465
clusterConfig:
467466
tls:
468467
serverSecretClass: simple-kafka-server-tls
@@ -488,6 +487,10 @@ mod tests {
488487
spec:
489488
image:
490489
productVersion: 3.9.2
490+
brokers:
491+
roleGroups:
492+
default:
493+
replicas: 1
491494
clusterConfig:
492495
tls:
493496
serverSecretClass: null
@@ -509,6 +512,10 @@ mod tests {
509512
spec:
510513
image:
511514
productVersion: 3.9.2
515+
brokers:
516+
roleGroups:
517+
default:
518+
replicas: 1
512519
zookeeperConfigMapName: xyz
513520
clusterConfig:
514521
tls:
@@ -534,6 +541,10 @@ mod tests {
534541
spec:
535542
image:
536543
productVersion: 3.9.2
544+
brokers:
545+
roleGroups:
546+
default:
547+
replicas: 1
537548
clusterConfig:
538549
zookeeperConfigMapName: xyz
539550
"#;
@@ -553,6 +564,10 @@ mod tests {
553564
spec:
554565
image:
555566
productVersion: 3.9.2
567+
brokers:
568+
roleGroups:
569+
default:
570+
replicas: 1
556571
clusterConfig:
557572
tls:
558573
internalSecretClass: simple-kafka-internal-tls
@@ -574,6 +589,10 @@ mod tests {
574589
spec:
575590
image:
576591
productVersion: 3.9.2
592+
brokers:
593+
roleGroups:
594+
default:
595+
replicas: 1
577596
clusterConfig:
578597
tls:
579598
serverSecretClass: simple-kafka-server-tls

0 commit comments

Comments
 (0)