Skip to content

Commit

Permalink
Use upstream ClusterRef over ZookeeperClusterRef (#383)
Browse files Browse the repository at this point in the history
## Description

This also incorporates the namespace-defaulting from #382 and, as such, supersedes it.



Co-authored-by: Stacky McStackface <stackable-bot@users.noreply.github.com>
  • Loading branch information
nightkr and stackable-bot committed Feb 4, 2022
1 parent 938d4f5 commit 40ae1a1
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 120 deletions.
175 changes: 92 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions deploy/crd/zookeeperznode.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ spec:
description: "A claim for a single ZooKeeper ZNode tree (filesystem node)\n\nA `ConfigMap` will automatically be created with the same name, containing the connection string in the field `ZOOKEEPER`. Each `ZookeeperZnode` gets an isolated ZNode chroot, which the `ZOOKEEPER` automatically contains. All data inside of this chroot will be deleted when the corresponding `ZookeeperZnode` is.\n\n`ZookeeperZnode` is *not* designed to manage the contents of this ZNode. Instead, it should be used to create a chroot for an installation of an application to work inside. Initializing the contents is the responsibility of the application."
properties:
clusterRef:
default: {}
description: "A reference to a [`ZookeeperCluster`]"
default:
name: ~
namespace: ~
description: "A reference to a product cluster (for example, a `ZookeeperCluster`)\n\n`namespace`'s defaulting only applies when retrieved via [`ClusterRef::namespace_relative_from`]"
properties:
name:
description: The name of the cluster
nullable: true
type: string
namespace:
description: "The namespace of the cluster\n\nThis field is optional, and will default to the namespace of the referring object."
nullable: true
type: string
type: object
Expand Down
8 changes: 6 additions & 2 deletions deploy/helm/zookeeper-operator/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,17 @@ spec:
description: "A claim for a single ZooKeeper ZNode tree (filesystem node)\n\nA `ConfigMap` will automatically be created with the same name, containing the connection string in the field `ZOOKEEPER`. Each `ZookeeperZnode` gets an isolated ZNode chroot, which the `ZOOKEEPER` automatically contains. All data inside of this chroot will be deleted when the corresponding `ZookeeperZnode` is.\n\n`ZookeeperZnode` is *not* designed to manage the contents of this ZNode. Instead, it should be used to create a chroot for an installation of an application to work inside. Initializing the contents is the responsibility of the application."
properties:
clusterRef:
default: {}
description: "A reference to a [`ZookeeperCluster`]"
default:
name: ~
namespace: ~
description: "A reference to a product cluster (for example, a `ZookeeperCluster`)\n\n`namespace`'s defaulting only applies when retrieved via [`ClusterRef::namespace_relative_from`]"
properties:
name:
description: The name of the cluster
nullable: true
type: string
namespace:
description: "The namespace of the cluster\n\nThis field is optional, and will default to the namespace of the referring object."
nullable: true
type: string
type: object
Expand Down
8 changes: 6 additions & 2 deletions deploy/manifests/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,17 @@ spec:
description: "A claim for a single ZooKeeper ZNode tree (filesystem node)\n\nA `ConfigMap` will automatically be created with the same name, containing the connection string in the field `ZOOKEEPER`. Each `ZookeeperZnode` gets an isolated ZNode chroot, which the `ZOOKEEPER` automatically contains. All data inside of this chroot will be deleted when the corresponding `ZookeeperZnode` is.\n\n`ZookeeperZnode` is *not* designed to manage the contents of this ZNode. Instead, it should be used to create a chroot for an installation of an application to work inside. Initializing the contents is the responsibility of the application."
properties:
clusterRef:
default: {}
description: "A reference to a [`ZookeeperCluster`]"
default:
name: ~
namespace: ~
description: "A reference to a product cluster (for example, a `ZookeeperCluster`)\n\n`namespace`'s defaulting only applies when retrieved via [`ClusterRef::namespace_relative_from`]"
properties:
name:
description: The name of the cluster
nullable: true
type: string
namespace:
description: "The namespace of the cluster\n\nThis field is optional, and will default to the namespace of the referring object."
nullable: true
type: string
type: object
Expand Down
2 changes: 1 addition & 1 deletion rust/crd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ repository = "https://github.com/stackabletech/zookeeper-operator"
serde = "1.0.133"
serde_json = "1.0.75"
snafu = "0.7.0"
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.8.0" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.10.0" }
strum = { version = "0.23.0", features = ["derive"] }
13 changes: 2 additions & 11 deletions rust/crd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use snafu::{OptionExt, Snafu};
use stackable_operator::{
crd::ClusterRef,
kube::{runtime::reflector::ObjectRef, CustomResource},
product_config_utils::{ConfigError, Configuration},
role_utils::{Role, RoleGroupRef},
Expand Down Expand Up @@ -225,15 +226,5 @@ impl ZookeeperPodRef {
#[serde(rename_all = "camelCase")]
pub struct ZookeeperZnodeSpec {
#[serde(default)]
pub cluster_ref: ZookeeperClusterRef,
}

/// A reference to a [`ZookeeperCluster`]
#[derive(Clone, Default, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ZookeeperClusterRef {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub namespace: Option<String>,
pub cluster_ref: ClusterRef<ZookeeperCluster>,
}
4 changes: 2 additions & 2 deletions rust/operator-binary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ tokio-executor = "0.1.10"
tokio-zookeeper = "0.1.3"
tracing = "0.1.29"
pin-project = "1.0.10"
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.8.0" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.10.0" }
stackable-zookeeper-crd = { path = "../crd" }
anyhow = "1.0.52"
fnv = "1.0.7"
clap = { version = "3.0.9", features = ["derive"] }

