Skip to content

Commit 99cf8f6

Browse files
committed
refactor: remove raw opacluster dependencies
1 parent c48c70e commit 99cf8f6

10 files changed

Lines changed: 29 additions & 47 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ mod tests {
146146
/// Renders `config.json` for the `default` server role group of an `OpaCluster` built from
147147
/// `spec`, and parses it back into a [`Value`].
148148
fn config_json_for(spec: Value) -> Value {
149-
let (_, validated) = validated_cluster_from_spec(spec);
149+
let validated = validated_cluster_from_spec(spec);
150150
let rg = validated.role_group_configs[&OpaRole::Server]
151151
.values()
152152
.next()

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pub(crate) mod test_support {
2626
crd::v1alpha2,
2727
};
2828

29-
/// Builds an `OpaCluster` from the given `spec` JSON and runs the validate step, returning both
30-
/// the raw cluster (for owner references) and the [`ValidatedCluster`].
31-
pub fn validated_cluster_from_spec(spec: Value) -> (v1alpha2::OpaCluster, ValidatedCluster) {
29+
/// Builds an `OpaCluster` from the given `spec` JSON and runs the validate step, returning the
30+
/// resulting [`ValidatedCluster`].
31+
pub fn validated_cluster_from_spec(spec: Value) -> ValidatedCluster {
3232
let opa: v1alpha2::OpaCluster = serde_json::from_value(json!({
3333
"apiVersion": "opa.stackable.tech/v1alpha2",
3434
"kind": "OpaCluster",
@@ -47,8 +47,6 @@ pub(crate) mod test_support {
4747
image_repository: "oci.stackable.tech/sdp".to_string(),
4848
};
4949

50-
let validated = validate(&opa, &operator_environment)
51-
.expect("validation should succeed for the fixture");
52-
(opa, validated)
50+
validate(&opa, &operator_environment).expect("validation should succeed for the fixture")
5351
}
5452
}

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

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

9090
/// Renders the ConfigMap of the `default` server role group of an `OpaCluster` built from `spec`.
9191
fn build_config_map(spec: Value) -> ConfigMap {
92-
let (_opa, validated) = validated_cluster_from_spec(spec);
92+
let validated = validated_cluster_from_spec(spec);
9393

9494
let role = OpaRole::Server;
9595
let (role_group_name, rg) = validated.role_group_configs[&role]

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use stackable_operator::{
1818
},
1919
},
2020
commons::{
21-
product_image_selection::ResolvedProductImage,
2221
secret_class::{
2322
SecretClassVolume, SecretClassVolumeProvisionParts, SecretClassVolumeScope,
2423
},
@@ -60,9 +59,7 @@ use stackable_operator::{
6059
use super::service::{self, APP_PORT, APP_PORT_NAME};
6160
use crate::{
6261
controller::{RoleGroupName, ValidatedCluster, ValidatedRoleGroup, build},
63-
crd::{
64-
Container, DEFAULT_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT, OpaConfig, user_info_fetcher, v1alpha2,
65-
},
62+
crd::{Container, DEFAULT_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT, OpaConfig, user_info_fetcher},
6663
operations::graceful_shutdown::add_graceful_shutdown_config,
6764
};
6865

@@ -234,16 +231,15 @@ fn http_status_liveness_probe(port: IntOrString, scheme: Option<String>) -> Prob
234231
/// policy queries (which are often chained in serial, and block other tasks in the products).
235232
#[allow(clippy::too_many_arguments)]
236233
pub fn build_server_rolegroup_daemonset(
237-
opa: &v1alpha2::OpaCluster,
238234
cluster: &ValidatedCluster,
239-
resolved_product_image: &ResolvedProductImage,
240235
role_group_name: &RoleGroupName,
241236
role_group: &ValidatedRoleGroup,
242237
opa_bundle_builder_image: &str,
243238
user_info_fetcher_image: &str,
244239
service_account: &ServiceAccount,
245240
cluster_info: &KubernetesClusterInfo,
246241
) -> Result<DaemonSet> {
242+
let resolved_product_image = &cluster.image;
247243
let rolegroup_config = &role_group.config;
248244
// All overrides were already merged (role group over role over defaults) in the validate step.
249245
let merged_config = &rolegroup_config.config;
@@ -314,7 +310,7 @@ pub fn build_server_rolegroup_daemonset(
314310
.args(vec![build_opa_start_command(
315311
merged_config,
316312
opa_container_name.as_ref(),
317-
opa.spec.cluster_config.tls_enabled(),
313+
cluster.cluster_config.tls.is_some(),
318314
&rolegroup_config.cli_overrides,
319315
)])
320316
.add_env_vars(rolegroup_config.env_overrides.clone())
@@ -329,7 +325,7 @@ pub fn build_server_rolegroup_daemonset(
329325
// .spec.template.spec.containers[name="opa"].ports: duplicate entries for key [containerPort=8081,protocol="TCP"]
330326
//
331327
// So we don't do that
332-
if opa.spec.cluster_config.tls_enabled() {
328+
if cluster.cluster_config.tls.is_some() {
333329
cb_opa.add_container_port(service::APP_TLS_PORT_NAME, service::APP_TLS_PORT.into());
334330
cb_opa
335331
.add_volume_mount(TLS_VOLUME_NAME.as_ref(), TLS_STORE_DIR)
@@ -345,7 +341,7 @@ pub fn build_server_rolegroup_daemonset(
345341
.context(AddVolumeMountSnafu)?
346342
.resources(merged_config.resources.to_owned().into());
347343

348-
let (probe_port_name, probe_scheme) = if opa.spec.cluster_config.tls_enabled() {
344+
let (probe_port_name, probe_scheme) = if cluster.cluster_config.tls.is_some() {
349345
(service::APP_TLS_PORT_NAME, Some("HTTPS".to_string()))
350346
} else {
351347
(APP_PORT_NAME, Some("HTTP".to_string()))
@@ -406,7 +402,7 @@ pub fn build_server_rolegroup_daemonset(
406402
.service_account_name(service_account.name_any())
407403
.security_context(PodSecurityContextBuilder::new().fs_group(1000).build());
408404

409-
if let Some(tls) = &opa.spec.cluster_config.tls {
405+
if let Some(tls) = &cluster.cluster_config.tls {
410406
pb.add_volume(
411407
VolumeBuilder::new(TLS_VOLUME_NAME.as_ref())
412408
.ephemeral(
@@ -431,7 +427,7 @@ pub fn build_server_rolegroup_daemonset(
431427
.context(AddVolumeSnafu)?;
432428
}
433429

434-
if let Some(user_info) = &opa.spec.cluster_config.user_info {
430+
if let Some(user_info) = &cluster.cluster_config.user_info {
435431
let user_info_fetcher_container_name = container_name(&Container::UserInfoFetcher);
436432
let mut cb_user_info_fetcher = new_container_builder(&user_info_fetcher_container_name);
437433

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ mod tests {
8282

8383
#[test]
8484
fn renders_http_url_without_tls() {
85-
let (_opa, validated) = validated_cluster_from_spec(serde_json::json!({
85+
let validated = validated_cluster_from_spec(serde_json::json!({
8686
"image": { "productVersion": "1.2.3" },
8787
"servers": { "roleGroups": { "default": {} } },
8888
}));
@@ -99,7 +99,7 @@ mod tests {
9999

100100
#[test]
101101
fn renders_https_url_and_secret_class_with_tls() {
102-
let (_opa, validated) = validated_cluster_from_spec(serde_json::json!({
102+
let validated = validated_cluster_from_spec(serde_json::json!({
103103
"image": { "productVersion": "1.2.3" },
104104
"clusterConfig": { "tls": { "serverSecretClass": "tls" } },
105105
"servers": { "roleGroups": { "default": {} } },

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ use stackable_operator::{
77
v2::builder::meta::ownerreference_from_resource,
88
};
99

10-
use crate::{
11-
controller::{RoleGroupName, ValidatedCluster},
12-
crd::v1alpha2,
13-
};
10+
use crate::controller::{RoleGroupName, ValidatedCluster};
1411

1512
pub const APP_PORT: u16 = 8081;
1613
pub const APP_TLS_PORT: u16 = 8443;
@@ -27,10 +24,7 @@ fn role_level_role_group_name() -> RoleGroupName {
2724

2825
/// The server-role service is the primary endpoint that should be used by clients that do not perform internal load balancing,
2926
/// including targets outside of the cluster.
30-
pub(crate) fn build_server_role_service(
31-
opa: &v1alpha2::OpaCluster,
32-
cluster: &ValidatedCluster,
33-
) -> Service {
27+
pub(crate) fn build_server_role_service(cluster: &ValidatedCluster) -> Service {
3428
let metadata = ObjectMetaBuilder::new()
3529
.name_and_namespace(cluster)
3630
.name(cluster.server_role_service_name())
@@ -39,7 +33,7 @@ pub(crate) fn build_server_role_service(
3933
.build();
4034

4135
let service_spec = ServiceSpec {
42-
type_: Some(opa.spec.cluster_config.listener_class.k8s_service_type()),
36+
type_: Some(cluster.cluster_config.listener_class.k8s_service_type()),
4337
ports: Some(data_service_ports(cluster.cluster_config.tls.is_some())),
4438
selector: Some(cluster.role_selector().into()),
4539
// This ensures that products (e.g. Trino) on a node always talk to the OPA pod on the

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ impl KubeResource for ValidatedCluster {
202202
pub struct ValidatedClusterConfig {
203203
pub user_info: Option<user_info_fetcher::v1alpha2::Config>,
204204
pub tls: Option<v1alpha2::OpaTls>,
205+
pub listener_class: v1alpha2::CurrentlySupportedListenerClasses,
205206
}
206207

207208
/// The validated configuration of a single role group.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ pub fn validate(
227227
ValidatedClusterConfig {
228228
user_info: opa.spec.cluster_config.user_info.clone(),
229229
tls: opa.spec.cluster_config.tls.clone(),
230+
listener_class: opa.spec.cluster_config.listener_class.clone(),
230231
},
231232
role_group_configs,
232233
))

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,6 @@ impl v1alpha2::CurrentlySupportedListenerClasses {
268268
}
269269
}
270270

271-
impl v1alpha2::OpaClusterConfig {
272-
/// Returns whether TLS encryption is enabled for the OPA server.
273-
pub fn tls_enabled(&self) -> bool {
274-
self.tls.is_some()
275-
}
276-
}
277-
278271
impl OpaConfig {
279272
pub fn default_config() -> OpaConfigFragment {
280273
OpaConfigFragment {

rust/operator-binary/src/opa_controller.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub async fn reconcile_opa(
170170

171171
// NOTE(@maltesander): There currently is no dereference (client required) step for OPA.
172172
// validate (no client required)
173-
let validated =
173+
let validated_cluster =
174174
validate::validate(opa, &ctx.operator_environment).context(ValidateClusterSnafu)?;
175175

176176
let opa_role = OpaRole::Server;
@@ -186,12 +186,12 @@ pub async fn reconcile_opa(
186186
.context(FailedToCreateClusterResourcesSnafu)?;
187187

188188
let empty_role_group_configs = BTreeMap::new();
189-
let role_group_configs = validated
189+
let role_group_configs = validated_cluster
190190
.role_group_configs
191191
.get(&opa_role)
192192
.unwrap_or(&empty_role_group_configs);
193193

194-
let server_role_service = build_server_role_service(opa, &validated);
194+
let server_role_service = build_server_role_service(&validated_cluster);
195195
cluster_resources
196196
.add(client, server_role_service)
197197
.await
@@ -225,20 +225,19 @@ pub async fn reconcile_opa(
225225
.map(|_| build::properties::product_logging::vector_config_file_content());
226226

227227
let rg_configmap = build::resource::config_map::build_rolegroup_config_map(
228-
&validated,
228+
&validated_cluster,
229229
rolegroup_name,
230230
&rolegroup.config,
231231
vector_config,
232232
)
233233
.with_context(|_| BuildRoleGroupConfigSnafu {
234234
rolegroup: rolegroup_name.clone(),
235235
})?;
236-
let rg_service = build_rolegroup_headless_service(&validated, rolegroup_name);
237-
let rg_metrics_service = build_rolegroup_metrics_service(&validated, rolegroup_name);
236+
let rg_service = build_rolegroup_headless_service(&validated_cluster, rolegroup_name);
237+
let rg_metrics_service =
238+
build_rolegroup_metrics_service(&validated_cluster, rolegroup_name);
238239
let rg_daemonset = build::resource::daemonset::build_server_rolegroup_daemonset(
239-
opa,
240-
&validated,
241-
&validated.image,
240+
&validated_cluster,
242241
rolegroup_name,
243242
rolegroup,
244243
&ctx.opa_bundle_builder_image,
@@ -302,7 +301,7 @@ pub async fn reconcile_opa(
302301
}
303302

304303
let discovery_cm = build::resource::discovery::build_discovery_config_map(
305-
&validated,
304+
&validated_cluster,
306305
&client.kubernetes_cluster_info,
307306
)
308307
.context(BuildDiscoveryConfigSnafu)?;

0 commit comments

Comments
 (0)