Skip to content

[Merged by Bors] - Delete orphaned resources #310

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ All notable changes to this project will be documented in this file.
### Added

- Added support for LDAP authentication ([#306]).
- Orphaned resources are deleted ([#310]).

### Changed

- `operator-rs` `0.22.0` -> `0.25.0` ([#306]).

[#306]: https://github.com/stackabletech/trino-operator/pull/306
[#310]: https://github.com/stackabletech/trino-operator/pull/310

## [0.7.0] - 2022-09-22

Expand Down
55 changes: 33 additions & 22 deletions rust/operator-binary/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
};
use indoc::formatdoc;
use snafu::{OptionExt, ResultExt, Snafu};
use stackable_operator::commons::tls::{CaCert, Tls, TlsServerVerification, TlsVerification};
use stackable_operator::{
builder::{
ConfigMapBuilder, ContainerBuilder, ObjectMetaBuilder, PodBuilder,
Expand All @@ -31,7 +30,7 @@ use stackable_operator::{
},
kube::{
runtime::{controller::Action, reflector::ObjectRef},
ResourceExt,
Resource, ResourceExt,
},
labels::{role_group_selector_labels, role_selector_labels},
logging::controller::ReconcilerError,
Expand All @@ -43,6 +42,10 @@ use stackable_operator::{
},
role_utils::RoleGroupRef,
};
use stackable_operator::{
cluster_resources::ClusterResources,
commons::tls::{CaCert, Tls, TlsServerVerification, TlsVerification},
};
use stackable_trino_crd::{
authentication,
authentication::TrinoAuthenticationConfig,
Expand Down Expand Up @@ -71,7 +74,6 @@ pub struct Ctx {
pub product_config: ProductConfigManager,
}

pub const FIELD_MANAGER_SCOPE: &str = "trinocluster";
const CONTROLLER_NAME: &str = "trino-operator";

#[derive(Snafu, Debug, EnumDiscriminants)]
Expand All @@ -84,6 +86,14 @@ pub enum Error {
MissingTrinoRole { role: String },
#[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,
Expand Down Expand Up @@ -218,6 +228,10 @@ pub async fn reconcile_trino(trino: Arc<TrinoCluster>, ctx: Arc<Ctx>) -> Result<
let validated_config =
validated_product_config(&trino, &trino_product_version, &ctx.product_config)?;

let mut cluster_resources =
ClusterResources::new(APP_NAME, CONTROLLER_NAME, &trino.object_ref(&()))
.context(CreateClusterResourcesSnafu)?;

let authentication_config = user_authentication(&trino, client).await?;

// Assemble the OPA connection string from the discovery and the given path if provided
Expand All @@ -239,12 +253,8 @@ pub async fn reconcile_trino(trino: Arc<TrinoCluster>, ctx: Arc<Ctx>) -> Result<

let coordinator_role_service = build_coordinator_role_service(&trino)?;

client
.apply_patch(
FIELD_MANAGER_SCOPE,
&coordinator_role_service,
&coordinator_role_service,
)
cluster_resources
.add(client, &coordinator_role_service)
.await
.context(ApplyRoleServiceSnafu)?;

Expand Down Expand Up @@ -281,40 +291,41 @@ pub async fn reconcile_trino(trino: Arc<TrinoCluster>, ctx: Arc<Ctx>) -> Result<
&resources,
)?;

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_catalog_configmap,
&rg_catalog_configmap,
)
cluster_resources
.add(client, &rg_catalog_configmap)
.await
.with_context(|_| ApplyRoleGroupConfigSnafu {
rolegroup: rolegroup.clone(),
})?;

client
.apply_patch(FIELD_MANAGER_SCOPE, &rg_stateful_set, &rg_stateful_set)
cluster_resources
.add(client, &rg_stateful_set)
.await
.with_context(|_| ApplyRoleGroupStatefulSetSnafu {
rolegroup: rolegroup.clone(),
})?;
}
}

cluster_resources
.delete_orphaned_resources(client)
.await
.context(DeleteOrphanedResourcesSnafu)?;

Ok(Action::await_change())
}

Expand Down Expand Up @@ -931,7 +942,7 @@ async fn create_shared_internal_secret(trino: &TrinoCluster, client: &Client) ->
.is_none()
{
client
.apply_patch(FIELD_MANAGER_SCOPE, &secret, &secret)
.apply_patch(CONTROLLER_NAME, &secret, &secret)
.await
.context(ApplyInternalSecretSnafu)?;
}
Expand Down
38 changes: 38 additions & 0 deletions tests/templates/kuttl/orphaned-resources/1-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
metadata:
name: install-trino
timeout: 1200
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: trino-coordinator-default
status:
readyReplicas: 1
replicas: 1
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: trino-coordinator-remove
status:
readyReplicas: 1
replicas: 1
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: trino-worker-default
status:
readyReplicas: 1
replicas: 1
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: trino-worker-remove
status:
readyReplicas: 1
replicas: 1
20 changes: 20 additions & 0 deletions tests/templates/kuttl/orphaned-resources/1-install-trino.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
apiVersion: trino.stackable.tech/v1alpha1
kind: TrinoCluster
metadata:
name: trino
spec:
version: {{ test_scenario['values']['trino-latest'] }}
catalogLabelSelector: {}
coordinators:
roleGroups:
default:
replicas: 1
remove:
replicas: 1
workers:
roleGroups:
default:
replicas: 1
remove:
replicas: 1
6 changes: 6 additions & 0 deletions tests/templates/kuttl/orphaned-resources/2-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
metadata:
name: remove-rolegroup
timeout: 600
50 changes: 50 additions & 0 deletions tests/templates/kuttl/orphaned-resources/2-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: trino-coordinator-remove
---
apiVersion: v1
kind: Pod
metadata:
name: trino-coordinator-remove-0
---
apiVersion: v1
kind: Service
metadata:
name: trino-coordinator-remove
---
apiVersion: v1
kind: ConfigMap
metadata:
name: trino-coordinator-remove
---
apiVersion: v1
kind: ConfigMap
metadata:
name: trino-coordinator-remove-catalog
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: trino-worker-remove
---
apiVersion: v1
kind: Pod
metadata:
name: trino-worker-remove-0
---
apiVersion: v1
kind: Service
metadata:
name: trino-worker-remove
---
apiVersion: v1
kind: ConfigMap
metadata:
name: trino-worker-remove
---
apiVersion: v1
kind: ConfigMap
metadata:
name: trino-worker-remove-catalog
12 changes: 12 additions & 0 deletions tests/templates/kuttl/orphaned-resources/2-remove-rolegroup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: trino.stackable.tech/v1alpha1
kind: TrinoCluster
metadata:
name: trino
spec:
coordinators:
roleGroups:
remove: null
workers:
roleGroups:
remove: null
6 changes: 6 additions & 0 deletions tests/test-definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ dimensions:
- 387-stackable0.1.0
- 395-stackable0.1.0
- 396-stackable0.1.0
- name: trino-latest
values:
- 396-stackable0.1.0
- name: hive
values:
- 2.3.9-stackable0.5.0
Expand Down Expand Up @@ -62,3 +65,6 @@ tests:
dimensions:
- trino
- ldap-use-tls
- name: orphaned-resources
dimensions:
- trino-latest