Skip to content

Commit a51931d

Browse files
feat: add repository url flag to cli (#1326)
1 parent 88654fe commit a51931d

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

agent-control/src/cli/install_agent_control.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ pub struct AgentControlInstallData {
7474
/// Initial delay for installation check
7575
#[arg(long, default_value = INSTALLATION_CHECK_DEFAULT_INITIAL_DELAY, value_parser = parse_duration_arg)]
7676
pub installation_check_initial_delay: Duration,
77+
78+
/// Repository URl from where the chart will be downloaded
79+
#[arg(long, default_value = REPOSITORY_URL)]
80+
pub repository_url: String,
7781
}
7882

7983
// helper needed because the arguments from the duration_str's parse function and the one expected by the clap
@@ -146,13 +150,18 @@ impl From<AgentControlInstallData> for Vec<DynamicObject> {
146150
let annotations = annotations.get();
147151

148152
vec![
149-
helm_repository(labels.clone(), annotations.clone()),
153+
helm_repository(
154+
value.repository_url.clone(),
155+
labels.clone(),
156+
annotations.clone(),
157+
),
150158
helm_release(&value, labels, annotations),
151159
]
152160
}
153161
}
154162

155163
fn helm_repository(
164+
repository_url: String,
156165
labels: BTreeMap<String, String>,
157166
annotations: BTreeMap<String, String>,
158167
) -> DynamicObject {
@@ -166,7 +175,7 @@ fn helm_repository(
166175
},
167176
data: serde_json::json!({
168177
"spec": {
169-
"url": REPOSITORY_URL,
178+
"url": repository_url,
170179
"interval": FIVE_MINUTES,
171180
}
172181
}),
@@ -296,6 +305,7 @@ mod tests {
296305
skip_installation_check: false,
297306
installation_check_initial_delay: Duration::from_secs(10),
298307
installation_check_timeout: Duration::from_secs(300),
308+
repository_url: REPOSITORY_URL.to_string(),
299309
}
300310
}
301311

agent-control/tests/k8s/agent_control_cli/dynamic_objects.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,29 @@ fn k8s_cli_install_agent_control_creates_resources() {
110110
)
111111
);
112112
}
113+
114+
#[test]
115+
#[ignore = "needs k8s cluster"]
116+
fn k8s_cli_install_agent_control_creates_resources_with_specific_repository_url() {
117+
let runtime = crate::common::runtime::tokio_runtime();
118+
119+
let mut k8s_env = runtime.block_on(K8sEnv::new());
120+
let namespace = runtime.block_on(k8s_env.test_namespace());
121+
122+
let repository_url = "https://cli-charts.newrelic.com";
123+
let mut cmd = Command::cargo_bin("newrelic-agent-control-cli").unwrap();
124+
cmd.arg("install-agent-control");
125+
cmd.arg("--release-name").arg(RELEASE_NAME);
126+
cmd.arg("--chart-version").arg("1.0.0");
127+
cmd.arg("--namespace").arg(namespace.clone());
128+
cmd.arg("--skip-installation-check"); // Skipping checks because we are merely checking that the resources are created.
129+
cmd.arg("--repository-url").arg(repository_url);
130+
cmd.assert().success();
131+
132+
let k8s_client = SyncK8sClient::try_new(runtime.clone(), namespace.clone()).unwrap();
133+
let repository = k8s_client
134+
.get_dynamic_object(&helmrepository_type_meta(), REPOSITORY_NAME)
135+
.unwrap()
136+
.unwrap();
137+
assert_eq!(repository.data["spec"]["url"], repository_url);
138+
}

0 commit comments

Comments
 (0)