Skip to content

Commit

Permalink
Remove unused structs
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsharm committed Jun 11, 2024
1 parent 000efc7 commit 5ad4b5b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 223 deletions.
78 changes: 2 additions & 76 deletions sources/models/src/de.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Option<Vec<RegistryMirror>>, D::Error>
where
D: Deserializer<'de>,
{
struct TableOrArray;

impl<'de> Visitor<'de> for TableOrArray {
type Value = Option<Vec<RegistryMirror>>;

fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
formatter.write_str("TOML array or TOML table")
}

fn visit_seq<A>(self, seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
Ok(Some(Deserialize::deserialize(SeqAccessDeserializer::new(
seq,
))?))
}

fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
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::<RegistrySettings>(TEST_MIRRORS_ARRAY).is_ok());
}

#[test]
fn registry_mirrors_table_representation() {
assert!(toml::from_str::<RegistrySettings>(TEST_MIRRORS_TABLE).is_ok());
}

#[test]
fn registry_mirrors_none_representation() {
let registry_settings = toml::from_str::<RegistrySettings>("").unwrap();
assert!(registry_settings.mirrors.is_none());
}

#[test]
fn representation_equal() {
assert_eq!(
toml::from_str::<RegistrySettings>(TEST_MIRRORS_TABLE).unwrap(),
toml::from_str::<RegistrySettings>(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
Expand Down
152 changes: 5 additions & 147 deletions sources/models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,16 @@ 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,
BootConfigKey, BootConfigValue, CpuManagerPolicy, CredentialProvider,
DNSDomain, ECSAgentImagePullBehavior, ECSAgentLogLevel, ECSAttributeKey, ECSAttributeValue,
ECSDurationValue, EtcHostsEntries, FriendlyVersion, Identifier, IntegerPercent, KmodKey,
ECSDurationValue, Identifier, IntegerPercent,
KubernetesAuthenticationMode, KubernetesBootstrapToken, KubernetesCloudProvider,
KubernetesClusterDnsIp, KubernetesClusterName, KubernetesDurationValue, KubernetesLabelKey,
KubernetesLabelValue, KubernetesQuantityValue, KubernetesReservedResourceKey,
KubernetesTaintValue, KubernetesThresholdValue, Lockdown, OciDefaultsCapability,
OciDefaultsResourceLimitType, PemCertificateString, SingleLineString, SysctlKey,
KubernetesTaintValue, KubernetesThresholdValue, OciDefaultsCapability,
OciDefaultsResourceLimitType, SingleLineString, SysctlKey,
TopologyManagerPolicy, TopologyManagerScope, Url, ValidBase64, ValidLinuxHostname,
};

Expand Down Expand Up @@ -333,94 +333,6 @@ struct ECSSettings {
enable_container_metadata: bool,
}

#[model]
struct RegistryMirror {
registry: SingleLineString,
endpoint: Vec<Url>,
}

#[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<RegistryMirror>,
#[serde(alias = "creds", default, skip_serializing_if = "Option::is_none")]
credentials: Vec<RegistryCredential>,
}

// 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<SingleLineString>,
}

// NTP settings
#[model]
struct NtpSettings {
time_servers: Vec<Url>,
}

// DNS Settings
#[model]
struct DnsSettings {
name_servers: Vec<IpAddr>,
search_list: Vec<ValidLinuxHostname>,
}

// Kernel settings
#[model]
struct KernelSettings {
lockdown: Lockdown,
modules: HashMap<KmodKey, KmodSetting>,
// Values are almost always a single line and often just an integer... but not always.
sysctl: HashMap<SysctlKey, String>,
}

// Kernel module settings
#[model]
struct KmodSetting {
allowed: bool,
autoload: bool,
}

// Kernel boot settings
#[model]
struct BootSettings {
Expand All @@ -441,37 +353,6 @@ struct BootSettings {
init_parameters: HashMap<BootConfigKey, Vec<BootConfigValue>>,
}

// 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<String>,
}

// 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 {
Expand Down Expand Up @@ -517,29 +398,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 {
Expand Down

0 comments on commit 5ad4b5b

Please sign in to comment.