From b1237d2863909b519574303a320ea4c875b52102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natalie=20Klestrup=20R=C3=B6ijezon?= Date: Mon, 7 Oct 2024 16:44:55 +0200 Subject: [PATCH 1/4] Use ClusterResources for Listener controller Fixes #221 --- .../src/listener_controller.rs | 101 ++++++++++++++---- rust/operator-binary/src/main.rs | 1 + 2 files changed, 79 insertions(+), 23 deletions(-) diff --git a/rust/operator-binary/src/listener_controller.rs b/rust/operator-binary/src/listener_controller.rs index 43b3639..0749df4 100644 --- a/rust/operator-binary/src/listener_controller.rs +++ b/rust/operator-binary/src/listener_controller.rs @@ -9,7 +9,8 @@ use futures::{ }; use snafu::{OptionExt, ResultExt, Snafu}; use stackable_operator::{ - builder::meta::OwnerReferenceBuilder, + builder::meta::ObjectMetaBuilder, + cluster_resources::{ClusterResourceApplyStrategy, ClusterResources}, commons::listener::{ AddressType, Listener, ListenerClass, ListenerIngress, ListenerPort, ListenerSpec, ListenerStatus, ServiceType, @@ -21,19 +22,23 @@ use stackable_operator::{ kube::{ api::{DynamicObject, ObjectMeta}, runtime::{controller, reflector::ObjectRef, watcher}, - ResourceExt, + Resource, ResourceExt, }, + kvp::Labels, logging::controller::{report_controller_reconciled, ReconcilerError}, time::Duration, }; use strum::IntoStaticStr; -use crate::{csi_server::node::NODE_TOPOLOGY_LABEL_HOSTNAME, utils::node_primary_address}; +use crate::{ + csi_server::node::NODE_TOPOLOGY_LABEL_HOSTNAME, utils::node_primary_address, APP_NAME, + OPERATOR_KEY, +}; #[cfg(doc)] use stackable_operator::k8s_openapi::api::core::v1::Pod; -const FIELD_MANAGER_SCOPE: &str = "listener"; +const CONTROLLER_NAME: &str = "listener"; pub async fn run(client: stackable_operator::client::Client) { let controller = @@ -112,6 +117,11 @@ pub enum Error { #[snafu(display("object has no name"))] NoName, + #[snafu(display("failed to create cluster resources"))] + CreateClusterResources { + source: stackable_operator::cluster_resources::Error, + }, + #[snafu(display("object has no ListenerClass (.spec.class_name)"))] NoListenerClass, @@ -130,6 +140,16 @@ pub enum Error { source: stackable_operator::client::Error, }, + #[snafu(display("failed to validate labels passed through from Listener"))] + ValidateListenerLabels { + source: stackable_operator::kvp::LabelError, + }, + + #[snafu(display("failed to build cluster resource labels"))] + BuildClusterResourcesLabels { + source: stackable_operator::kvp::LabelError, + }, + #[snafu(display("failed to get {obj}"))] GetObject { source: stackable_operator::client::Error, @@ -143,10 +163,15 @@ pub enum Error { #[snafu(display("failed to apply {svc}"))] ApplyService { - source: stackable_operator::client::Error, + source: stackable_operator::cluster_resources::Error, svc: ObjectRef, }, + #[snafu(display("failed to delete orphaned resources"))] + DeleteOrphans { + source: stackable_operator::cluster_resources::Error, + }, + #[snafu(display("failed to apply status for Listener"))] ApplyStatus { source: stackable_operator::client::Error, @@ -162,19 +187,33 @@ impl ReconcilerError for Error { match self { Self::NoNs => None, Self::NoName => None, + Self::CreateClusterResources { source: _ } => None, Self::NoListenerClass => None, Self::ListenerPvSelector { source: _ } => None, Self::ListenerPodSelector { source: _ } => None, Self::GetListenerPvs { source: _ } => None, + Self::ValidateListenerLabels { source: _ } => None, + Self::BuildClusterResourcesLabels { source: _ } => None, Self::GetObject { source: _, obj } => Some(obj.clone()), Self::BuildListenerOwnerRef { .. } => None, Self::ApplyService { source: _, svc } => Some(svc.clone().erase()), + Self::DeleteOrphans { source: _ } => None, Self::ApplyStatus { source: _ } => None, } } } pub async fn reconcile(listener: Arc, ctx: Arc) -> Result { + let mut cluster_resources = ClusterResources::new( + APP_NAME, + OPERATOR_KEY, + CONTROLLER_NAME, + &listener.object_ref(&()), + // Listeners don't currently support pausing + ClusterResourceApplyStrategy::Default, + ) + .context(CreateClusterResourcesSnafu)?; + let ns = listener.metadata.namespace.as_deref().context(NoNsSnafu)?; let listener_class_name = listener .spec @@ -228,17 +267,29 @@ pub async fn reconcile(listener: Arc, ctx: Arc) -> Result, ctx: Arc) -> Result; let addresses: Vec<(&str, AddressType)>; @@ -363,8 +412,14 @@ pub async fn reconcile(listener: Arc, ctx: Arc) -> Result Date: Mon, 7 Oct 2024 16:49:41 +0200 Subject: [PATCH 2/4] Changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df9415c..c9f426e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file. ### Changed - Listener.status.addresses for NodePort listeners now includes replicas that are currently unavailable ([#231]). +- Stale Listener subobjects will now be deleted ([#232]). +- Tagged Listener Services with the SDP labels ([#232]). ### Fixed @@ -14,6 +16,7 @@ All notable changes to this project will be documented in this file. - Listener controller now listens for ListenerClass updates ([#231]). [#231]: https://github.com/stackabletech/listener-operator/pull/231 +[#232]: https://github.com/stackabletech/listener-operator/pull/232 ## [24.7.0] - 2024-07-24 From f462cafebf6cb03034ecb8b2a7a4b824675bdf8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natalie=20Klestrup=20R=C3=B6ijezon?= Date: Fri, 18 Oct 2024 13:22:52 +0200 Subject: [PATCH 3/4] Update op-rs to fix the labels bug --- Cargo.lock | 6 +++--- Cargo.nix | 12 ++++++------ crate-hashes.json | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9707dce..af3742f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2325,7 +2325,7 @@ dependencies = [ [[package]] name = "stackable-operator" version = "0.78.0" -source = "git+https://github.com/stackabletech//operator-rs.git?branch=main#d51e8a73e94aa65d5d45338edf4959169b65e00e" +source = "git+https://github.com/stackabletech//operator-rs.git?branch=main#82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2" dependencies = [ "chrono", "clap", @@ -2363,7 +2363,7 @@ dependencies = [ [[package]] name = "stackable-operator-derive" version = "0.3.1" -source = "git+https://github.com/stackabletech//operator-rs.git?branch=main#d51e8a73e94aa65d5d45338edf4959169b65e00e" +source = "git+https://github.com/stackabletech//operator-rs.git?branch=main#82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2" dependencies = [ "darling", "proc-macro2", @@ -2374,7 +2374,7 @@ dependencies = [ [[package]] name = "stackable-shared" version = "0.0.1" -source = "git+https://github.com/stackabletech//operator-rs.git?branch=main#d51e8a73e94aa65d5d45338edf4959169b65e00e" +source = "git+https://github.com/stackabletech//operator-rs.git?branch=main#82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2" dependencies = [ "kube", "semver", diff --git a/Cargo.nix b/Cargo.nix index d6ec8b0..6e11659 100644 --- a/Cargo.nix +++ b/Cargo.nix @@ -7365,8 +7365,8 @@ rec { workspace_member = null; src = pkgs.fetchgit { url = "https://github.com/stackabletech//operator-rs.git"; - rev = "d51e8a73e94aa65d5d45338edf4959169b65e00e"; - sha256 = "0cq00sqbwashcsakd0bfmpzpdvvm3xh1xcsjnwaspm6mfi38a9cj"; + rev = "82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2"; + sha256 = "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv"; }; libName = "stackable_operator"; authors = [ @@ -7523,8 +7523,8 @@ rec { workspace_member = null; src = pkgs.fetchgit { url = "https://github.com/stackabletech//operator-rs.git"; - rev = "d51e8a73e94aa65d5d45338edf4959169b65e00e"; - sha256 = "0cq00sqbwashcsakd0bfmpzpdvvm3xh1xcsjnwaspm6mfi38a9cj"; + rev = "82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2"; + sha256 = "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv"; }; procMacro = true; libName = "stackable_operator_derive"; @@ -7558,8 +7558,8 @@ rec { workspace_member = null; src = pkgs.fetchgit { url = "https://github.com/stackabletech//operator-rs.git"; - rev = "d51e8a73e94aa65d5d45338edf4959169b65e00e"; - sha256 = "0cq00sqbwashcsakd0bfmpzpdvvm3xh1xcsjnwaspm6mfi38a9cj"; + rev = "82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2"; + sha256 = "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv"; }; libName = "stackable_shared"; authors = [ diff --git a/crate-hashes.json b/crate-hashes.json index 258e5db..e2d4c35 100644 --- a/crate-hashes.json +++ b/crate-hashes.json @@ -1,6 +1,6 @@ { - "git+https://github.com/stackabletech//operator-rs.git?branch=main#stackable-operator-derive@0.3.1": "0cq00sqbwashcsakd0bfmpzpdvvm3xh1xcsjnwaspm6mfi38a9cj", - "git+https://github.com/stackabletech//operator-rs.git?branch=main#stackable-operator@0.78.0": "0cq00sqbwashcsakd0bfmpzpdvvm3xh1xcsjnwaspm6mfi38a9cj", - "git+https://github.com/stackabletech//operator-rs.git?branch=main#stackable-shared@0.0.1": "0cq00sqbwashcsakd0bfmpzpdvvm3xh1xcsjnwaspm6mfi38a9cj", + "git+https://github.com/stackabletech//operator-rs.git?branch=main#stackable-operator-derive@0.3.1": "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv", + "git+https://github.com/stackabletech//operator-rs.git?branch=main#stackable-operator@0.78.0": "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv", + "git+https://github.com/stackabletech//operator-rs.git?branch=main#stackable-shared@0.0.1": "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv", "git+https://github.com/stackabletech/product-config.git?tag=0.7.0#product-config@0.7.0": "0gjsm80g6r75pm3824dcyiz4ysq1ka4c1if6k1mjm9cnd5ym0gny" } \ No newline at end of file From 4522338ed715a25b7b6888420c3760a5b6a5489b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natalie=20Klestrup=20R=C3=B6ijezon?= Date: Fri, 18 Oct 2024 13:27:55 +0200 Subject: [PATCH 4/4] Update to op-rs 0.79.0 --- Cargo.lock | 8 ++++---- Cargo.nix | 20 ++++++++++---------- Cargo.toml | 4 ++-- crate-hashes.json | 6 +++--- rust/operator-binary/src/main.rs | 3 ++- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af3742f..b937dd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2324,8 +2324,8 @@ dependencies = [ [[package]] name = "stackable-operator" -version = "0.78.0" -source = "git+https://github.com/stackabletech//operator-rs.git?branch=main#82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2" +version = "0.79.0" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.79.0#a2ac5f525edfd9a2fab884ba753e79a325fbb752" dependencies = [ "chrono", "clap", @@ -2363,7 +2363,7 @@ dependencies = [ [[package]] name = "stackable-operator-derive" version = "0.3.1" -source = "git+https://github.com/stackabletech//operator-rs.git?branch=main#82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.79.0#a2ac5f525edfd9a2fab884ba753e79a325fbb752" dependencies = [ "darling", "proc-macro2", @@ -2374,7 +2374,7 @@ dependencies = [ [[package]] name = "stackable-shared" version = "0.0.1" -source = "git+https://github.com/stackabletech//operator-rs.git?branch=main#82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.79.0#a2ac5f525edfd9a2fab884ba753e79a325fbb752" dependencies = [ "kube", "semver", diff --git a/Cargo.nix b/Cargo.nix index 6e11659..963cf94 100644 --- a/Cargo.nix +++ b/Cargo.nix @@ -7360,13 +7360,13 @@ rec { }; "stackable-operator" = rec { crateName = "stackable-operator"; - version = "0.78.0"; + version = "0.79.0"; edition = "2021"; workspace_member = null; src = pkgs.fetchgit { - url = "https://github.com/stackabletech//operator-rs.git"; - rev = "82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2"; - sha256 = "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv"; + url = "https://github.com/stackabletech/operator-rs.git"; + rev = "a2ac5f525edfd9a2fab884ba753e79a325fbb752"; + sha256 = "070wv4w3mqz7m3zdkh3gm377f4zm04i4dx4dv4pqxj7w6m6m0ca0"; }; libName = "stackable_operator"; authors = [ @@ -7522,9 +7522,9 @@ rec { edition = "2021"; workspace_member = null; src = pkgs.fetchgit { - url = "https://github.com/stackabletech//operator-rs.git"; - rev = "82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2"; - sha256 = "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv"; + url = "https://github.com/stackabletech/operator-rs.git"; + rev = "a2ac5f525edfd9a2fab884ba753e79a325fbb752"; + sha256 = "070wv4w3mqz7m3zdkh3gm377f4zm04i4dx4dv4pqxj7w6m6m0ca0"; }; procMacro = true; libName = "stackable_operator_derive"; @@ -7557,9 +7557,9 @@ rec { edition = "2021"; workspace_member = null; src = pkgs.fetchgit { - url = "https://github.com/stackabletech//operator-rs.git"; - rev = "82a0ef6d14c6f4e144ee1b4f5eff6abebf0108f2"; - sha256 = "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv"; + url = "https://github.com/stackabletech/operator-rs.git"; + rev = "a2ac5f525edfd9a2fab884ba753e79a325fbb752"; + sha256 = "070wv4w3mqz7m3zdkh3gm377f4zm04i4dx4dv4pqxj7w6m6m0ca0"; }; libName = "stackable_shared"; authors = [ diff --git a/Cargo.toml b/Cargo.toml index 66999ba..2e530ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ prost = "0.13" prost-types = "0.13" serde = "1.0" snafu = "0.8" -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.78.0" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.79.0" } strum = { version = "0.26", features = ["derive"] } socket2 = { version = "0.5", features = ["all"] } tokio = { version = "1.40", features = ["full"] } @@ -33,4 +33,4 @@ tracing = "0.1.40" [patch."https://github.com/stackabletech/operator-rs.git"] # stackable-operator = { path = "../operator-rs/crates/stackable-operator" } -stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "main" } +# stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "main" } diff --git a/crate-hashes.json b/crate-hashes.json index e2d4c35..5c5528b 100644 --- a/crate-hashes.json +++ b/crate-hashes.json @@ -1,6 +1,6 @@ { - "git+https://github.com/stackabletech//operator-rs.git?branch=main#stackable-operator-derive@0.3.1": "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv", - "git+https://github.com/stackabletech//operator-rs.git?branch=main#stackable-operator@0.78.0": "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv", - "git+https://github.com/stackabletech//operator-rs.git?branch=main#stackable-shared@0.0.1": "1x4ik75nsjmhzxi1h90vla5qi8n5jvm0h6337rrx5zhwh13fsppv", + "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.79.0#stackable-operator-derive@0.3.1": "070wv4w3mqz7m3zdkh3gm377f4zm04i4dx4dv4pqxj7w6m6m0ca0", + "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.79.0#stackable-operator@0.79.0": "070wv4w3mqz7m3zdkh3gm377f4zm04i4dx4dv4pqxj7w6m6m0ca0", + "git+https://github.com/stackabletech/operator-rs.git?tag=stackable-operator-0.79.0#stackable-shared@0.0.1": "070wv4w3mqz7m3zdkh3gm377f4zm04i4dx4dv4pqxj7w6m6m0ca0", "git+https://github.com/stackabletech/product-config.git?tag=0.7.0#product-config@0.7.0": "0gjsm80g6r75pm3824dcyiz4ysq1ka4c1if6k1mjm9cnd5ym0gny" } \ No newline at end of file diff --git a/rust/operator-binary/src/main.rs b/rust/operator-binary/src/main.rs index 6f6dd43..2de454d 100644 --- a/rust/operator-binary/src/main.rs +++ b/rust/operator-binary/src/main.rs @@ -85,7 +85,8 @@ async fn main() -> anyhow::Result<()> { built_info::RUSTC_VERSION, ); let client = - stackable_operator::client::create_client(Some(OPERATOR_KEY.to_string())).await?; + stackable_operator::client::initialize_operator(Some(OPERATOR_KEY.to_string())) + .await?; if csi_endpoint .symlink_metadata() .map_or(false, |meta| meta.file_type().is_socket())