From e9925b0a5eb7105704151ae06f69ce909fcdc985 Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Fri, 18 Nov 2022 13:59:27 +0100 Subject: [PATCH 1/4] adapted to 0.27.1 - compiling --- Cargo.lock | 354 ++++++------------- rust/crd/Cargo.toml | 2 +- rust/crd/src/lib.rs | 173 +++++---- rust/operator-binary/Cargo.toml | 9 +- rust/operator-binary/src/command.rs | 3 +- rust/operator-binary/src/discovery.rs | 37 +- rust/operator-binary/src/main.rs | 17 +- rust/operator-binary/src/zk_controller.rs | 182 +++++----- rust/operator-binary/src/znode_controller.rs | 47 ++- 9 files changed, 387 insertions(+), 437 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e283a8cb..59e78ffb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,10 +19,11 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.7.6" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "bf6ccdb167abbf410dcb915cabd428929d7f6a04980b54a11f26a39f1c7f7107" dependencies = [ + "cfg-if 1.0.0", "getrandom", "once_cell", "version_check", @@ -223,26 +224,24 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.23" +version = "4.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +checksum = "2148adefda54e14492fb9bddcc600b4344c5d1a3123bd666dcb939c6f0e0e57e" dependencies = [ "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", "once_cell", "strsim", "termcolor", - "textwrap", ] [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" dependencies = [ "heck", "proc-macro-error", @@ -253,9 +252,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -299,16 +298,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -384,9 +373,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888" +checksum = "d4a41a86530d0fe7f5d9ea779916b7cadd2d4f9add748b99c2c029cbbdfaf453" dependencies = [ "cc", "cxxbridge-flags", @@ -396,9 +385,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3" +checksum = "06416d667ff3e3ad2df1cd8cd8afae5da26cf9cec4d0825040f88b5ca659a2f0" dependencies = [ "cc", "codespan-reporting", @@ -411,15 +400,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f" +checksum = "820a9a2af1669deeef27cb271f476ffd196a2c4b6731336011e0ba63e2c7cf71" [[package]] name = "cxxbridge-macro" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" +checksum = "a08a6e2fcc370a089ad3b4aaf54db3b1b4cee38ddabce5896b33eb693275f470" dependencies = [ "proc-macro2", "quote", @@ -461,6 +450,19 @@ dependencies = [ "syn", ] +[[package]] +name = "dashmap" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown", + "lock_api 0.4.9", + "once_cell", + "parking_lot_core 0.9.4", +] + [[package]] name = "derivative" version = "2.2.0" @@ -607,15 +609,6 @@ dependencies = [ "regex", ] -[[package]] -name = "fastrand" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" -dependencies = [ - "instant", -] - [[package]] name = "fnv" version = "1.0.7" @@ -902,19 +895,6 @@ dependencies = [ "tokio-io-timeout", ] -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes 1.2.1", - "hyper", - "native-tls", - "tokio 1.21.2", - "tokio-native-tls", -] - [[package]] name = "iana-time-zone" version = "0.1.53" @@ -957,9 +937,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown", @@ -1048,9 +1028,9 @@ dependencies = [ [[package]] name = "k8s-openapi" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2ae2c04fcee6b01b04e3aadd56bb418932c8e0a9d8a93f48bc68c6bdcdb559d" +checksum = "6d9455388f4977de4d0934efa9f7d36296295537d774574113a20f6082de03da" dependencies = [ "base64", "bytes 1.2.1", @@ -1073,9 +1053,9 @@ dependencies = [ [[package]] name = "kube" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a527a8001a61d8d470dab27ac650889938760c243903e7cd90faaf7c60a34bdd" +checksum = "fcf241a3a42bca4a2d1c21f2f34a659655032a7858270c7791ad4433aa8d79cb" dependencies = [ "k8s-openapi", "kube-client", @@ -1086,9 +1066,9 @@ dependencies = [ [[package]] name = "kube-client" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0d48f42df4e8342e9f488c4b97e3759d0042c4e7ab1a853cc285adb44409480" +checksum = "7e442b4e6d55c4b3d0c0c70d79a8865bf17e2c33725f9404bfcb8a29ee002ffe" dependencies = [ "base64", "bytes 1.2.1", @@ -1101,7 +1081,6 @@ dependencies = [ "hyper", "hyper-openssl", "hyper-timeout", - "hyper-tls", "jsonpath_lib", "k8s-openapi", "kube-core", @@ -1114,7 +1093,6 @@ dependencies = [ "serde_yaml 0.8.26", "thiserror", "tokio 1.21.2", - "tokio-native-tls", "tokio-util", "tower", "tower-http", @@ -1123,9 +1101,9 @@ dependencies = [ [[package]] name = "kube-core" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91f56027f862fdcad265d2e9616af416a355e28a1c620bb709083494753e070d" +checksum = "eca2e1b1528287ba61602bbd17d0aa717fbb4d0fb257f4fa3a5fa884116ef778" dependencies = [ "chrono", "form_urlencoded", @@ -1141,9 +1119,9 @@ dependencies = [ [[package]] name = "kube-derive" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d74121eb41af4480052901f31142d8d9bbdf1b7c6b856da43bcb02f5b1b177" +checksum = "1af50996adb7e1251960d278859772fa30df99879dc154d792e36832209637cb" dependencies = [ "darling", "proc-macro2", @@ -1154,9 +1132,9 @@ dependencies = [ [[package]] name = "kube-runtime" -version = "0.74.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fdcf5a20f968768e342ef1a457491bb5661fccd81119666d626c57500b16d99" +checksum = "0b9b312c38884a3f41d67e2f7580824b6f45d360b98497325b5630664b3a359d" dependencies = [ "ahash", "backoff", @@ -1331,7 +1309,7 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -1357,24 +1335,6 @@ dependencies = [ "ws2_32-sys", ] -[[package]] -name = "native-tls" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "net2" version = "0.2.38" @@ -1466,12 +1426,6 @@ dependencies = [ "syn", ] -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - [[package]] name = "openssl-sys" version = "0.9.77" @@ -1487,33 +1441,24 @@ dependencies = [ [[package]] name = "opentelemetry" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6105e89802af13fdf48c49d7646d3b533a70e536d818aae7e78ba0433d01acb8" +checksum = "69d6c3d7288a106c0a363e4b0e8d308058d56902adefb16f4936f417ffef086e" dependencies = [ - "async-trait", - "crossbeam-channel", - "futures-channel", - "futures-executor", - "futures-util", - "js-sys", - "lazy_static", - "percent-encoding", - "pin-project", - "rand", - "thiserror", - "tokio 1.21.2", - "tokio-stream", + "opentelemetry_api", + "opentelemetry_sdk", ] [[package]] name = "opentelemetry-jaeger" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c0b12cd9e3f9b35b52f6e0dac66866c519b26f424f4bbf96e3fe8bfbdc5229" +checksum = "1e785d273968748578931e4dc3b4f5ec86b26e09d9e0d66b55adda7fce742f7a" dependencies = [ "async-trait", - "lazy_static", + "futures 0.3.25", + "futures-executor", + "once_cell", "opentelemetry", "opentelemetry-semantic-conventions", "thiserror", @@ -1523,13 +1468,51 @@ dependencies = [ [[package]] name = "opentelemetry-semantic-conventions" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "985cc35d832d412224b2cffe2f9194b1b89b6aa5d0bef76d080dce09d90e62bd" +checksum = "9b02e0230abb0ab6636d18e2ba8fa02903ea63772281340ccac18e0af3ec9eeb" dependencies = [ "opentelemetry", ] +[[package]] +name = "opentelemetry_api" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c24f96e21e7acc813c7a8394ee94978929db2bcc46cf6b5014fc612bf7760c22" +dependencies = [ + "fnv", + "futures-channel", + "futures-util", + "indexmap", + "js-sys", + "once_cell", + "pin-project-lite", + "thiserror", +] + +[[package]] +name = "opentelemetry_sdk" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca41c4933371b61c2a2f214bf16931499af4ec90543604ec828f7a625c09113" +dependencies = [ + "async-trait", + "crossbeam-channel", + "dashmap", + "fnv", + "futures-channel", + "futures-executor", + "futures-util", + "once_cell", + "opentelemetry_api", + "percent-encoding", + "rand", + "thiserror", + "tokio 1.21.2", + "tokio-stream", +] + [[package]] name = "ordered-float" version = "1.1.1" @@ -1606,7 +1589,7 @@ dependencies = [ "libc", "redox_syscall 0.2.16", "smallvec 1.10.0", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -1808,15 +1791,6 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "rustc-demangle" version = "0.1.21" @@ -1844,16 +1818,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" -[[package]] -name = "schannel" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" -dependencies = [ - "lazy_static", - "windows-sys 0.36.1", -] - [[package]] name = "schemars" version = "0.8.11" @@ -1900,29 +1864,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "security-framework" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "0.9.0" @@ -1990,9 +1931,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.87" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" +checksum = "8e8b3801309262e8184d9687fb697586833e939767aea0dda89f5a8e650e8bd7" dependencies = [ "indexmap", "itoa", @@ -2107,8 +2048,8 @@ dependencies = [ [[package]] name = "stackable-operator" -version = "0.25.3" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.25.3#406c2fb62144e834981fdd89ed7203c10c0a9e5e" +version = "0.27.1" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.27.1#c470ea5de96c0f4081e77fd7c8ce197ecebbd406" dependencies = [ "chrono", "clap", @@ -2129,6 +2070,7 @@ dependencies = [ "serde", "serde_json", "serde_yaml 0.9.14", + "snafu", "stackable-operator-derive", "strum", "thiserror", @@ -2140,8 +2082,8 @@ dependencies = [ [[package]] name = "stackable-operator-derive" -version = "0.25.3" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.25.3#406c2fb62144e834981fdd89ed7203c10c0a9e5e" +version = "0.27.1" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.27.1#c470ea5de96c0f4081e77fd7c8ce197ecebbd406" dependencies = [ "darling", "proc-macro2", @@ -2174,7 +2116,6 @@ dependencies = [ "pin-project", "semver 1.0.14", "serde", - "serde_json", "snafu", "stackable-operator", "stackable-zookeeper-crd", @@ -2237,20 +2178,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "tempfile" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" -dependencies = [ - "cfg-if 1.0.0", - "fastrand", - "libc", - "redox_syscall 0.2.16", - "remove_dir_all", - "winapi 0.3.9", -] - [[package]] name = "termcolor" version = "1.1.3" @@ -2260,12 +2187,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.37" @@ -2306,9 +2227,9 @@ dependencies = [ [[package]] name = "thrift" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b82ca8f46f95b3ce96081fe3dd89160fdea970c254bb72925255d1b62aae692e" +checksum = "09678c4cdbb4eed72e18b7c2af1329c69825ed16fcbac62d083fc3e2b0590ff0" dependencies = [ "byteorder", "integer-encoding", @@ -2461,16 +2382,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" -dependencies = [ - "native-tls", - "tokio 1.21.2", -] - [[package]] name = "tokio-openssl" version = "0.6.3" @@ -2733,9 +2644,9 @@ dependencies = [ [[package]] name = "tracing-opentelemetry" -version = "0.17.4" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbbe89715c1dbbb790059e2565353978564924ee85017b5fff365c872ff6721f" +checksum = "21ebb87a95ea13271332df069020513ab70bdb5637ca42d6e492dc3bbbad48de" dependencies = [ "once_cell", "opentelemetry", @@ -2965,19 +2876,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", -] - [[package]] name = "windows-sys" version = "0.42.0" @@ -2985,12 +2883,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.0", - "windows_i686_gnu 0.42.0", - "windows_i686_msvc 0.42.0", - "windows_x86_64_gnu 0.42.0", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.0", + "windows_x86_64_msvc", ] [[package]] @@ -2999,48 +2897,24 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - [[package]] name = "windows_aarch64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - [[package]] name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - [[package]] name = "windows_i686_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - [[package]] name = "windows_x86_64_gnu" version = "0.42.0" @@ -3053,12 +2927,6 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - [[package]] name = "windows_x86_64_msvc" version = "0.42.0" diff --git a/rust/crd/Cargo.toml b/rust/crd/Cargo.toml index 94c05943..86af9ced 100644 --- a/rust/crd/Cargo.toml +++ b/rust/crd/Cargo.toml @@ -12,7 +12,7 @@ publish = false serde = "1.0.138" serde_json = "1.0.82" snafu = "0.7.1" -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.25.3" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.27.1" } strum = { version = "0.24.1", features = ["derive"] } [dev-dependencies] diff --git a/rust/crd/src/lib.rs b/rust/crd/src/lib.rs index cfd14005..a5d51311 100644 --- a/rust/crd/src/lib.rs +++ b/rust/crd/src/lib.rs @@ -1,9 +1,11 @@ use serde::{Deserialize, Serialize}; -use snafu::{OptionExt, Snafu}; -use stackable_operator::memory::BinaryMultiple; +use snafu::{OptionExt, ResultExt, Snafu}; use stackable_operator::{ - commons::resources::{CpuLimits, MemoryLimits, NoRuntimeLimits, PvcConfig, Resources}, - config::merge::Merge, + commons::resources::{ + CpuLimitsFragment, MemoryLimitsFragment, NoRuntimeLimits, NoRuntimeLimitsFragment, + PvcConfig, PvcConfigFragment, Resources, ResourcesFragment, + }, + config::{fragment, fragment::Fragment, fragment::ValidationError, merge::Merge}, crd::ClusterRef, error::OperatorResult, k8s_openapi::{ @@ -12,11 +14,15 @@ use stackable_operator::{ }, kube::{runtime::reflector::ObjectRef, CustomResource}, memory::to_java_heap_value, + memory::BinaryMultiple, product_config_utils::{ConfigError, Configuration}, role_utils::{Role, RoleGroupRef}, schemars::{self, JsonSchema}, }; use std::collections::BTreeMap; +use strum::{Display, EnumString}; + +pub const ZOOKEEPER_PROPERTIES_FILE: &str = "zoo.cfg"; pub const CLIENT_PORT: u16 = 2181; pub const SECURE_CLIENT_PORT: u16 = 2282; @@ -35,6 +41,18 @@ pub const SYSTEM_TRUST_STORE_DIR: &str = "/etc/pki/java/cacerts"; const JVM_HEAP_FACTOR: f32 = 0.8; const TLS_DEFAULT_SECRET_CLASS: &str = "tls"; +#[derive(Snafu, Debug)] +pub enum Error { + #[snafu(display("object has no namespace associated"))] + NoNamespace, + #[snafu(display("object defines no version"))] + ObjectHasNoVersion, + #[snafu(display("unknown ZooKeeper role found {role}. Should be one of {roles:?}"))] + UnknownZookeeperRole { role: String, roles: Vec }, + #[snafu(display("fragment validation failure"))] + FragmentValidationFailure { source: ValidationError }, +} + /// A cluster of ZooKeeper nodes #[derive(Clone, CustomResource, Debug, Deserialize, JsonSchema, PartialEq, Serialize)] #[kube( @@ -135,13 +153,25 @@ pub struct ZookeeperConfig { pub sync_limit: Option, pub tick_time: Option, pub myid_offset: Option, - pub resources: Option>, + pub resources: Option>, } -#[derive(Clone, Debug, Default, Deserialize, Merge, JsonSchema, PartialEq, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct Storage { - #[serde(default)] +#[derive(Clone, Debug, Default, JsonSchema, PartialEq, Fragment)] +#[fragment_attrs( + derive( + Clone, + Debug, + Default, + Deserialize, + Merge, + JsonSchema, + PartialEq, + Serialize + ), + serde(rename_all = "camelCase") +)] +pub struct ZookeeperStorageConfig { + #[fragment_attrs(serde(default))] pub data: PvcConfig, } @@ -179,6 +209,26 @@ impl ZookeeperConfig { fn myid_offset(&self) -> u16 { self.myid_offset.unwrap_or(1) } + + fn default_resources() -> ResourcesFragment { + ResourcesFragment { + cpu: CpuLimitsFragment { + min: Some(Quantity("500m".to_owned())), + max: Some(Quantity("4".to_owned())), + }, + memory: MemoryLimitsFragment { + limit: Some(Quantity("512Mi".to_owned())), + runtime_limits: NoRuntimeLimitsFragment {}, + }, + storage: ZookeeperStorageConfigFragment { + data: PvcConfigFragment { + capacity: Some(Quantity("1Gi".to_owned())), + storage_class: None, + selectors: None, + }, + }, + } + } } impl Configuration for ZookeeperConfig { @@ -328,9 +378,12 @@ impl Configuration for ZookeeperConfig { } } -#[derive(strum::Display)] +#[derive( + Clone, Debug, Deserialize, Display, EnumString, Eq, Hash, JsonSchema, PartialEq, Serialize, +)] #[strum(serialize_all = "camelCase")] pub enum ZookeeperRole { + #[strum(serialize = "server")] Server, } @@ -342,11 +395,15 @@ pub struct ZookeeperClusterStatus { pub discovery_hash: Option, } -#[derive(Debug, Snafu)] -#[snafu(display("object has no namespace associated"))] -pub struct NoNamespaceError; - impl ZookeeperCluster { + /// The image version provided in the `spec.version` field + pub fn image_version(&self) -> Result<&str, Error> { + self.spec + .version + .as_deref() + .context(ObjectHasNoVersionSnafu) + } + /// The name of the role-level load-balanced Kubernetes `Service` pub fn server_role_service_name(&self) -> Option { self.metadata.name.clone() @@ -379,7 +436,7 @@ impl ZookeeperCluster { /// avoid instance churn. For example, regenerating zoo.cfg based on the cluster state would lead to /// a lot of spurious restarts, as well as opening us up to dangerous split-brain conditions because /// the pods have inconsistent snapshots of which servers they should expect to be in quorum. - pub fn pods(&self) -> Result + '_, NoNamespaceError> { + pub fn pods(&self) -> Result + '_, Error> { let ns = self.metadata.namespace.clone().context(NoNamespaceSnafu)?; Ok(self .spec @@ -446,60 +503,52 @@ impl ZookeeperCluster { /// 3. a default PVC with 1Gi capacity pub fn resources( &self, + role: &ZookeeperRole, rolegroup_ref: &RoleGroupRef, - ) -> (Vec, ResourceRequirements) { - let mut role_resources = self.role_resources().unwrap_or_default(); - role_resources.merge(&Self::default_resources()); - let mut resources = self.rolegroup_resources(rolegroup_ref).unwrap_or_default(); - resources.merge(&role_resources); + ) -> Result<(Vec, ResourceRequirements), Error> { + // Initialize the result with all default values as baseline + let conf_defaults = ZookeeperConfig::default_resources(); + + let role = match role { + ZookeeperRole::Server => { + self.spec + .servers + .as_ref() + .context(UnknownZookeeperRoleSnafu { + role: role.to_string(), + roles: vec![role.to_string()], + })? + } + }; + + // Retrieve role resource config + let mut conf_role: ResourcesFragment = + role.config.config.resources.clone().unwrap_or_default(); + + // Retrieve rolegroup specific resource config + let mut conf_rolegroup: ResourcesFragment = role + .role_groups + .get(&rolegroup_ref.role_group) + .and_then(|rg| rg.config.config.resources.clone()) + .unwrap_or_default(); + + // Merge more specific configs into default config + // Hierarchy is: + // 1. RoleGroup + // 2. Role + // 3. Default + conf_role.merge(&conf_defaults); + conf_rolegroup.merge(&conf_role); + + let resources: Resources = + fragment::validate(conf_rolegroup).context(FragmentValidationFailureSnafu)?; let data_pvc = resources .storage .data .build_pvc("data", Some(vec!["ReadWriteOnce"])); - let pod_resources = resources.clone().into(); - - (vec![data_pvc], pod_resources) - } - - fn rolegroup_resources( - &self, - rolegroup_ref: &RoleGroupRef, - ) -> Option> { - let spec: &ZookeeperClusterSpec = &self.spec; - spec.servers - .as_ref()? - .role_groups - .get(&rolegroup_ref.role_group)? - .config - .config - .resources - .clone() - } - - fn role_resources(&self) -> Option> { - let spec: &ZookeeperClusterSpec = &self.spec; - spec.servers.as_ref()?.config.config.resources.clone() - } - fn default_resources() -> Resources { - Resources { - cpu: CpuLimits { - min: Some(Quantity("500m".to_owned())), - max: Some(Quantity("4".to_owned())), - }, - memory: MemoryLimits { - limit: Some(Quantity("512Mi".to_owned())), - runtime_limits: NoRuntimeLimits {}, - }, - storage: Storage { - data: PvcConfig { - capacity: Some(Quantity("1Gi".to_owned())), - storage_class: None, - selectors: None, - }, - }, - } + Ok((vec![data_pvc], resources.into())) } pub fn heap_limits(&self, resources: &ResourceRequirements) -> OperatorResult> { diff --git a/rust/operator-binary/Cargo.toml b/rust/operator-binary/Cargo.toml index 3aef819a..374eff19 100644 --- a/rust/operator-binary/Cargo.toml +++ b/rust/operator-binary/Cargo.toml @@ -10,25 +10,24 @@ publish = false [dependencies] anyhow = "1.0.58" -clap = { version = "3.2.8", features = ["derive"] } +clap = "4.0.26" failure = "0.1.8" fnv = "1.0.7" futures = { version = "0.3.21", features = ["compat"] } semver = "1.0.12" serde = "1.0.138" -serde_json = "1.0.82" snafu = "0.7.1" strum = { version = "0.24.1", features = ["derive"] } -tokio = { version = "1.21.1", features = ["full"], package = "tokio" } +tokio = { version = "1.21.2", features = ["full"], package = "tokio" } tokio01 = { version = "0.1.22", package = "tokio" } tokio-executor = "0.1.10" tokio-zookeeper = "0.1.3" tracing = "0.1.35" pin-project = "1.0.11" -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.25.3" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.27.1" } stackable-zookeeper-crd = { path = "../crd" } [build-dependencies] built = { version = "0.5.1", features = ["chrono", "git2"] } -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.25.3" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.27.1" } stackable-zookeeper-crd = { path = "../crd" } diff --git a/rust/operator-binary/src/command.rs b/rust/operator-binary/src/command.rs index 8279ed90..581e5b91 100644 --- a/rust/operator-binary/src/command.rs +++ b/rust/operator-binary/src/command.rs @@ -1,6 +1,7 @@ use stackable_zookeeper_crd::{ ZookeeperCluster, ZookeeperConfig, CLIENT_TLS_DIR, CLIENT_TLS_MOUNT_DIR, QUORUM_TLS_DIR, QUORUM_TLS_MOUNT_DIR, STACKABLE_CONFIG_DIR, STACKABLE_DATA_DIR, STACKABLE_RW_CONFIG_DIR, + ZOOKEEPER_PROPERTIES_FILE, }; const STORE_PASSWORD_ENV: &str = "STORE_PASSWORD"; @@ -70,7 +71,7 @@ fn generate_password() -> String { /// to the zoo.cfg to set key and truststore passwords. fn write_store_password_to_config(property: &str) -> String { format!( - "echo {property}=${STORE_PASSWORD_ENV} >> {rwconf}/zoo.cfg", + "echo {property}=${STORE_PASSWORD_ENV} >> {rwconf}/{ZOOKEEPER_PROPERTIES_FILE}", property = property, rwconf = STACKABLE_RW_CONFIG_DIR ) diff --git a/rust/operator-binary/src/discovery.rs b/rust/operator-binary/src/discovery.rs index 190274fb..fc90cf31 100644 --- a/rust/operator-binary/src/discovery.rs +++ b/rust/operator-binary/src/discovery.rs @@ -1,4 +1,5 @@ -use std::{collections::BTreeSet, num::TryFromIntError}; +use crate::zk_controller::build_recommended_labels; +use crate::ZK_CONTROLLER_NAME; use snafu::{OptionExt, ResultExt, Snafu}; use stackable_operator::{ @@ -7,8 +8,7 @@ use stackable_operator::{ kube::{runtime::reflector::ObjectRef, Resource}, }; use stackable_zookeeper_crd::{ZookeeperCluster, ZookeeperRole}; - -use crate::{zk_controller::zk_version, APP_NAME}; +use std::{collections::BTreeSet, num::TryFromIntError}; #[derive(Snafu, Debug)] pub enum Error { @@ -23,9 +23,13 @@ pub enum Error { NoName, #[snafu(display("object has no namespace associated"))] NoNamespace, + #[snafu(display("object has no version"))] + NoVersion { + source: stackable_zookeeper_crd::Error, + }, #[snafu(display("failed to list expected pods"))] ExpectedPods { - source: stackable_zookeeper_crd::NoNamespaceError, + source: stackable_zookeeper_crd::Error, }, #[snafu(display("could not find service port with name {}", port_name))] NoServicePort { port_name: String }, @@ -46,23 +50,21 @@ pub enum Error { /// Builds discovery [`ConfigMap`]s for connecting to a [`ZookeeperCluster`] for all expected scenarios pub async fn build_discovery_configmaps( - client: &stackable_operator::client::Client, - owner: &impl Resource, zk: &ZookeeperCluster, + owner: &impl Resource, + client: &stackable_operator::client::Client, svc: &Service, chroot: Option<&str>, - app_managed_by: &str, ) -> Result, Error> { let name = owner.meta().name.as_deref().context(NoNameSnafu)?; Ok(vec![ - build_discovery_configmap(name, owner, zk, chroot, pod_hosts(zk)?, app_managed_by)?, + build_discovery_configmap(name, owner, zk, chroot, pod_hosts(zk)?)?, build_discovery_configmap( &format!("{}-nodeport", name), owner, zk, chroot, nodeport_hosts(client, svc, "zk").await?, - app_managed_by, )?, ]) } @@ -76,7 +78,6 @@ fn build_discovery_configmap( zk: &ZookeeperCluster, chroot: Option<&str>, hosts: impl IntoIterator, u16)>, - app_managed_by: &str, ) -> Result { // Write a connection string of the format that Java ZooKeeper client expects: // "{host1}:{port1},{host2:port2},.../{chroot}" @@ -102,14 +103,13 @@ fn build_discovery_configmap( .with_context(|_| ObjectMissingMetadataForOwnerRefSnafu { zk: ObjectRef::from_obj(zk), })? - .with_recommended_labels( - owner, - APP_NAME, - zk_version(zk).unwrap_or("unknown"), - app_managed_by, + .with_recommended_labels(build_recommended_labels( + &zk, + ZK_CONTROLLER_NAME, + zk.image_version().context(NoVersionSnafu)?, &ZookeeperRole::Server.to_string(), "discovery", - ) + )) .build(), ) .add_data("ZOOKEEPER", conn_str) @@ -150,7 +150,10 @@ async fn nodeport_hosts( let endpoints = client .get::( svc.metadata.name.as_deref().context(NoNameSnafu)?, - svc.metadata.namespace.as_deref(), + svc.metadata + .namespace + .as_deref() + .context(NoNamespaceSnafu)?, ) .await .with_context(|_| FindEndpointsSnafu { diff --git a/rust/operator-binary/src/main.rs b/rust/operator-binary/src/main.rs index f82aaae6..2a32e566 100644 --- a/rust/operator-binary/src/main.rs +++ b/rust/operator-binary/src/main.rs @@ -4,9 +4,10 @@ mod utils; mod zk_controller; mod znode_controller; -use std::sync::Arc; - use crate::utils::Tokio01ExecutorExt; +use crate::zk_controller::ZK_CONTROLLER_NAME; +use crate::znode_controller::ZNODE_CONTROLLER_NAME; + use clap::Parser; use futures::{compat::Future01CompatExt, StreamExt}; use stackable_operator::{ @@ -23,12 +24,14 @@ use stackable_operator::{ CustomResourceExt, }; use stackable_zookeeper_crd::{ZookeeperCluster, ZookeeperZnode}; +use std::sync::Arc; mod built_info { include!(concat!(env!("OUT_DIR"), "/built.rs")); } const APP_NAME: &str = "zookeeper"; +const OPERATOR_NAME: &str = "zookeeper.stackable.tech"; #[derive(clap::Parser)] #[clap(about = built_info::PKG_DESCRIPTION, author = stackable_operator::cli::AUTHOR)] @@ -70,10 +73,8 @@ async fn main() -> anyhow::Result<()> { "deploy/config-spec/properties.yaml", "/etc/stackable/zookeeper-operator/config-spec/properties.yaml", ])?; - let client = stackable_operator::client::create_client(Some( - "zookeeper.stackable.tech".to_string(), - )) - .await?; + let client = + stackable_operator::client::create_client(Some(OPERATOR_NAME.to_string())).await?; let zk_controller_builder = Controller::new( watch_namespace.get_api::(&client), ListParams::default(), @@ -119,7 +120,7 @@ async fn main() -> anyhow::Result<()> { .map(|res| { report_controller_reconciled( &client, - "zookeeperclusters.zookeeper.stackable.tech", + &format!("{ZK_CONTROLLER_NAME}.{OPERATOR_NAME}"), &res, ); }); @@ -162,7 +163,7 @@ async fn main() -> anyhow::Result<()> { .map(|res| { report_controller_reconciled( &client, - "zookeeperznode.zookeeper.stackable.tech", + &format!("{ZNODE_CONTROLLER_NAME}.{OPERATOR_NAME}"), &res, ); }); diff --git a/rust/operator-binary/src/zk_controller.rs b/rust/operator-binary/src/zk_controller.rs index a39979bd..93d20bd6 100644 --- a/rust/operator-binary/src/zk_controller.rs +++ b/rust/operator-binary/src/zk_controller.rs @@ -2,8 +2,9 @@ use crate::{ command::create_init_container_command_args, discovery::{self, build_discovery_configmaps}, - ObjectRef, APP_NAME, + ObjectRef, APP_NAME, OPERATOR_NAME, }; + use fnv::FnvHasher; use snafu::{OptionExt, ResultExt, Snafu}; use stackable_operator::{ @@ -24,12 +25,12 @@ use stackable_operator::{ ExecAction, ObjectFieldSelector, PodSecurityContext, Probe, Service, ServiceAccount, ServicePort, ServiceSpec, Volume, }, - rbac::v1::{RoleRef, Subject}, + rbac::v1::{RoleBinding, RoleRef, Subject}, }, apimachinery::pkg::apis::meta::v1::LabelSelector, }, - kube::{api::DynamicObject, runtime::controller, Resource}, - labels::{role_group_selector_labels, role_selector_labels}, + kube::{api::DynamicObject, runtime::controller, Resource, ResourceExt}, + labels::{role_group_selector_labels, role_selector_labels, ObjectLabels}, logging::controller::ReconcilerError, product_config::{ types::PropertyNameKind, writer::to_java_properties_string, ProductConfigManager, @@ -37,23 +38,22 @@ use stackable_operator::{ product_config_utils::{transform_all_roles_to_config, validate_all_roles_and_groups_config}, role_utils::RoleGroupRef, }; -use stackable_operator::{k8s_openapi::api::rbac::v1::RoleBinding, kube::ResourceExt}; use stackable_zookeeper_crd::{ ZookeeperCluster, ZookeeperClusterStatus, ZookeeperConfig, ZookeeperRole, CLIENT_TLS_DIR, CLIENT_TLS_MOUNT_DIR, QUORUM_TLS_DIR, QUORUM_TLS_MOUNT_DIR, STACKABLE_CONFIG_DIR, - STACKABLE_DATA_DIR, STACKABLE_RW_CONFIG_DIR, + STACKABLE_DATA_DIR, STACKABLE_RW_CONFIG_DIR, ZOOKEEPER_PROPERTIES_FILE, }; use std::{ borrow::Cow, collections::{BTreeMap, HashMap}, hash::Hasher, + str::FromStr, sync::Arc, time::Duration, }; use strum::{EnumDiscriminants, IntoStaticStr}; -const RESOURCE_SCOPE: &str = "zookeeper-operator_zookeepercluster"; - +pub const ZK_CONTROLLER_NAME: &str = "zookeepercluster"; const SERVICE_ACCOUNT: &str = "zookeeper-serviceaccount"; pub struct Ctx { @@ -67,10 +67,17 @@ pub struct Ctx { pub enum Error { #[snafu(display("object has no namespace"))] ObjectHasNoNamespace, - #[snafu(display("object defines no version"))] - ObjectHasNoVersion, + #[snafu(display("crd validation failure"))] + CrdValidationFailure { + source: stackable_zookeeper_crd::Error, + }, #[snafu(display("object defines no server role"))] NoServerRole, + #[snafu(display("could not parse role [{role}]"))] + RoleParseFailure { + source: strum::ParseError, + role: String, + }, #[snafu(display("failed to calculate global service name"))] GlobalServiceNameNotFound, #[snafu(display("failed to calculate service name for role {}", rolegroup))] @@ -109,7 +116,7 @@ pub enum Error { InvalidProductConfig { source: stackable_operator::error::Error, }, - #[snafu(display("failed to serialize zoo.cfg for {}", rolegroup))] + #[snafu(display("failed to serialize [{ZOOKEEPER_PROPERTIES_FILE}] for {}", rolegroup))] SerializeZooCfg { source: stackable_operator::product_config::writer::PropertiesWriterError, rolegroup: RoleGroupRef, @@ -169,8 +176,9 @@ impl ReconcilerError for Error { fn secondary_object(&self) -> Option> { match self { Error::ObjectHasNoNamespace => None, - Error::ObjectHasNoVersion => None, + Error::CrdValidationFailure { .. } => None, Error::NoServerRole => None, + Error::RoleParseFailure { .. } => None, Error::GlobalServiceNameNotFound => None, Error::RoleGroupServiceNameNotFound { .. } => None, Error::ApplyRoleService { .. } => None, @@ -201,16 +209,19 @@ impl ReconcilerError for Error { } } -const PROPERTIES_FILE: &str = "zoo.cfg"; - pub async fn reconcile_zk(zk: Arc, ctx: Arc) -> Result { tracing::info!("Starting reconcile"); let client = &ctx.client; - let mut cluster_resources = - ClusterResources::new(APP_NAME, RESOURCE_SCOPE, &zk.object_ref(&())).unwrap(); + let mut cluster_resources = ClusterResources::new( + APP_NAME, + OPERATOR_NAME, + ZK_CONTROLLER_NAME, + &zk.object_ref(&()), + ) + .unwrap(); let validated_config = validate_all_roles_and_groups_config( - zk_version(&zk)?, + zk.image_version().context(CrdValidationFailureSnafu)?, &transform_all_roles_to_config( &*zk, [( @@ -218,7 +229,7 @@ pub async fn reconcile_zk(zk: Arc, ctx: Arc) -> Result, ctx: Arc) -> Result(auth_class, None) // AuthenticationClass has ClusterScope + AuthenticationClass::resolve(client, auth_class) .await .context(AuthenticationClassRetrievalSnafu { authentication_class: ObjectRef::::new(auth_class), @@ -262,19 +271,19 @@ pub async fn reconcile_zk(zk: Arc, ctx: Arc) -> Result, ctx: Arc) -> Result, ctx: Arc) -> Result Result<(ServiceAccount, metadata: ObjectMetaBuilder::new() .name_and_namespace(zk) .name(SERVICE_ACCOUNT.to_string()) - .with_recommended_labels( + .with_recommended_labels(build_recommended_labels( zk, - APP_NAME, - zk_version(zk)?, - RESOURCE_SCOPE, + ZK_CONTROLLER_NAME, + zk.image_version().context(CrdValidationFailureSnafu)?, "global", "global", - ) + )) .build(), ..ServiceAccount::default() }; @@ -359,14 +360,13 @@ pub fn build_zk_rbac_resources(zk: &ZookeeperCluster) -> Result<(ServiceAccount, metadata: ObjectMetaBuilder::new() .name_and_namespace(zk) .name("zookeeper-rolebinding".to_string()) - .with_recommended_labels( + .with_recommended_labels(build_recommended_labels( zk, - APP_NAME, - zk_version(zk)?, - RESOURCE_SCOPE, + ZK_CONTROLLER_NAME, + zk.image_version().context(CrdValidationFailureSnafu)?, "global", "global", - ) + )) .build(), role_ref: RoleRef { kind: "ClusterRole".to_string(), @@ -400,14 +400,13 @@ pub fn build_server_role_service(zk: &ZookeeperCluster) -> Result { .name(&role_svc_name) .ownerreference_from_resource(zk, None, Some(true)) .context(ObjectMissingMetadataForOwnerRefSnafu)? - .with_recommended_labels( + .with_recommended_labels(build_recommended_labels( zk, - APP_NAME, - zk_version(zk)?, - RESOURCE_SCOPE, + ZK_CONTROLLER_NAME, + zk.image_version().context(CrdValidationFailureSnafu)?, &role_name, "global", - ) + )) .build(), spec: Some(ServiceSpec { ports: Some(vec![ServicePort { @@ -426,12 +425,14 @@ pub fn build_server_role_service(zk: &ZookeeperCluster) -> Result { /// The rolegroup [`ConfigMap`] configures the rolegroup based on the configuration given by the administrator fn build_server_rolegroup_config_map( - rolegroup: &RoleGroupRef, zk: &ZookeeperCluster, + rolegroup: &RoleGroupRef, server_config: &HashMap>, ) -> Result { let mut zoo_cfg = server_config - .get(&PropertyNameKind::File(PROPERTIES_FILE.to_string())) + .get(&PropertyNameKind::File( + ZOOKEEPER_PROPERTIES_FILE.to_string(), + )) .cloned() .unwrap_or_default(); zoo_cfg.extend(zk.pods().into_iter().flatten().map(|pod| { @@ -452,18 +453,17 @@ fn build_server_rolegroup_config_map( .name(rolegroup.object_name()) .ownerreference_from_resource(zk, None, Some(true)) .context(ObjectMissingMetadataForOwnerRefSnafu)? - .with_recommended_labels( + .with_recommended_labels(build_recommended_labels( zk, - APP_NAME, - zk_version(zk)?, - RESOURCE_SCOPE, + ZK_CONTROLLER_NAME, + zk.image_version().context(CrdValidationFailureSnafu)?, &rolegroup.role, &rolegroup.role_group, - ) + )) .build(), ) .add_data( - "zoo.cfg", + ZOOKEEPER_PROPERTIES_FILE, to_java_properties_string(zoo_cfg.iter().map(|(k, v)| (k, v))).with_context(|_| { SerializeZooCfgSnafu { rolegroup: rolegroup.clone(), @@ -480,8 +480,8 @@ fn build_server_rolegroup_config_map( /// /// This is mostly useful for internal communication between peers, or for clients that perform client-side load balancing. fn build_server_rolegroup_service( - rolegroup: &RoleGroupRef, zk: &ZookeeperCluster, + rolegroup: &RoleGroupRef, ) -> Result { Ok(Service { metadata: ObjectMetaBuilder::new() @@ -489,14 +489,13 @@ fn build_server_rolegroup_service( .name(&rolegroup.object_name()) .ownerreference_from_resource(zk, None, Some(true)) .context(ObjectMissingMetadataForOwnerRefSnafu)? - .with_recommended_labels( + .with_recommended_labels(build_recommended_labels( zk, - APP_NAME, - zk_version(zk)?, - RESOURCE_SCOPE, + ZK_CONTROLLER_NAME, + zk.image_version().context(CrdValidationFailureSnafu)?, &rolegroup.role, &rolegroup.role_group, - ) + )) .with_label("prometheus.io/scrape", "true") .build(), spec: Some(ServiceSpec { @@ -532,13 +531,16 @@ fn build_server_rolegroup_service( /// /// The [`Pod`](`stackable_operator::k8s_openapi::api::core::v1::Pod`)s are accessible through the corresponding [`Service`] (from [`build_server_rolegroup_service`]). fn build_server_rolegroup_statefulset( - rolegroup_ref: &RoleGroupRef, zk: &ZookeeperCluster, + rolegroup_ref: &RoleGroupRef, server_config: &HashMap>, client_authentication_class: Option<&AuthenticationClass>, ) -> Result { - let zk_version = zk_version(zk)?; - + let zk_version = zk.image_version().context(CrdValidationFailureSnafu)?; + let zk_role = + ZookeeperRole::from_str(&rolegroup_ref.role).with_context(|_| RoleParseFailureSnafu { + role: rolegroup_ref.role.to_string(), + })?; let rolegroup = zk .spec .servers @@ -558,7 +560,9 @@ fn build_server_rolegroup_statefulset( }) .collect::>(); - let (pvc, resources) = zk.resources(rolegroup_ref); + let (pvc, resources) = zk + .resources(&zk_role, rolegroup_ref) + .context(CrdValidationFailureSnafu)?; // set heap size if available let heap_limits = zk .heap_limits(&resources) @@ -649,14 +653,13 @@ fn build_server_rolegroup_statefulset( let pod_template = pod_builder .metadata_builder(|m| { - m.with_recommended_labels( + m.with_recommended_labels(build_recommended_labels( zk, - APP_NAME, + ZK_CONTROLLER_NAME, zk_version, - RESOURCE_SCOPE, &rolegroup_ref.role, &rolegroup_ref.role_group, - ) + )) }) .add_init_container(container_prepare) .add_container(container_zk) @@ -689,14 +692,13 @@ fn build_server_rolegroup_statefulset( .name(&rolegroup_ref.object_name()) .ownerreference_from_resource(zk, None, Some(true)) .context(ObjectMissingMetadataForOwnerRefSnafu)? - .with_recommended_labels( + .with_recommended_labels(build_recommended_labels( zk, - APP_NAME, + ZK_CONTROLLER_NAME, zk_version, - RESOURCE_SCOPE, &rolegroup_ref.role, &rolegroup_ref.role_group, - ) + )) .build(), spec: Some(StatefulSetSpec { pod_management_policy: Some("Parallel".to_string()), @@ -794,10 +796,28 @@ fn create_tls_volume(volume_name: &str, secret_class_name: &str) -> Volume { .build() } -pub fn zk_version(zk: &ZookeeperCluster) -> Result<&str> { - zk.spec.version.as_deref().context(ObjectHasNoVersionSnafu) +pub fn build_recommended_labels<'a>( + owner: &'a ZookeeperCluster, + controller_name: &'a str, + app_version: &'a str, + role: &'a str, + role_group: &'a str, +) -> ObjectLabels<'a, ZookeeperCluster> { + ObjectLabels { + owner, + app_name: APP_NAME, + app_version, + operator_name: OPERATOR_NAME, + controller_name, + role, + role_group, + } } -pub fn error_policy(_error: &Error, _ctx: Arc) -> controller::Action { +pub fn error_policy( + _obj: Arc, + _error: &Error, + _ctx: Arc, +) -> controller::Action { controller::Action::requeue(Duration::from_secs(5)) } diff --git a/rust/operator-binary/src/znode_controller.rs b/rust/operator-binary/src/znode_controller.rs index 6eff651a..cbbc666b 100644 --- a/rust/operator-binary/src/znode_controller.rs +++ b/rust/operator-binary/src/znode_controller.rs @@ -6,7 +6,7 @@ use std::{convert::Infallible, sync::Arc, time::Duration}; use crate::{ discovery::{self, build_discovery_configmaps}, - APP_NAME, + APP_NAME, OPERATOR_NAME, }; use snafu::{OptionExt, ResultExt, Snafu}; use stackable_operator::{ @@ -24,7 +24,7 @@ use stackable_operator::{ use stackable_zookeeper_crd::{ZookeeperCluster, ZookeeperZnode}; use strum::{EnumDiscriminants, IntoStaticStr}; -const RESOURCE_SCOPE: &str = "zookeeper-operator_zookeeperznode"; +pub const ZNODE_CONTROLLER_NAME: &str = "znode"; pub struct Ctx { pub client: stackable_operator::client::Client, @@ -89,6 +89,8 @@ pub enum Error { DeleteOrphans { source: stackable_operator::error::Error, }, + #[snafu(display("object has no namespace"))] + ObjectHasNoNamespace, } type Result = std::result::Result; @@ -131,6 +133,7 @@ impl ReconcilerError for Error { Error::Finalizer { source: _ } => None, Error::ObjectMissingMetadataForOwnerRef { source: _ } => None, Error::DeleteOrphans { source: _ } => None, + Error::ObjectHasNoNamespace => None, } } } @@ -158,8 +161,8 @@ pub async fn reconcile_znode( let znode_path = format!("/znode-{}", uid); finalizer( - &client.get_namespaced_api::(&ns), - "zookeeper.stackable.tech/znode", + &client.get_api::(&ns), + &format!("{OPERATOR_NAME}/znode"), znode, |ev| async { match ev { @@ -181,8 +184,13 @@ async fn reconcile_apply( znode_path: &str, ) -> Result { let zk = zk?; - let mut cluster_resources = - ClusterResources::new(APP_NAME, RESOURCE_SCOPE, &znode.object_ref(&())).unwrap(); + let mut cluster_resources = ClusterResources::new( + APP_NAME, + OPERATOR_NAME, + ZNODE_CONTROLLER_NAME, + &znode.object_ref(&()), + ) + .unwrap(); znode_mgmt::ensure_znode_exists(&zk_mgmt_addr(&zk)?, znode_path) .await @@ -197,22 +205,19 @@ async fn reconcile_apply( .with_context(|| NoZkSvcNameSnafu { zk: ObjectRef::from_obj(&zk), })?, - zk.metadata.namespace.as_deref(), + zk.metadata + .namespace + .as_deref() + .context(ObjectHasNoNamespaceSnafu)?, ) .await .context(FindZkSvcSnafu { zk: ObjectRef::from_obj(&zk), })?; - for discovery_cm in build_discovery_configmaps( - client, - znode, - &zk, - &server_role_service, - Some(znode_path), - RESOURCE_SCOPE, - ) - .await - .context(BuildDiscoveryConfigMapSnafu)? + for discovery_cm in + build_discovery_configmaps(&zk, znode, client, &server_role_service, Some(znode_path)) + .await + .context(BuildDiscoveryConfigMapSnafu)? { cluster_resources .add(client, &discovery_cm) @@ -273,7 +278,7 @@ async fn find_zk_of_znode( zk_ref.name.as_deref(), zk_ref.namespace_relative_from(znode), ) { - match client.get::(zk_name, Some(zk_ns)).await { + match client.get::(zk_name, zk_ns).await { Ok(zk) => Ok(zk), Err(err) => match &err { stackable_operator::error::Error::KubeError { @@ -291,7 +296,11 @@ async fn find_zk_of_znode( } } -pub fn error_policy(_error: &Error, _ctx: Arc) -> controller::Action { +pub fn error_policy( + _obj: Arc, + _error: &Error, + _ctx: Arc, +) -> controller::Action { controller::Action::requeue(Duration::from_secs(5)) } From 4c26e438ceb4ac04eff84e90feb40969eeed868c Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Fri, 18 Nov 2022 14:29:13 +0100 Subject: [PATCH 2/4] clippy - tests working --- rust/operator-binary/src/discovery.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/operator-binary/src/discovery.rs b/rust/operator-binary/src/discovery.rs index fc90cf31..6a4e23a8 100644 --- a/rust/operator-binary/src/discovery.rs +++ b/rust/operator-binary/src/discovery.rs @@ -104,7 +104,7 @@ fn build_discovery_configmap( zk: ObjectRef::from_obj(zk), })? .with_recommended_labels(build_recommended_labels( - &zk, + zk, ZK_CONTROLLER_NAME, zk.image_version().context(NoVersionSnafu)?, &ZookeeperRole::Server.to_string(), From bd04ddf12daee85c5d1834260fe394014da9018f Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Fri, 18 Nov 2022 14:35:46 +0100 Subject: [PATCH 3/4] adapted changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2552dc3d..ba24b220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,10 @@ All notable changes to this project will be documented in this file. ### Changed - Updated stackable image versions ([#586]). +- Operator-rs: 0.25.3 -> 0.27.1 ([#591]). [#586]: https://github.com/stackabletech/zookeeper-operator/pull/586 +[#591]: https://github.com/stackabletech/zookeeper-operator/pull/591 ## [0.12.0] - 2022-11-07 From 126458a36ffc17bc424455a6eaa1515002afdf55 Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Fri, 18 Nov 2022 16:54:16 +0100 Subject: [PATCH 4/4] moved build_recommended_labels to utils crate --- rust/operator-binary/src/discovery.rs | 2 +- rust/operator-binary/src/utils.rs | 21 +++++++++++++++++++++ rust/operator-binary/src/zk_controller.rs | 21 ++------------------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/rust/operator-binary/src/discovery.rs b/rust/operator-binary/src/discovery.rs index 6a4e23a8..75cd7aca 100644 --- a/rust/operator-binary/src/discovery.rs +++ b/rust/operator-binary/src/discovery.rs @@ -1,4 +1,4 @@ -use crate::zk_controller::build_recommended_labels; +use crate::utils::build_recommended_labels; use crate::ZK_CONTROLLER_NAME; use snafu::{OptionExt, ResultExt, Snafu}; diff --git a/rust/operator-binary/src/utils.rs b/rust/operator-binary/src/utils.rs index 92843165..493f0c87 100644 --- a/rust/operator-binary/src/utils.rs +++ b/rust/operator-binary/src/utils.rs @@ -1,5 +1,7 @@ +use crate::{APP_NAME, OPERATOR_NAME}; use futures::Future; use pin_project::pin_project; +use stackable_operator::labels::ObjectLabels; #[pin_project] pub struct WithTokio01Executor { @@ -34,3 +36,22 @@ pub trait Tokio01ExecutorExt { } impl Tokio01ExecutorExt for E {} + +/// Creates recommended `ObjectLabels` to be used in deployed resources +pub fn build_recommended_labels<'a, T>( + owner: &'a T, + controller_name: &'a str, + app_version: &'a str, + role: &'a str, + role_group: &'a str, +) -> ObjectLabels<'a, T> { + ObjectLabels { + owner, + app_name: APP_NAME, + app_version, + operator_name: OPERATOR_NAME, + controller_name, + role, + role_group, + } +} diff --git a/rust/operator-binary/src/zk_controller.rs b/rust/operator-binary/src/zk_controller.rs index 93d20bd6..7ea721fd 100644 --- a/rust/operator-binary/src/zk_controller.rs +++ b/rust/operator-binary/src/zk_controller.rs @@ -2,6 +2,7 @@ use crate::{ command::create_init_container_command_args, discovery::{self, build_discovery_configmaps}, + utils::build_recommended_labels, ObjectRef, APP_NAME, OPERATOR_NAME, }; @@ -30,7 +31,7 @@ use stackable_operator::{ apimachinery::pkg::apis::meta::v1::LabelSelector, }, kube::{api::DynamicObject, runtime::controller, Resource, ResourceExt}, - labels::{role_group_selector_labels, role_selector_labels, ObjectLabels}, + labels::{role_group_selector_labels, role_selector_labels}, logging::controller::ReconcilerError, product_config::{ types::PropertyNameKind, writer::to_java_properties_string, ProductConfigManager, @@ -796,24 +797,6 @@ fn create_tls_volume(volume_name: &str, secret_class_name: &str) -> Volume { .build() } -pub fn build_recommended_labels<'a>( - owner: &'a ZookeeperCluster, - controller_name: &'a str, - app_version: &'a str, - role: &'a str, - role_group: &'a str, -) -> ObjectLabels<'a, ZookeeperCluster> { - ObjectLabels { - owner, - app_name: APP_NAME, - app_version, - operator_name: OPERATOR_NAME, - controller_name, - role, - role_group, - } -} - pub fn error_policy( _obj: Arc, _error: &Error,