Skip to content

Commit 62f843a

Browse files
fix: Modify upgrade_local_vs_remote test to get new remote version from config instead of updater (#1462)
1 parent 84fe471 commit 62f843a

File tree

5 files changed

+62
-27
lines changed

5 files changed

+62
-27
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
use crate::common::opamp::FakeServer;
12
use crate::common::runtime::block_on;
23
use crate::k8s::self_update::LOCAL_CHART_REPOSITORY;
34
use crate::k8s::tools::cmd::{assert_stdout_contains, print_cli_output};
45
use crate::k8s::tools::k8s_api::create_values_secret;
56
use crate::k8s::tools::k8s_env::K8sEnv;
7+
use crate::k8s::tools::opamp::get_minikube_opamp_url_from_fake_server;
68
use assert_cmd::Command;
79
use kube::Client;
810
use std::time::Duration;
9-
1011
// NOTE: The tests below are using the latest '*' chart version, and they will likely fail
1112
// if breaking changes need to be introduced in the chart.
1213
// If this situation occurs, we need to temporarily skip the tests or use
@@ -20,12 +21,14 @@ fn k8s_cli_install_agent_control_installation_with_invalid_chart_version() {
2021
let mut k8s_env = block_on(K8sEnv::new());
2122
let ac_namespace = block_on(k8s_env.test_namespace());
2223
let subagents_namespace = block_on(k8s_env.test_namespace());
24+
let opamp_server = FakeServer::start_new();
2325

2426
create_simple_values_secret(
2527
k8s_env.client.clone(),
2628
&ac_namespace,
2729
&subagents_namespace,
2830
"test-secret",
31+
opamp_server.endpoint().as_str(),
2932
"values.yaml",
3033
);
3134

@@ -71,12 +74,14 @@ fn k8s_cli_install_agent_control_installation_failed_upgrade() {
7174
let mut k8s_env = block_on(K8sEnv::new());
7275
let ac_namespace = block_on(k8s_env.test_namespace());
7376
let subagents_namespace = block_on(k8s_env.test_namespace());
77+
let opamp_server = FakeServer::start_new();
7478

7579
create_simple_values_secret(
7680
k8s_env.client.clone(),
7781
&ac_namespace,
7882
&subagents_namespace,
7983
"test-secret",
84+
opamp_server.endpoint().as_str(),
8085
"values.yaml",
8186
);
8287

@@ -116,15 +121,28 @@ pub(crate) fn create_simple_values_secret(
116121
ac_ns: &str,
117122
subagents_ns: &str,
118123
secret_name: &str,
124+
opamp_url: &str,
119125
values_key: &str,
120126
) {
127+
let opamp_endpoint = get_minikube_opamp_url_from_fake_server(opamp_url);
128+
121129
let values = serde_json::json!({
122130
"nameOverride": "",
123131
"subAgentsNamespace": subagents_ns,
124132
"config": {
125133
"fleet_control": {
126134
"enabled": false,
127135
},
136+
"agentControl": {
137+
"content": {
138+
"fleet_control": {
139+
"endpoint": opamp_endpoint.as_str(),
140+
"signature_validation": {
141+
"enabled": "false",
142+
},
143+
},
144+
},
145+
},
128146
},
129147
"global": {
130148
"cluster": "test-cluster",

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

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
use crate::common::opamp::{ConfigResponse, FakeServer};
12
use crate::common::retry::retry;
23
use crate::common::runtime::{block_on, tokio_runtime};
34
use crate::k8s::agent_control_cli::installation::{ac_install_cmd, create_simple_values_secret};
45
use crate::k8s::self_update::{LOCAL_CHART_NEW_VERSION, LOCAL_CHART_PREVIOUS_VERSION};
56
use crate::k8s::tools::cmd::print_cli_output;
7+
use crate::k8s::tools::instance_id;
68
use crate::k8s::tools::k8s_env::K8sEnv;
7-
use newrelic_agent_control::agent_control::config::{
8-
AgentControlDynamicConfig, helmrelease_v2_type_meta,
9-
};
10-
use newrelic_agent_control::agent_control::version_updater::k8s::K8sACUpdater;
11-
use newrelic_agent_control::agent_control::version_updater::updater::VersionUpdater;
9+
use crate::k8s::tools::logs::print_pod_logs;
10+
use newrelic_agent_control::agent_control::agent_id::AgentID;
11+
use newrelic_agent_control::agent_control::config::helmrelease_v2_type_meta;
1212
use newrelic_agent_control::cli::install_agent_control::RELEASE_NAME;
1313
use newrelic_agent_control::k8s::client::{ClientConfig, SyncK8sClient};
1414
use newrelic_agent_control::k8s::labels::{AGENT_CONTROL_VERSION_SET_FROM, LOCAL_VAL, REMOTE_VAL};
@@ -17,24 +17,30 @@ use std::error::Error;
1717
use std::sync::Arc;
1818
use std::time::Duration;
1919

20+
const CLI_AC_LABEL_SELECTOR: &str = "app.kubernetes.io/name=agent-control-deployment";
21+
2022
#[test]
2123
#[ignore = "needs k8s cluster"]
2224
// This test can break if the chart introduces any breaking changes.
2325
// If this situation occurs, we will need to disable the test or use
2426
// a similar workaround than the one we use in the tiltfile.
2527
// The test is checking how local and remote upgrade are interacting
2628
fn k8s_cli_local_and_remote_updates() {
29+
let mut opamp_server = FakeServer::start_new();
2730
let mut k8s_env = block_on(K8sEnv::new());
2831
let ac_namespace = block_on(k8s_env.test_namespace());
2932
let subagents_namespace = block_on(k8s_env.test_namespace());
3033
let k8s_client =
3134
Arc::new(SyncK8sClient::try_new(tokio_runtime(), &ClientConfig::new()).unwrap());
3235

36+
print_pod_logs(k8s_env.client.clone(), &ac_namespace, CLI_AC_LABEL_SELECTOR);
37+
3338
create_simple_values_secret(
3439
k8s_env.client.clone(),
3540
&ac_namespace,
3641
&subagents_namespace,
3742
"test-secret",
43+
opamp_server.endpoint().as_str(),
3844
"values.yaml",
3945
);
4046

@@ -76,20 +82,24 @@ fn k8s_cli_local_and_remote_updates() {
7682
)
7783
});
7884

79-
// running updater doing an upgrade to "*"
80-
let updater = K8sACUpdater::new(
81-
k8s_client.clone(),
82-
ac_namespace.clone(),
83-
LOCAL_CHART_NEW_VERSION.to_string(),
84-
);
8585
let latest_version = "*";
86-
let config_to_update = &AgentControlDynamicConfig {
87-
agents: Default::default(),
88-
chart_version: Some(latest_version.to_string()),
89-
};
90-
updater
91-
.update(config_to_update)
92-
.expect("updater should not fail");
86+
let ac_instance_id = instance_id::get_instance_id(
87+
k8s_env.client.clone(),
88+
ac_namespace.as_str(),
89+
&AgentID::new_agent_control_id(),
90+
);
91+
opamp_server.set_config_response(
92+
ac_instance_id.clone(),
93+
ConfigResponse::from(
94+
format!(
95+
r#"
96+
agents: {{}}
97+
chart_version: "{latest_version}"
98+
"#
99+
)
100+
.as_str(),
101+
),
102+
);
93103

94104
retry(15, Duration::from_secs(5), || {
95105
check_version_and_source(&k8s_client, latest_version, REMOTE_VAL, &ac_namespace)

agent-control/tests/k8s/self_update.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::common::retry::retry;
88
use crate::common::runtime::block_on;
99
use crate::k8s::tools::instance_id;
1010
use crate::k8s::tools::logs::{AC_LABEL_SELECTOR, print_pod_logs};
11+
use crate::k8s::tools::opamp::get_minikube_opamp_url_from_fake_server;
1112
use assert_cmd::Command;
1213
use k8s_openapi::api::core::v1::Pod;
1314
use kube::api::ListParams;
@@ -17,10 +18,8 @@ use newrelic_agent_control::agent_control::defaults::OPAMP_CHART_VERSION_ATTRIBU
1718
use newrelic_agent_control::opamp::instance_id::InstanceID;
1819
use opamp_client::opamp::proto::any_value::Value;
1920
use opamp_client::opamp::proto::{AnyValue, KeyValue, RemoteConfigStatuses};
20-
use std::str::FromStr;
2121
use std::time::Duration;
2222
use url::Url;
23-
2423
// These tests leverages an in-cluster chart repository populated with fixed versions which consist in the latest
2524
// released chart with a changed version.
2625
// The AC image corresponds to the compiled from the current code. Tilt is used to orchestrate all these
@@ -41,10 +40,6 @@ const MISSING_VERSION: &str = "9.9.9";
4140
const SECRET_NAME: &str = "ac-values";
4241
const VALUES_KEY: &str = "values.yaml";
4342

44-
// URL to access to services binded on ports from minikube host
45-
// https://minikube.sigs.k8s.io/docs/handbook/host-access/
46-
const MINIKUBE_HOST_ACCESS: &str = "host.minikube.internal";
47-
4843
#[test]
4944
#[ignore = "needs k8s cluster"]
5045
/// This test installs AC using the image from our public repository,
@@ -381,8 +376,7 @@ fn bootstrap_ac(
381376
namespace: &str,
382377
chart_version: &str,
383378
) -> InstanceID {
384-
let mut opamp_endpoint = Url::from_str(&opamp_server.endpoint()).unwrap();
385-
opamp_endpoint.set_host(Some(MINIKUBE_HOST_ACCESS)).unwrap();
379+
let opamp_endpoint = get_minikube_opamp_url_from_fake_server(opamp_server.endpoint().as_str());
386380

387381
print_pod_logs(client.clone(), namespace, AC_LABEL_SELECTOR);
388382

agent-control/tests/k8s/tools/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ pub mod k8s_api;
1010
/// Provides a k8s testing environment.
1111
pub mod k8s_env;
1212
pub mod logs;
13+
pub mod opamp;
1314
/// Defines the Foo CRD to be created and used in testing k8s clusters.
1415
pub mod test_crd;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use std::str::FromStr;
2+
use url::Url;
3+
4+
// URL to access to services binded on ports from minikube host
5+
// https://minikube.sigs.k8s.io/docs/handbook/host-access/
6+
pub const MINIKUBE_HOST_ACCESS: &str = "host.minikube.internal";
7+
8+
pub fn get_minikube_opamp_url_from_fake_server(opamp_endpoint: &str) -> Url {
9+
let mut opamp_endpoint = Url::from_str(opamp_endpoint).unwrap();
10+
opamp_endpoint.set_host(Some(MINIKUBE_HOST_ACCESS)).unwrap();
11+
opamp_endpoint
12+
}

0 commit comments

Comments
 (0)