Skip to content

Commit 50e0568

Browse files
feat: global registry support (#2448)
1 parent 17e0fdc commit 50e0568

16 files changed

Lines changed: 166 additions & 75 deletions

File tree

agent-control/agent-type-registry/newrelic/com.newrelic.infrastructure-0.1.0.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ variables:
2929
required: false
3030
default: 18003
3131
oci:
32-
registry:
33-
description: "Package registry url"
34-
type: string
35-
required: false
36-
default: docker.io
37-
variants:
38-
ac_config_field: "oci_registry_urls"
39-
values: [ "docker.io" ]
4032
repository:
4133
description: "Package repository name"
4234
type: string
@@ -81,14 +73,6 @@ variables:
8173
required: false
8274
default: 18003
8375
oci:
84-
registry:
85-
description: "Package registry url"
86-
type: string
87-
required: false
88-
default: docker.io
89-
variants:
90-
ac_config_field: "oci_registry_urls"
91-
values: [ "docker.io" ]
9276
repository:
9377
description: "Package repository name"
9478
type: string
@@ -182,7 +166,6 @@ deployment:
182166
infra-agent:
183167
download:
184168
oci:
185-
registry: ${nr-var:oci.registry}
186169
repository: ${nr-var:oci.repository}
187170
version: ${nr-var:version}
188171
public_key_url: https://publickeys.newrelic.com/g/agent-control-oci/global/nrinfraagent/jwks.json
@@ -252,7 +235,6 @@ deployment:
252235
infra-agent:
253236
download:
254237
oci:
255-
registry: ${nr-var:oci.registry}
256238
repository: ${nr-var:oci.repository}
257239
version: ${nr-var:version}
258240
public_key_url: https://publickeys.newrelic.com/g/agent-control-oci/global/nrinfraagent/jwks.json

agent-control/agent-type-registry/newrelic/com.newrelic.opentelemetry.collector-0.1.0.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ variables:
3333
required: false
3434
default: 13133
3535
oci:
36-
registry:
37-
description: "Package registry url"
38-
type: string
39-
required: false
40-
default: docker.io
41-
variants:
42-
ac_config_field: "oci_nrdot_registry_urls"
43-
values: [ "docker.io" ]
4436
repository:
4537
description: "Package repository name"
4638
type: string
@@ -79,14 +71,6 @@ variables:
7971
required: false
8072
default: 13133
8173
oci:
82-
registry:
83-
description: "Package registry url"
84-
type: string
85-
required: false
86-
default: docker.io
87-
variants:
88-
ac_config_field: "oci_nrdot_registry_repositories"
89-
values: [ "docker.io" ]
9074
repository:
9175
description: "Package repository name"
9276
type: string
@@ -153,7 +137,6 @@ deployment:
153137
nrdot:
154138
download:
155139
oci:
156-
registry: ${nr-var:oci.registry}
157140
repository: ${nr-var:oci.repository}
158141
version: ${nr-var:version}
159142
public_key_url: https://publickeys.newrelic.com/g/agent-control-oci/global/nrdot/jwks.json
@@ -186,7 +169,6 @@ deployment:
186169
nrdot:
187170
download:
188171
oci:
189-
registry: ${nr-var:oci.registry}
190172
repository: ${nr-var:oci.repository}
191173
version: ${nr-var:version}
192174
public_key_url: https://publickeys.newrelic.com/g/agent-control-oci/global/nrdot/jwks.json

agent-control/src/agent_control/config.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ pub struct AgentControlConfig {
7676
/// Contains configuration for on-host self-update mechanism
7777
#[serde(default)]
7878
pub self_update: SelfUpdateConfig,
79+
80+
/// Oci configuration (used for AC and agents packages)
81+
#[serde(default)]
82+
pub oci: OciConfig,
7983
}
8084

8185
#[derive(Debug, Default, Deserialize, PartialEq, Clone)]
@@ -94,6 +98,48 @@ pub struct PackagesConfig {
9498
pub signature_verification_enabled: SignatureVerificationEnabled,
9599
}
96100

101+
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
102+
pub struct OciConfig {
103+
#[serde(default = "OciConfig::default_registry")]
104+
pub registry: String,
105+
#[serde(default)]
106+
pub auth: OciAuth,
107+
}
108+
109+
impl Default for OciConfig {
110+
fn default() -> Self {
111+
OciConfig {
112+
registry: Self::default_registry(),
113+
auth: OciAuth::default(),
114+
}
115+
}
116+
}
117+
118+
impl OciConfig {
119+
fn default_registry() -> String {
120+
"docker.io".to_string()
121+
}
122+
}
123+
124+
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq)]
125+
pub struct OciAuth {
126+
#[serde(default)]
127+
pub basic: BasicAuth,
128+
#[serde(default)]
129+
pub bearer: BearerAuth,
130+
}
131+
132+
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq)]
133+
pub struct BasicAuth {
134+
pub username: String,
135+
pub password: String,
136+
}
137+
138+
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq)]
139+
pub struct BearerAuth {
140+
pub token: String,
141+
}
142+
97143
const DEFAULT_SIGNATURE_VERIFICATION_ENABLED: bool = true;
98144
#[derive(Debug, Deserialize, Clone, Copy, PartialEq, WrapperWithDefault)]
99145
#[wrapper_default_value(DEFAULT_SIGNATURE_VERIFICATION_ENABLED)]
@@ -1041,6 +1087,31 @@ k8s:
10411087
assert_matches!(result, Err(AgentControlConfigError(_)));
10421088
}
10431089

