Skip to content

Commit c657d57

Browse files
committed
adapt to op-rs 0.79.0
1 parent 3e0a1bb commit c657d57

File tree

9 files changed

+139
-52
lines changed

9 files changed

+139
-52
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- The operator can now run on Kubernetes clusters using a non-default cluster domain. It should automatically detect the
10+
correct domain to use, but you can also use the env var `KUBERNETES_CLUSTER_DOMAIN` to set the domain explicitly
11+
or use the helm-chart property `kubernetesClusterDomain` ([#xxx]).
12+
713
### Changed
814

915
- Reduce CRD size from `483KB` to `57KB` by accepting arbitrary YAML input instead of the underlying schema for the following fields ([#853]):
@@ -16,6 +22,7 @@ All notable changes to this project will be documented in this file.
1622

1723
[#853]: https://github.com/stackabletech/zookeeper-operator/pull/853
1824
[#857]: https://github.com/stackabletech/zookeeper-operator/pull/857
25+
[#xxx]: https://github.com/stackabletech/zookeeper-operator/pull/xxx
1926

2027
## [24.7.0] - 2024-07-24
2128

Cargo.lock

Lines changed: 17 additions & 3 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
@@ -22,7 +22,7 @@ serde = { version = "1.0", features = ["derive"] }
2222
serde_json = "1.0"
2323
serde_yaml = "0.9"
2424
snafu = "0.8"
25-
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.76.0" }
25+
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.79.0" }
2626
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }
2727
strum = { version = "0.26", features = ["derive"] }
2828
tokio = { version = "1.40", features = ["full"] }

deploy/helm/zookeeper-operator/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,8 @@ nodeSelector: {}
4747
tolerations: []
4848

4949
affinity: {}
50+
51+
# When running on a non-default Kubernetes cluster domain and the auto detection is not working correctly,
52+
# you can set your custom cluster domain here.
53+
# See the https://docs.stackable.tech/home/stable/guides/kubernetes-cluster-domain guide for details
54+
# kubernetesClusterDomain: my-cluster.local

rust/crd/src/authentication.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ impl ResolvedAuthenticationClasses {
7373
AuthenticationClassProvider::Tls(_) => {}
7474
AuthenticationClassProvider::Ldap(_)
7575
| AuthenticationClassProvider::Oidc(_)
76-
| AuthenticationClassProvider::Static(_) => {
76+
| AuthenticationClassProvider::Static(_)
77+
| AuthenticationClassProvider::Kerberos(_) => {
7778
return Err(Error::AuthenticationMethodNotSupported {
7879
authentication_class: ObjectRef::from_obj(auth_class),
7980
method: auth_class.spec.provider.to_string(),

rust/crd/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use stackable_operator::{
2929
schemars::{self, JsonSchema},
3030
status::condition::{ClusterCondition, HasStatusCondition},
3131
time::Duration,
32+
utils::cluster_domain::KUBERNETES_CLUSTER_DOMAIN,
3233
};
3334
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
3435

@@ -483,10 +484,14 @@ impl ZookeeperCluster {
483484

484485
/// The fully-qualified domain name of the role-level load-balanced Kubernetes `Service`
485486
pub fn server_role_service_fqdn(&self) -> Option<String> {
487+
let cluster_domain = KUBERNETES_CLUSTER_DOMAIN
488+
.get()
489+
.expect("Could not resolve the Kubernetes cluster domain!");
486490
Some(format!(
487-
"{}.{}.svc.cluster.local",
491+
"{}.{}.svc.{}",
488492
self.server_role_service_name()?,
489-
self.metadata.namespace.as_ref()?
493+
self.metadata.namespace.as_ref()?,
494+
cluster_domain
490495
))
491496
}
492497

@@ -667,9 +672,12 @@ pub struct ZookeeperPodRef {
667672

668673
impl ZookeeperPodRef {
669674
pub fn fqdn(&self) -> String {
675+
let cluster_domain = KUBERNETES_CLUSTER_DOMAIN
676+
.get()
677+
.expect("Could not resolve the Kubernetes cluster domain!");
670678
format!(
671-
"{}.{}.{}.svc.cluster.local",
672-
self.pod_name, self.role_group_service_name, self.namespace
679+
"{}.{}.{}.svc.{}",
680+
self.pod_name, self.role_group_service_name, self.namespace, cluster_domain
673681
)
674682
}
675683
}

rust/crd/src/security.rs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ use std::collections::BTreeMap;
88

99
use snafu::{ResultExt, Snafu};
1010
use stackable_operator::{
11-
builder::pod::{
12-
container::ContainerBuilder,
13-
volume::{
14-
SecretFormat, SecretOperatorVolumeSourceBuilder,
15-
SecretOperatorVolumeSourceBuilderError, VolumeBuilder,
11+
builder::{
12+
self,
13+
pod::{
14+
container::ContainerBuilder,
15+
volume::{
16+
SecretFormat, SecretOperatorVolumeSourceBuilder,
17+
SecretOperatorVolumeSourceBuilderError, VolumeBuilder,
18+
},
19+
PodBuilder,
1620
},
17-
PodBuilder,
1821
},
1922
client::Client,
2023
commons::authentication::AuthenticationClassProvider,
@@ -35,6 +38,14 @@ pub enum Error {
3538
source: SecretOperatorVolumeSourceBuilderError,
3639
volume_name: String,
3740
},
41+
42+
#[snafu(display("failed to add needed volume"))]
43+
AddVolume { source: builder::pod::Error },
44+
45+
#[snafu(display("failed to add needed volumeMount"))]
46+
AddVolumeMount {
47+
source: builder::pod::container::Error,
48+
},
3849
}
3950

4051
/// Helper struct combining TLS settings for server and quorum with the resolved AuthenticationClasses
@@ -141,17 +152,25 @@ impl ZookeeperSecurity {
141152

142153
if let Some(secret_class) = tls_secret_class {
143154
let tls_volume_name = "server-tls";
144-
cb_zookeeper.add_volume_mount(tls_volume_name, Self::SERVER_TLS_DIR);
145-
pod_builder.add_volume(Self::create_tls_volume(tls_volume_name, secret_class)?);
155+
cb_zookeeper
156+
.add_volume_mount(tls_volume_name, Self::SERVER_TLS_DIR)
157+
.context(AddVolumeMountSnafu)?;
158+
pod_builder
159+
.add_volume(Self::create_tls_volume(tls_volume_name, secret_class)?)
160+
.context(AddVolumeSnafu)?;
146161
}
147162

148163
// quorum
149164
let tls_volume_name = "quorum-tls";
150-
cb_zookeeper.add_volume_mount(tls_volume_name, Self::QUORUM_TLS_DIR);
151-
pod_builder.add_volume(Self::create_tls_volume(
152-
tls_volume_name,
153-
&self.quorum_secret_class,
154-
)?);
165+
cb_zookeeper
166+
.add_volume_mount(tls_volume_name, Self::QUORUM_TLS_DIR)
167+
.context(AddVolumeMountSnafu)?;
168+
pod_builder
169+
.add_volume(Self::create_tls_volume(
170+
tls_volume_name,
171+
&self.quorum_secret_class,
172+
)?)
173+
.context(AddVolumeSnafu)?;
155174

156175
Ok(())
157176
}
@@ -264,7 +283,8 @@ impl ZookeeperSecurity {
264283
AuthenticationClassProvider::Tls(tls) => tls.client_cert_secret_class.as_ref(),
265284
AuthenticationClassProvider::Ldap(_)
266285
| AuthenticationClassProvider::Oidc(_)
267-
| AuthenticationClassProvider::Static(_) => None,
286+
| AuthenticationClassProvider::Static(_)
287+
| AuthenticationClassProvider::Kerberos(_) => None,
268288
})
269289
.or(self.server_secret_class.as_ref())
270290
}

rust/operator-binary/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ async fn main() -> anyhow::Result<()> {
6969
"/etc/stackable/zookeeper-operator/config-spec/properties.yaml",
7070
])?;
7171
let client =
72-
stackable_operator::client::create_client(Some(OPERATOR_NAME.to_string())).await?;
72+
stackable_operator::client::initialize_operator(Some(OPERATOR_NAME.to_string()))
73+
.await?;
74+
7375
let zk_controller_builder = Controller::new(
7476
watch_namespace.get_api::<ZookeeperCluster>(&client),
7577
watcher::Config::default(),

rust/operator-binary/src/zk_controller.rs

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use product_config::{
1717
use snafu::{OptionExt, ResultExt, Snafu};
1818
use stackable_operator::{
1919
builder::{
20+
self,
2021
configmap::ConfigMapBuilder,
2122
meta::ObjectMetaBuilder,
2223
pod::{container::ContainerBuilder, resources::ResourceRequirementsBuilder, PodBuilder},
@@ -245,6 +246,14 @@ pub enum Error {
245246

246247
#[snafu(display("failed to add TLS volume mounts"))]
247248
AddTlsVolumeMounts { source: security::Error },
249+
250+
#[snafu(display("failed to add needed volume"))]
251+
AddVolume { source: builder::pod::Error },
252+
253+
#[snafu(display("failed to add needed volumeMount"))]
254+
AddVolumeMount {
255+
source: builder::pod::container::Error,
256+
},
248257
}
249258

250259
impl ReconcilerError for Error {
@@ -285,6 +294,8 @@ impl ReconcilerError for Error {
285294
Error::BuildLabel { .. } => None,
286295
Error::ObjectMeta { .. } => None,
287296
Error::AddTlsVolumeMounts { .. } => None,
297+
Error::AddVolume { .. } => None,
298+
Error::AddVolumeMount { .. } => None,
288299
}
289300
}
290301
}
@@ -801,9 +812,13 @@ fn build_server_rolegroup_statefulset(
801812
..EnvVar::default()
802813
}])
803814
.add_volume_mount("data", STACKABLE_DATA_DIR)
815+
.unwrap()
804816
.add_volume_mount("config", STACKABLE_CONFIG_DIR)
817+
.unwrap()
805818
.add_volume_mount("rwconfig", STACKABLE_RW_CONFIG_DIR)
819+
.unwrap()
806820
.add_volume_mount("log", STACKABLE_LOG_DIR)
821+
.unwrap()
807822
.resources(
808823
ResourceRequirementsBuilder::new()
809824
.with_cpu_request("200m")
@@ -860,10 +875,15 @@ fn build_server_rolegroup_statefulset(
860875
.add_container_port("zk-election", 3888)
861876
.add_container_port("metrics", 9505)
862877
.add_volume_mount("data", STACKABLE_DATA_DIR)
878+
.unwrap()
863879
.add_volume_mount("config", STACKABLE_CONFIG_DIR)
880+
.unwrap()
864881
.add_volume_mount("log-config", STACKABLE_LOG_CONFIG_DIR)
882+
.unwrap()
865883
.add_volume_mount("rwconfig", STACKABLE_RW_CONFIG_DIR)
884+
.unwrap()
866885
.add_volume_mount("log", STACKABLE_LOG_DIR)
886+
.unwrap()
867887
.resources(resources)
868888
.build();
869889

@@ -892,6 +912,7 @@ fn build_server_rolegroup_statefulset(
892912
}),
893913
..Volume::default()
894914
})
915+
.context(AddVolumeSnafu)?
895916
.add_volume(Volume {
896917
empty_dir: Some(EmptyDirVolumeSource {
897918
medium: None,
@@ -900,12 +921,14 @@ fn build_server_rolegroup_statefulset(
900921
name: "rwconfig".to_string(),
901922
..Volume::default()
902923
})
924+
.context(AddVolumeSnafu)?
903925
.add_empty_dir_volume(
904926
"log",
905927
Some(product_logging::framework::calculate_log_volume_size_limit(
906928
&[MAX_ZK_LOG_FILES_SIZE, MAX_PREPARE_LOG_FILE_SIZE],
907929
)),
908930
)
931+
.context(AddVolumeSnafu)?
909932
.security_context(PodSecurityContext {
910933
run_as_user: Some(ZK_UID),
911934
run_as_group: Some(0),
@@ -921,38 +944,45 @@ fn build_server_rolegroup_statefulset(
921944
})),
922945
}) = logging.containers.get(&Container::Zookeeper)
923946
{
924-
pod_builder.add_volume(Volume {
925-
name: "log-config".to_string(),
926-
config_map: Some(ConfigMapVolumeSource {
927-
name: config_map.into(),
928-
..ConfigMapVolumeSource::default()
929-
}),
930-
..Volume::default()
931-
});
947+
pod_builder
948+
.add_volume(Volume {
949+
name: "log-config".to_string(),
950+
config_map: Some(ConfigMapVolumeSource {
951+
name: config_map.into(),
952+
..ConfigMapVolumeSource::default()
953+
}),
954+
..Volume::default()
955+
})
956+
.context(AddVolumeSnafu)?;
932957
} else {
933-
pod_builder.add_volume(Volume {
934-
name: "log-config".to_string(),
935-
config_map: Some(ConfigMapVolumeSource {
936-
name: rolegroup_ref.object_name(),
937-
..ConfigMapVolumeSource::default()
938-
}),
939-
..Volume::default()
940-
});
958+
pod_builder
959+
.add_volume(Volume {
960+
name: "log-config".to_string(),
961+
config_map: Some(ConfigMapVolumeSource {
962+
name: rolegroup_ref.object_name(),
963+
..ConfigMapVolumeSource::default()
964+
}),
965+
..Volume::default()
966+
})
967+
.context(AddVolumeSnafu)?;
941968
}
942969

943970
if logging.enable_vector_agent {
944-
pod_builder.add_container(product_logging::framework::vector_container(
945-
resolved_product_image,
946-
"config",
947-
"log",
948-
logging.containers.get(&Container::Vector),
949-
ResourceRequirementsBuilder::new()
950-
.with_cpu_request("250m")
951-
.with_cpu_limit("500m")
952-
.with_memory_request("128Mi")
953-
.with_memory_limit("128Mi")
954-
.build(),
955-
));
971+
pod_builder.add_container(
972+
product_logging::framework::vector_container(
973+
resolved_product_image,
974+
"config",
975+
"log",
976+
logging.containers.get(&Container::Vector),
977+
ResourceRequirementsBuilder::new()
978+
.with_cpu_request("250m")
979+
.with_cpu_limit("500m")
980+
.with_memory_request("128Mi")
981+
.with_memory_limit("128Mi")
982+
.build(),
983+
)
984+
.unwrap(),
985+
);
956986
}
957987

958988
add_graceful_shutdown_config(config, &mut pod_builder).context(GracefulShutdownSnafu)?;

0 commit comments

Comments
 (0)