Skip to content

Commit 79b37dd

Browse files
moldhousejhl-aa
authored andcommitted
feat: prioritize oci registry over file registry
1 parent a46cabc commit 79b37dd

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

src/namespace_watcher/config.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ impl OperatorConfig {
127127
#[derive(Deserialize, Clone, PartialEq, Eq, Debug)]
128128
#[serde(untagged)]
129129
pub enum Registry {
130-
File {
131-
path: String,
132-
},
130+
// https://serde.rs/enum-representations.html#untagged
131+
// Serde will try to match the data against each variant in order and the first one that
132+
// deserializes successfully is the one returned.
133+
//
134+
// Therefore, we put `Oci` first as this is most likely the variant someone will use in production.
133135
#[serde(rename_all = "kebab-case")]
134136
Oci {
135137
registry: String,
@@ -139,6 +141,9 @@ pub enum Registry {
139141
#[serde(rename = "registry-password")]
140142
password: String,
141143
},
144+
File {
145+
path: String,
146+
},
142147
}
143148

144149
#[derive(Deserialize, Clone, PartialEq, Eq, Debug)]
@@ -496,6 +501,31 @@ registry-password = \"{password}\"
496501
assert!(config.namespaces.contains_key(&namespace));
497502
}
498503

504+
#[test]
505+
fn prioritizes_oci_registry() {
506+
// When deserializing a config which contains both, an oci and a file registry
507+
// for the same namespace
508+
let config = toml::from_str::<OperatorConfig>(
509+
r#"
510+
[namespaces.pharia-kernel-team]
511+
config-url = "https://dummy_url"
512+
config-access-token = "GITLAB_CONFIG_ACCESS_TOKEN"
513+
registry = "registry.gitlab.aleph-alpha.de"
514+
base-repository = "engineering/pharia-skills/skills"
515+
registry-user = "PHARIA_KERNEL_TEAM_REGISTRY_USER"
516+
registry-password = "PHARIA_KERNEL_TEAM_REGISTRY_PASSWORD"
517+
path = "local-path"
518+
"#,
519+
)
520+
.unwrap();
521+
522+
let key = Namespace::new("pharia-kernel-team");
523+
let namespace = config.namespaces.get(&key).unwrap();
524+
525+
// Then the `Oci` variants is prioritized
526+
assert!(matches!(namespace.registry(), Registry::Oci { .. }));
527+
}
528+
499529
#[test]
500530
fn deserializes_multiple_namespaces() {
501531
let config = toml::from_str::<OperatorConfig>(

0 commit comments

Comments
 (0)