Skip to content

Commit 1a4bd62

Browse files
test(k8s): flux self-update harness (NR-436895) (#1512)
* test(k8s): flux install/update test --------- Co-authored-by: Paolo Gallina <paologallina1992@gmail.com>
1 parent 33763f2 commit 1a4bd62

File tree

13 files changed

+436
-45
lines changed

13 files changed

+436
-45
lines changed

.github/workflows/push_pr_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ jobs:
146146
strategy:
147147
fail-fast: false
148148
matrix:
149-
group: [ part1, part2 ]
149+
group: [ part1, part2, flux-self-update ]
150150
steps:
151151
- uses: actions/checkout@v4
152152
with:

agent-control/Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,19 @@ test/k8s/integration-part1:
4545
cargo test k8s::scenarios -- --nocapture --ignored --test-threads=1
4646
cargo test k8s::agent_control_cli -- --nocapture --ignored --test-threads=1
4747

48+
# Flux upgrade tests require isolated test environments with Flux installed.
49+
# This installs an initial Flux instance with CRDs that only reconciles the default namespace,
50+
# allowing each test to create its own namespace with a separate Flux instance.
51+
.PHONY: test/k8s/integration-flux-self-update
52+
test/k8s/integration-flux-self-update:
53+
KUBECONFIG='./tests/k8s/.kubeconfig-dev' minikube update-context
54+
WATCH_ALL_NAMESPACES=false tilt ci --file ./tests/k8s/Tiltfile
55+
cargo test k8s::flux_self_update -- --nocapture --ignored --test-threads=1
56+
4857
.PHONY: test/k8s/integration-part2
4958
test/k8s/integration-part2:
5059
KUBECONFIG='./tests/k8s/.kubeconfig-dev' minikube update-context
51-
ENABLE_VAULT=true tilt ci --file ./tests/k8s/Tiltfile
60+
tilt ci --file ./tests/k8s/Tiltfile
5261
# reducing the number of threads to 1 forces the tests to run sequentially
5362
# We use this approach to split the k8s tests into two parts. We need to update it if this takes too long to run.
54-
cargo test k8s_ -- --skip k8s::scenarios --skip k8s::agent_control_cli --nocapture --ignored --test-threads=1
63+
cargo test k8s_ -- --skip k8s::scenarios --skip k8s::agent_control_cli --skip k8s::flux_self_update --nocapture --ignored --test-threads=1

agent-control/tests/common/retry.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,20 @@ where
1717
}
1818
last_err.unwrap_or_else(|err| panic!("retry failed after {max_attempts} attempts: {err}"))
1919
}
20+
21+
/// DeferredCommand is a struct that allows you to register a cleanup function that is executed on Drop.
22+
pub struct DeferredCommand {
23+
cleanup_fn: Box<dyn Fn()>,
24+
}
25+
26+
impl DeferredCommand {
27+
pub fn new(cleanup_fn: Box<dyn Fn()>) -> Self {
28+
Self { cleanup_fn }
29+
}
30+
}
31+
32+
impl Drop for DeferredCommand {
33+
fn drop(&mut self) {
34+
(self.cleanup_fn)()
35+
}
36+
}

agent-control/tests/k8s/Tiltfile

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ helm_repo(
1414
resource_name='newrelic-helm-repo',
1515
)
1616

17+
watch_all_namespaces = os.getenv('WATCH_ALL_NAMESPACES','true')
18+
19+
flags_helm = [
20+
# Each integration test runs on a different ephimeral namespace.
21+
'--set=agent-control-cd.flux2.watchAllNamespaces=' + watch_all_namespaces,
22+
'--set=agent-control-deployment.enabled=false',
23+
]
24+
1725
helm_resource(
1826
'flux',
1927
'newrelic/agent-control',
20-
namespace='default',
2128
release_name='flux',
2229
# workaround for https://github.com/tilt-dev/tilt/issues/6058
2330
pod_readiness='ignore',
2431
update_dependencies=False,
25-
flags=[
26-
'--create-namespace',
27-
'--version=>=0.0.0-beta',
28-
# Each integration test runs on a different ephimeral namespace.
29-
'--set=agent-control-cd.flux2.watchAllNamespaces=true',
30-
'--set=agent-control-deployment.enabled=false',
31-
],
32+
flags= flags_helm,
3233
resource_deps=['newrelic-helm-repo']
3334
)
3435

