Skip to content
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

Add configuration object #379

Merged
merged 22 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
96a6508
Add config to state object
christoph-hamm Sep 9, 2024
42e8679
Fix problem with tests not building for common
christoph-hamm Sep 12, 2024
da99bed
Improve YAML serialization of ConfigItem
christoph-hamm Sep 12, 2024
e9b4217
Add internal config object
christoph-hamm Sep 13, 2024
43bf139
Fix unit tests
christoph-hamm Sep 17, 2024
848c0d6
Fix clippy error about unequal enum sizes
christoph-hamm Sep 18, 2024
7c7ca19
Remove unused import
christoph-hamm Sep 18, 2024
8309e0f
Interpret None fields as default instead of failing
christoph-hamm Sep 18, 2024
a954f8e
Add configs to filtered state used in the ank CLI
christoph-hamm Sep 25, 2024
09c3804
Also update server state if non workload has been changed
christoph-hamm Sep 26, 2024
5a41e83
Merge branch 'main' into 267_Add_configuration_object
christoph-hamm Sep 26, 2024
f599aec
Add missing fields in tests
christoph-hamm Sep 26, 2024
7c391e1
Remove commented out code
christoph-hamm Sep 26, 2024
9610370
Fix year in copyright header of new files
christoph-hamm Sep 26, 2024
29a45e1
Apply suggestions from code review
christoph-hamm Sep 30, 2024
989d3f4
Remove commented out code
christoph-hamm Sep 30, 2024
73a9ca2
Add missing use statement
christoph-hamm Sep 30, 2024
a81ad0b
Allow missing workloads in UpdateStateRequeset
christoph-hamm Sep 30, 2024
8440e58
Fix configs in sample objects
christoph-hamm Oct 1, 2024
592efe2
Merge branch 'main' into 267_Add_configuration_object
christoph-hamm Oct 1, 2024
e2b632f
Add missing config
christoph-hamm Oct 1, 2024
9e4afbf
Fix filtering redundant mask
inf17101 Oct 1, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions agent/src/runtime_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,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 {
Expand Down
62 changes: 59 additions & 3 deletions ank/src/cli_commands/server_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_1".into()),
("ref2".into(), "config_2".into()),
]
.into(),
}),
},
)]),
),
Expand All @@ -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_1".into()),
("ref2".into(), "config_2".into()),
]
.into()
})
},
)])
.into())
Expand Down Expand Up @@ -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_1".into()),
("ref2".into(), "config_2".into()),
]
.into(),
}),
},
)]),
)),
Expand Down Expand Up @@ -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_1".into()),
("ref2".into(), "config_2".into()),
]
.into(),
}),
},
)]),
),
Expand All @@ -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_1".into()),
("ref2".into(), "config_2".into()),
]
.into()
})
},
)])
.into())
Expand Down Expand Up @@ -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_1".into()),
("ref2".into(), "config_2".into()),
]
.into(),
}),
},
)]),
),
Expand All @@ -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_1".into()),
("ref2".into(), "config_2".into()),
]
.into()
})
},
)])
.into())
Expand Down Expand Up @@ -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_1".into()),
("ref2".into(), "config_2".into()),
]
.into(),
}),
},
)]),
)),
Expand Down
1 change: 1 addition & 0 deletions ank/src/cli_commands/set_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ mod tests {
desired_state: State {
workloads: HashMap::from([("nginx".to_string(), workload_spec)]),
api_version: "api_version".into(),
..Default::default()
},
..Default::default()
};
Expand Down
27 changes: 25 additions & 2 deletions ank/src/filtered_complete_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ use std::collections::HashMap;
use api::ank_base;
use common::{
helpers::serialize_to_ordered_map,
objects::{AddCondition, ControlInterfaceAccess, RestartPolicy, Tag, WorkloadStatesMap},
objects::{
AddCondition, ConfigItem, ControlInterfaceAccess, RestartPolicy, Tag, WorkloadStatesMap,
},
};
use serde::{Deserialize, Serialize, Serializer};

use crate::output_and_error;
use crate::{output_and_error, output_warn};

