-
-
Notifications
You must be signed in to change notification settings - Fork 4
[Merged by Bors] - Orphaned resources handling #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2a37410
494f8a4
b27a631
d4e8c0a
2396dba
2315e1f
8efd97b
a007b56
6d81268
5fb1fbc
30f1508
90ae417
f110337
40f4aee
1634499
0e834ef
2c4a099
411975d
3762c53
0b18a87
a8f50f9
ccbca8a
258ad6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the same. The field manager needs to identify the controller within the operator.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "hbase-operator" is the controller name in this case. As there is only one controller in this operator, it should not pose a problem. But if you see a problem then please create a ticket. I agree that this naming is a bit confusing. So we could provide both, operator name and controller name, to ClusterResources.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| 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<HbaseCluster>, ctx: Arc<Ctx>) -> 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,27 +193,32 @@ pub async fn reconcile_hbase(hbase: Arc<HbaseCluster>, ctx: Arc<Ctx>) -> 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(), | ||
| })?; | ||
| } | ||
| } | ||
|
|
||
| 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<Service> | |
| .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") | ||
sbernauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .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, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
Uh oh!
There was an error while loading. Please reload this page.