1090+
#[test]
1091+
fn test_deserialize_oci_config() {
1092+
let config_input = r#"agents: {}"#;
1093+
let config = serde_yaml::from_str::<AgentControlConfig>(config_input).unwrap();
1094+
assert_eq!("docker.io".to_string(), config.oci.registry);
1095+
1096+
let config_input = r#"
1097+
agents: {}
1098+
oci:
1099+
auth:
1100+
bearer:
1101+
token: "token"
1102+
"#;
1103+
let config = serde_yaml::from_str::<AgentControlConfig>(config_input).unwrap();
1104+
assert_eq!("docker.io".to_string(), config.oci.registry);
1105+
1106+
let config_input = r#"
1107+
agents: {}
1108+
oci:
1109+
registry: "custom-registry.io"
1110+
"#;
1111+
let config = serde_yaml::from_str::<AgentControlConfig>(config_input).unwrap();
1112+
assert_eq!("custom-registry.io".to_string(), config.oci.registry);
1113+
}
1114+
10441115
////////////////////////////////////////////////////////////////////////////////////
10451116
// Test helpers
10461117
////////////////////////////////////////////////////////////////////////////////////

agent-control/src/agent_control/run/on_host.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ impl AgentControlRunner {
175175
let agents_package_manager = OCIPackageManager::new(
176176
OCIArtifactDownloader::new(
177177
oci_client.clone(),
178+
self.bootstrap_config.oci.registry.clone(),
178179
agent_control_config
179180
.agent_packages
180181
.signature_verification_enabled
@@ -225,6 +226,7 @@ impl AgentControlRunner {
225226
let agent_control_package_manager = OCIPackageManager::new(
226227
OCIArtifactDownloader::new(
227228
oci_client.clone(),
229+
self.bootstrap_config.oci.registry.clone(),
228230
agent_control_config
229231
.self_update
230232
.signature_verification_enabled

agent-control/src/agent_type/runtime_config/on_host.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ mod tests {
160160
let pkg = Package {
161161
download: Download {
162162
oci: Oci {
163-
registry: TemplateableValue::from_template("${nr-var:registry}".to_string()),
164163
repository: TemplateableValue::from_template(
165164
"${nr-var:repository}".to_string(),
166165
),
@@ -191,7 +190,6 @@ packages:
191190
my-pkg:
192191
download:
193192
oci:
194-
registry: my.registry
195193
repository: my/repo
196194
version: latest
197195
"#;
@@ -221,7 +219,7 @@ packages:
221219
.join("agent-id")
222220
.join("stored_packages")
223221
.join("my-pkg")
224-
.join("oci_my_registry__my__repo_latest")
222+
.join("oci_base_io__my__repo_latest")
225223
.to_string_lossy()
226224
.to_string(),
227225
);

agent-control/src/agent_type/runtime_config/on_host/package.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ pub struct Download {
2626

2727
#[derive(Debug, Deserialize, Default, Clone, PartialEq)]
2828
pub struct Oci {
29-
/// OCI registry url.
30-
pub registry: TemplateableValue<String>,
3129
/// Repository name.
3230
pub repository: TemplateableValue<String>,
3331
/// Package version including tag, digest or tag + digest.
@@ -58,7 +56,7 @@ impl Templateable for Download {
5856
impl Templateable for Oci {
5957
type Output = rendered::Oci;
6058
fn template_with(self, variables: &Variables) -> Result<Self::Output, AgentTypeError> {
61-
let registry = self.registry.template_with(variables)?;
59+
let registry = "base.io";
6260
let repository = self.repository.template_with(variables)?;
6361
let mut version = self.version.template_with(variables)?;
6462

@@ -132,10 +130,6 @@ mod tests {
132130
};
133131

134132
let mut variables = Variables::new();
135-
variables.insert(
136-
"nr-var:registry".to_string(),
137-
Variable::new_final_string_variable("registry.com".to_string()),
138-
);
139133
variables.insert(
140134
"nr-var:repository".to_string(),
141135
Variable::new_final_string_variable("repo".to_string()),
@@ -152,7 +146,6 @@ mod tests {
152146
}
153147

154148
let oci = Oci {
155-
registry: TemplateableValue::from_template("${nr-var:registry}".to_string()),
156149
repository: TemplateableValue::from_template("${nr-var:repository}".to_string()),
157150
version: TemplateableValue::from_template("${nr-var:version}".to_string()),
158151
public_key_url: public_key_url
@@ -163,7 +156,7 @@ mod tests {
163156
let rendered_oci = oci.template_with(&variables);
164157
let rendered_oci = rendered_oci.unwrap();
165158

166-
assert_eq!(rendered_oci.reference.registry(), "registry.com");
159+
assert_eq!(rendered_oci.reference.registry(), "base.io");
167160
assert_eq!(rendered_oci.reference.repository(), "repo");
168161
assert_eq!(rendered_oci.reference.tag(), expected_tag);
169162
assert_eq!(rendered_oci.reference.digest(), expected_digest);

agent-control/src/oci.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,14 @@ pub mod tests {
359359
self
360360
}
361361

362+
pub fn registry(&self) -> String {
363+
self.server
364+
.as_ref()
365+
.expect("Call build() first")
366+
.address()
367+
.to_string()
368+
}
369+
362370
pub fn reference(&self) -> Reference {
363371
self.reference_on_server(self.server.as_ref().expect("Call build() first"))
364372
}

0 commit comments

Comments
 (0)