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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
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.path.1".into()),
("ref2".into(), "config.path.2".into()),
Comment on lines +431 to +432
Copy link
Contributor

@inf17101 inf17101 Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like mentioned in the issue #267, we decided to go with just one level of referencing configs in workloads. I will implement in the upcoming changes for workload configs also a naming convention for config key names to prevent messing up the filtering (same regex like for agents and workloads)

Can you change all test data occurrences to a version without the extended path with dots. Just one level of config key reference?

]
.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.path.1".into()),
("ref2".into(), "config.path.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.path.1".into()),
("ref2".into(), "config.path.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.path.1".into()),
("ref2".into(), "config.path.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.path.1".into()),
("ref2".into(), "config.path.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.path.1".into()),
("ref2".into(), "config.path.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.path.1".into()),
("ref2".into(), "config.path.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.path.1".into()),
("ref2".into(), "config.path.2".into()),
]
.into(),
}),
},
)]),
)),
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!("One config item could not be converted: {}", err);
christoph-hamm marked this conversation as resolved.
Show resolved Hide resolved
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
10 changes: 10 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 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; /// Configurations values which can be referenced in workload configurations.
christoph-hamm marked this conversation as resolved.
Show resolved Hide resolved
}

/**
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;
christoph-hamm marked this conversation as resolved.
Show resolved Hide resolved
}

/**
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