Skip to content

Commit

Permalink
Better debug messages for reconcile_gordo (#218)
Browse files Browse the repository at this point in the history
* Better debug messages for reconcile_gordo

* Additional log messages
  • Loading branch information
koropets authored Mar 27, 2022
1 parent 8c0b0ca commit fa51304
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/crd/gordo/gordo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use kube::{
use k8s_openapi::{
api::batch::v1::Job,
};
use log::{error, info};
use log::{error, info, debug};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::collections::HashMap;
Expand Down Expand Up @@ -97,6 +97,7 @@ pub async fn start_gordo_deploy_job(
config: &Config,
) -> () {
// Job manifest for launching this gordo config into a workflow
debug!("Start gordo deploy Job");
let revision = get_revision();
let gordo_name = gordo.metadata.name.to_owned().unwrap().to_owned();
let created_job = create_deploy_job(&gordo, &config);
Expand Down
4 changes: 3 additions & 1 deletion src/deploy_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta as OpenApiObjectM
use kube::api::ObjectMeta;
use std::collections::BTreeMap;
use std::iter::FromIterator;
use log::{warn};
use log::{warn, info};

// TODO builder

Expand Down Expand Up @@ -121,6 +121,8 @@ pub fn create_deploy_job(gordo: &Gordo, config: &Config) -> Option<Job> {
);
let job_name = deploy_job_name("gordo-dpl-", &job_name_suffix);

info!("Creating job \"{}\" for Gordo \"{}\"", job_name, name);

let owner_references_result = object_to_owner_reference::<Gordo>(
gordo.metadata.clone()
);
Expand Down
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ struct Data {
config: Config,
}


#[warn(unused_variables)]
async fn reconcile_gordo(gordo: Gordo, ctx: Context<Data>) -> Result<ReconcilerAction, Error> {
debug!("reconcile gordo {:?}", gordo);
let namespace = gordo
.metadata
.namespace
Expand All @@ -140,7 +140,7 @@ async fn reconcile_gordo(gordo: Gordo, ctx: Context<Data>) -> Result<ReconcilerA
let config = ctx.get_ref().config.clone();

let gordo_api: Api<Gordo> = Api::namespaced(client.clone(), namespace);
info!("gordo: {:?}, namespace: {:?}", gordo_name, namespace);
info!("Reconcile gordo: {:?}, namespace: {:?}", gordo_name, namespace);
let model_labels = format!("applications.gordo.equinor.com/project-name={}", gordo_name);
let lp = ListParams::default().labels(&model_labels);

Expand All @@ -149,18 +149,21 @@ async fn reconcile_gordo(gordo: Gordo, ctx: Context<Data>) -> Result<ReconcilerA
let model_api: Api<Model> = Api::namespaced(client.clone(), namespace);
let models_obj_list = model_api.list(&lp).await.map_err(Error::KubeError)?;
let models: Vec<_> = models_obj_list.into_iter().collect();
debug!("models {:?}", models);
let names = utils::resource_names(&models);
debug!("Reconcile {} {}: {}", models.len(), utils::plural_str(models.len(), "models"), names);
monitor_models(&model_api, &gordo_api, &models, &vec![gordo.clone()]).await;

let workflow_api: Api<Workflow> = Api::namespaced(client.clone(), namespace);
let workflows_obj_list = workflow_api.list(&lp).await.map_err(Error::KubeError)?;
let workflows: Vec<_> = workflows_obj_list.into_iter().collect();
debug!("workflows {:?}", workflows);
let names = utils::resource_names(&workflows);
debug!("Reconcile {} {}: {}", workflows.len(), utils::plural_str(workflows.len(), "workflows"), names);

let pod_api: Api<Pod> = Api::namespaced(client.clone(), namespace);
let pod_obj_list = pod_api.list(&lp).await.map_err(Error::KubeError)?;
let pods: Vec<_> = pod_obj_list.into_iter().collect();
debug!("pods {:?}", pods);
let names = utils::resource_names(&pods);
debug!("Reconcile {} {}: {}", pods.len(), utils::plural_str(pods.len(), "pods"), names);

monitor_wf(&model_api, &workflows, &models, &pods).await;
monitor_pods(&model_api, &models, &pods).await;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn main() -> Result<(), errors::Error> {
info!("actix exited");
}
_ = controller => {
warn!("controller drained");
warn!("gordo controller drained");
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ pub fn object_to_owner_reference<K: Resource<DynamicType = ()>>(
})
}

pub fn resource_names<T: Resource<DynamicType=()>>(resource: &Vec<T>) -> String {
resource.iter()
.map(|resource| {
let name = resource.meta().name.as_ref();
format!("\"{}\"", name.unwrap_or(&"".to_string()))
})
.collect()
}

pub fn plural_str(length: usize, word: &str) -> &str {
if length == 1 {
word.trim_end_matches('s')
} else {
word
}
}

pub fn env_var(name: &str, value: &str) -> EnvVar {
EnvVar {
name: name.to_string(),
Expand Down

0 comments on commit fa51304

Please sign in to comment.