pub fn serialize_option_to_ordered_map<S, T: Serialize>(
value: &Option<HashMap<String, T>>,
Expand Down Expand Up @@ -59,6 +61,9 @@ pub struct FilteredState {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, serialize_with = "serialize_option_to_ordered_map")]
pub workloads: Option<HashMap<String, FilteredWorkloadSpec>>,
#[serde(serialize_with = "serialize_option_to_ordered_map")]
#[serde(skip_serializing_if = "Option::is_none")]
pub configs: Option<HashMap<String, ConfigItem>>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -91,6 +96,9 @@ pub struct FilteredWorkloadSpec {
pub runtime_config: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub control_interface_access: Option<ControlInterfaceAccess>,
#[serde(serialize_with = "serialize_option_to_ordered_map")]
#[serde(skip_serializing_if = "Option::is_none")]
pub configs: Option<HashMap<String, String>>,
}

impl From<ank_base::CompleteState> for FilteredCompleteState {
Expand All @@ -113,6 +121,20 @@ impl From<ank_base::State> for FilteredState {
.map(|(k, v)| (k, v.into()))
.collect()
}),
configs: value.configs.map(|x| {
x.configs
.into_iter()
.filter_map(|(key, value)| -> Option<(String, ConfigItem)> {
match value.try_into() {
Ok(value) => Some((key, value)),
Err(err) => {
output_warn!("Config item could not be converted: {}", err);
None
}
}
})
.collect()
}),
}
}
}
Expand Down Expand Up @@ -149,6 +171,7 @@ impl From<ank_base::Workload> for FilteredWorkloadSpec {
.map(|x| x.try_into().unwrap_or_else(|error| {
output_and_error!("Could not convert the ControlInterfaceAccess.\nError: '{error}'. Check the Ankaios component compatibility.")
})),
configs: value.configs.map(|x| x.configs)
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure()
.build_server(true)
.boxed("Request.RequestContent.updateStateRequest")
.type_attribute(".", "#[derive(serde::Deserialize, serde::Serialize)]")
.type_attribute(".", "#[serde(rename_all = \"camelCase\")]")
.type_attribute(
"ank_base.ConfigItem",
"#[serde(into = \"serde_yaml::Value\")]",
)
.type_attribute(
"ank_base.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(
Expand All @@ -28,6 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.field_attribute("ExecutionsStatesForId.idStateMap", "#[serde(flatten)]")
.field_attribute("WorkloadMap.workloads", "#[serde(flatten)]")
.field_attribute("AgentMap.agents", "#[serde(flatten)]")
.field_attribute("ConfigMap.configs", "#[serde(flatten)]")
.field_attribute(
"ControlInterfaceAccess.allowRules",
"#[serde(with = \"serde_yaml::with::singleton_map_recursive\")]",
Expand Down
38 changes: 38 additions & 0 deletions api/proto/ank_base.proto
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ message WorkloadInstanceName {
message State {
string apiVersion = 1; /// The current version of the API.
WorkloadMap workloads = 2; /// A mapping from workload names to workload configurations.
ConfigMap configs = 3; /// Configuration values which can be referenced in workload configurations.
}

/**
Expand All @@ -244,6 +245,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; /// A mapping containing the configurations assigned to the workload.
}

/**
Expand Down Expand Up @@ -319,3 +321,39 @@ enum ReadWriteEnum {
RW_READ_WRITE = 5; // Allow read and write
}

/**
* This is a workaround for proto not supporing optional maps
*/
message ConfigMappings {
map<string, string> configs = 1;
}


/**
* This is a workaround for proto not supporing optional maps
*/
message ConfigMap {
map<string, ConfigItem> configs = 1;
}



/**
* An enum type describing possible configuration objects.
*/
message ConfigItem {
oneof ConfigItem {
string String = 1;
ConfigArray array = 2;
ConfigObject object = 3;
}
}


message ConfigArray {
repeated ConfigItem values = 1;
}

message ConfigObject {
map<string, ConfigItem> fields = 1;
}
Loading