Skip to content

Commit fca3d49

Browse files
committed
feat: Support dynamic image repositories
1 parent 9d0b22c commit fca3d49

8 files changed

Lines changed: 72 additions & 44 deletions

File tree

Cargo.lock

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.nix

Lines changed: 18 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repository = "https://github.com/stackabletech/zookeeper-operator"
1111

1212
[workspace.dependencies]
1313
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.8.0" }
14-
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.110.1", features = ["webhook"] }
14+
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.111.1", features = ["webhook"] }
1515

1616
anyhow = "1.0"
1717
built = { version = "0.8", features = ["chrono", "git2"] }

crate-hashes.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extra/crds.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ spec:
145145
properties:
146146
custom:
147147
description: |-
148-
Overwrite the docker image.
149-
Specify the full docker image name, e.g. `oci.stackable.tech/sdp/superset:1.4.1-stackable2.1.0`
148+
Provide a custom container image.
149+
150+
Specify the full container image name, e.g. `oci.example.tech/namespace/superset:1.4.1-my-tag`
150151
type: string
151152
productVersion:
152153
description: Version of the product, e.g. `1.4.1`.
@@ -173,14 +174,20 @@ spec:
173174
nullable: true
174175
type: array
175176
repo:
176-
description: Name of the docker repo, e.g. `oci.stackable.tech/sdp`
177+
description: |-
178+
The repository on the container image registry where the container image is located, e.g.
179+
`oci.example.com/namespace`.
180+
181+
If not specified, the operator will use the image registry provided via the operator
182+
environment options.
177183
nullable: true
178184
type: string
179185
stackableVersion:
180186
description: |-
181187
Stackable version of the product, e.g. `23.4`, `23.4.1` or `0.0.0-dev`.
182-
If not specified, the operator will use its own version, e.g. `23.4.1`.
183-
When using a nightly operator or a pr version, it will use the nightly `0.0.0-dev` image.
188+
189+
If not specified, the operator will use its own version, e.g. `23.4.1`. When using a nightly
190+
operator or a PR version, it will use the nightly `0.0.0-dev` image.
184191
nullable: true
185192
type: string
186193
type: object

rust/operator-binary/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ async fn main() -> anyhow::Result<()> {
158158
zk_controller::reconcile_zk,
159159
zk_controller::error_policy,
160160
Arc::new(zk_controller::Ctx {
161+
operator_environment: operator_environment.clone(),
161162
client: client.clone(),
162163
product_config,
163164
}),
@@ -224,6 +225,7 @@ async fn main() -> anyhow::Result<()> {
224225
znode_controller::error_policy,
225226
Arc::new(znode_controller::Ctx {
226227
client: client.clone(),
228+
operator_environment,
227229
}),
228230
)
229231
// We can let the reporting happen in the background

rust/operator-binary/src/zk_controller.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use stackable_operator::{
2828
volume::{ListenerOperatorVolumeSourceBuilder, ListenerReference},
2929
},
3030
},
31+
cli::OperatorEnvironmentOptions,
3132
cluster_resources::{ClusterResourceApplyStrategy, ClusterResources},
3233
commons::{
3334
product_image_selection::{self, ResolvedProductImage},
@@ -80,7 +81,7 @@ use crate::{
8081
command::create_init_container_command_args,
8182
config::jvm::{construct_non_heap_jvm_args, construct_zk_server_heap_env},
8283
crd::{
83-
DOCKER_IMAGE_BASE_NAME, JMX_METRICS_PORT_NAME, JVM_SECURITY_PROPERTIES_FILE,
84+
CONTAINER_IMAGE_BASE_NAME, JMX_METRICS_PORT_NAME, JVM_SECURITY_PROPERTIES_FILE,
8485
MAX_PREPARE_LOG_FILE_SIZE, MAX_ZK_LOG_FILES_SIZE, METRICS_PROVIDER_HTTP_PORT_NAME,
8586
STACKABLE_CONFIG_DIR, STACKABLE_DATA_DIR, STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR,
8687
STACKABLE_RW_CONFIG_DIR, ZOOKEEPER_ELECTION_PORT, ZOOKEEPER_ELECTION_PORT_NAME,
@@ -108,6 +109,7 @@ pub const LISTENER_VOLUME_DIR: &str = "/stackable/listener";
108109
pub struct Ctx {
109110
pub client: stackable_operator::client::Client,
110111
pub product_config: ProductConfigManager,
112+
pub operator_environment: OperatorEnvironmentOptions,
111113
}
112114

113115
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -365,7 +367,11 @@ pub async fn reconcile_zk(
365367
let resolved_product_image = zk
366368
.spec
367369
.image
368-
.resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::PKG_VERSION)
370+
.resolve(
371+
CONTAINER_IMAGE_BASE_NAME,
372+
&ctx.operator_environment.image_repository,
373+
crate::built_info::PKG_VERSION,
374+
)
369375
.context(ResolveProductImageSnafu)?;
370376

371377
let mut cluster_resources = ClusterResources::new(
@@ -1149,7 +1155,7 @@ mod tests {
11491155
let resolved_product_image = zookeeper
11501156
.spec
11511157
.image
1152-
.resolve(DOCKER_IMAGE_BASE_NAME, "0.0.0-dev")
1158+
.resolve(CONTAINER_IMAGE_BASE_NAME, "oci.example.org", "0.0.0-dev")
11531159
.expect("test resolved product image is always valid");
11541160

11551161
let validated_config = validate_all_roles_and_groups_config(

rust/operator-binary/src/znode_controller.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{borrow::Cow, convert::Infallible, sync::Arc};
66
use const_format::concatcp;
77
use snafu::{OptionExt, ResultExt, Snafu};
88
use stackable_operator::{
9+
cli::OperatorEnvironmentOptions,
910
cluster_resources::{ClusterResourceApplyStrategy, ClusterResources},
1011
commons::product_image_selection::{self, ResolvedProductImage},
1112
crd::listener,
@@ -25,7 +26,7 @@ use tracing::{debug, info};
2526

2627
use crate::{
2728
APP_NAME, OPERATOR_NAME,
28-
crd::{DOCKER_IMAGE_BASE_NAME, ZookeeperRole, security::ZookeeperSecurity, v1alpha1},
29+
crd::{CONTAINER_IMAGE_BASE_NAME, ZookeeperRole, security::ZookeeperSecurity, v1alpha1},
2930
discovery::{self, build_discovery_configmap},
3031
listener::role_listener_name,
3132
};
@@ -35,6 +36,7 @@ pub const ZNODE_FULL_CONTROLLER_NAME: &str = concatcp!(ZNODE_CONTROLLER_NAME, '.
3536

3637
pub struct Ctx {
3738
pub client: stackable_operator::client::Client,
39+
pub operator_environment: OperatorEnvironmentOptions,
3840
}
3941

4042
#[derive(Snafu, Debug, EnumDiscriminants)]
@@ -253,7 +255,11 @@ pub async fn reconcile_znode(
253255
let resolved_product_image = zk
254256
.spec
255257
.image
256-
.resolve(DOCKER_IMAGE_BASE_NAME, crate::built_info::PKG_VERSION)
258+
.resolve(
259+
CONTAINER_IMAGE_BASE_NAME,
260+
&ctx.operator_environment.image_repository,
261+
crate::built_info::PKG_VERSION,
262+
)
257263
.context(ResolveProductImageSnafu)?;
258264
reconcile_apply(client, &znode, Ok(zk), &znode_path, &resolved_product_image)
259265
.await

0 commit comments

Comments
 (0)