Skip to content

Commit

Permalink
service_account for deploy job (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
koropets authored May 9, 2022
1 parent 055907b commit 83ff88c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/deploy_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use k8s_openapi::api::core::v1::{SecurityContext, Volume, VolumeMount, EmptyDirV
use k8s_openapi::apimachinery::pkg::api::resource::Quantity;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta as OpenApiObjectMeta;
use kube::api::ObjectMeta;
use std::collections::BTreeMap;
use std::collections::{BTreeMap, HashMap};
use std::iter::FromIterator;
use log::{warn, info};

Expand Down Expand Up @@ -100,6 +100,7 @@ fn deploy_pod_spec(containers: Vec<Container>, config: &Config) -> PodSpec {
}
]);
}
pod_spec.service_account = config.argo_service_account.as_ref().map(|v| { v.to_string() });
pod_spec
}

Expand Down Expand Up @@ -181,16 +182,28 @@ pub fn create_deploy_job(gordo: &Gordo, config: &Config) -> Option<Job> {
env_var("DEBUG_SHOW_WORKFLOW", debug_show_workflow),
];

let mut additional_environment: HashMap<String, String> = HashMap::new();

// As long as we calling env_config.validate() method in the main function
// there should not be circumstances from which panic should occur here
let default_deploy_environment = &config.default_deploy_environment;

if let Some(deploy_environment) = default_deploy_environment {
for (key, value) in deploy_environment {
environment.push(env_var(key, value));
}
additional_environment.extend(
deploy_environment.
into_iter().
map(|(k, v)| (k.to_string(), v.to_string()))
);
}

if let Some(argo_service_account) = &config.argo_service_account {
additional_environment.insert("ARGO_SERVICE_ACCOUNT".into(), argo_service_account.into());
}

additional_environment.iter().for_each(|(key, value)| {
environment.push(env_var(key, value));
});

let resources_labels = &config.resources_labels;

// push in any that were supplied by the Gordo.spec.gordo_environment mapping
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct GordoEnvironmentConfig {
pub resources_labels: String,
#[serde(default="default_deploy_ro_fs")]
pub deploy_job_ro_fs: bool,
pub argo_service_account: Option<String>
}

#[derive(Debug, Clone)]
Expand All @@ -73,6 +74,7 @@ pub struct Config {
pub default_deploy_environment: Option<HashMap<String, String>>,
pub resources_labels: Option<BTreeMap<String, String>>,
pub deploy_job_ro_fs: bool,
pub argo_service_account: Option<String>
}

impl Config {
Expand All @@ -87,6 +89,7 @@ impl Config {
server_host: env_config.server_host.clone(),
docker_registry: env_config.docker_registry.clone(),
deploy_job_ro_fs: env_config.deploy_job_ro_fs,
argo_service_account: env_config.argo_service_account,
default_deploy_environment,
resources_labels,
})
Expand Down Expand Up @@ -125,6 +128,7 @@ impl Default for GordoEnvironmentConfig {
default_deploy_environment: "".to_owned(),
resources_labels: "".to_owned(),
deploy_job_ro_fs: false,
argo_service_account: None,
}
}
}
Expand Down

0 comments on commit 83ff88c

Please sign in to comment.