[build-dependencies]
built = { version = "0.5.1", features = ["chrono", "git2"] }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.8.0" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.10.0" }
stackable-zookeeper-crd = { path = "../crd" }
4 changes: 2 additions & 2 deletions rust/operator-binary/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async fn main() -> anyhow::Result<()> {
zk.metadata.namespace == endpoints.metadata.namespace
&& zk.server_role_service_name() == endpoints.metadata.name
})
.map(|zk| ObjectRef::from_obj(&zk))
.map(|zk| ObjectRef::from_obj(&*zk))
},
)
.owns(client.get_all_api::<StatefulSet>(), ListParams::default())
Expand Down Expand Up @@ -129,7 +129,7 @@ async fn main() -> anyhow::Result<()> {
zk.metadata.namespace == znode.spec.cluster_ref.namespace
&& zk.metadata.name == znode.spec.cluster_ref.name
})
.map(|znode| ObjectRef::from_obj(&znode))
.map(|znode| ObjectRef::from_obj(&*znode))
},
)
.shutdown_on_signal()
Expand Down
12 changes: 8 additions & 4 deletions rust/operator-binary/src/zk_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
borrow::Cow,
collections::{BTreeMap, HashMap},
hash::Hasher,
sync::Arc,
time::Duration,
};

Expand Down Expand Up @@ -117,14 +118,17 @@ type Result<T, E = Error> = std::result::Result<T, E>;

const PROPERTIES_FILE: &str = "zoo.cfg";

pub async fn reconcile_zk(zk: ZookeeperCluster, ctx: Context<Ctx>) -> Result<ReconcilerAction> {
pub async fn reconcile_zk(
zk: Arc<ZookeeperCluster>,
ctx: Context<Ctx>,
) -> Result<ReconcilerAction> {
tracing::info!("Starting reconcile");
let client = &ctx.get_ref().client;

let validated_config = validate_all_roles_and_groups_config(
zk_version(&zk)?,
&transform_all_roles_to_config(
&zk,
&*zk,
[(
ZookeeperRole::Server.to_string(),
(
Expand Down Expand Up @@ -186,7 +190,7 @@ pub async fn reconcile_zk(zk: ZookeeperCluster, ctx: Context<Ctx>) -> Result<Rec
// std's SipHasher is deprecated, and DefaultHasher is unstable across Rust releases.
// We don't /need/ stability, but it's still nice to avoid spurious changes where possible.
let mut discovery_hash = FnvHasher::with_key(0);
for discovery_cm in build_discovery_configmaps(client, &zk, &zk, &server_role_service, None)
for discovery_cm in build_discovery_configmaps(client, &*zk, &zk, &server_role_service, None)
.await
.context(BuildDiscoveryConfigSnafu)?
{
Expand All @@ -205,7 +209,7 @@ pub async fn reconcile_zk(zk: ZookeeperCluster, ctx: Context<Ctx>) -> Result<Rec
discovery_hash: Some(discovery_hash.finish().to_string()),
};
client
.apply_patch_status(FIELD_MANAGER_SCOPE, &zk, &status)
.apply_patch_status(FIELD_MANAGER_SCOPE, &*zk, &status)
.await
.context(ApplyStatusSnafu)?;

Expand Down
20 changes: 9 additions & 11 deletions rust/operator-binary/src/znode_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! See [`ZookeeperZnode`] for more details.
use std::{convert::Infallible, time::Duration};
use std::{convert::Infallible, sync::Arc, time::Duration};

use crate::{
discovery::{self, build_discovery_configmaps},
Expand All @@ -21,7 +21,7 @@ use stackable_operator::{
},
},
};
use stackable_zookeeper_crd::{ZookeeperCluster, ZookeeperClusterRef, ZookeeperZnode};
use stackable_zookeeper_crd::{ZookeeperCluster, ZookeeperZnode};

const FIELD_MANAGER_SCOPE: &str = "zookeeperznode";

Expand Down Expand Up @@ -104,7 +104,10 @@ impl Error {
}
}

pub async fn reconcile_znode(znode: ZookeeperZnode, ctx: Context<Ctx>) -> Result<ReconcilerAction> {
pub async fn reconcile_znode(
znode: Arc<ZookeeperZnode>,
ctx: Context<Ctx>,
) -> Result<ReconcilerAction> {
tracing::info!("Starting reconcile");
let (ns, uid) = if let ObjectMeta {
namespace: Some(ns),
Expand Down Expand Up @@ -227,15 +230,10 @@ async fn find_zk_of_znode(
client: &stackable_operator::client::Client,
znode: &ZookeeperZnode,
) -> Result<ZookeeperCluster> {
let ZookeeperClusterRef {
name: zk_name,
namespace: zk_ns,
} = &znode.spec.cluster_ref;
let zk_ref = &znode.spec.cluster_ref;
if let (Some(zk_name), Some(zk_ns)) = (
zk_name,
zk_ns
.as_deref()
.or_else(|| znode.metadata.namespace.as_deref()),
zk_ref.name.as_deref(),
zk_ref.namespace_relative_from(znode),
) {
match client.get::<ZookeeperCluster>(zk_name, Some(zk_ns)).await {
Ok(zk) => Ok(zk),
Expand Down

0 comments on commit 40ae1a1

Please sign in to comment.