Skip to content

Commit b3a02e1

Browse files
committed
refactor: use v2 Port
1 parent 882eb00 commit b3a02e1

4 files changed

Lines changed: 29 additions & 27 deletions

File tree

rust/operator-binary/src/controller.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,18 @@ impl ValidatedCluster {
191191

192192
if requested_kafka_role.is_none() || Some(role) == requested_kafka_role {
193193
let resource_names = self.resource_names(role, role_group_name);
194-
let role_group_statefulset_name =
195-
resource_names.stateful_set_name().to_string();
196-
let role_group_service_name =
197-
resource_names.headless_service_name().to_string();
194+
let role_group_statefulset_name = resource_names.stateful_set_name();
195+
let role_group_service_name = resource_names.headless_service_name();
198196
for replica in 0..validated_rg.replicas {
199197
pod_descriptors.push(KafkaPodDescriptor {
200-
namespace: self.namespace.to_string(),
201-
role: role.to_string(),
198+
namespace: self.namespace.clone(),
202199
role_group_service_name: role_group_service_name.clone(),
203200
role_group_statefulset_name: role_group_statefulset_name.clone(),
204201
replica,
205202
cluster_domain: self.cluster_domain.clone(),
206203
node_id: node_id_hash_offset + u32::from(replica),
207-
client_port,
204+
role: role.clone(),
205+
client_port: client_port.clone(),
208206
});
209207
}
210208
}

rust/operator-binary/src/controller/build/properties/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn uses_legacy_log4j(product_version: &str) -> bool {
5959
pub(crate) fn kraft_controllers(pod_descriptors: &[KafkaPodDescriptor]) -> Vec<String> {
6060
pod_descriptors
6161
.iter()
62-
.filter(|pd| pd.role == KafkaRole::Controller.to_string())
62+
.filter(|pd| pd.role == KafkaRole::Controller)
6363
.map(|desc| {
6464
format!(
6565
"{fqdn}:{client_port}",

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ use stackable_operator::{
2121
schemars::{self, JsonSchema},
2222
status::condition::{ClusterCondition, HasStatusCondition},
2323
v2::{
24-
config_overrides::KeyValueConfigOverrides, role_utils::JavaCommonConfig,
25-
types::kubernetes::ConfigMapName,
24+
config_overrides::KeyValueConfigOverrides,
25+
role_utils::JavaCommonConfig,
26+
types::{
27+
common::Port,
28+
kubernetes::{ConfigMapName, NamespaceName, ServiceName, StatefulSetName},
29+
},
2630
},
2731
versioned::versioned,
2832
};
@@ -40,7 +44,7 @@ pub const OPERATOR_NAME: &str = "kafka.stackable.tech";
4044
pub const FIELD_MANAGER: &str = "kafka-operator";
4145
// metrics
4246
pub const METRICS_PORT_NAME: &str = "metrics";
43-
pub const METRICS_PORT: u16 = 9606;
47+
pub const METRICS_PORT: Port = Port(9606);
4448
// env vars
4549
pub const KAFKA_HEAP_OPTS: &str = "KAFKA_HEAP_OPTS";
4650
// server_properties
@@ -350,16 +354,16 @@ impl v1alpha1::KafkaCluster {
350354
/// Reference to a single `Pod` that is a component of a [`KafkaCluster`]
351355
///
352356
/// Used for service discovery.
353-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
357+
#[derive(Debug, PartialEq, Eq)]
354358
pub struct KafkaPodDescriptor {
355-
pub(crate) namespace: String,
356-
pub(crate) role_group_statefulset_name: String,
357-
pub(crate) role_group_service_name: String,
359+
pub(crate) namespace: NamespaceName,
360+
pub(crate) role_group_statefulset_name: StatefulSetName,
361+
pub(crate) role_group_service_name: ServiceName,
358362
pub(crate) replica: u16,
359363
pub(crate) cluster_domain: DomainName,
360364
pub(crate) node_id: u32,
361-
pub role: String,
362-
pub client_port: u16,
365+
pub role: KafkaRole,
366+
pub client_port: Port,
363367
}
364368

365369
impl KafkaPodDescriptor {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use stackable_operator::{
2020
crd::authentication::core,
2121
k8s_openapi::api::core::v1::Volume,
2222
shared::time::Duration,
23-
v2::types::kubernetes::SecretClassName,
23+
v2::types::{common::Port, kubernetes::SecretClassName},
2424
};
2525

2626
use super::listener::KafkaListenerProtocol;
@@ -66,28 +66,28 @@ pub struct KafkaTlsSecurity {
6666
}
6767

6868
impl KafkaTlsSecurity {
69-
pub const BOOTSTRAP_PORT: u16 = 9094;
69+
pub const BOOTSTRAP_PORT: Port = Port(9094);
7070
// bootstrap: we will have a single named port with different values for
7171
// secure (9095) and insecure (9094). The bootstrap listener is needed to
7272
// be able to expose principals for both the broker and bootstrap in the
7373
// JAAS configuration, so that clients can use both.
7474
pub const BOOTSTRAP_PORT_NAME: &'static str = "bootstrap";
75-
pub const CLIENT_PORT: u16 = 9092;
75+
pub const CLIENT_PORT: Port = Port(9092);
7676
// ports
7777
pub const CLIENT_PORT_NAME: &'static str = "kafka";
7878
// internal
79-
pub const INTERNAL_PORT: u16 = 19092;
79+
pub const INTERNAL_PORT: Port = Port(19092);
8080
// - TLS internal
8181
const INTER_BROKER_LISTENER_NAME: &'static str = "inter.broker.listener.name";
8282
// - TLS global
8383
const KEYSTORE_P12_FILE_NAME: &'static str = "keystore.p12";
8484
const OPA_TLS_MOUNT_PATH: &str = "/stackable/tls-opa";
8585
// opa
8686
const OPA_TLS_VOLUME_NAME: &str = "tls-opa";
87-
pub const SECURE_BOOTSTRAP_PORT: u16 = 9095;
88-
pub const SECURE_CLIENT_PORT: u16 = 9093;
87+
pub const SECURE_BOOTSTRAP_PORT: Port = Port(9095);
88+
pub const SECURE_CLIENT_PORT: Port = Port(9093);
8989
pub const SECURE_CLIENT_PORT_NAME: &'static str = "kafka-tls";
90-
pub const SECURE_INTERNAL_PORT: u16 = 19093;
90+
pub const SECURE_INTERNAL_PORT: Port = Port(19093);
9191
const SSL_STORE_PASSWORD: &'static str = "";
9292
const SSL_STORE_TYPE_PKCS12: &'static str = "PKCS12";
9393
const STACKABLE_TLS_KAFKA_INTERNAL_DIR: &'static str = "/stackable/tls-kafka-internal";
@@ -222,15 +222,15 @@ impl KafkaTlsSecurity {
222222
}
223223

224224
/// Return the Kafka (secure) client port depending on tls or authentication settings.
225-
pub fn client_port(&self) -> u16 {
225+
pub fn client_port(&self) -> Port {
226226
if self.tls_enabled() {
227227
Self::SECURE_CLIENT_PORT
228228
} else {
229229
Self::CLIENT_PORT
230230
}
231231
}
232232

233-
pub fn bootstrap_port(&self) -> u16 {
233+
pub fn bootstrap_port(&self) -> Port {
234234
if self.tls_enabled() {
235235
Self::SECURE_BOOTSTRAP_PORT
236236
} else {
@@ -252,7 +252,7 @@ impl KafkaTlsSecurity {
252252
}
253253

254254
/// Return the Kafka (secure) internal port depending on tls settings.
255-
pub fn internal_port(&self) -> u16 {
255+
pub fn internal_port(&self) -> Port {
256256
if self.tls_internal_secret_class().is_some() {
257257
Self::SECURE_INTERNAL_PORT
258258
} else {

0 commit comments

Comments
 (0)