From f716d514adf793acdabf13f77681c380d8454adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=91=BD=20mgsharm?= Date: Mon, 10 Jun 2024 16:04:06 -0400 Subject: [PATCH] Remove unused structs --- sources/models/src/de.rs | 78 +------------------ sources/models/src/lib.rs | 159 ++------------------------------------ 2 files changed, 10 insertions(+), 227 deletions(-) diff --git a/sources/models/src/de.rs b/sources/models/src/de.rs index c1a0f11444b..14920d1336c 100644 --- a/sources/models/src/de.rs +++ b/sources/models/src/de.rs @@ -1,6 +1,5 @@ -use crate::{KubernetesLabelKey, KubernetesTaintValue, RegistryMirror}; -use serde::de::value::SeqAccessDeserializer; -use serde::de::{Error, MapAccess, SeqAccess, Visitor}; +use crate::{KubernetesLabelKey, KubernetesTaintValue}; +use serde::de::{Error, MapAccess, Visitor}; use serde::{Deserialize, Deserializer}; use std::collections::HashMap; use std::convert::TryFrom; @@ -135,79 +134,6 @@ mod node_taint_tests { } } -// Our standard representation of registry mirrors is a `Vec` of `RegistryMirror`; for backward compatibility, we also allow a `HashMap` of registry to endpoints. -pub(crate) fn deserialize_mirrors<'de, D>( - deserializer: D, -) -> Result>, D::Error> -where - D: Deserializer<'de>, -{ - struct TableOrArray; - - impl<'de> Visitor<'de> for TableOrArray { - type Value = Option>; - - fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result { - formatter.write_str("TOML array or TOML table") - } - - fn visit_seq(self, seq: A) -> Result - where - A: SeqAccess<'de>, - { - Ok(Some(Deserialize::deserialize(SeqAccessDeserializer::new( - seq, - ))?)) - } - - fn visit_map(self, mut map: M) -> Result - where - M: MapAccess<'de>, - { - let mut vec = Vec::new(); - while let Some((k, v)) = map.next_entry()? { - vec.push(RegistryMirror { - registry: Some(k), - endpoint: Some(v), - }); - } - Ok(Some(vec)) - } - } - deserializer.deserialize_any(TableOrArray) -} - -#[cfg(test)] -mod mirrors_tests { - use crate::RegistrySettings; - static TEST_MIRRORS_ARRAY: &str = include_str!("../tests/data/mirrors-array"); - static TEST_MIRRORS_TABLE: &str = include_str!("../tests/data/mirrors-table"); - - #[test] - fn registry_mirrors_array_representation() { - assert!(toml::from_str::(TEST_MIRRORS_ARRAY).is_ok()); - } - - #[test] - fn registry_mirrors_table_representation() { - assert!(toml::from_str::(TEST_MIRRORS_TABLE).is_ok()); - } - - #[test] - fn registry_mirrors_none_representation() { - let registry_settings = toml::from_str::("").unwrap(); - assert!(registry_settings.mirrors.is_none()); - } - - #[test] - fn representation_equal() { - assert_eq!( - toml::from_str::(TEST_MIRRORS_TABLE).unwrap(), - toml::from_str::(TEST_MIRRORS_ARRAY).unwrap() - ); - } -} - // This specifies that any non negative i64 integer, -1, and "unlimited" /// are the valid resource-limits. The hard-limit set to "unlimited" or -1 /// and soft-limit set to "unlimited" or -1 are converted to u64::MAX in diff --git a/sources/models/src/lib.rs b/sources/models/src/lib.rs index 6062de45461..493baecb7c1 100644 --- a/sources/models/src/lib.rs +++ b/sources/models/src/lib.rs @@ -219,16 +219,15 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::net::IpAddr; -use crate::de::{deserialize_limit, deserialize_mirrors, deserialize_node_taints}; +use crate::de::{deserialize_limit, deserialize_node_taints}; use modeled_types::{ - BootConfigKey, BootConfigValue, BootstrapContainerMode, CpuManagerPolicy, CredentialProvider, - DNSDomain, ECSAgentImagePullBehavior, ECSAgentLogLevel, ECSAttributeKey, ECSAttributeValue, - ECSDurationValue, EtcHostsEntries, FriendlyVersion, Identifier, IntegerPercent, KmodKey, - KubernetesAuthenticationMode, KubernetesBootstrapToken, KubernetesCloudProvider, - KubernetesClusterDnsIp, KubernetesClusterName, KubernetesDurationValue, KubernetesLabelKey, - KubernetesLabelValue, KubernetesQuantityValue, KubernetesReservedResourceKey, - KubernetesTaintValue, KubernetesThresholdValue, Lockdown, OciDefaultsCapability, - OciDefaultsResourceLimitType, PemCertificateString, SingleLineString, SysctlKey, + BootConfigKey, BootConfigValue, CpuManagerPolicy, CredentialProvider, DNSDomain, + ECSAgentImagePullBehavior, ECSAgentLogLevel, ECSAttributeKey, ECSAttributeValue, + ECSDurationValue, Identifier, IntegerPercent, KubernetesAuthenticationMode, + KubernetesBootstrapToken, KubernetesCloudProvider, KubernetesClusterDnsIp, KubernetesClusterName, + KubernetesDurationValue, KubernetesLabelKey, KubernetesLabelValue, KubernetesQuantityValue, + KubernetesReservedResourceKey, KubernetesTaintValue, KubernetesThresholdValue, + OciDefaultsCapability, OciDefaultsResourceLimitType, SingleLineString, SysctlKey, TopologyManagerPolicy, TopologyManagerScope, Url, ValidBase64, ValidLinuxHostname, }; @@ -333,94 +332,6 @@ struct ECSSettings { enable_container_metadata: bool, } -#[model] -struct RegistryMirror { - registry: SingleLineString, - endpoint: Vec, -} - -#[model] -struct RegistryCredential { - registry: SingleLineString, - username: SingleLineString, - password: SingleLineString, - // This is the base64 encoding of "username:password" - auth: ValidBase64, - identitytoken: SingleLineString, -} - -// Image registry settings for the container runtimes. -#[model] -struct RegistrySettings { - #[serde( - default, - skip_serializing_if = "Option::is_none", - deserialize_with = "deserialize_mirrors" - )] - mirrors: Vec, - #[serde(alias = "creds", default, skip_serializing_if = "Option::is_none")] - credentials: Vec, -} - -// Update settings. Taken from userdata. The 'seed' setting is generated -// by the "Bork" settings generator at runtime. -#[model] -struct UpdatesSettings { - metadata_base_url: Url, - targets_base_url: Url, - seed: u32, - // Version to update to when updating via the API. - version_lock: FriendlyVersion, - ignore_waves: bool, -} - -#[model] -struct HostContainer { - source: Url, - enabled: bool, - superpowered: bool, - user_data: ValidBase64, -} - -// Network settings. These settings will affect host service components' network behavior -#[model] -struct NetworkSettings { - hostname: ValidLinuxHostname, - hosts: EtcHostsEntries, - https_proxy: Url, - // We allow some flexibility in NO_PROXY values because different services support different formats. - no_proxy: Vec, -} - -// NTP settings -#[model] -struct NtpSettings { - time_servers: Vec, -} - -// DNS Settings -#[model] -struct DnsSettings { - name_servers: Vec, - search_list: Vec, -} - -// Kernel settings -#[model] -struct KernelSettings { - lockdown: Lockdown, - modules: HashMap, - // Values are almost always a single line and often just an integer... but not always. - sysctl: HashMap, -} - -// Kernel module settings -#[model] -struct KmodSetting { - allowed: bool, - autoload: bool, -} - // Kernel boot settings #[model] struct BootSettings { @@ -441,37 +352,6 @@ struct BootSettings { init_parameters: HashMap>, } -// Platform-specific settings -#[model] -struct AwsSettings { - region: SingleLineString, - config: ValidBase64, - credentials: ValidBase64, - profile: SingleLineString, -} - -// Metrics settings -#[model] -struct MetricsSettings { - metrics_url: Url, - send_metrics: bool, - service_checks: Vec, -} - -// CloudFormation settings -#[model] -struct CloudFormationSettings { - should_signal: bool, - stack_name: SingleLineString, - logical_resource_id: SingleLineString, -} - -// AutoScaling settings -#[model] -struct AutoScalingSettings { - should_wait: bool, -} - // Container runtime settings #[model] struct ContainerRuntimeSettings { @@ -517,29 +397,6 @@ struct Metadata { val: toml::Value, } -///// Bootstrap Containers - -#[model] -struct BootstrapContainer { - source: Url, - mode: BootstrapContainerMode, - user_data: ValidBase64, - essential: bool, -} - -///// PEM Certificates -#[model] -struct PemCertificate { - data: PemCertificateString, - trusted: bool, -} - -///// OCI hooks -#[model] -struct OciHooks { - log4j_hotpatch_enabled: bool, -} - ///// OCI defaults specifies the default values that will be used in cri-base-json. #[model] struct OciDefaults {