Skip to content

Commit eb7e77c

Browse files
authored
Fix name collision between cluster_id (run_plugin.py) and t8s HelmRelease name (#1261)
run_plugin.py sets config['name'] to the cluster_id for every plugin kind, so PluginT8s's use of the same key for the VAP/RBAC-mandated HelmRelease name never fell back to its intended value. Renamed to 'hrName', now set explicitly in clusters.yaml.j2 for each teuto entry instead of defaulted in code. Signed-off-by: Chris Werner Rau <cwrau@cwrau.info>
1 parent 514377b commit eb7e77c

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

Tests/kaas/plugin/plugin_t8s.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ class PluginT8s(KubernetesClusterPlugin):
2929
via a Flux HelmRelease.
3030
3131
Creates a HelmRelease on mgmt-bfe2-prod and waits for the resulting cluster's
32-
kubeconfig to appear in the secret '<name>-kubeconfig'.
32+
kubeconfig to appear in the secret '<hrName>-kubeconfig'.
33+
34+
Note: `config['name']` is set by run_plugin.py to the cluster_id (e.g. 'teuto-1.36')
35+
for all plugins; that is unrelated to the HelmRelease name below, which is why this
36+
plugin uses the distinct key `hrName` instead of reusing `name`.
3337
3438
Expected config keys:
3539
kubernetesVersion: '1.35' (major.minor)
@@ -38,8 +42,8 @@ class PluginT8s(KubernetesClusterPlugin):
3842
kubeconfig: t8s-kubeconfig.yaml (management cluster kubeconfig template)
3943
secrets:
4044
token: '{{ clouds_conf.teuto_mgmt_token }}'
41-
name: 'scs-kaas-certification' (optional, defaults to 'scs-kaas-certification';
42-
the kubeconfig secret name is derived as '<name>-kubeconfig')
45+
hrName: 'scs-kaas-certification' (the kubeconfig secret name is derived as
46+
'<hrName>-kubeconfig')
4347
cloud: 'bfe2-prod' (optional, defaults to 'bfe2-prod')
4448
controlPlaneHosted: true (optional, defaults to true)
4549
nodePools: (optional, defaults to a single 'pool-0')
@@ -62,7 +66,7 @@ def __init__(self, config: dict[str, Any], basepath: str = ".", cwd: str = ".")
6266
# and cannot be changed without updating both the VAP and the RBAC. They are instance
6367
# (rather than module-level) attributes because, in principle, different certification
6468
# targets could be configured with different values here.
65-
self.hr_name = config.get("name", "scs-kaas-certification")
69+
self.hr_name = config["hrName"]
6670
self.hr_namespace = "scs-kaas-certification"
6771
self.hr_kubeconfig_secret = f"{self.hr_name}-kubeconfig"
6872
self.hr_chart_ref: dict[str, str] = {

Tests/kaas/plugin/test_plugin_t8s.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def plugin(tmp_path):
3636
config = {
3737
"kubernetesVersion": "1.35",
3838
"version_patch": 2,
39+
"hrName": "scs-kaas-certification",
3940
"templates": {"kubeconfig": tpl.name},
4041
"secrets": {},
4142
}
@@ -136,6 +137,7 @@ def _make_plugin(tmp_path, **config_overrides):
136137
config = {
137138
"kubernetesVersion": "1.35",
138139
"version_patch": 2,
140+
"hrName": "scs-kaas-certification",
139141
"templates": {"kubeconfig": tpl.name},
140142
"secrets": {},
141143
**config_overrides,
@@ -175,14 +177,22 @@ def test_hr_name_defaults(plugin):
175177

176178

177179
def test_hr_name_from_config(tmp_path):
178-
plugin = _make_plugin(tmp_path, name="other-target")
180+
plugin = _make_plugin(tmp_path, hrName="other-target")
179181
assert plugin.hr_name == "other-target"
180182
assert plugin.hr_kubeconfig_secret == "other-target-kubeconfig"
181183

182184
hr = plugin._build_helmrelease()
183185
assert hr["metadata"]["name"] == "other-target"
184186

185187

188+
def test_hr_name_ignores_run_plugin_name(tmp_path):
189+
# run_plugin.py does config.setdefault('name', cluster_id) for every plugin kind;
190+
# that generic identifier must not leak into the (differently-keyed) HR name.
191+
plugin = _make_plugin(tmp_path, name="teuto-1.36")
192+
assert plugin.hr_name == "scs-kaas-certification"
193+
assert plugin.hr_kubeconfig_secret == "scs-kaas-certification-kubeconfig"
194+
195+
186196
# --- version parsing ---
187197

188198
@pytest.mark.parametrize("version,version_patch,expected", [
@@ -196,6 +206,7 @@ def test_version_parsing(tmp_path, version, version_patch, expected):
196206
config = {
197207
"kubernetesVersion": version,
198208
"version_patch": version_patch,
209+
"hrName": "scs-kaas-certification",
199210
"templates": {"kubeconfig": tpl.name},
200211
"secrets": {},
201212
}
@@ -209,6 +220,7 @@ def test_version_patch_defaults_to_zero(tmp_path):
209220
tpl.write_text(KUBECONFIG_TEMPLATE)
210221
config = {
211222
"kubernetesVersion": "1.35",
223+
"hrName": "scs-kaas-certification",
212224
"templates": {"kubeconfig": tpl.name},
213225
"secrets": {},
214226
}

playbooks/clusters.yaml.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ clusters:
214214
config:
215215
kubernetesVersion: '1.35'
216216
version_patch: 2
217+
hrName: scs-kaas-certification
217218
templates:
218219
kubeconfig: t8s-kubeconfig.yaml
219220
secrets:
@@ -223,6 +224,7 @@ clusters:
223224
config:
224225
kubernetesVersion: '1.36'
225226
version_patch: 0
227+
hrName: scs-kaas-certification
226228
templates:
227229
kubeconfig: t8s-kubeconfig.yaml
228230
secrets:

0 commit comments

Comments
 (0)