Skip to content

Commit e7fa7be

Browse files
chore: Improve comments and unit tests
1 parent 86eb855 commit e7fa7be

4 files changed

Lines changed: 26 additions & 10 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ mod tests {
9393
role_utils::GenericProductSpecificCommonConfig,
9494
types::{
9595
common::Port,
96-
kubernetes::{Hostname, ListenerClassName, NamespaceName},
96+
kubernetes::{Hostname, ListenerClassName, NamespaceName, SecretClassName},
9797
operator::{
9898
ClusterName, ControllerName, OperatorName, ProductName, ProductVersion,
9999
RoleGroupName,
@@ -137,7 +137,8 @@ mod tests {
137137
"my-opensearch",
138138
"my-opensearch-nodes-cluster-manager",
139139
"my-opensearch-nodes-coordinating",
140-
"my-opensearch-nodes-data"
140+
"my-opensearch-nodes-data",
141+
"my-opensearch-security-config"
141142
],
142143
extract_resource_names(&resources.config_maps)
143144
);
@@ -212,7 +213,11 @@ mod tests {
212213
),
213214
]
214215
.into(),
215-
ValidatedSecurity::Disabled,
216+
ValidatedSecurity::ManagedByApi {
217+
settings: v1alpha1::SecuritySettings::default(),
218+
tls_server_secret_class: None,
219+
tls_internal_secret_class: SecretClassName::from_str_unsafe("tls"),
220+
},
216221
vec![],
217222
Some(ValidatedDiscoveryEndpoint {
218223
hostname: Hostname::from_str_unsafe("1.2.3.4"),

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ impl<'a> RoleGroupBuilder<'a> {
715715
};
716716

717717
if let RoleGroupSecurityMode::Initializing { settings, .. } = &self.security_mode {
718+
// Mount the security configuration files using `subPath`, because the configuration
719+
// files are only used for initializing the security index and hot-reloading is not
720+
// required.
718721
volume_mounts.extend(self.security_config_volume_mounts(settings, true));
719722
};
720723

@@ -778,6 +781,13 @@ impl<'a> RoleGroupBuilder<'a> {
778781

779782
/// Builds the security settings volume mounts for the [`v1alpha1::Container::OpenSearch`]
780783
/// container or the [`v1alpha1::Container::UpdateSecurityConfig`] container
784+
///
785+
/// If `use_sub_path` is set to `true`, then the configuration files are directly mounted via
786+
/// `subPath` into the opensearch-security configuration directory. If it is set to `false`,
787+
/// then they are mounted into sub directories of the opensearch-security configuration
788+
/// directory without using `subPath`. Files mounted via `subPath` are not updated on changes
789+
/// in the ConfigMap or Secret volume. Therefore, hot-reloading works only without `subPath`,
790+
/// but links from the configuration directory into the sub directories are required.
781791
fn security_config_volume_mounts(
782792
&self,
783793
settings: &v1alpha1::SecuritySettings,
@@ -882,6 +892,9 @@ impl<'a> RoleGroupBuilder<'a> {
882892
..VolumeMount::default()
883893
},
884894
];
895+
896+
// Mount the security configuration files without using `subPath`, so that hot-reloading
897+
// works.
885898
volume_mounts.extend(self.security_config_volume_mounts(settings, false));
886899

887900
let mut env_vars = EnvVarSet::new()

rust/operator-binary/src/controller/build/scripts/update-security-config.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Expected environment variables:
3+
# Required environment variables:
44
# - OPENSEARCH_PATH_CONF
55
# - POD_NAME
66
# - MANAGE_ACTIONGROUPS
@@ -13,8 +13,6 @@
1313
# - MANAGE_ROLESMAPPING
1414
# - MANAGE_TENANTS
1515

16-
# TODO config_files vs. configuration_files
17-
1816
set -u -o pipefail
1917

2018
VECTOR_CONTROL_DIR=/stackable/log/_vector
@@ -80,6 +78,7 @@ function config_file () {
8078
echo "$SECURITY_CONFIG_DIR/${CONFIG_FILENAME[$filetype]}"
8179
}
8280

81+
# Create link for every configuration file in SECURITY_CONFIG_DIR
8382
function symlink_config_files () {
8483
for filetype in "${CONFIG_FILETYPES[@]}"
8584
do
@@ -89,14 +88,13 @@ function symlink_config_files () {
8988
done
9089
}
9190

92-
function initialize_managed_configuration_filetypes () {
91+
function initialize_managed_config_filetypes () {
9392
for filetype in "${CONFIG_FILETYPES[@]}"
9493
do
9594
envvar="MANAGE_${filetype^^}"
9695
if test "${!envvar}" = "true"
9796
then
9897
info "Watch managed configuration type \"$filetype\"."
99-
10098
managed_filetypes+=("$filetype")
10199
else
102100
info "Skip unmanaged configuration type \"$filetype\"."
@@ -250,7 +248,7 @@ mkdir --parents "$VECTOR_CONTROL_DIR"
250248

251249
check_pod
252250
symlink_config_files
253-
initialize_managed_configuration_filetypes
251+
initialize_managed_config_filetypes
254252

255253
while true
256254
do

rust/operator-binary/src/framework/builder/meta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ mod tests {
137137

138138
#[test]
139139
fn test_annotation_ignore_restarter() {
140-
// Test that the functions do not panic
140+
// Test that the function does not panic
141141
annotation_ignore_restarter();
142142
}
143143
}

0 commit comments

Comments
 (0)