diff --git a/CHANGELOG.md b/CHANGELOG.md index b6531266..b86565c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,15 @@ ## Changed +- Startup probe created and thresholds in liveness and readiness probes fine-tuned ([#193]). - Include chart name when installing with a custom release name ([#209], [#210]). +- Orphaned resources are deleted ([#215]). - Fix HBase-shell start failure ([#218]). +[#193]: https://github.com/stackabletech/hbase-operator/pull/193 [#209]: https://github.com/stackabletech/hbase-operator/pull/209 [#210]: https://github.com/stackabletech/hbase-operator/pull/210 +[#215]: https://github.com/stackabletech/hbase-operator/pull/215 [#218]: https://github.com/stackabletech/hbase-operator/pull/218 ## [0.3.0] - 2022-06-30 @@ -30,7 +34,6 @@ - `hbaseManagesZk`: defaults to false - `hbaseClusterDistributed`: defaults to true - [BREAKING] Specifying the product version has been changed to adhere to [ADR018](https://docs.stackable.tech/home/contributor/adr/ADR018-product_image_versioning.html) instead of just specifying the product version you will now have to add the Stackable image version as well, so `version: 3.5.8` becomes (for example) `version: 3.5.8-stackable0.1.0` ([#179]) -- Startup probe created and thresholds in liveness and readiness probes fine-tuned ([#193]). [#133]: https://github.com/stackabletech/hbase-operator/pull/133 [#137]: https://github.com/stackabletech/hbase-operator/pull/137 @@ -39,7 +42,6 @@ [#162]: https://github.com/stackabletech/hbase-operator/pull/162 [#163]: https://github.com/stackabletech/hbase-operator/pull/163 [#179]: https://github.com/stackabletech/hbase-operator/pull/179 -[#193]: https://github.com/stackabletech/hbase-operator/pull/193 [#197]: https://github.com/stackabletech/hbase-operator/pull/197 ## [0.2.0] - 2022-02-14 diff --git a/Cargo.lock b/Cargo.lock index 6f9ad460..deadb2bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -830,9 +830,9 @@ dependencies = [ [[package]] name = "kube" -version = "0.73.1" +version = "0.74.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f68b954ea9ad888de953fb1488bd8f377c4c78d82d4642efa5925189210b50b7" +checksum = "a527a8001a61d8d470dab27ac650889938760c243903e7cd90faaf7c60a34bdd" dependencies = [ "k8s-openapi", "kube-client", @@ -843,9 +843,9 @@ dependencies = [ [[package]] name = "kube-client" -version = "0.73.1" +version = "0.74.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9150dc7107d9acf4986088f284a0a6dddc5ae37ef1ffdf142f6811dc5998dd58" +checksum = "c0d48f42df4e8342e9f488c4b97e3759d0042c4e7ab1a853cc285adb44409480" dependencies = [ "base64", "bytes", @@ -880,9 +880,9 @@ dependencies = [ [[package]] name = "kube-core" -version = "0.73.1" +version = "0.74.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc8c429676abe6a73b374438d5ca02caaf9ae7a635441253c589b779fa5d0622" +checksum = "91f56027f862fdcad265d2e9616af416a355e28a1c620bb709083494753e070d" dependencies = [ "chrono", "form_urlencoded", @@ -898,9 +898,9 @@ dependencies = [ [[package]] name = "kube-derive" -version = "0.73.1" +version = "0.74.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfb405f0d39181acbfdc7c79e3fc095330c9b6465ab50aeb662d762e53b662f1" +checksum = "66d74121eb41af4480052901f31142d8d9bbdf1b7c6b856da43bcb02f5b1b177" dependencies = [ "darling", "proc-macro2", @@ -911,9 +911,9 @@ dependencies = [ [[package]] name = "kube-runtime" -version = "0.73.1" +version = "0.74.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6e9e9da456f0101b77f864a9da44866b9891ad4740db508b4b269343ebeb01d" +checksum = "8fdcf5a20f968768e342ef1a457491bb5661fccd81119666d626c57500b16d99" dependencies = [ "ahash", "backoff", @@ -1696,8 +1696,8 @@ dependencies = [ [[package]] name = "stackable-operator" -version = "0.22.0" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.22.0#5543877169d27770578e634d0d734aa6126f838c" +version = "0.24.0" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.24.0#8667365352e384e298caa8ebe9f99b2381c190ed" dependencies = [ "backoff", "chrono", @@ -1730,8 +1730,8 @@ dependencies = [ [[package]] name = "stackable-operator-derive" -version = "0.22.0" -source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.22.0#5543877169d27770578e634d0d734aa6126f838c" +version = "0.24.0" +source = "git+https://github.com/stackabletech/operator-rs.git?tag=0.24.0#8667365352e384e298caa8ebe9f99b2381c190ed" dependencies = [ "darling", "proc-macro2", diff --git a/rust/crd/Cargo.toml b/rust/crd/Cargo.toml index 752d925b..ceed313c 100644 --- a/rust/crd/Cargo.toml +++ b/rust/crd/Cargo.toml @@ -10,5 +10,5 @@ version = "0.4.0-nightly" [dependencies] serde = "1.0" serde_json = "1.0" -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.22.0" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.24.0" } strum = { version = "0.24", features = ["derive"] } diff --git a/rust/operator-binary/Cargo.toml b/rust/operator-binary/Cargo.toml index 9fcb51c8..ec68ad31 100644 --- a/rust/operator-binary/Cargo.toml +++ b/rust/operator-binary/Cargo.toml @@ -16,7 +16,7 @@ serde = "1.0" serde_yaml = "0.9" snafu = "0.7" stackable-hbase-crd = { path = "../crd" } -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.22.0" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.24.0" } strum = { version = "0.24", features = ["derive"] } tokio = { version = "1.20", features = ["macros", "rt-multi-thread"] } tracing = "0.1" @@ -24,4 +24,4 @@ tracing = "0.1" [build-dependencies] built = { version = "0.5", features = ["chrono", "git2"] } stackable-hbase-crd = { path = "../crd" } -stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.22.0" } +stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.24.0" } diff --git a/rust/operator-binary/src/discovery.rs b/rust/operator-binary/src/discovery.rs index adba475f..432b7002 100644 --- a/rust/operator-binary/src/discovery.rs +++ b/rust/operator-binary/src/discovery.rs @@ -13,6 +13,7 @@ use std::collections::HashMap; pub fn build_discovery_configmap( hbase: &HbaseCluster, zookeeper_connect_string: &str, + managed_by: &str, ) -> OperatorResult { let hbase_site_data: HashMap> = [( HBASE_ZOOKEEPER_QUORUM.to_string(), @@ -29,6 +30,7 @@ pub fn build_discovery_configmap( hbase, APP_NAME, hbase_version(hbase).map_err(|_| Error::MissingObjectKey { key: "version" })?, + managed_by, &HbaseRole::RegionServer.to_string(), "discovery", ) diff --git a/rust/operator-binary/src/hbase_controller.rs b/rust/operator-binary/src/hbase_controller.rs index ceef3f2a..5ee58a56 100644 --- a/rust/operator-binary/src/hbase_controller.rs +++ b/rust/operator-binary/src/hbase_controller.rs @@ -8,6 +8,7 @@ use stackable_hbase_crd::{ }; use stackable_operator::{ builder::{ConfigMapBuilder, ContainerBuilder, ObjectMetaBuilder, PodBuilder}, + cluster_resources::ClusterResources, k8s_openapi::{ api::{ apps::v1::{StatefulSet, StatefulSetSpec}, @@ -18,7 +19,7 @@ use stackable_operator::{ }, apimachinery::pkg::{apis::meta::v1::LabelSelector, util::intstr::IntOrString}, }, - kube::{runtime::controller::Action, ResourceExt}, + kube::{runtime::controller::Action, Resource, ResourceExt}, labels::{role_group_selector_labels, role_selector_labels}, logging::controller::ReconcilerError, product_config::{types::PropertyNameKind, writer, ProductConfigManager}, @@ -32,7 +33,7 @@ use std::{ }; use strum::{EnumDiscriminants, IntoStaticStr}; -const FIELD_MANAGER_SCOPE: &str = "hbasecluster"; +const CONTROLLER_NAME: &str = "hbase-operator"; const CONFIG_DIR_NAME: &str = "/stackable/conf"; const HDFS_DISCOVERY_TMP_DIR: &str = "/stackable/tmp/hdfs"; @@ -57,6 +58,14 @@ pub enum Error { NoRegionServerRole, #[snafu(display("failed to calculate global service name"))] GlobalServiceNameNotFound, + #[snafu(display("failed to create cluster resources"))] + CreateClusterResources { + source: stackable_operator::error::Error, + }, + #[snafu(display("failed to delete orphaned resources"))] + DeleteOrphanedResources { + source: stackable_operator::error::Error, + }, #[snafu(display("failed to apply global Service"))] ApplyRoleService { source: stackable_operator::error::Error, @@ -155,21 +164,21 @@ pub async fn reconcile_hbase(hbase: Arc, ctx: Arc) -> Result< ) .context(InvalidProductConfigSnafu)?; + let mut cluster_resources = + ClusterResources::new(APP_NAME, CONTROLLER_NAME, &hbase.object_ref(&())) + .context(CreateClusterResourcesSnafu)?; + let region_server_role_service = build_region_server_role_service(&hbase)?; - client - .apply_patch( - FIELD_MANAGER_SCOPE, - ®ion_server_role_service, - ®ion_server_role_service, - ) + cluster_resources + .add(client, ®ion_server_role_service) .await .context(ApplyRoleServiceSnafu)?; // discovery config map - let discovery_cm = build_discovery_configmap(&hbase, &zk_connect_string) + let discovery_cm = build_discovery_configmap(&hbase, &zk_connect_string, CONTROLLER_NAME) .context(BuildDiscoveryConfigMapSnafu)?; - client - .apply_patch(FIELD_MANAGER_SCOPE, &discovery_cm, &discovery_cm) + cluster_resources + .add(client, &discovery_cm) .await .context(ApplyDiscoveryConfigMapSnafu)?; @@ -184,20 +193,20 @@ pub async fn reconcile_hbase(hbase: Arc, ctx: Arc) -> Result< &zk_connect_string, )?; let rg_statefulset = build_rolegroup_statefulset(&hbase, &rolegroup, rolegroup_config)?; - client - .apply_patch(FIELD_MANAGER_SCOPE, &rg_service, &rg_service) + cluster_resources + .add(client, &rg_service) .await .with_context(|_| ApplyRoleGroupServiceSnafu { rolegroup: rolegroup.clone(), })?; - client - .apply_patch(FIELD_MANAGER_SCOPE, &rg_configmap, &rg_configmap) + cluster_resources + .add(client, &rg_configmap) .await .with_context(|_| ApplyRoleGroupConfigSnafu { rolegroup: rolegroup.clone(), })?; - client - .apply_patch(FIELD_MANAGER_SCOPE, &rg_statefulset, &rg_statefulset) + cluster_resources + .add(client, &rg_statefulset) .await .with_context(|_| ApplyRoleGroupStatefulSetSnafu { rolegroup: rolegroup.clone(), @@ -205,6 +214,11 @@ pub async fn reconcile_hbase(hbase: Arc, ctx: Arc) -> Result< } } + cluster_resources + .delete_orphaned_resources(client) + .await + .context(DeleteOrphanedResourcesSnafu)?; + Ok(Action::await_change()) } @@ -233,7 +247,14 @@ pub fn build_region_server_role_service(hbase: &HbaseCluster) -> Result .name(&role_svc_name) .ownerreference_from_resource(hbase, None, Some(true)) .context(ObjectMissingMetadataForOwnerRefSnafu)? - .with_recommended_labels(hbase, APP_NAME, hbase_version(hbase)?, &role_name, "global") + .with_recommended_labels( + hbase, + APP_NAME, + hbase_version(hbase)?, + CONTROLLER_NAME, + &role_name, + "global", + ) .build(), spec: Some(ServiceSpec { ports: Some(ports), @@ -285,6 +306,7 @@ fn build_rolegroup_config_map( hbase, APP_NAME, hbase_version(hbase)?, + CONTROLLER_NAME, &rolegroup.role, &rolegroup.role_group, ) @@ -332,6 +354,7 @@ fn build_rolegroup_service( hbase, APP_NAME, hbase_version(hbase)?, + CONTROLLER_NAME, &rolegroup.role, &rolegroup.role_group, ) @@ -423,6 +446,7 @@ fn build_rolegroup_statefulset( }; let container = ContainerBuilder::new("hbase") + .expect("ContainerBuilder not created") .image(image) .command(vec![ "/bin/bash".to_string(), @@ -471,6 +495,7 @@ fn build_rolegroup_statefulset( hbase, APP_NAME, hbase_version, + CONTROLLER_NAME, &rolegroup_ref.role, &rolegroup_ref.role_group, ) @@ -494,6 +519,7 @@ fn build_rolegroup_statefulset( hbase, APP_NAME, hbase_version, + CONTROLLER_NAME, &rolegroup_ref.role, &rolegroup_ref.role_group, ) diff --git a/tests/templates/kuttl/orphaned_resources/00-assert.yaml b/tests/templates/kuttl/orphaned_resources/00-assert.yaml new file mode 100644 index 00000000..a1e216b4 --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/00-assert.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +metadata: + name: install-zk +timeout: 600 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-zk-server-default +status: + readyReplicas: 1 + replicas: 1 diff --git a/tests/templates/kuttl/orphaned_resources/00-install-zookeeper.yaml.j2 b/tests/templates/kuttl/orphaned_resources/00-install-zookeeper.yaml.j2 new file mode 100644 index 00000000..0626058f --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/00-install-zookeeper.yaml.j2 @@ -0,0 +1,19 @@ +--- +apiVersion: zookeeper.stackable.tech/v1alpha1 +kind: ZookeeperCluster +metadata: + name: test-zk +spec: + servers: + roleGroups: + default: + replicas: 1 + version: {{ test_scenario['values']['zookeeper-latest'] }} +--- +apiVersion: zookeeper.stackable.tech/v1alpha1 +kind: ZookeeperZnode +metadata: + name: test-znode +spec: + clusterRef: + name: test-zk diff --git a/tests/templates/kuttl/orphaned_resources/01-assert.yaml b/tests/templates/kuttl/orphaned_resources/01-assert.yaml new file mode 100644 index 00000000..8800b24d --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/01-assert.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +metadata: + name: install-hdfs +timeout: 600 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-hdfs-namenode-default +status: + readyReplicas: 2 + replicas: 2 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-hdfs-journalnode-default +status: + readyReplicas: 1 + replicas: 1 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-hdfs-datanode-default +status: + readyReplicas: 1 + replicas: 1 diff --git a/tests/templates/kuttl/orphaned_resources/01-install-hdfs.yaml.j2 b/tests/templates/kuttl/orphaned_resources/01-install-hdfs.yaml.j2 new file mode 100644 index 00000000..c130c457 --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/01-install-hdfs.yaml.j2 @@ -0,0 +1,21 @@ +--- +apiVersion: hdfs.stackable.tech/v1alpha1 +kind: HdfsCluster +metadata: + name: test-hdfs +spec: + version: {{ test_scenario['values']['hdfs-latest'] }} + zookeeperConfigMapName: test-znode + log4j: "" + nameNodes: + roleGroups: + default: + replicas: 2 + dataNodes: + roleGroups: + default: + replicas: 1 + journalNodes: + roleGroups: + default: + replicas: 1 diff --git a/tests/templates/kuttl/orphaned_resources/02-assert.yaml b/tests/templates/kuttl/orphaned_resources/02-assert.yaml new file mode 100644 index 00000000..c50ea9af --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/02-assert.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +metadata: + name: install-hbase +timeout: 600 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-hbase-master-default +status: + readyReplicas: 1 + replicas: 1 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-hbase-regionserver-default +status: + readyReplicas: 1 + replicas: 1 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-hbase-restserver-default +status: + readyReplicas: 1 + replicas: 1 diff --git a/tests/templates/kuttl/orphaned_resources/02-install-hbase.yaml.j2 b/tests/templates/kuttl/orphaned_resources/02-install-hbase.yaml.j2 new file mode 100644 index 00000000..4ac58b8c --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/02-install-hbase.yaml.j2 @@ -0,0 +1,23 @@ +--- +apiVersion: hbase.stackable.tech/v1alpha1 +kind: HbaseCluster +metadata: + name: test-hbase +spec: + version: {{ test_scenario['values']['hbase-latest'] }} + hdfsConfigMapName: test-hdfs-namenode-default + zookeeperConfigMapName: test-znode + config: + hbaseRootdir: /hbase + masters: + roleGroups: + default: + replicas: 1 + regionServers: + roleGroups: + default: + replicas: 1 + restServers: + roleGroups: + default: + replicas: 1 diff --git a/tests/templates/kuttl/orphaned_resources/03-assert.yaml b/tests/templates/kuttl/orphaned_resources/03-assert.yaml new file mode 100644 index 00000000..69833745 --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/03-assert.yaml @@ -0,0 +1,6 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +metadata: + name: remove-restserver +timeout: 600 diff --git a/tests/templates/kuttl/orphaned_resources/03-errors.yaml b/tests/templates/kuttl/orphaned_resources/03-errors.yaml new file mode 100644 index 00000000..ece984dc --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/03-errors.yaml @@ -0,0 +1,20 @@ +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-hbase-restserver-default +--- +apiVersion: v1 +kind: Pod +metadata: + name: test-hbase-restserver-default-0 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: test-hbase-restserver-default +--- +apiVersion: v1 +kind: Service +metadata: + name: test-hbase-restserver-default diff --git a/tests/templates/kuttl/orphaned_resources/03-remove-restserver.yaml b/tests/templates/kuttl/orphaned_resources/03-remove-restserver.yaml new file mode 100644 index 00000000..062c532b --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/03-remove-restserver.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: hbase.stackable.tech/v1alpha1 +kind: HbaseCluster +metadata: + name: test-hbase +spec: + restServers: null diff --git a/tests/templates/kuttl/orphaned_resources/04-assert.yaml b/tests/templates/kuttl/orphaned_resources/04-assert.yaml new file mode 100644 index 00000000..bfeeddc9 --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/04-assert.yaml @@ -0,0 +1,26 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +metadata: + name: change-regionserver-rolegroup +timeout: 600 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-hbase-regionserver-newrolegroup +--- +apiVersion: v1 +kind: Pod +metadata: + name: test-hbase-regionserver-newrolegroup-0 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: test-hbase-regionserver-newrolegroup +--- +apiVersion: v1 +kind: Service +metadata: + name: test-hbase-regionserver-newrolegroup diff --git a/tests/templates/kuttl/orphaned_resources/04-change-regionserver-rolegroup.yaml b/tests/templates/kuttl/orphaned_resources/04-change-regionserver-rolegroup.yaml new file mode 100644 index 00000000..aaed32c8 --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/04-change-regionserver-rolegroup.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: hbase.stackable.tech/v1alpha1 +kind: HbaseCluster +metadata: + name: test-hbase +spec: + regionServers: + roleGroups: + default: null + newrolegroup: + replicas: 1 diff --git a/tests/templates/kuttl/orphaned_resources/04-errors.yaml b/tests/templates/kuttl/orphaned_resources/04-errors.yaml new file mode 100644 index 00000000..645452c0 --- /dev/null +++ b/tests/templates/kuttl/orphaned_resources/04-errors.yaml @@ -0,0 +1,20 @@ +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: test-hbase-regionserver-default +--- +apiVersion: v1 +kind: Pod +metadata: + name: test-hbase-regionserver-default-0 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: test-hbase-regionserver-default +--- +apiVersion: v1 +kind: Service +metadata: + name: test-hbase-regionserver-default diff --git a/tests/test-definition.yaml b/tests/test-definition.yaml index ceaf8f37..11a39051 100644 --- a/tests/test-definition.yaml +++ b/tests/test-definition.yaml @@ -1,23 +1,37 @@ --- dimensions: - - name: hdfs - values: - - 3.2.2-stackable0.5.0 - - 3.3.3-stackable0.1.0 - name: hbase values: - 2.4.8-stackable0.6.0 - 2.4.9-stackable0.6.0 - 2.4.11-stackable0.6.0 - 2.4.12-stackable0.1.0 + - name: hbase-latest + values: + - 2.4.12-stackable0.1.0 + - name: hdfs + values: + - 3.2.2-stackable0.5.0 + - 3.3.3-stackable0.1.0 + - name: hdfs-latest + values: + - 3.3.3-stackable0.1.0 - name: zookeeper values: - 3.6.3-stackable0.7.1 - 3.7.0-stackable0.7.1 - 3.8.0-stackable0.7.1 + - name: zookeeper-latest + values: + - 3.8.0-stackable0.7.1 tests: - name: smoke dimensions: - hbase - - zookeeper - hdfs + - zookeeper + - name: orphaned_resources + dimensions: + - hbase-latest + - hdfs-latest + - zookeeper-latest