Skip to content

Commit 74197eb

Browse files
chore: Use constant for HTTP port name
1 parent 1ffffd4 commit 74197eb

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

rust/operator-binary/src/controller.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ mod dereference;
5353
mod update_status;
5454
mod validate;
5555

56+
pub const HTTP_PORT_NAME: &str = "http";
57+
pub const HTTP_PORT: Port = Port(9200);
58+
pub const TRANSPORT_PORT_NAME: &str = "transport";
59+
pub const TRANSPORT_PORT: Port = Port(9300);
60+
5661
/// Names in the controller context which are passed to the submodules of the controller
5762
///
5863
/// The names are not directly defined in [`Context`] because not every submodule requires a

rust/operator-binary/src/controller/build/role_builder.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ use stackable_operator::{
2222

2323
use crate::{
2424
controller::{
25-
ContextNames, ValidatedCluster,
26-
build::role_group_builder::{
27-
HTTP_PORT, HTTP_PORT_NAME, RoleGroupBuilder, TRANSPORT_PORT, TRANSPORT_PORT_NAME,
28-
},
25+
ContextNames, HTTP_PORT, HTTP_PORT_NAME, TRANSPORT_PORT, TRANSPORT_PORT_NAME,
26+
ValidatedCluster, build::role_group_builder::RoleGroupBuilder,
2927
},
3028
framework::{
3129
NameIsValidLabelValue,

rust/operator-binary/src/controller/build/role_group_builder.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ use super::{
4141
use crate::{
4242
constant,
4343
controller::{
44-
ContextNames, OpenSearchRoleGroupConfig, ValidatedCluster,
44+
ContextNames, HTTP_PORT, HTTP_PORT_NAME, OpenSearchRoleGroupConfig, TRANSPORT_PORT,
45+
TRANSPORT_PORT_NAME, ValidatedCluster,
4546
build::product_logging::config::{
4647
MAX_OPENSEARCH_SERVER_LOG_FILES_SIZE, vector_config_file_extra_env_vars,
4748
},
@@ -61,7 +62,6 @@ use crate::{
6162
},
6263
role_group_utils::ResourceNames,
6364
types::{
64-
common::Port,
6565
kubernetes::{
6666
ListenerName, PersistentVolumeClaimName, SecretClassName, ServiceAccountName,
6767
ServiceName, VolumeName,
@@ -71,11 +71,6 @@ use crate::{
7171
},
7272
};
7373

74-
pub const HTTP_PORT_NAME: &str = "http";
75-
pub const HTTP_PORT: Port = Port(9200);
76-
pub const TRANSPORT_PORT_NAME: &str = "transport";
77-
pub const TRANSPORT_PORT: Port = Port(9300);
78-
7974
constant!(CONFIG_VOLUME_NAME: VolumeName = "config");
8075

8176
constant!(LOG_CONFIG_VOLUME_NAME: VolumeName = "log-config");

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::{
1414
ValidatedLogging, ValidatedOpenSearchConfig,
1515
};
1616
use crate::{
17-
controller::{DereferencedObjects, ValidatedDiscoveryEndpoint},
17+
controller::{DereferencedObjects, HTTP_PORT_NAME, ValidatedDiscoveryEndpoint},
1818
crd::v1alpha1::{self},
1919
framework::{
2020
builder::pod::container::{EnvVarName, EnvVarSet},
@@ -146,7 +146,11 @@ pub fn validate(
146146
role_group_configs.insert(role_group_name, validated_role_group_config);
147147
}
148148

149-
let validated_discovery_endpoint = validate_discovery_endpoint(dereferenced_objects)?;
149+
let validated_discovery_endpoint = validate_discovery_endpoint(
150+
dereferenced_objects
151+
.maybe_discovery_service_listener
152+
.as_ref(),
153+
)?;
150154

151155
Ok(ValidatedCluster::new(
152156
product_image,
@@ -259,11 +263,13 @@ fn validate_logging_configuration(
259263
})
260264
}
261265

266+
/// Return the validated discovery endpoint if a Listener is given with a status containing the
267+
/// endpoint
262268
fn validate_discovery_endpoint(
263-
dereferenced_objects: &DereferencedObjects,
269+
maybe_discovery_service_listener: Option<&listener::v1alpha1::Listener>,
264270
) -> Result<Option<ValidatedDiscoveryEndpoint>> {
265271
let validated_discovery_endpoint = if let Some(discovery_service_listener) =
266-
&dereferenced_objects.maybe_discovery_service_listener
272+
maybe_discovery_service_listener
267273
{
268274
if let Some((hostname, port)) = extract_listener_ingresses(discovery_service_listener)? {
269275
tracing::info!(
@@ -293,6 +299,7 @@ fn validate_discovery_endpoint(
293299
Ok(validated_discovery_endpoint)
294300
}
295301

302+
/// Return the first address and the HTTP port from the given Listener if it has a status
296303
fn extract_listener_ingresses(
297304
discovery_service_listener: &listener::v1alpha1::Listener,
298305
) -> Result<Option<(Hostname, Port)>> {
@@ -311,8 +318,7 @@ fn extract_listener_ingresses(
311318

312319
let raw_port = *ingress_address
313320
.ports
314-
// TODO Use HTTP_PORT_NAME somehow
315-
.get("http")
321+
.get(HTTP_PORT_NAME)
316322
.context(GetListenerStatusPortSnafu)?;
317323
let port = Port::try_from(raw_port).context(ParseListenerStatusPortSnafu)?;
318324

0 commit comments

Comments
 (0)