|
1 | | -// use crate::common::retry::retry; |
| 1 | +use crate::common::retry::retry; |
2 | 2 | use crate::common::runtime::block_on; |
3 | | -// use crate::k8s::agent_control_cli::installation::ac_install_cmd; |
| 3 | +use crate::k8s::agent_control_cli::installation::ac_install_cmd; |
4 | 4 | use crate::k8s::tools::cmd::print_cli_output; |
5 | | -// use crate::k8s::tools::k8s_api::create_values_secret; |
| 5 | +use crate::k8s::tools::k8s_api::create_values_secret; |
6 | 6 | use crate::k8s::tools::k8s_env::K8sEnv; |
7 | | -// use crate::k8s::tools::local_chart::agent_control_deploymet::CHART_VERSION_LATEST_RELEASE; |
8 | | -// use crate::k8s::tools::logs::{AC_LABEL_SELECTOR, print_pod_logs}; |
| 7 | +use crate::k8s::tools::local_chart::agent_control_deploymet::CHART_VERSION_LATEST_RELEASE; |
| 8 | +use crate::k8s::tools::logs::{AC_LABEL_SELECTOR, print_pod_logs}; |
9 | 9 | use assert_cmd::{Command, cargo_bin_cmd}; |
10 | | -// use k8s_openapi::api::apps::v1::Deployment; |
11 | | -// use k8s_openapi::api::core::v1::{ConfigMap, Secret}; |
12 | | -// use kube::Api; |
13 | | -// use std::time::Duration; |
14 | | -// /// TODO: Re-enable this test after PR #1752 (this repo) and helm-charts PR #1965 are merged to main. |
15 | | -// #[test] |
16 | | -// #[ignore = "needs k8s cluster"] |
17 | | -// // This test can break if the chart introduces any breaking changes. |
18 | | -// // If this situation occurs, we will need to disable the test or use |
19 | | -// // a similar workaround than the one we use in the tiltfile. |
20 | | -// fn k8s_cli_install_agent_control_installation_and_uninstallation() { |
21 | | -// let mut k8s_env = block_on(K8sEnv::new()); |
22 | | -// let ac_namespace = block_on(k8s_env.test_namespace()); |
23 | | -// let subagents_namespace = block_on(k8s_env.test_namespace()); |
24 | | -// |
25 | | -// let values = serde_json::json!({ |
26 | | -// "nameOverride": "", |
27 | | -// "cleanupManagedResources": false, |
28 | | -// "subAgentsNamespace": subagents_namespace, |
29 | | -// "config": { |
30 | | -// "fleet_control": { |
31 | | -// "enabled": false, |
32 | | -// }, |
33 | | -// "agents": { |
34 | | -// "nrdot":{ |
35 | | -// "agent_type" : "newrelic/io.opentelemetry.collector:0.1.0", |
36 | | -// }, |
37 | | -// } |
38 | | -// }, |
39 | | -// "agentsConfig": { |
40 | | -// "nrdot":{ |
41 | | -// "chart_version" : "*" |
42 | | -// }, |
43 | | -// }, |
44 | | -// "global": { |
45 | | -// "cluster": "test-cluster", |
46 | | -// "licenseKey": "thisisafakelicensekey", |
47 | | -// }, |
48 | | -// }) |
49 | | -// .to_string(); |
50 | | -// create_values_secret( |
51 | | -// k8s_env.client.clone(), |
52 | | -// &ac_namespace, |
53 | | -// "test-secret", |
54 | | -// "values.yaml", |
55 | | -// values, |
56 | | -// ); |
57 | | -// |
58 | | -// print_pod_logs(k8s_env.client.clone(), &ac_namespace, AC_LABEL_SELECTOR); |
59 | | -// |
60 | | -// let release_name = "install-ac-installation-and-uninstallation"; |
61 | | -// let mut cmd = ac_install_cmd( |
62 | | -// &ac_namespace, |
63 | | -// CHART_VERSION_LATEST_RELEASE, |
64 | | -// release_name, |
65 | | -// "test-secret=values.yaml", |
66 | | -// ); |
67 | | -// let assert = cmd.assert(); |
68 | | -// print_cli_output(&assert); |
69 | | -// assert.success(); |
70 | | -// |
71 | | -// let deployments: Api<Deployment> = Api::namespaced(k8s_env.client.clone(), &ac_namespace); |
72 | | -// let config_maps: Api<ConfigMap> = Api::namespaced(k8s_env.client.clone(), &ac_namespace); |
73 | | -// let secrets: Api<Secret> = Api::namespaced(k8s_env.client.clone(), &ac_namespace); |
74 | | -// |
75 | | -// let deployment_name = format!("{}-agent-control-deploy", release_name); |
76 | | -// retry(10, Duration::from_secs(1), || { |
77 | | -// // We set "nameOverride" in the secret values to force the deployment name |
78 | | -// // to be equal to the release name. This avoids breaking the test if the |
79 | | -// // default value changes in the chart. |
80 | | -// let _ = block_on(deployments.get(&deployment_name))?; |
81 | | -// Ok(()) |
82 | | -// }); |
83 | | -// retry(10, Duration::from_secs(1), || { |
84 | | -// let _ = block_on(config_maps.get("local-data-nrdot"))?; |
85 | | -// Ok(()) |
86 | | -// }); |
87 | | -// retry(10, Duration::from_secs(1), || { |
88 | | -// let _ = block_on(secrets.get("values-nrdot"))?; |
89 | | -// Ok(()) |
90 | | -// }); |
91 | | -// |
92 | | -// let mut cmd = ac_uninstall_cmd(&ac_namespace, &subagents_namespace, release_name); |
93 | | -// let assert = cmd.assert(); |
94 | | -// print_cli_output(&assert); |
95 | | -// assert.success(); |
96 | | -// |
97 | | -// let _ = |
98 | | -// block_on(deployments.get(&deployment_name)).expect_err("AC deployment should be deleted"); |
99 | | -// let _ = block_on(config_maps.get("local-data-nrdot")) |
100 | | -// .expect_err("SubAgent config_map should be deleted"); |
101 | | -// let _ = block_on(secrets.get("values-nrdot")).expect_err("SubAgent secret should be deleted"); |
102 | | -// } |
| 10 | +use k8s_openapi::api::apps::v1::Deployment; |
| 11 | +use k8s_openapi::api::core::v1::{ConfigMap, Secret}; |
| 12 | +use kube::Api; |
| 13 | +use std::time::Duration; |
| 14 | +#[test] |
| 15 | +#[ignore = "needs k8s cluster"] |
| 16 | +// This test can break if the chart introduces any breaking changes. |
| 17 | +// If this situation occurs, we will need to disable the test or use |
| 18 | +// a similar workaround than the one we use in the tiltfile. |
| 19 | +fn k8s_cli_install_agent_control_installation_and_uninstallation() { |
| 20 | + let mut k8s_env = block_on(K8sEnv::new()); |
| 21 | + let ac_namespace = block_on(k8s_env.test_namespace()); |
| 22 | + let subagents_namespace = block_on(k8s_env.test_namespace()); |
| 23 | + |
| 24 | + let values = serde_json::json!({ |
| 25 | + "nameOverride": "", |
| 26 | + "cleanupManagedResources": false, |
| 27 | + "subAgentsNamespace": subagents_namespace, |
| 28 | + "config": { |
| 29 | + "fleet_control": { |
| 30 | + "enabled": false, |
| 31 | + }, |
| 32 | + "agents": { |
| 33 | + "nrdot":{ |
| 34 | + "agent_type" : "newrelic/io.opentelemetry.collector:0.1.0", |
| 35 | + }, |
| 36 | + } |
| 37 | + }, |
| 38 | + "agentsConfig": { |
| 39 | + "nrdot":{ |
| 40 | + "chart_version" : "*" |
| 41 | + }, |
| 42 | + }, |
| 43 | + "global": { |
| 44 | + "cluster": "test-cluster", |
| 45 | + "licenseKey": "thisisafakelicensekey", |
| 46 | + }, |
| 47 | + }) |
| 48 | + .to_string(); |
| 49 | + create_values_secret( |
| 50 | + k8s_env.client.clone(), |
| 51 | + &ac_namespace, |
| 52 | + "test-secret", |
| 53 | + "values.yaml", |
| 54 | + values, |
| 55 | + ); |
| 56 | + |
| 57 | + print_pod_logs(k8s_env.client.clone(), &ac_namespace, AC_LABEL_SELECTOR); |
| 58 | + |
| 59 | + let release_name = "install-ac-installation-and-uninstallation"; |
| 60 | + let mut cmd = ac_install_cmd( |
| 61 | + &ac_namespace, |
| 62 | + CHART_VERSION_LATEST_RELEASE, |
| 63 | + release_name, |
| 64 | + "test-secret=values.yaml", |
| 65 | + ); |
| 66 | + let assert = cmd.assert(); |
| 67 | + print_cli_output(&assert); |
| 68 | + assert.success(); |
| 69 | + |
| 70 | + let deployments: Api<Deployment> = Api::namespaced(k8s_env.client.clone(), &ac_namespace); |
| 71 | + let config_maps: Api<ConfigMap> = Api::namespaced(k8s_env.client.clone(), &ac_namespace); |
| 72 | + let secrets: Api<Secret> = Api::namespaced(k8s_env.client.clone(), &ac_namespace); |
| 73 | + |
| 74 | + let deployment_name = format!("{}-agent-control-deploy", release_name); |
| 75 | + retry(10, Duration::from_secs(1), || { |
| 76 | + // We set "nameOverride" in the secret values to force the deployment name |
| 77 | + // to be equal to the release name. This avoids breaking the test if the |
| 78 | + // default value changes in the chart. |
| 79 | + let _ = block_on(deployments.get(&deployment_name))?; |
| 80 | + Ok(()) |
| 81 | + }); |
| 82 | + retry(10, Duration::from_secs(1), || { |
| 83 | + let _ = block_on(config_maps.get("local-data-nrdot"))?; |
| 84 | + Ok(()) |
| 85 | + }); |
| 86 | + retry(10, Duration::from_secs(1), || { |
| 87 | + let _ = block_on(secrets.get("values-nrdot"))?; |
| 88 | + Ok(()) |
| 89 | + }); |
| 90 | + |
| 91 | + let mut cmd = ac_uninstall_cmd(&ac_namespace, &subagents_namespace, release_name); |
| 92 | + let assert = cmd.assert(); |
| 93 | + print_cli_output(&assert); |
| 94 | + assert.success(); |
| 95 | + |
| 96 | + let _ = |
| 97 | + block_on(deployments.get(&deployment_name)).expect_err("AC deployment should be deleted"); |
| 98 | + let _ = block_on(config_maps.get("local-data-nrdot")) |
| 99 | + .expect_err("SubAgent config_map should be deleted"); |
| 100 | + let _ = block_on(secrets.get("values-nrdot")).expect_err("SubAgent secret should be deleted"); |
| 101 | +} |
103 | 102 |
|
104 | 103 | #[test] |
105 | 104 | #[ignore = "needs k8s cluster"] |
|
0 commit comments