Skip to content

Commit 53d0529

Browse files
doc: Add code comments
1 parent 1a30db1 commit 53d0529

7 files changed

Lines changed: 113 additions & 58 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The apply step in the OpenSearchCluster controller
2+
13
use std::marker::PhantomData;
24

35
use snafu::{ResultExt, Snafu};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The build step in the OpenSearchCluster controller
2+
13
use std::marker::PhantomData;
24

35
use role_builder::RoleBuilder;

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Configuration of an OpenSearch node
2+
13
use std::str::FromStr;
24

35
use serde_json::{Value, json};
@@ -14,33 +16,49 @@ use crate::{
1416
},
1517
};
1618

19+
/// The main configuration file of OpenSearch
1720
pub const CONFIGURATION_FILE_OPENSEARCH_YML: &str = "opensearch.yml";
1821

19-
/// type: string
22+
/// The cluster name.
23+
/// Type: string
2024
pub const CONFIG_OPTION_CLUSTER_NAME: &str = "cluster.name";
2125

22-
/// type: (comma-separated) list of strings
26+
/// The list of hosts that perform discovery when a node is started.
27+
/// Type: (comma-separated) list of strings
2328
pub const CONFIG_OPTION_DISCOVERY_SEED_HOSTS: &str = "discovery.seed_hosts";
2429

25-
/// type: string
30+
/// By default, OpenSearch forms a multi-node cluster. Set `discovery.type` to `single-node` to
31+
/// form a single-node cluster.
32+
/// Type: string
2633
pub const CONFIG_OPTION_DISCOVERY_TYPE: &str = "discovery.type";
2734

28-
/// type: (comma-separated) list of strings
35+
/// A list of cluster-manager-eligible nodes used to bootstrap the cluster.
36+
/// Type: (comma-separated) list of strings
2937
pub const CONFIG_OPTION_INITIAL_CLUSTER_MANAGER_NODES: &str =
3038
"cluster.initial_cluster_manager_nodes";
3139

32-
/// type: string
40+
/// Binds an OpenSearch node to an address.
41+
/// Type: string
3342
pub const CONFIG_OPTION_NETWORK_HOST: &str = "network.host";
3443

35-
/// type: string
44+
/// A descriptive name for the node.
45+
/// Type: string
3646
pub const CONFIG_OPTION_NODE_NAME: &str = "node.name";
3747

38-
/// type: (comma-separated) list of strings
48+
/// Defines one or more roles for an OpenSearch node.
49+
/// Type: (comma-separated) list of strings
3950
pub const CONFIG_OPTION_NODE_ROLES: &str = "node.roles";
4051

41-
/// type: (comma-separated) list of strings
52+
/// Specifies a list of distinguished names (DNs) that denote the other nodes in the cluster.
53+
/// Type: (comma-separated) list of strings
4254
pub const CONFIG_OPTION_PLUGINS_SECURITY_NODES_DN: &str = "plugins.security.nodes_dn";
4355

56+
/// Whether to enable TLS on the REST layer. If enabled, only HTTPS is allowed.
57+
/// Type: boolean
58+
pub const CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_ENABLED: &str =
59+
"plugins.security.ssl.http.enabled";
60+
61+
/// Configuration of an OpenSearch node based on the cluster and role-group configuration
4462
pub struct NodeConfig {
4563
cluster: ValidatedCluster,
4664
role_group_config: OpenSearchRoleGroupConfig,
@@ -62,12 +80,15 @@ impl NodeConfig {
6280
}
6381
}
6482

65-
/// static for the cluster
83+
/// Creates the main OpenSearch configuration file in YAML format
6684
pub fn static_opensearch_config_file(&self) -> String {
6785
Self::to_yaml(self.static_opensearch_config())
6886
}
6987

