Skip to content

Commit

Permalink
Remove prometheus-exporter resources from the cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
nhudson committed Dec 15, 2023
1 parent b2c262d commit 59e5087
Show file tree
Hide file tree
Showing 14 changed files with 750 additions and 478 deletions.
4 changes: 4 additions & 0 deletions tembo-operator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tembo-operator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "controller"
description = "Tembo Operator for Postgres"
version = "0.27.1"
version = "0.28.0"
edition = "2021"
default-run = "controller"
license = "Apache-2.0"
Expand Down
10 changes: 4 additions & 6 deletions tembo-operator/src/apis/coredb_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,8 @@ pub struct CoreDBSpec {
#[serde(default = "defaults::default_pkglibdir_storage")]
pub pkglibdirStorage: Quantity,

/// Enable the use of the Postgres Exporter deployment for metrics collection
///
/// **Default**: true.
/// **DEPRECATED** Enable the use of the Postgres Exporter deployment for metrics collection
/// This is no longer used and will be removed in a future release.
#[serde(default = "defaults::default_postgres_exporter_enabled")]
pub postgresExporterEnabled: bool,

Expand All @@ -379,9 +378,8 @@ pub struct CoreDBSpec {
#[serde(default = "defaults::default_image")]
pub image: String,

/// The postgres-exporter image you want to use for the postgres-exporter deployment.
///
/// **Default**: quay.io/prometheuscommunity/postgres-exporter:v0.12.0
/// **DEPRECATED** The postgres-exporter image you want to use for the postgres-exporter deployment.
/// This is no longer used and will be removed in a future release.
#[serde(default = "defaults::default_postgres_exporter_image")]
pub postgresExporterImage: String,

Expand Down
15 changes: 15 additions & 0 deletions tembo-operator/src/cloudnativepg/cnpg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::{
defaults::{default_image, default_llm_image},
errors::ValueError,
is_postgres_ready, patch_cdb_status_merge,
postgres_exporter::EXPORTER_CONFIGMAP_PREFIX,
psql::PsqlOutput,
trunk::extensions_that_require_load,
Context, RESTARTED_AT,
Expand Down Expand Up @@ -601,6 +602,20 @@ pub fn cnpg_cluster_from_cdb(
})
}

if cdb
.spec
.metrics
.as_ref()
.and_then(|m| m.queries.as_ref())
.is_some()
{
let configmap = format!("{}{}", EXPORTER_CONFIGMAP_PREFIX, cdb.name_any());
metrics.push(ClusterMonitoringCustomQueriesConfigMap {
key: "tembo-queries".to_string(),
name: configmap,
})
}

Cluster {
metadata: ObjectMeta {
name: Some(name.clone()),
Expand Down
3 changes: 3 additions & 0 deletions tembo-operator/src/configmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ pub async fn apply_configmap(
cm_name: &str,
data: BTreeMap<String, String>,
) -> Result<(), Error> {
let mut labels: BTreeMap<String, String> = BTreeMap::new();
labels.insert("cnpg.io/reload".to_owned(), "true".to_owned());
let cm_api: Api<ConfigMap> = Api::namespaced(client, namespace);
let cm = ConfigMap {
metadata: ObjectMeta {
name: Some(cm_name.to_string()),
labels: Some(labels),
..Default::default()
},
data: Some(data),
Expand Down
19 changes: 3 additions & 16 deletions tembo-operator/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ use crate::{
cnpg::{cnpg_cluster_from_cdb, reconcile_cnpg, reconcile_cnpg_scheduled_backup, reconcile_pooler},
},
config::Config,
deployment_postgres_exporter::reconcile_prometheus_exporter_deployment,
exec::{ExecCommand, ExecOutput},
extensions::database_queries::is_not_restarting,
heartbeat::reconcile_heartbeat,
ingress::reconcile_postgres_ing_route_tcp,
postgres_certificates::reconcile_certificates,
psql::{PsqlCommand, PsqlOutput},
secret::{reconcile_postgres_role_secret, reconcile_secret},
service::reconcile_prometheus_exporter_service,
telemetry, Error, Metrics, Result,
};
use k8s_openapi::{
Expand Down Expand Up @@ -270,22 +268,11 @@ impl CoreDB {
reconcile_cnpg_scheduled_backup(self, ctx.clone()).await?;
}

if self.spec.postgresExporterEnabled {
debug!("Reconciling prometheus exporter deployment");
reconcile_prometheus_exporter_deployment(self, ctx.clone())
.await
.map_err(|e| {
error!("Error reconciling prometheus exporter deployment: {:?}", e);
Action::requeue(Duration::from_secs(300))
})?;
};

// reconcile service
debug!("Reconciling prometheus exporter service");
reconcile_prometheus_exporter_service(self, ctx.clone())
// Cleanup old Postgres Exporter Deployments, Service, ServiceAccount, Role and RoleBinding
crate::deployment_postgres_exporter::cleanup_postgres_exporter(self, ctx.clone())
.await
.map_err(|e| {
error!("Error reconciling service: {:?}", e);
error!("Error reconciling prometheus exporter deployment: {:?}", e);
Action::requeue(Duration::from_secs(300))
})?;

Expand Down
2 changes: 1 addition & 1 deletion tembo-operator/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn default_resources() -> ResourceRequirements {
}

pub fn default_postgres_exporter_enabled() -> bool {
true
false
}

pub fn default_uid() -> i32 {
Expand Down
Loading

0 comments on commit 59e5087

Please sign in to comment.