Skip to content

Commit 38a0996

Browse files
committed
refactor: Switch to a lis of objects (as opposed to a big string field)
1 parent 00fd1b7 commit 38a0996

5 files changed

Lines changed: 175 additions & 173 deletions

File tree

crates/stackable-operator/src/cluster_resources.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ use k8s_openapi::{
2222
},
2323
apimachinery::pkg::apis::meta::v1::{LabelSelector, LabelSelectorRequirement},
2424
};
25-
use kube::{Resource, ResourceExt, api::DynamicObject, core::ErrorResponse};
25+
use kube::{Resource, ResourceExt, core::ErrorResponse};
2626
use serde::{Serialize, de::DeserializeOwned};
2727
use snafu::{OptionExt, ResultExt, Snafu};
28-
use stackable_shared::patchinator::{self, apply_patches, parse_patches};
2928
use strum::Display;
3029
use tracing::{debug, info, warn};
3130

@@ -43,6 +42,7 @@ use crate::{
4342
Label, LabelError, Labels,
4443
consts::{K8S_APP_INSTANCE_KEY, K8S_APP_MANAGED_BY_KEY, K8S_APP_NAME_KEY},
4544
},
45+
patchinator::{self, ObjectOverrides, apply_patches},
4646
utils::format_full_controller_name,
4747
};
4848

@@ -422,7 +422,7 @@ impl ClusterResource for Deployment {
422422
/// }
423423
/// ```
424424
#[derive(Debug)]
425-
pub struct ClusterResources {
425+
pub struct ClusterResources<'a> {
426426
/// The namespace of the cluster
427427
namespace: String,
428428

@@ -452,10 +452,10 @@ pub struct ClusterResources {
452452
apply_strategy: ClusterResourceApplyStrategy,
453453

454454
/// Arbitrary Kubernetes object overrides specified by the user via the CRD.
455-
object_overrides: Vec<DynamicObject>,
455+
object_overrides: &'a ObjectOverrides,
456456
}
457457

458-
impl ClusterResources {
458+
impl<'a> ClusterResources<'a> {
459459
/// Constructs new `ClusterResources`.
460460
///
461461
/// # Arguments
@@ -481,7 +481,7 @@ impl ClusterResources {
481481
controller_name: &str,
482482
cluster: &ObjectReference,
483483
apply_strategy: ClusterResourceApplyStrategy,
484-
object_overrides: Option<impl AsRef<str>>,
484+
object_overrides: &'a ObjectOverrides,
485485
) -> Result<Self> {
486486
let namespace = cluster
487487
.namespace
@@ -495,12 +495,6 @@ impl ClusterResources {
495495
.uid
496496
.clone()
497497
.context(MissingObjectKeySnafu { key: "uid" })?;
498-
let object_overrides = match object_overrides {
499-
Some(object_overrides) => {
500-
parse_patches(object_overrides).context(ParseObjectOverridesSnafu)?
501-
}
502-
None => vec![],
503-
};
504498

505499
Ok(ClusterResources {
506500
namespace,
@@ -585,8 +579,7 @@ impl ClusterResources {
585579
let mut mutated = resource.maybe_mutate(&self.apply_strategy);
586580

587581
// We apply the object overrides of the user at the very last to offer maximum flexibility.
588-
apply_patches(&mut mutated, self.object_overrides.iter())
589-
.context(ApplyObjectOverridesSnafu)?;
582+
apply_patches(&mut mutated, self.object_overrides).context(ApplyObjectOverridesSnafu)?;
590583

591584
let patched_resource = self
592585
.apply_strategy

crates/stackable-operator/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub mod kvp;
2222
pub mod logging;
2323
pub mod memory;
2424
pub mod namespace;
25+
pub mod patchinator;
2526
pub mod pod_utils;
2627
pub mod product_config_utils;
2728
pub mod product_logging;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use kube::api::DynamicObject;
2+
use schemars::JsonSchema;
3+
use serde::{Deserialize, Serialize};
4+
5+
use crate::utils::crds::raw_object_list_schema;
6+
7+
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
8+
#[serde(rename_all = "camelCase")]
9+
pub struct ObjectOverrides {
10+
#[serde(default)]
11+
#[schemars(schema_with = "raw_object_list_schema")]
12+
pub object_overrides: Vec<DynamicObject>,
13+
}

0 commit comments

Comments
 (0)