70-
/// static for the cluster
88+
/// Creates the main OpenSearch configuration file as JSON map
89+
///
90+
/// The file should only contain cluster-wide configuration options. Node-specific options
91+
/// should be defined as environment variables.
7192
pub fn static_opensearch_config(&self) -> serde_json::Map<String, Value> {
7293
let mut config = serde_json::Map::new();
7394

@@ -107,13 +128,15 @@ impl NodeConfig {
107128
config
108129
}
109130

131+
/// Returns `true` if TLS is enabled on the HTTP port
110132
pub fn tls_on_http_port_enabled(&self) -> bool {
111133
self.static_opensearch_config()
112-
.get("plugins.security.ssl.http.enabled")
134+
.get(CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_ENABLED)
113135
.and_then(Self::value_as_bool)
114136
== Some(true)
115137
}
116138

139+
/// Converts the given JSON value to `bool` if possible
117140
pub fn value_as_bool(value: &Value) -> Option<bool> {
118141
value.as_bool().or(
119142
// OpenSearch parses the strings "true" and "false" as boolean, see
@@ -124,7 +147,10 @@ impl NodeConfig {
124147
)
125148
}
126149

127-
/// different for every node
150+
/// Creates environment variables for the OpenSearch configurations
151+
///
152+
/// The environment variables should only contain node-specific configuration options.
153+
/// Cluster-wide options should be added to the configuration file.
128154
pub fn environment_variables(&self) -> EnvVarSet {
129155
EnvVarSet::new()
130156
// Set the OpenSearch node name to the Pod name.

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Builder for role resources
2+
13
use stackable_operator::{
24
builder::meta::ObjectMetaBuilder,
35
k8s_openapi::{
@@ -31,6 +33,7 @@ use crate::{
3133

3234
const PDB_DEFAULT_MAX_UNAVAILABLE: u16 = 1;
3335

36+
/// Builder for role resources
3437
pub struct RoleBuilder<'a> {
3538
cluster: ValidatedCluster,
3639
context_names: &'a ContextNames,
@@ -49,6 +52,7 @@ impl<'a> RoleBuilder<'a> {
4952
}
5053
}
5154

55+
/// Creates role-group builders which are initialized with the role-level context
5256
pub fn role_group_builders(&self) -> Vec<RoleGroupBuilder<'_>> {
5357
self.cluster
5458
.role_group_configs
@@ -66,6 +70,7 @@ impl<'a> RoleBuilder<'a> {
6670
.collect()
6771
}
6872

73+
/// Builds a ServiceAccount used by all role-groups
6974
pub fn build_service_account(&self) -> ServiceAccount {
7075
let metadata = self.common_metadata(self.resource_names.service_account_name());
7176

@@ -75,6 +80,7 @@ impl<'a> RoleBuilder<'a> {
7580
}
7681
}
7782

83+
/// Builds a RoleBinding used by all role-groups
7884
pub fn build_role_binding(&self) -> RoleBinding {
7985
let metadata = self.common_metadata(self.resource_names.role_binding_name());
8086

@@ -94,6 +100,14 @@ impl<'a> RoleBuilder<'a> {
94100
}
95101
}
96102

103+
/// Builds a Service that references all nodes with the cluster_manager node role
104+
///
105+
/// Initially, this service was meant to be used by
106+
/// `NodeConfig::initial_cluster_manager_nodes`, but the function uses now another approach.
107+
/// Afterwards, it was meant to be used as an entry point to OpenSearch, but it could also make
108+
/// sense to use coordinating only nodes as entry points and not cluster manager nodes.
109+
/// Therefore, this service will bei either adapted or removed. There is already an according
110+
/// task entry in <https://github.com/stackabletech/opensearch-operator/issues/1>.
97111
pub fn build_cluster_manager_service(&self) -> Service {
98112
let ports = vec![
99113
ServicePort {
@@ -130,6 +144,7 @@ impl<'a> RoleBuilder<'a> {
130144
}
131145
}
132146

147+
/// Builds a PodDisruptionBudget used by all role-groups
133148
pub fn build_pdb(&self) -> Option<PodDisruptionBudget> {
134149
let pdb_config = &self.cluster.role_config.pod_disruption_budget;
135150

@@ -153,6 +168,7 @@ impl<'a> RoleBuilder<'a> {
153168
}
154169
}
155170

171+
/// Common metadata for role resources
156172
fn common_metadata(&self, resource_name: impl Into<String>) -> ObjectMeta {
157173
ObjectMetaBuilder::new()
158174
.name(resource_name)
@@ -166,7 +182,7 @@ impl<'a> RoleBuilder<'a> {
166182
.build()
167183
}
168184

169-
/// Labels on role resources
185+
/// Common labels for role resources
170186
fn labels(&self) -> Labels {
171187
// Well-known Kubernetes labels
172188
let mut labels = Labels::role_selector(

0 commit comments

Comments
 (0)