diff --git a/agent/src/runtime_manager.rs b/agent/src/runtime_manager.rs index 9465c20bf..3888fb4e9 100644 --- a/agent/src/runtime_manager.rs +++ b/agent/src/runtime_manager.rs @@ -1821,6 +1821,8 @@ mod tests { runtime: Some("runtime1".to_string()), runtime_config: Some("generalOptions: [\"--version\"]\ncommandOptions: [\"--network=host\"]\nimage: alpine:latest\ncommandArgs: [\"bash\"]\n".to_string()), control_interface_access: None, + configs: Some(ank_base::ConfigMappings { + configs: Default::default()}) })]; let mut complete_state = test_utils::generate_test_proto_complete_state(&workloads); complete_state.workload_states = Some(ank_base::WorkloadStatesMap { diff --git a/ank/src/cli_commands/server_connection.rs b/ank/src/cli_commands/server_connection.rs index 6fbc0c7cc..d91e2f49b 100644 --- a/ank/src/cli_commands/server_connection.rs +++ b/ank/src/cli_commands/server_connection.rs @@ -426,6 +426,13 @@ mod tests { restart_policy: Some(ank_base::RestartPolicy::Never as i32), runtime_config: Some(String::default()), control_interface_access: None, + configs: Some(ank_base::ConfigMappings { + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into(), + }), }, )]), ), @@ -449,7 +456,14 @@ mod tests { }), restart_policy: Some(ank_base::RestartPolicy::Never as i32), runtime_config: Some("".to_string()), - control_interface_access: None + control_interface_access: None, + configs: Some(ank_base::ConfigMappings { + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into() + }) }, )]) .into()) @@ -526,6 +540,13 @@ mod tests { restart_policy: Some(ank_base::RestartPolicy::Never as i32), runtime_config: Some("".to_string()), control_interface_access: None, + configs: Some(ank_base::ConfigMappings { + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into(), + }), }, )]), )), @@ -554,6 +575,13 @@ mod tests { restart_policy: Some(ank_base::RestartPolicy::Never as i32), runtime_config: Some("".to_string()), control_interface_access: None, + configs: Some(ank_base::ConfigMappings { + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into(), + }), }, )]), ), @@ -577,7 +605,14 @@ mod tests { }), restart_policy: Some(ank_base::RestartPolicy::Never as i32), runtime_config: Some("".to_string()), - control_interface_access: None + control_interface_access: None, + configs: Some(ank_base::ConfigMappings { + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into() + }) }, )]) .into()) @@ -619,6 +654,13 @@ mod tests { restart_policy: Some(ank_base::RestartPolicy::Never as i32), runtime_config: Some("".to_string()), control_interface_access: None, + configs: Some(ank_base::ConfigMappings { + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into(), + }), }, )]), ), @@ -642,7 +684,14 @@ mod tests { }), restart_policy: Some(ank_base::RestartPolicy::Never as i32), runtime_config: Some("".to_string()), - control_interface_access: None + control_interface_access: None, + configs: Some(ank_base::ConfigMappings { + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into() + }) }, )]) .into()) @@ -789,6 +838,13 @@ mod tests { restart_policy: Some(ank_base::RestartPolicy::Never as i32), runtime_config: Some("".to_string()), control_interface_access: None, + configs: Some(ank_base::ConfigMappings { + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into(), + }), }, )]), )), diff --git a/api/build.rs b/api/build.rs index 244241f36..3247e82c7 100644 --- a/api/build.rs +++ b/api/build.rs @@ -27,6 +27,7 @@ fn main() -> Result<(), Box> { ) // .type_attribute("ConfigItem", "#[serde(try_from = \"serde_yaml::Value\")]") .field_attribute("Workload.tags", "#[serde(flatten)]") + .field_attribute("Workload.configs", "#[serde(flatten)]") .field_attribute("Workload.dependencies", "#[serde(flatten)]") .field_attribute("WorkloadStatesMap.agentStateMap", "#[serde(flatten)]") .field_attribute( diff --git a/api/proto/ank_base.proto b/api/proto/ank_base.proto index 9b05cc097..e51853327 100644 --- a/api/proto/ank_base.proto +++ b/api/proto/ank_base.proto @@ -244,6 +244,7 @@ message Workload { optional string runtime = 5; /// The name of the runtime e.g. podman. optional string runtimeConfig = 6; /// The configuration information specific to the runtime. ControlInterfaceAccess controlInterfaceAccess = 7; + ConfigMappings configs = 8; } /** @@ -319,6 +320,14 @@ enum ReadWriteEnum { RW_READ_WRITE = 5; // Allow read and write } +/** +* This is a workaround for proto not supporing optional maps +*/ +message ConfigMappings { + map configs = 1; +} + + /** * This is a workaround for proto not supporing optional maps */ diff --git a/common/src/commands.rs b/common/src/commands.rs index 34ddff89a..083e93438 100644 --- a/common/src/commands.rs +++ b/common/src/commands.rs @@ -171,8 +171,9 @@ mod tests { mod ank_base { pub use api::ank_base::{ - request::RequestContent, CompleteState, CompleteStateRequest, Dependencies, Request, - RestartPolicy, State, Tag, Tags, UpdateStateRequest, Workload, WorkloadMap, + request::RequestContent, CompleteState, CompleteStateRequest, ConfigMappings, + Dependencies, Request, RestartPolicy, State, Tag, Tags, UpdateStateRequest, Workload, + WorkloadMap, }; } @@ -276,6 +277,13 @@ mod tests { }], }), control_interface_access: Default::default(), + configs: Some(ank_base::ConfigMappings { + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into(), + }), } }; (ankaios) => { @@ -290,6 +298,11 @@ mod tests { runtime: RUNTIME.to_string(), runtime_config: RUNTIME_CONFIG.to_string(), control_interface_access: Default::default(), + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into(), } }; } diff --git a/common/src/objects/stored_workload_spec.rs b/common/src/objects/stored_workload_spec.rs index 0e7a58bc3..25ea42a75 100644 --- a/common/src/objects/stored_workload_spec.rs +++ b/common/src/objects/stored_workload_spec.rs @@ -38,6 +38,8 @@ pub struct StoredWorkloadSpec { pub runtime_config: String, #[serde(default)] pub control_interface_access: ControlInterfaceAccess, + #[serde(default)] + pub configs: HashMap, } impl TryFrom for StoredWorkloadSpec { @@ -67,6 +69,7 @@ impl TryFrom for StoredWorkloadSpec { .control_interface_access .unwrap_or_default() .try_into()?, + configs: value.configs.ok_or("Missing field configs")?.configs, }) } } @@ -89,6 +92,9 @@ impl From for ank_base::Workload { tags: workload.tags.into_iter().map(|x| x.into()).collect(), }), control_interface_access: workload.control_interface_access.into(), + configs: Some(ank_base::ConfigMappings { + configs: workload.configs, + }), } } } @@ -121,6 +127,7 @@ impl From for StoredWorkloadSpec { tags: value.tags, runtime_config: value.runtime_config, control_interface_access: value.control_interface_access, + configs: Default::default(), } } } @@ -153,6 +160,11 @@ pub fn generate_test_stored_workload_spec_with_config( }], runtime_config: runtime_config.into(), control_interface_access: Default::default(), + configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into(), } } diff --git a/common/src/state_manipulation/object.rs b/common/src/state_manipulation/object.rs index ad346e456..3a3eaf0b1 100644 --- a/common/src/state_manipulation/object.rs +++ b/common/src/state_manipulation/object.rs @@ -766,6 +766,12 @@ mod tests { Mapping::default() .entry("allowRules", vec![] as Vec) .entry("denyRules", vec![] as Vec), + ) + .entry( + "configs", + Mapping::default() + .entry("ref1", "config.path.1") + .entry("ref2", "config.path.2") ), ), ) diff --git a/common/src/test_utils.rs b/common/src/test_utils.rs index 286b43c2f..de57a341b 100644 --- a/common/src/test_utils.rs +++ b/common/src/test_utils.rs @@ -14,12 +14,12 @@ use std::collections::HashMap; -use api::ank_base::{self, Dependencies, Tags, WorkloadMap}; +use api::ank_base::{self, ConfigMappings, Dependencies, Tags, WorkloadMap}; use serde::{Serialize, Serializer}; use crate::objects::{ - generate_test_workload_spec_with_param, DeleteCondition, DeletedWorkload, State, - WorkloadInstanceName, WorkloadSpec, + generate_test_runtime_config, generate_test_stored_workload_spec_with_config, DeleteCondition, + DeletedWorkload, State, StoredWorkloadSpec, WorkloadInstanceName, WorkloadSpec, }; const RUNTIME_NAME: &str = "runtime"; @@ -33,7 +33,16 @@ pub fn generate_test_state_from_workloads(workloads: Vec) -> State api_version: API_VERSION.into(), workloads: workloads .into_iter() - .map(|v| (v.instance_name.workload_name().to_owned(), v.into())) + .map(|v| { + let name = v.instance_name.workload_name().to_owned(); + let mut w = StoredWorkloadSpec::from(v); + w.configs = [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ] + .into(); + (name, w) + }) .collect(), configs: HashMap::new(), } @@ -86,20 +95,20 @@ pub fn generate_test_state() -> State { let mut ankaios_workloads = HashMap::new(); - let workload_1 = generate_test_workload_spec_with_param( + let workload_1 = generate_test_stored_workload_spec_with_config( AGENT_NAME.to_owned(), - WORKLOAD_1_NAME.to_owned(), RUNTIME_NAME.to_owned(), + generate_test_runtime_config(), ); - let workload_2 = generate_test_workload_spec_with_param( + let workload_2 = generate_test_stored_workload_spec_with_config( AGENT_NAME.to_owned(), - WORKLOAD_2_NAME.to_owned(), RUNTIME_NAME.to_owned(), + generate_test_runtime_config(), ); - ankaios_workloads.insert(workload_name_1, workload_1.into()); - ankaios_workloads.insert(workload_name_2, workload_2.into()); + ankaios_workloads.insert(workload_name_1, workload_1); + ankaios_workloads.insert(workload_name_2, workload_2); State { api_version: API_VERSION.into(), @@ -161,7 +170,11 @@ pub fn generate_test_proto_workload_with_param( key: "key".into(), value: "value".into(), }]}), - control_interface_access: Default::default() + control_interface_access: Default::default(), + configs: Some(ConfigMappings{configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ].into()}) } } @@ -177,7 +190,11 @@ pub fn generate_test_proto_workload() -> ank_base::Workload { key: "key".into(), value: "value".into(), }]}), - control_interface_access: Default::default() + control_interface_access: Default::default(), + configs: Some(ConfigMappings{configs: [ + ("ref1".into(), "config.path.1".into()), + ("ref2".into(), "config.path.2".into()), + ].into()}) } } diff --git a/server/src/ankaios_server/server_state.rs b/server/src/ankaios_server/server_state.rs index b72498bd0..d75522579 100644 --- a/server/src/ankaios_server/server_state.rs +++ b/server/src/ankaios_server/server_state.rs @@ -455,6 +455,7 @@ mod tests { runtime: None, runtime_config: None, control_interface_access: None, + configs: None, }, ), ( @@ -475,6 +476,7 @@ mod tests { runtime: Some(w1.runtime.clone()), runtime_config: Some(w1.runtime_config.clone()), control_interface_access: w1.control_interface_access.into(), + configs: Some(Default::default()), }, ), ];