Skip to content

Commit

Permalink
agent: convert enum vals to kebab-case in cfg file
Browse files Browse the repository at this point in the history
fixes kata-containers#9810

Add an annotation to the enum values in the agent config that will
deserialize them using a kebab-case conversion, aligning the behaviour
to parsing of params specified via kernel cmdline.

drive-by fix: add config override for guest_component_procs variable

Signed-off-by: Magnus Kulke <magnuskulke@microsoft.com>
  • Loading branch information
mkulke authored and wainersm committed Jun 11, 2024
1 parent 1c8db85 commit d2632ca
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/agent/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const ERR_INVALID_GUEST_COMPONENTS_PROCS_VALUE: &str = "invalid guest components
#[derive(Clone, Copy, Debug, Default, Display, Deserialize, EnumString, PartialEq)]
// Features seem to typically be in kebab-case format, but we only have single words at the moment
#[strum(serialize_all = "kebab-case")]
#[serde(rename_all = "kebab-case")]
pub enum GuestComponentsFeatures {
All,
Attestation,
Expand All @@ -76,6 +77,7 @@ pub enum GuestComponentsFeatures {
#[derive(Clone, Copy, Debug, Default, Display, Deserialize, EnumString, PartialEq)]
/// Attestation-related processes that we want to spawn as children of the agent
#[strum(serialize_all = "kebab-case")]
#[serde(rename_all = "kebab-case")]
pub enum GuestComponentsProcs {
None,
/// ApiServerRest implies ConfidentialDataHub and AttestationAgent
Expand Down Expand Up @@ -224,6 +226,7 @@ impl FromStr for AgentConfig {
agent_config,
guest_components_rest_api
);
config_override!(agent_config_builder, agent_config, guest_components_procs);

Ok(agent_config)
}
Expand Down Expand Up @@ -1655,13 +1658,23 @@ Caused by:
r#"
dev_mode = true
server_addr = 'vsock://8:2048'
guest_components_procs = "api-server-rest"
guest_components_rest_api = "all"
"#,
)
.unwrap();

// Verify that the override worked
assert!(config.dev_mode);
assert_eq!(config.server_addr, "vsock://8:2048");
assert_eq!(
config.guest_components_procs,
GuestComponentsProcs::ApiServerRest
);
assert_eq!(
config.guest_components_rest_api,
GuestComponentsFeatures::All
);

// Verify that the default values are valid
assert_eq!(config.hotplug_timeout, DEFAULT_HOTPLUG_TIMEOUT);
Expand Down

0 comments on commit d2632ca

Please sign in to comment.