Skip to content

Commit c48fadf

Browse files
feat: Make OPENSEARCH_HOME and OPENSEARCH_PATH_CONF overridable (#18)
* Make OPENSEARCH_HOME configurable * doc: Document the environment variables OPENSEARCH_HOME and OPENSEARCH_PATH_CONF * chore: Update changelog
1 parent ccf6161 commit c48fadf

File tree

8 files changed

+129
-63
lines changed

8 files changed

+129
-63
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ All notable changes to this project will be documented in this file.
1717
- PodDisruptionBudgets
1818
- Replicas
1919
- Add Listener support ([#17]).
20+
- Make the environment variables `OPENSEARCH_HOME` and `OPENSEARCH_PATH_CONF` overridable, so that
21+
images can be used which have a different directory structure than the Stackable image ([#18]).
2022

2123
[#10]: https://github.com/stackabletech/opensearch-operator/pull/10
2224
[#17]: https://github.com/stackabletech/opensearch-operator/pull/17
25+
[#18]: https://github.com/stackabletech/opensearch-operator/pull/18

docs/modules/opensearch/pages/usage-guide/configuration-environment-overrides.adoc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ nodes:
131131
default:
132132
config: {}
133133
envOverrides:
134-
OPENSEARCH_PATH_CONF: /etc/opensearch
134+
OPENSEARCH_HOME: /usr/share/opensearch
135135
----
136136

137137
or per role:
@@ -140,12 +140,21 @@ or per role:
140140
----
141141
nodes:
142142
envOverrides:
143-
OPENSEARCH_PATH_CONF: /etc/opensearch
143+
OPENSEARCH_HOME: /usr/share/opensearch
144144
roleGroups:
145145
default:
146146
config: {}
147147
----
148148

149+
The environment variables `OPENSEARCH_HOME` and `OPENSEARCH_PATH_CONF` are worth mentioning.
150+
`OPENSEARCH_HOME` contains the path in the image where OpenSearch is installed.
151+
`OPENSEARCH_PATH_CONF` contains the path with the OpenSearch configuration files.
152+
They are usually set in the image.
153+
In the Stackable image, `OPENSEARCH_HOME` is set to `/stackable/opensearch` and `OPENSEARCH_PATH_CONF` to `$\{OPENSEARCH_HOME}/config`.
154+
The operator must also know the values of these environment variables to mount volumes to the correct paths.
155+
Since the operator cannot read the values from the image, it assumes the ones from the Stackable image.
156+
If you use a custom image with different paths, you can override one or both of these environment variables as shown in the example above.
157+
149158
== CLI parameters
150159

151160
CLI parameters can be set with `cliOverrides` per role group:

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ const DATA_VOLUME_NAME: &str = "data";
4141
const LISTENER_VOLUME_NAME: &str = "listener";
4242
const LISTENER_VOLUME_DIR: &str = "/stackable/listener";
4343

44-
// Path in opensearchproject/opensearch:3.0.0
45-
const OPENSEARCH_BASE_PATH: &str = "/stackable/opensearch";
44+
const DEFAULT_OPENSEARCH_HOME: &str = "/stackable/opensearch";
4645

4746
pub struct RoleGroupBuilder<'a> {
4847
service_account_name: String,
@@ -271,26 +270,40 @@ impl<'a> RoleGroupBuilder<'a> {
271270
..Probe::default()
272271
};
273272

273+
let env_vars = self.node_config.environment_variables();
274+
275+
// Use `OPENSEARCH_HOME` from envOverrides or default to `DEFAULT_OPENSEARCH_HOME`.
276+
let opensearch_home = env_vars
277+
.get_env_var("OPENSEARCH_HOME")
278+
.and_then(|env_var| env_var.value.clone())
279+
.unwrap_or(DEFAULT_OPENSEARCH_HOME.to_owned());
280+
// Use `OPENSEARCH_PATH_CONF` from envOverrides or default to `{OPENSEARCH_HOME}/config`,
281+
// i.e. depend on `OPENSEARCH_HOME`.
282+
let opensearch_path_conf = env_vars
283+
.get_env_var("OPENSEARCH_PATH_CONF")
284+
.and_then(|env_var| env_var.value.clone())
285+
.unwrap_or(format!("{opensearch_home}/config"));
286+
274287
ContainerBuilder::new("opensearch")
275288
.expect("should be a valid container name")
276289
.image_from_product_image(&product_image)
277290
.command(vec![format!(
278-
"{OPENSEARCH_BASE_PATH}/opensearch-docker-entrypoint.sh"
291+
"{opensearch_home}/opensearch-docker-entrypoint.sh"
279292
)])
280293
.args(role_group_config.cli_overrides_to_vec())
281-
.add_env_vars(self.node_config.environment_variables().into())
294+
.add_env_vars(env_vars.into())
282295
.add_volume_mounts([
283296
VolumeMount {
284297
mount_path: format!(
285-
"{OPENSEARCH_BASE_PATH}/config/{CONFIGURATION_FILE_OPENSEARCH_YML}"
298+
"{opensearch_path_conf}/{CONFIGURATION_FILE_OPENSEARCH_YML}"
286299
),
287300
name: CONFIG_VOLUME_NAME.to_owned(),
288301
read_only: Some(true),
289302
sub_path: Some(CONFIGURATION_FILE_OPENSEARCH_YML.to_owned()),
290303
..VolumeMount::default()
291304
},
292305
VolumeMount {
293-
mount_path: format!("{OPENSEARCH_BASE_PATH}/data"),
306+
mount_path: format!("{opensearch_home}/data"),
294307
name: DATA_VOLUME_NAME.to_owned(),
295308
..VolumeMount::default()
296309
},

rust/operator-binary/src/framework/builder/pod/container.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ impl EnvVarSet {
1616
Self::default()
1717
}
1818

19+
pub fn get_env_var(&self, env_var_name: impl Into<EnvVarName>) -> Option<&EnvVar> {
20+
self.0.get(&env_var_name.into())
21+
}
22+
23+
pub fn add_env_var(mut self, env_var: EnvVar) -> Self {
24+
self.0.insert(env_var.name.clone(), env_var);
25+
26+
self
27+
}
28+
29+
pub fn merge(mut self, mut env_var_set: EnvVarSet) -> Self {
30+
self.0.append(&mut env_var_set.0);
31+
32+
self
33+
}
34+
1935
pub fn with_values<I, K, V>(self, env_vars: I) -> Self
2036
where
2137
I: IntoIterator<Item = (K, V)>,

tests/templates/kuttl/external-access/opensearch.yaml.j2

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ metadata:
55
name: opensearch
66
spec:
77
image:
8-
productVersion: 3.1.0
8+
{% if test_scenario['values']['opensearch'].find(",") > 0 %}
9+
custom: "{{ test_scenario['values']['opensearch'].split(',')[1] }}"
10+
productVersion: "{{ test_scenario['values']['opensearch'].split(',')[0] }}"
11+
{% else %}
12+
productVersion: "{{ test_scenario['values']['opensearch'] }}"
13+
{% endif %}
914
pullPolicy: IfNotPresent
1015
nodes:
1116
roleGroups:
@@ -57,6 +62,7 @@ spec:
5762
envOverrides:
5863
# TODO Make these the defaults in the image
5964
DISABLE_INSTALL_DEMO_CONFIG: "true"
65+
OPENSEARCH_HOME: {{ test_scenario['values']['opensearch_home'] }}
6066
configOverrides:
6167
# TODO Add the required options to the operator
6268
opensearch.yml:
@@ -66,24 +72,25 @@ spec:
6672
# TODO Check that this is safe despite the warning in the documentation
6773
plugins.security.allow_default_init_securityindex: "true"
6874
plugins.security.ssl.transport.enabled: "true"
69-
plugins.security.ssl.transport.pemcert_filepath: /stackable/opensearch/config/tls/tls.crt
70-
plugins.security.ssl.transport.pemkey_filepath: /stackable/opensearch/config/tls/tls.key
71-
plugins.security.ssl.transport.pemtrustedcas_filepath: /stackable/opensearch/config/tls/ca.crt
75+
plugins.security.ssl.transport.pemcert_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/tls.crt
76+
plugins.security.ssl.transport.pemkey_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/tls.key
77+
plugins.security.ssl.transport.pemtrustedcas_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/ca.crt
7278
plugins.security.ssl.http.enabled: "true"
73-
plugins.security.ssl.http.pemcert_filepath: /stackable/opensearch/config/tls/tls.crt
74-
plugins.security.ssl.http.pemkey_filepath: /stackable/opensearch/config/tls/tls.key
75-
plugins.security.ssl.http.pemtrustedcas_filepath: /stackable/opensearch/config/tls/ca.crt
79+
plugins.security.ssl.http.pemcert_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/tls.crt
80+
plugins.security.ssl.http.pemkey_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/tls.key
81+
plugins.security.ssl.http.pemtrustedcas_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/ca.crt
7682
plugins.security.authcz.admin_dn: "CN=generated certificate for pod"
7783
podOverrides:
7884
spec:
7985
containers:
8086
- name: opensearch
8187
volumeMounts:
8288
- name: security-config
83-
mountPath: /stackable/opensearch/config/opensearch-security
89+
mountPath: {{ test_scenario['values']['opensearch_home'] }}/config/opensearch-security
8490
readOnly: true
8591
- name: tls
86-
mountPath: /stackable/opensearch/config/tls
92+
# The Java policy allows reading from ${OPENSEARCH_HOME}/config.
93+
mountPath: {{ test_scenario['values']['opensearch_home'] }}/config/tls
8794
readOnly: true
8895
securityContext:
8996
fsGroup: 1000

0 commit comments

Comments
 (0)