@@ -110,27 +111,43 @@ feature_branch = "master"
110111
# - 0.0.0-crash use an image executing exit 1
111112

112113

114+
local_resource(
115+
'clone-charts-repo',
116+
cmd="""rm -rf local/helm-charts-tmp && git clone --depth=1 https://github.com/newrelic/helm-charts --branch """ + feature_branch +""" local/helm-charts-tmp""",
117+
)
118+
119+
local_resource(
120+
'package-and-upload-ac-cd',
121+
cmd="""helm package --dependency-update --version "0.0.1-upstream" --destination local/helm-charts-tmp local/helm-charts-tmp/charts/agent-control-cd &&
122+
helm package --dependency-update --version "0.0.2-upstream" --destination local/helm-charts-tmp local/helm-charts-tmp/charts/agent-control-cd &&
123+
curl -X DELETE http://localhost:8080/api/charts/agent-control-cd/0.0.1-upstream &&
124+
curl -X DELETE http://localhost:8080/api/charts/agent-control-cd/0.0.2-upstream &&
125+
curl --data-binary "@local/helm-charts-tmp/agent-control-cd-0.0.1-upstream.tgz" http://localhost:8080/api/charts &&
126+
curl --data-binary "@local/helm-charts-tmp/agent-control-cd-0.0.2-upstream.tgz" http://localhost:8080/api/charts
127+
""",
128+
resource_deps=['chartmuseum','clone-charts-repo'],
129+
)
130+
113131
local_resource(
114132
'package-and-upload-remote-image-chart',
115-
cmd="""rm -rf local/helm-charts-tmp && git clone --depth=1 https://github.com/newrelic/helm-charts --branch """ + feature_branch +""" local/helm-charts-tmp &&
116-
helm package --dependency-update --version "0.0.0-latest-released" --destination local local/helm-charts-tmp/charts/agent-control-deployment &&
133+
cmd="""helm package --dependency-update --version "0.0.0-latest-released" --destination local/helm-charts-tmp local/helm-charts-tmp/charts/agent-control-deployment &&
117134
curl -X DELETE http://localhost:8080/api/charts/agent-control-deployment/0.0.0-latest-released &&
118-
curl --data-binary "@local/agent-control-deployment-0.0.0-latest-released.tgz" http://localhost:8080/api/charts
135+
curl --data-binary "@local/helm-charts-tmp/agent-control-deployment-0.0.0-latest-released.tgz" http://localhost:8080/api/charts
119136
""",
120-
resource_deps=['chartmuseum'],
137+
resource_deps=['package-and-upload-ac-cd'],
121138
)
122139

123140
# We are modifying the default image to tilt.local/ac-dev:dev.
124141
local_resource(
125142
'package-and-upload-local-image-chart',
126143
cmd="""yq eval ".image.repository = \\"tilt.local/ac-dev\\"" -i local/helm-charts-tmp/charts/agent-control-deployment/values.yaml &&
127144
yq eval ".image.tag = \\"dev\\"" -i local/helm-charts-tmp/charts/agent-control-deployment/values.yaml &&
128-
helm package --dependency-update --version "0.0.1-dev" --destination local local/helm-charts-tmp/charts/agent-control-deployment &&
129-
helm package --dependency-update --version "0.0.2-dev" --destination local local/helm-charts-tmp/charts/agent-control-deployment &&
145+
helm package --dependency-update --version "0.0.1-dev" --destination local/helm-charts-tmp local/helm-charts-tmp/charts/agent-control-deployment &&
146+
helm package --dependency-update --version "0.0.2-dev" --destination local/helm-charts-tmp local/helm-charts-tmp/charts/agent-control-deployment &&
130147
curl -X DELETE http://localhost:8080/api/charts/agent-control-deployment/0.0.1-dev &&
131148
curl -X DELETE http://localhost:8080/api/charts/agent-control-deployment/0.0.2-dev &&
132-
curl --data-binary "@local/agent-control-deployment-0.0.1-dev.tgz" http://localhost:8080/api/charts &&
133-
curl --data-binary "@local/agent-control-deployment-0.0.2-dev.tgz" http://localhost:8080/api/charts
149+
curl --data-binary "@local/helm-charts-tmp/agent-control-deployment-0.0.1-dev.tgz" http://localhost:8080/api/charts &&
150+
curl --data-binary "@local/helm-charts-tmp/agent-control-deployment-0.0.2-dev.tgz" http://localhost:8080/api/charts
134151
""",
135152
resource_deps=['package-and-upload-remote-image-chart'],
136153
)
@@ -143,9 +160,9 @@ local_resource(
143160
yq eval ".image.tag = \\"latest\\"" -i local/helm-charts-tmp/charts/agent-control-deployment/values.yaml &&
144161
yq eval ".image.command = [\\"sh\\", \\"-c\\", \\"exit 1\\"]" -i local/helm-charts-tmp/charts/agent-control-deployment/values.yaml &&
145162
yq eval ".podLabels.app = \\"failing-pod\\"" -i local/helm-charts-tmp/charts/agent-control-deployment/values.yaml &&
146-
helm package --dependency-update --version "0.0.0-crash" --destination local local/helm-charts-tmp/charts/agent-control-deployment &&
163+
helm package --dependency-update --version "0.0.0-crash" --destination local/helm-charts-tmp local/helm-charts-tmp/charts/agent-control-deployment &&
147164
curl -X DELETE http://localhost:8080/api/charts/agent-control-deployment/0.0.0-crash &&
148-
curl --data-binary "@local/agent-control-deployment-0.0.0-crash.tgz" http://localhost:8080/api/charts
165+
curl --data-binary "@local/helm-charts-tmp/agent-control-deployment-0.0.0-crash.tgz" http://localhost:8080/api/charts
149166
""",
150167
resource_deps=['package-and-upload-local-image-chart'],
151168
)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::k8s::tools::cmd::{assert_stdout_contains, print_cli_output};
44
use crate::k8s::tools::k8s_api::create_values_secret;
55
use crate::k8s::tools::k8s_env::K8sEnv;
66
use crate::k8s::tools::local_chart::{
7-
CHART_VERSION_LATEST_RELEASE, LOCAL_CHART_REPOSITORY, MISSING_VERSION,
7+
LOCAL_CHART_REPOSITORY,
8+
agent_control_deploymet::{CHART_VERSION_LATEST_RELEASE, MISSING_VERSION},
89
};
910
use crate::k8s::tools::opamp::get_minikube_opamp_url_from_fake_server;
1011
use assert_cmd::Command;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::k8s::agent_control_cli::installation::ac_install_cmd;
44
use crate::k8s::tools::cmd::print_cli_output;
55
use crate::k8s::tools::k8s_api::create_values_secret;
66
use crate::k8s::tools::k8s_env::K8sEnv;
7-
use crate::k8s::tools::local_chart::CHART_VERSION_LATEST_RELEASE;
7+
use crate::k8s::tools::local_chart::agent_control_deploymet::CHART_VERSION_LATEST_RELEASE;
88
use crate::k8s::tools::logs::{AC_LABEL_SELECTOR, print_pod_logs};
99
use assert_cmd::Command;
1010
use k8s_openapi::api::apps::v1::Deployment;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::k8s::agent_control_cli::installation::{ac_install_cmd, create_simple_
55
use crate::k8s::tools::cmd::print_cli_output;
66
use crate::k8s::tools::instance_id;
77
use crate::k8s::tools::k8s_env::K8sEnv;
8-
use crate::k8s::tools::local_chart::{
8+
use crate::k8s::tools::local_chart::agent_control_deploymet::{
99
CHART_VERSION_DEV_1, CHART_VERSION_DEV_2, CHART_VERSION_LATEST_RELEASE,
1010
};
1111
use crate::k8s::tools::logs::print_pod_logs;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
k8s:
2+
namespace: <ns>
3+
namespace_agents: <agents-ns>
4+
cluster_name: <cluster-name>
5+
cd_remote_update: true
6+
ac_remote_update: false
7+
cd_release_name: agent-control-cd
8+
fleet_control:
9+
endpoint: <opamp-endpoint>
10+
poll_interval: 5s
11+
signature_validation:
12+
certificate_pem_file_path: <cert-path>
13+
agents: {}

0 commit comments

Comments
 (0)