blob: 5bb0f600c0c1a79299f674c0308f79b3559be0ec [file] [log] [blame]
garciadeblas96b94f52024-07-08 16:18:21 +02001#######################################################################################
2# Copyright ETSI Contributors and Others.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#######################################################################################
17
18
19from pyrage import x25519
20import yaml
21import base64
22
23
24def gather_age_key(cluster):
25 pubkey = cluster.get("age_pubkey")
26 privkey = cluster.get("age_privkey")
27 # return both public and private key
28 return pubkey, privkey
29
30
31def generate_age_key():
32 ident = x25519.Identity.generate()
33 # gets the public key
34 pubkey = ident.to_public()
35 # gets the private key
36 privkey = str(ident)
37 # return both public and private key
38 return pubkey, privkey
39
40
garciadeblasdde3a312024-09-17 13:25:06 +020041async def create_cluster(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +020042 self.logger.info(f"create_cluster Enter. Operation {op_id}. Params: {op_params}")
43 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +020044
45 db_cluster = content["cluster"]
46 db_vim_account = content["vim_account"]
47
garciadeblas96b94f52024-07-08 16:18:21 +020048 workflow_template = "launcher-create-crossplane-cluster-and-bootstrap.j2"
49 workflow_name = f"create-cluster-{db_cluster['_id']}"
garciadeblas96b94f52024-07-08 16:18:21 +020050 cluster_name = db_cluster["git_name"].lower()
51
garciadeblas96b94f52024-07-08 16:18:21 +020052 # Get age key
53 public_key_new_cluster, private_key_new_cluster = gather_age_key(db_cluster)
garciadeblasdc805482025-02-04 16:08:51 +010054 # self.logger.debug(f"public_key_new_cluster={public_key_new_cluster}")
55 # self.logger.debug(f"private_key_new_cluster={private_key_new_cluster}")
garciadeblas96b94f52024-07-08 16:18:21 +020056
57 # Test kubectl connection
garciadeblas619a0a32025-02-06 13:34:37 +010058 self.logger.debug(f"Testing kubectl: {self._kubectl}")
59 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
60 self.logger.debug(
61 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
62 )
garciadeblas96b94f52024-07-08 16:18:21 +020063 self.logger.debug(self._kubectl._get_kubectl_version())
64
garciadeblasdde3a312024-09-17 13:25:06 +020065 # Create temporal secret with agekey
garciadeblas96b94f52024-07-08 16:18:21 +020066 secret_name = f"secret-age-{cluster_name}"
67 secret_namespace = "osm-workflows"
68 secret_key = "agekey"
69 secret_value = private_key_new_cluster
garciadeblasadb81e82024-11-08 01:11:46 +010070 try:
garciadeblas619a0a32025-02-06 13:34:37 +010071 self.logger.debug(f"Testing kubectl: {self._kubectl}")
72 self.logger.debug(
73 f"Testing kubectl configuration: {self._kubectl.configuration}"
74 )
75 self.logger.debug(
76 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
77 )
garciadeblasadb81e82024-11-08 01:11:46 +010078 await self.create_secret(
79 secret_name,
80 secret_namespace,
81 secret_key,
82 secret_value,
83 )
84 except Exception as e:
85 self.logger.info(f"Cannot create secret {secret_name}: {e}")
garciadeblasdc805482025-02-04 16:08:51 +010086 return False, f"Cannot create secret {secret_name}: {e}"
garciadeblas96b94f52024-07-08 16:18:21 +020087
88 # Additional params for the workflow
89 cluster_kustomization_name = cluster_name
90 osm_project_name = "osm_admin" # TODO: get project name from content
garciadeblasdde3a312024-09-17 13:25:06 +020091 vim_account_id = db_cluster["vim_account"]
92 providerconfig_name = f"{vim_account_id}-config"
93 vim_type = db_vim_account["vim_type"]
garciadeblas753b1e32024-11-06 12:56:33 +010094 if db_cluster.get("bootstrap", True):
95 skip_bootstrap = "false"
96 else:
97 skip_bootstrap = "true"
garciadeblasdde3a312024-09-17 13:25:06 +020098 if vim_type == "azure":
99 cluster_type = "aks"
100 elif vim_type == "aws":
101 cluster_type = "eks"
102 elif vim_type == "gcp":
103 cluster_type = "gke"
garciadeblas96b94f52024-07-08 16:18:21 +0200104 else:
garciadeblasdde3a312024-09-17 13:25:06 +0200105 raise Exception("Not suitable VIM account to register cluster")
garciadeblas96b94f52024-07-08 16:18:21 +0200106
107 # Render workflow
108 # workflow_kwargs = {
109 # "git_fleet_url": f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git",
110 # "git_sw_catalogs_url": f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git",
111 # }
112 # manifest = self.render_jinja_template(
113 # workflow_template,
114 # output_file=None,
115 # **workflow_kwargs
116 # )
117 manifest = self.render_jinja_template(
118 workflow_template,
119 output_file=None,
120 workflow_name=workflow_name,
121 git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git",
122 git_sw_catalogs_url=f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git",
123 cluster_name=cluster_name,
124 cluster_type=cluster_type,
125 cluster_kustomization_name=cluster_kustomization_name,
126 providerconfig_name=providerconfig_name,
127 public_key_mgmt=self._pubkey,
128 public_key_new_cluster=public_key_new_cluster,
129 secret_name_private_key_new_cluster=secret_name,
130 vm_size=db_cluster["node_size"],
131 node_count=db_cluster["node_count"],
132 k8s_version=db_cluster["k8s_version"],
133 cluster_location=db_cluster["region_name"],
134 osm_project_name=osm_project_name,
garciadeblasd84808e2024-11-18 17:10:00 +0100135 rg_name=db_cluster.get("resource_group", "''"),
136 preemptible_nodes=db_cluster.get("preemptible_nodes", "false"),
garciadeblas753b1e32024-11-06 12:56:33 +0100137 skip_bootstrap=skip_bootstrap,
garciadeblas96b94f52024-07-08 16:18:21 +0200138 workflow_debug=self._workflow_debug,
139 workflow_dry_run=self._workflow_dry_run,
140 )
141 self.logger.debug(f"Workflow manifest: {manifest}")
142
143 # Submit workflow
garciadeblas619a0a32025-02-06 13:34:37 +0100144 self.logger.debug(f"Testing kubectl: {self._kubectl}")
145 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
146 self.logger.debug(
147 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
148 )
garciadeblas96b94f52024-07-08 16:18:21 +0200149 self._kubectl.create_generic_object(
150 namespace="osm-workflows",
151 manifest_dict=yaml.safe_load(manifest),
152 api_group="argoproj.io",
153 api_plural="workflows",
154 api_version="v1alpha1",
155 )
garciadeblasadb81e82024-11-08 01:11:46 +0100156 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200157
garciadeblas96b94f52024-07-08 16:18:21 +0200158
159async def update_cluster(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200160 self.logger.info(f"update_cluster Enter. Operation {op_id}. Params: {op_params}")
161 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +0200162
163 db_cluster = content["cluster"]
164 db_vim_account = content["vim_account"]
garciadeblas73cd5a22024-11-06 10:45:22 +0100165 cluster_name = db_cluster["git_name"].lower()
garciadeblas96b94f52024-07-08 16:18:21 +0200166
167 workflow_template = "launcher-update-crossplane-cluster.j2"
garciadeblasc8c75d42024-11-13 12:36:13 +0100168 workflow_name = f"update-cluster-{op_id}"
garciadeblas96b94f52024-07-08 16:18:21 +0200169 # cluster_name = db_cluster["name"].lower()
garciadeblas96b94f52024-07-08 16:18:21 +0200170
171 # Get age key
172 public_key_cluster, private_key_cluster = gather_age_key(db_cluster)
173 self.logger.debug(f"public_key_new_cluster={public_key_cluster}")
174 self.logger.debug(f"private_key_new_cluster={private_key_cluster}")
175
176 # Create secret with agekey
177 secret_name = f"secret-age-{cluster_name}"
178 secret_namespace = "osm-workflows"
179 secret_key = "agekey"
180 secret_value = private_key_cluster
garciadeblasadb81e82024-11-08 01:11:46 +0100181 try:
garciadeblas619a0a32025-02-06 13:34:37 +0100182 self.logger.debug(f"Testing kubectl: {self._kubectl}")
183 self.logger.debug(
184 f"Testing kubectl configuration: {self._kubectl.configuration}"
185 )
186 self.logger.debug(
187 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
188 )
garciadeblasadb81e82024-11-08 01:11:46 +0100189 await self.create_secret(
190 secret_name,
191 secret_namespace,
192 secret_key,
193 secret_value,
194 )
195 except Exception as e:
196 self.logger.info(f"Cannot create secret {secret_name}: {e}")
garciadeblasdc805482025-02-04 16:08:51 +0100197 return False, f"Cannot create secret {secret_name}: {e}"
garciadeblas96b94f52024-07-08 16:18:21 +0200198
199 # Additional params for the workflow
200 cluster_kustomization_name = cluster_name
201 osm_project_name = "osm_admin" # TODO: get project name from db_cluster
202 vim_account_id = db_cluster["vim_account"]
203 providerconfig_name = f"{vim_account_id}-config"
204 vim_type = db_vim_account["vim_type"]
garciadeblas73cd5a22024-11-06 10:45:22 +0100205 vm_size = op_params.get("node_size", db_cluster["node_size"])
206 node_count = op_params.get("node_count", db_cluster["node_count"])
207 k8s_version = op_params.get("k8s_version", db_cluster["k8s_version"])
garciadeblas96b94f52024-07-08 16:18:21 +0200208 if vim_type == "azure":
209 cluster_type = "aks"
210 elif vim_type == "aws":
211 cluster_type = "eks"
212 elif vim_type == "gcp":
213 cluster_type = "gke"
214 else:
215 raise Exception("Not suitable VIM account to update cluster")
216
217 # Render workflow
218 manifest = self.render_jinja_template(
219 workflow_template,
220 output_file=None,
221 workflow_name=workflow_name,
222 git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git",
223 git_sw_catalogs_url=f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git",
224 cluster_name=cluster_name,
225 cluster_type=cluster_type,
226 cluster_kustomization_name=cluster_kustomization_name,
227 providerconfig_name=providerconfig_name,
228 public_key_mgmt=self._pubkey,
229 public_key_new_cluster=public_key_cluster,
230 secret_name_private_key_new_cluster=secret_name,
garciadeblas73cd5a22024-11-06 10:45:22 +0100231 vm_size=vm_size,
232 node_count=node_count,
233 k8s_version=k8s_version,
garciadeblas96b94f52024-07-08 16:18:21 +0200234 cluster_location=db_cluster["region_name"],
235 osm_project_name=osm_project_name,
garciadeblasd84808e2024-11-18 17:10:00 +0100236 rg_name=db_cluster.get("resource_group", "''"),
237 preemptible_nodes=db_cluster.get("preemptible_nodes", "false"),
garciadeblas96b94f52024-07-08 16:18:21 +0200238 workflow_debug=self._workflow_debug,
239 workflow_dry_run=self._workflow_dry_run,
240 )
241 self.logger.info(manifest)
242
243 # Submit workflow
garciadeblas619a0a32025-02-06 13:34:37 +0100244 self.logger.debug(f"Testing kubectl: {self._kubectl}")
245 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
246 self.logger.debug(
247 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
248 )
garciadeblas96b94f52024-07-08 16:18:21 +0200249 self._kubectl.create_generic_object(
250 namespace="osm-workflows",
251 manifest_dict=yaml.safe_load(manifest),
252 api_group="argoproj.io",
253 api_plural="workflows",
254 api_version="v1alpha1",
255 )
garciadeblasadb81e82024-11-08 01:11:46 +0100256 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200257
258
259async def delete_cluster(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200260 self.logger.info(f"delete_cluster Enter. Operation {op_id}. Params: {op_params}")
261 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +0200262
263 db_cluster = content["cluster"]
264
265 workflow_template = "launcher-delete-cluster.j2"
266 workflow_name = f"delete-cluster-{db_cluster['_id']}"
267 # cluster_name = db_cluster["name"].lower()
268 cluster_name = db_cluster["git_name"].lower()
269
270 # Additional params for the workflow
271 cluster_kustomization_name = cluster_name
272 osm_project_name = "osm_admin" # TODO: get project name from DB
273
274 # Render workflow
275 manifest = self.render_jinja_template(
276 workflow_template,
277 output_file=None,
278 workflow_name=workflow_name,
279 git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git",
280 git_sw_catalogs_url=f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git",
281 cluster_name=cluster_name,
282 cluster_kustomization_name=cluster_kustomization_name,
283 osm_project_name=osm_project_name,
284 workflow_debug=self._workflow_debug,
285 workflow_dry_run=self._workflow_dry_run,
286 )
287 self.logger.info(manifest)
288
289 # Submit workflow
garciadeblas619a0a32025-02-06 13:34:37 +0100290 self.logger.debug(f"Testing kubectl: {self._kubectl}")
291 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
292 self.logger.debug(
293 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
294 )
garciadeblas96b94f52024-07-08 16:18:21 +0200295 self._kubectl.create_generic_object(
296 namespace="osm-workflows",
297 manifest_dict=yaml.safe_load(manifest),
298 api_group="argoproj.io",
299 api_plural="workflows",
300 api_version="v1alpha1",
301 )
garciadeblasadb81e82024-11-08 01:11:46 +0100302 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200303
304
305async def register_cluster(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200306 self.logger.info(f"register_cluster Enter. Operation {op_id}. Params: {op_params}")
307 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +0200308
309 db_cluster = content["cluster"]
garciadeblas96b94f52024-07-08 16:18:21 +0200310 cluster_name = db_cluster["git_name"].lower()
311
garciadeblasdde3a312024-09-17 13:25:06 +0200312 workflow_template = "launcher-bootstrap-cluster.j2"
313 workflow_name = f"register-cluster-{db_cluster['_id']}"
314
315 # Get age key
316 public_key_new_cluster, private_key_new_cluster = gather_age_key(db_cluster)
317 self.logger.debug(f"public_key_new_cluster={public_key_new_cluster}")
318 self.logger.debug(f"private_key_new_cluster={private_key_new_cluster}")
319
320 # Create temporal secret with agekey
321 secret_name = f"secret-age-{cluster_name}"
322 secret_namespace = "osm-workflows"
323 secret_key = "agekey"
324 secret_value = private_key_new_cluster
garciadeblasadb81e82024-11-08 01:11:46 +0100325 try:
garciadeblas619a0a32025-02-06 13:34:37 +0100326 self.logger.debug(f"Testing kubectl: {self._kubectl}")
327 self.logger.debug(
328 f"Testing kubectl configuration: {self._kubectl.configuration}"
329 )
330 self.logger.debug(
331 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
332 )
garciadeblasadb81e82024-11-08 01:11:46 +0100333 await self.create_secret(
334 secret_name,
335 secret_namespace,
336 secret_key,
337 secret_value,
338 )
339 except Exception as e:
340 self.logger.info(
341 f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}"
342 )
garciadeblasdc805482025-02-04 16:08:51 +0100343 return (
344 False,
345 f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}",
346 )
garciadeblas96b94f52024-07-08 16:18:21 +0200347
garciadeblasdde3a312024-09-17 13:25:06 +0200348 # Create secret with kubeconfig
349 secret_name2 = f"kubeconfig-{cluster_name}"
350 secret_namespace2 = "managed-resources"
351 secret_key2 = "kubeconfig"
352 secret_value2 = yaml.safe_dump(
garciadeblasa82300f2024-11-18 10:24:26 +0100353 db_cluster["credentials"], indent=2, default_flow_style=False, sort_keys=False
garciadeblasdde3a312024-09-17 13:25:06 +0200354 )
garciadeblas91bb2c42024-11-12 11:17:12 +0100355 try:
garciadeblas619a0a32025-02-06 13:34:37 +0100356 self.logger.debug(f"Testing kubectl: {self._kubectl}")
357 self.logger.debug(
358 f"Testing kubectl configuration: {self._kubectl.configuration}"
359 )
360 self.logger.debug(
361 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
362 )
garciadeblas91bb2c42024-11-12 11:17:12 +0100363 await self.create_secret(
364 secret_name2,
365 secret_namespace2,
366 secret_key2,
367 secret_value2,
368 )
369 except Exception as e:
370 self.logger.info(
371 f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}"
372 )
garciadeblasdc805482025-02-04 16:08:51 +0100373 return (
374 False,
375 f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}",
376 )
garciadeblasdde3a312024-09-17 13:25:06 +0200377
378 # Additional params for the workflow
379 cluster_kustomization_name = cluster_name
380 osm_project_name = "osm_admin" # TODO: get project name from content
garciadeblasdde3a312024-09-17 13:25:06 +0200381
382 manifest = self.render_jinja_template(
383 workflow_template,
384 output_file=None,
385 workflow_name=workflow_name,
386 git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git",
387 git_sw_catalogs_url=f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git",
388 cluster_name=cluster_name,
389 cluster_kustomization_name=cluster_kustomization_name,
garciadeblasdde3a312024-09-17 13:25:06 +0200390 public_key_mgmt=self._pubkey,
391 public_key_new_cluster=public_key_new_cluster,
392 secret_name_private_key_new_cluster=secret_name,
393 osm_project_name=osm_project_name,
394 workflow_debug=self._workflow_debug,
395 workflow_dry_run=self._workflow_dry_run,
396 )
397 self.logger.debug(f"Workflow manifest: {manifest}")
398
399 # Submit workflow
garciadeblas619a0a32025-02-06 13:34:37 +0100400 self.logger.debug(f"Testing kubectl: {self._kubectl}")
401 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
402 self.logger.debug(
403 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
404 )
garciadeblasdde3a312024-09-17 13:25:06 +0200405 self._kubectl.create_generic_object(
406 namespace="osm-workflows",
407 manifest_dict=yaml.safe_load(manifest),
408 api_group="argoproj.io",
409 api_plural="workflows",
410 api_version="v1alpha1",
411 )
garciadeblasadb81e82024-11-08 01:11:46 +0100412 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200413
414
415async def deregister_cluster(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200416 self.logger.info(
417 f"deregister_cluster Enter. Operation {op_id}. Params: {op_params}"
418 )
419 # self.logger.debug(f"Content: {content}")
garciadeblasdde3a312024-09-17 13:25:06 +0200420
421 db_cluster = content["cluster"]
422 cluster_name = db_cluster["git_name"].lower()
423
424 workflow_template = "launcher-disconnect-flux-remote-cluster.j2"
425 workflow_name = f"deregister-cluster-{db_cluster['_id']}"
426
427 # Additional params for the workflow
428 cluster_kustomization_name = cluster_name
429 osm_project_name = "osm_admin" # TODO: get project name from DB
430
431 # Render workflow
432 manifest = self.render_jinja_template(
433 workflow_template,
434 output_file=None,
435 workflow_name=workflow_name,
436 git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git",
437 cluster_kustomization_name=cluster_kustomization_name,
438 osm_project_name=osm_project_name,
439 workflow_debug=self._workflow_debug,
440 workflow_dry_run=self._workflow_dry_run,
441 )
442 self.logger.info(manifest)
443
444 # Submit workflow
garciadeblas619a0a32025-02-06 13:34:37 +0100445 self.logger.debug(f"Testing kubectl: {self._kubectl}")
446 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
447 self.logger.debug(
448 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
449 )
garciadeblasdde3a312024-09-17 13:25:06 +0200450 self._kubectl.create_generic_object(
451 namespace="osm-workflows",
452 manifest_dict=yaml.safe_load(manifest),
453 api_group="argoproj.io",
454 api_plural="workflows",
455 api_version="v1alpha1",
456 )
garciadeblasadb81e82024-11-08 01:11:46 +0100457 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200458
459
460async def get_cluster_credentials(self, db_cluster):
461 """
462 returns the kubeconfig file of a K8s cluster in a dictionary
463 """
garciadeblas9e532812024-10-22 14:04:36 +0200464 self.logger.info("get_cluster_credentials Enter")
465 # self.logger.debug(f"Content: {db_cluster}")
garciadeblas96b94f52024-07-08 16:18:21 +0200466
467 secret_name = f"kubeconfig-{db_cluster['git_name'].lower()}"
468 secret_namespace = "managed-resources"
469 secret_key = "kubeconfig"
470
471 self.logger.info(f"Checking content of secret {secret_name} ...")
472 try:
473 returned_secret_data = await self._kubectl.get_secret_content(
474 name=secret_name,
475 namespace=secret_namespace,
476 )
477 returned_secret_value = base64.b64decode(
478 returned_secret_data[secret_key]
479 ).decode("utf-8")
480 return True, yaml.safe_load(returned_secret_value)
481 except Exception as e:
482 message = f"Not possible to get the credentials of the cluster. Exception: {e}"
483 self.logger.critical(message)
484 return False, message
485
486
garciadeblas28bff0f2024-09-16 12:53:07 +0200487async def clean_items_cluster_create(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200488 self.logger.info(
489 f"clean_items_cluster_create Enter. Operation {op_id}. Params: {op_params}"
490 )
491 self.logger.debug(f"Content: {content}")
garciadeblas28bff0f2024-09-16 12:53:07 +0200492 items = {
493 "secrets": [
494 {
495 "name": f"secret-age-{content['cluster']['git_name'].lower()}",
496 "namespace": "osm-workflows",
497 }
498 ]
499 }
500 try:
501 await self.clean_items(items)
502 return True, "OK"
503 except Exception as e:
504 return False, f"Error while cleaning items: {e}"
505
506
507async def clean_items_cluster_update(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200508 self.logger.info(
509 f"clean_items_cluster_update Enter. Operation {op_id}. Params: {op_params}"
510 )
511 # self.logger.debug(f"Content: {content}")
garciadeblas28bff0f2024-09-16 12:53:07 +0200512 return await self.clean_items_cluster_create(op_id, op_params, content)
513
514
garciadeblasdde3a312024-09-17 13:25:06 +0200515async def clean_items_cluster_register(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200516 self.logger.info(
517 f"clean_items_cluster_register Enter. Operation {op_id}. Params: {op_params}"
518 )
519 # self.logger.debug(f"Content: {content}")
garciadeblasdde3a312024-09-17 13:25:06 +0200520 # Clean secrets
521 cluster_name = content["cluster"]["git_name"].lower()
522 items = {
523 "secrets": [
524 {
525 "name": f"secret-age-{cluster_name}",
526 "namespace": "osm-workflows",
527 },
528 ]
529 }
530
531 try:
532 await self.clean_items(items)
garciadeblas28d6e692024-10-15 13:14:39 +0200533 return True, "OK"
garciadeblasdde3a312024-09-17 13:25:06 +0200534 except Exception as e:
535 return False, f"Error while cleaning items: {e}"
garciadeblas91bb2c42024-11-12 11:17:12 +0100536
537
538async def clean_items_cluster_deregister(self, op_id, op_params, content):
539 self.logger.info(
540 f"clean_items_cluster_deregister Enter. Operation {op_id}. Params: {op_params}"
541 )
542 # self.logger.debug(f"Content: {content}")
543 # Clean secrets
544 self.logger.info("Cleaning kubeconfig")
545 cluster_name = content["cluster"]["git_name"].lower()
546 items = {
547 "secrets": [
548 {
549 "name": f"kubeconfig-{cluster_name}",
550 "namespace": "managed-resources",
551 },
552 ]
553 }
554
555 try:
556 await self.clean_items(items)
557 return True, "OK"
558 except Exception as e:
559 return False, f"Error while cleaning items: {e}"