blob: c5ea6c00a90dc4dbbef0f86f60cf6c286a1f2088 [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
garciadeblas96b94f52024-07-08 16:18:21 +020019import yaml
20import base64
21
22
23def gather_age_key(cluster):
24 pubkey = cluster.get("age_pubkey")
25 privkey = cluster.get("age_privkey")
26 # return both public and private key
27 return pubkey, privkey
28
29
garciadeblasdde3a312024-09-17 13:25:06 +020030async def create_cluster(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +020031 self.logger.info(f"create_cluster Enter. Operation {op_id}. Params: {op_params}")
32 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +020033
34 db_cluster = content["cluster"]
35 db_vim_account = content["vim_account"]
36
garciadeblas96b94f52024-07-08 16:18:21 +020037 workflow_template = "launcher-create-crossplane-cluster-and-bootstrap.j2"
38 workflow_name = f"create-cluster-{db_cluster['_id']}"
garciadeblas96b94f52024-07-08 16:18:21 +020039 cluster_name = db_cluster["git_name"].lower()
40
garciadeblas96b94f52024-07-08 16:18:21 +020041 # Get age key
42 public_key_new_cluster, private_key_new_cluster = gather_age_key(db_cluster)
garciadeblasdc805482025-02-04 16:08:51 +010043 # self.logger.debug(f"public_key_new_cluster={public_key_new_cluster}")
44 # self.logger.debug(f"private_key_new_cluster={private_key_new_cluster}")
garciadeblas96b94f52024-07-08 16:18:21 +020045
46 # Test kubectl connection
garciadeblas619a0a32025-02-06 13:34:37 +010047 self.logger.debug(f"Testing kubectl: {self._kubectl}")
48 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
49 self.logger.debug(
50 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
51 )
garciadeblas96b94f52024-07-08 16:18:21 +020052 self.logger.debug(self._kubectl._get_kubectl_version())
53
garciadeblasdde3a312024-09-17 13:25:06 +020054 # Create temporal secret with agekey
garciadeblas96b94f52024-07-08 16:18:21 +020055 secret_name = f"secret-age-{cluster_name}"
56 secret_namespace = "osm-workflows"
57 secret_key = "agekey"
58 secret_value = private_key_new_cluster
garciadeblasadb81e82024-11-08 01:11:46 +010059 try:
garciadeblas619a0a32025-02-06 13:34:37 +010060 self.logger.debug(f"Testing kubectl: {self._kubectl}")
61 self.logger.debug(
62 f"Testing kubectl configuration: {self._kubectl.configuration}"
63 )
64 self.logger.debug(
65 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
66 )
garciadeblasadb81e82024-11-08 01:11:46 +010067 await self.create_secret(
68 secret_name,
69 secret_namespace,
70 secret_key,
71 secret_value,
72 )
73 except Exception as e:
74 self.logger.info(f"Cannot create secret {secret_name}: {e}")
garciadeblasdc805482025-02-04 16:08:51 +010075 return False, f"Cannot create secret {secret_name}: {e}"
garciadeblas96b94f52024-07-08 16:18:21 +020076
77 # Additional params for the workflow
78 cluster_kustomization_name = cluster_name
79 osm_project_name = "osm_admin" # TODO: get project name from content
garciadeblasdde3a312024-09-17 13:25:06 +020080 vim_account_id = db_cluster["vim_account"]
81 providerconfig_name = f"{vim_account_id}-config"
82 vim_type = db_vim_account["vim_type"]
garciadeblas753b1e32024-11-06 12:56:33 +010083 if db_cluster.get("bootstrap", True):
84 skip_bootstrap = "false"
85 else:
86 skip_bootstrap = "true"
garciadeblasdde3a312024-09-17 13:25:06 +020087 if vim_type == "azure":
88 cluster_type = "aks"
89 elif vim_type == "aws":
90 cluster_type = "eks"
91 elif vim_type == "gcp":
92 cluster_type = "gke"
garciadeblas96b94f52024-07-08 16:18:21 +020093 else:
garciadeblasdde3a312024-09-17 13:25:06 +020094 raise Exception("Not suitable VIM account to register cluster")
garciadeblas96b94f52024-07-08 16:18:21 +020095
96 # Render workflow
97 # workflow_kwargs = {
garciadeblas1c62c112025-05-26 15:29:46 +020098 # "git_fleet_url": self._repo_fleet_url,
99 # "git_sw_catalogs_url": self._repo_sw_catalogs_url,
garciadeblas96b94f52024-07-08 16:18:21 +0200100 # }
101 # manifest = self.render_jinja_template(
102 # workflow_template,
103 # output_file=None,
104 # **workflow_kwargs
105 # )
106 manifest = self.render_jinja_template(
107 workflow_template,
108 output_file=None,
109 workflow_name=workflow_name,
garciadeblas1c62c112025-05-26 15:29:46 +0200110 git_fleet_url=self._repo_fleet_url,
111 git_sw_catalogs_url=self._repo_sw_catalogs_url,
garciadeblas96b94f52024-07-08 16:18:21 +0200112 cluster_name=cluster_name,
113 cluster_type=cluster_type,
114 cluster_kustomization_name=cluster_kustomization_name,
115 providerconfig_name=providerconfig_name,
116 public_key_mgmt=self._pubkey,
117 public_key_new_cluster=public_key_new_cluster,
118 secret_name_private_key_new_cluster=secret_name,
119 vm_size=db_cluster["node_size"],
120 node_count=db_cluster["node_count"],
121 k8s_version=db_cluster["k8s_version"],
122 cluster_location=db_cluster["region_name"],
123 osm_project_name=osm_project_name,
garciadeblasd84808e2024-11-18 17:10:00 +0100124 rg_name=db_cluster.get("resource_group", "''"),
125 preemptible_nodes=db_cluster.get("preemptible_nodes", "false"),
garciadeblas753b1e32024-11-06 12:56:33 +0100126 skip_bootstrap=skip_bootstrap,
garciadeblas96b94f52024-07-08 16:18:21 +0200127 workflow_debug=self._workflow_debug,
128 workflow_dry_run=self._workflow_dry_run,
129 )
130 self.logger.debug(f"Workflow manifest: {manifest}")
131
132 # Submit workflow
garciadeblas619a0a32025-02-06 13:34:37 +0100133 self.logger.debug(f"Testing kubectl: {self._kubectl}")
134 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
135 self.logger.debug(
136 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
137 )
garciadeblas96b94f52024-07-08 16:18:21 +0200138 self._kubectl.create_generic_object(
139 namespace="osm-workflows",
140 manifest_dict=yaml.safe_load(manifest),
141 api_group="argoproj.io",
142 api_plural="workflows",
143 api_version="v1alpha1",
144 )
garciadeblasadb81e82024-11-08 01:11:46 +0100145 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200146
garciadeblas96b94f52024-07-08 16:18:21 +0200147
148async def update_cluster(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200149 self.logger.info(f"update_cluster Enter. Operation {op_id}. Params: {op_params}")
150 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +0200151
152 db_cluster = content["cluster"]
153 db_vim_account = content["vim_account"]
garciadeblas73cd5a22024-11-06 10:45:22 +0100154 cluster_name = db_cluster["git_name"].lower()
garciadeblas96b94f52024-07-08 16:18:21 +0200155
156 workflow_template = "launcher-update-crossplane-cluster.j2"
garciadeblasc8c75d42024-11-13 12:36:13 +0100157 workflow_name = f"update-cluster-{op_id}"
garciadeblas96b94f52024-07-08 16:18:21 +0200158 # cluster_name = db_cluster["name"].lower()
garciadeblas96b94f52024-07-08 16:18:21 +0200159
160 # Get age key
161 public_key_cluster, private_key_cluster = gather_age_key(db_cluster)
162 self.logger.debug(f"public_key_new_cluster={public_key_cluster}")
163 self.logger.debug(f"private_key_new_cluster={private_key_cluster}")
164
165 # Create secret with agekey
166 secret_name = f"secret-age-{cluster_name}"
167 secret_namespace = "osm-workflows"
168 secret_key = "agekey"
169 secret_value = private_key_cluster
garciadeblasadb81e82024-11-08 01:11:46 +0100170 try:
garciadeblas619a0a32025-02-06 13:34:37 +0100171 self.logger.debug(f"Testing kubectl: {self._kubectl}")
172 self.logger.debug(
173 f"Testing kubectl configuration: {self._kubectl.configuration}"
174 )
175 self.logger.debug(
176 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
177 )
garciadeblasadb81e82024-11-08 01:11:46 +0100178 await self.create_secret(
179 secret_name,
180 secret_namespace,
181 secret_key,
182 secret_value,
183 )
184 except Exception as e:
185 self.logger.info(f"Cannot create secret {secret_name}: {e}")
garciadeblasdc805482025-02-04 16:08:51 +0100186 return False, f"Cannot create secret {secret_name}: {e}"
garciadeblas96b94f52024-07-08 16:18:21 +0200187
188 # Additional params for the workflow
189 cluster_kustomization_name = cluster_name
190 osm_project_name = "osm_admin" # TODO: get project name from db_cluster
191 vim_account_id = db_cluster["vim_account"]
192 providerconfig_name = f"{vim_account_id}-config"
193 vim_type = db_vim_account["vim_type"]
garciadeblas73cd5a22024-11-06 10:45:22 +0100194 vm_size = op_params.get("node_size", db_cluster["node_size"])
195 node_count = op_params.get("node_count", db_cluster["node_count"])
196 k8s_version = op_params.get("k8s_version", db_cluster["k8s_version"])
garciadeblas96b94f52024-07-08 16:18:21 +0200197 if vim_type == "azure":
198 cluster_type = "aks"
199 elif vim_type == "aws":
200 cluster_type = "eks"
201 elif vim_type == "gcp":
202 cluster_type = "gke"
203 else:
204 raise Exception("Not suitable VIM account to update cluster")
205
206 # Render workflow
207 manifest = self.render_jinja_template(
208 workflow_template,
209 output_file=None,
210 workflow_name=workflow_name,
garciadeblas1c62c112025-05-26 15:29:46 +0200211 git_fleet_url=self._repo_fleet_url,
212 git_sw_catalogs_url=self._repo_sw_catalogs_url,
garciadeblas96b94f52024-07-08 16:18:21 +0200213 cluster_name=cluster_name,
214 cluster_type=cluster_type,
215 cluster_kustomization_name=cluster_kustomization_name,
216 providerconfig_name=providerconfig_name,
217 public_key_mgmt=self._pubkey,
218 public_key_new_cluster=public_key_cluster,
219 secret_name_private_key_new_cluster=secret_name,
garciadeblas73cd5a22024-11-06 10:45:22 +0100220 vm_size=vm_size,
221 node_count=node_count,
222 k8s_version=k8s_version,
garciadeblas96b94f52024-07-08 16:18:21 +0200223 cluster_location=db_cluster["region_name"],
224 osm_project_name=osm_project_name,
garciadeblasd84808e2024-11-18 17:10:00 +0100225 rg_name=db_cluster.get("resource_group", "''"),
226 preemptible_nodes=db_cluster.get("preemptible_nodes", "false"),
garciadeblas96b94f52024-07-08 16:18:21 +0200227 workflow_debug=self._workflow_debug,
228 workflow_dry_run=self._workflow_dry_run,
229 )
230 self.logger.info(manifest)
231
232 # Submit workflow
garciadeblas619a0a32025-02-06 13:34:37 +0100233 self.logger.debug(f"Testing kubectl: {self._kubectl}")
234 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
235 self.logger.debug(
236 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
237 )
garciadeblas96b94f52024-07-08 16:18:21 +0200238 self._kubectl.create_generic_object(
239 namespace="osm-workflows",
240 manifest_dict=yaml.safe_load(manifest),
241 api_group="argoproj.io",
242 api_plural="workflows",
243 api_version="v1alpha1",
244 )
garciadeblasadb81e82024-11-08 01:11:46 +0100245 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200246
247
248async def delete_cluster(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200249 self.logger.info(f"delete_cluster Enter. Operation {op_id}. Params: {op_params}")
250 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +0200251
252 db_cluster = content["cluster"]
253
254 workflow_template = "launcher-delete-cluster.j2"
255 workflow_name = f"delete-cluster-{db_cluster['_id']}"
256 # cluster_name = db_cluster["name"].lower()
257 cluster_name = db_cluster["git_name"].lower()
258
259 # Additional params for the workflow
260 cluster_kustomization_name = cluster_name
261 osm_project_name = "osm_admin" # TODO: get project name from DB
262
263 # Render workflow
264 manifest = self.render_jinja_template(
265 workflow_template,
266 output_file=None,
267 workflow_name=workflow_name,
garciadeblas1c62c112025-05-26 15:29:46 +0200268 git_fleet_url=self._repo_fleet_url,
269 git_sw_catalogs_url=self._repo_sw_catalogs_url,
garciadeblas96b94f52024-07-08 16:18:21 +0200270 cluster_name=cluster_name,
271 cluster_kustomization_name=cluster_kustomization_name,
272 osm_project_name=osm_project_name,
273 workflow_debug=self._workflow_debug,
274 workflow_dry_run=self._workflow_dry_run,
275 )
276 self.logger.info(manifest)
277
278 # Submit workflow
garciadeblas619a0a32025-02-06 13:34:37 +0100279 self.logger.debug(f"Testing kubectl: {self._kubectl}")
280 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
281 self.logger.debug(
282 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
283 )
garciadeblas96b94f52024-07-08 16:18:21 +0200284 self._kubectl.create_generic_object(
285 namespace="osm-workflows",
286 manifest_dict=yaml.safe_load(manifest),
287 api_group="argoproj.io",
288 api_plural="workflows",
289 api_version="v1alpha1",
290 )
garciadeblasadb81e82024-11-08 01:11:46 +0100291 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200292
293
294async def register_cluster(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200295 self.logger.info(f"register_cluster Enter. Operation {op_id}. Params: {op_params}")
296 # self.logger.debug(f"Content: {content}")
garciadeblas96b94f52024-07-08 16:18:21 +0200297
298 db_cluster = content["cluster"]
garciadeblas96b94f52024-07-08 16:18:21 +0200299 cluster_name = db_cluster["git_name"].lower()
300
garciadeblasdde3a312024-09-17 13:25:06 +0200301 workflow_template = "launcher-bootstrap-cluster.j2"
302 workflow_name = f"register-cluster-{db_cluster['_id']}"
303
304 # Get age key
305 public_key_new_cluster, private_key_new_cluster = gather_age_key(db_cluster)
306 self.logger.debug(f"public_key_new_cluster={public_key_new_cluster}")
307 self.logger.debug(f"private_key_new_cluster={private_key_new_cluster}")
308
309 # Create temporal secret with agekey
310 secret_name = f"secret-age-{cluster_name}"
311 secret_namespace = "osm-workflows"
312 secret_key = "agekey"
313 secret_value = private_key_new_cluster
garciadeblasadb81e82024-11-08 01:11:46 +0100314 try:
garciadeblas619a0a32025-02-06 13:34:37 +0100315 self.logger.debug(f"Testing kubectl: {self._kubectl}")
316 self.logger.debug(
317 f"Testing kubectl configuration: {self._kubectl.configuration}"
318 )
319 self.logger.debug(
320 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
321 )
garciadeblasadb81e82024-11-08 01:11:46 +0100322 await self.create_secret(
323 secret_name,
324 secret_namespace,
325 secret_key,
326 secret_value,
327 )
328 except Exception as e:
329 self.logger.info(
330 f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}"
331 )
garciadeblasdc805482025-02-04 16:08:51 +0100332 return (
333 False,
334 f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}",
335 )
garciadeblas96b94f52024-07-08 16:18:21 +0200336
garciadeblasdde3a312024-09-17 13:25:06 +0200337 # Create secret with kubeconfig
338 secret_name2 = f"kubeconfig-{cluster_name}"
339 secret_namespace2 = "managed-resources"
340 secret_key2 = "kubeconfig"
341 secret_value2 = yaml.safe_dump(
garciadeblasa82300f2024-11-18 10:24:26 +0100342 db_cluster["credentials"], indent=2, default_flow_style=False, sort_keys=False
garciadeblasdde3a312024-09-17 13:25:06 +0200343 )
garciadeblas91bb2c42024-11-12 11:17:12 +0100344 try:
garciadeblas619a0a32025-02-06 13:34:37 +0100345 self.logger.debug(f"Testing kubectl: {self._kubectl}")
346 self.logger.debug(
347 f"Testing kubectl configuration: {self._kubectl.configuration}"
348 )
349 self.logger.debug(
350 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
351 )
garciadeblas91bb2c42024-11-12 11:17:12 +0100352 await self.create_secret(
353 secret_name2,
354 secret_namespace2,
355 secret_key2,
356 secret_value2,
357 )
358 except Exception as e:
359 self.logger.info(
360 f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}"
361 )
garciadeblasdc805482025-02-04 16:08:51 +0100362 return (
363 False,
364 f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}",
365 )
garciadeblasdde3a312024-09-17 13:25:06 +0200366
367 # Additional params for the workflow
368 cluster_kustomization_name = cluster_name
369 osm_project_name = "osm_admin" # TODO: get project name from content
garciadeblasdde3a312024-09-17 13:25:06 +0200370
371 manifest = self.render_jinja_template(
372 workflow_template,
373 output_file=None,
374 workflow_name=workflow_name,
garciadeblas1c62c112025-05-26 15:29:46 +0200375 git_fleet_url=self._repo_fleet_url,
376 git_sw_catalogs_url=self._repo_sw_catalogs_url,
garciadeblasdde3a312024-09-17 13:25:06 +0200377 cluster_name=cluster_name,
378 cluster_kustomization_name=cluster_kustomization_name,
garciadeblasdde3a312024-09-17 13:25:06 +0200379 public_key_mgmt=self._pubkey,
380 public_key_new_cluster=public_key_new_cluster,
381 secret_name_private_key_new_cluster=secret_name,
382 osm_project_name=osm_project_name,
383 workflow_debug=self._workflow_debug,
384 workflow_dry_run=self._workflow_dry_run,
385 )
386 self.logger.debug(f"Workflow manifest: {manifest}")
387
388 # Submit workflow
garciadeblas619a0a32025-02-06 13:34:37 +0100389 self.logger.debug(f"Testing kubectl: {self._kubectl}")
390 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
391 self.logger.debug(
392 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
393 )
garciadeblasdde3a312024-09-17 13:25:06 +0200394 self._kubectl.create_generic_object(
395 namespace="osm-workflows",
396 manifest_dict=yaml.safe_load(manifest),
397 api_group="argoproj.io",
398 api_plural="workflows",
399 api_version="v1alpha1",
400 )
garciadeblasadb81e82024-11-08 01:11:46 +0100401 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200402
403
404async def deregister_cluster(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200405 self.logger.info(
406 f"deregister_cluster Enter. Operation {op_id}. Params: {op_params}"
407 )
408 # self.logger.debug(f"Content: {content}")
garciadeblasdde3a312024-09-17 13:25:06 +0200409
410 db_cluster = content["cluster"]
411 cluster_name = db_cluster["git_name"].lower()
412
413 workflow_template = "launcher-disconnect-flux-remote-cluster.j2"
414 workflow_name = f"deregister-cluster-{db_cluster['_id']}"
415
416 # Additional params for the workflow
417 cluster_kustomization_name = cluster_name
418 osm_project_name = "osm_admin" # TODO: get project name from DB
419
420 # Render workflow
421 manifest = self.render_jinja_template(
422 workflow_template,
423 output_file=None,
424 workflow_name=workflow_name,
garciadeblas1c62c112025-05-26 15:29:46 +0200425 git_fleet_url=self._repo_fleet_url,
garciadeblasdde3a312024-09-17 13:25:06 +0200426 cluster_kustomization_name=cluster_kustomization_name,
427 osm_project_name=osm_project_name,
428 workflow_debug=self._workflow_debug,
429 workflow_dry_run=self._workflow_dry_run,
430 )
431 self.logger.info(manifest)
432
433 # Submit workflow
garciadeblas619a0a32025-02-06 13:34:37 +0100434 self.logger.debug(f"Testing kubectl: {self._kubectl}")
435 self.logger.debug(f"Testing kubectl configuration: {self._kubectl.configuration}")
436 self.logger.debug(
437 f"Testing kubectl configuration Host: {self._kubectl.configuration.host}"
438 )
garciadeblasdde3a312024-09-17 13:25:06 +0200439 self._kubectl.create_generic_object(
440 namespace="osm-workflows",
441 manifest_dict=yaml.safe_load(manifest),
442 api_group="argoproj.io",
443 api_plural="workflows",
444 api_version="v1alpha1",
445 )
garciadeblasadb81e82024-11-08 01:11:46 +0100446 return True, workflow_name
garciadeblas96b94f52024-07-08 16:18:21 +0200447
448
449async def get_cluster_credentials(self, db_cluster):
450 """
451 returns the kubeconfig file of a K8s cluster in a dictionary
452 """
garciadeblas9e532812024-10-22 14:04:36 +0200453 self.logger.info("get_cluster_credentials Enter")
454 # self.logger.debug(f"Content: {db_cluster}")
garciadeblas96b94f52024-07-08 16:18:21 +0200455
456 secret_name = f"kubeconfig-{db_cluster['git_name'].lower()}"
457 secret_namespace = "managed-resources"
458 secret_key = "kubeconfig"
459
460 self.logger.info(f"Checking content of secret {secret_name} ...")
461 try:
462 returned_secret_data = await self._kubectl.get_secret_content(
463 name=secret_name,
464 namespace=secret_namespace,
465 )
466 returned_secret_value = base64.b64decode(
467 returned_secret_data[secret_key]
468 ).decode("utf-8")
469 return True, yaml.safe_load(returned_secret_value)
470 except Exception as e:
471 message = f"Not possible to get the credentials of the cluster. Exception: {e}"
472 self.logger.critical(message)
473 return False, message
474
475
garciadeblas28bff0f2024-09-16 12:53:07 +0200476async def clean_items_cluster_create(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200477 self.logger.info(
478 f"clean_items_cluster_create Enter. Operation {op_id}. Params: {op_params}"
479 )
480 self.logger.debug(f"Content: {content}")
garciadeblas28bff0f2024-09-16 12:53:07 +0200481 items = {
482 "secrets": [
483 {
484 "name": f"secret-age-{content['cluster']['git_name'].lower()}",
485 "namespace": "osm-workflows",
486 }
487 ]
488 }
489 try:
490 await self.clean_items(items)
491 return True, "OK"
492 except Exception as e:
493 return False, f"Error while cleaning items: {e}"
494
495
496async def clean_items_cluster_update(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200497 self.logger.info(
498 f"clean_items_cluster_update Enter. Operation {op_id}. Params: {op_params}"
499 )
500 # self.logger.debug(f"Content: {content}")
garciadeblas28bff0f2024-09-16 12:53:07 +0200501 return await self.clean_items_cluster_create(op_id, op_params, content)
502
503
garciadeblasdde3a312024-09-17 13:25:06 +0200504async def clean_items_cluster_register(self, op_id, op_params, content):
garciadeblas9e532812024-10-22 14:04:36 +0200505 self.logger.info(
506 f"clean_items_cluster_register Enter. Operation {op_id}. Params: {op_params}"
507 )
508 # self.logger.debug(f"Content: {content}")
garciadeblasdde3a312024-09-17 13:25:06 +0200509 # Clean secrets
510 cluster_name = content["cluster"]["git_name"].lower()
511 items = {
512 "secrets": [
513 {
514 "name": f"secret-age-{cluster_name}",
515 "namespace": "osm-workflows",
516 },
517 ]
518 }
519
520 try:
521 await self.clean_items(items)
garciadeblas28d6e692024-10-15 13:14:39 +0200522 return True, "OK"
garciadeblasdde3a312024-09-17 13:25:06 +0200523 except Exception as e:
524 return False, f"Error while cleaning items: {e}"
garciadeblas91bb2c42024-11-12 11:17:12 +0100525
526
527async def clean_items_cluster_deregister(self, op_id, op_params, content):
528 self.logger.info(
529 f"clean_items_cluster_deregister Enter. Operation {op_id}. Params: {op_params}"
530 )
531 # self.logger.debug(f"Content: {content}")
532 # Clean secrets
533 self.logger.info("Cleaning kubeconfig")
534 cluster_name = content["cluster"]["git_name"].lower()
535 items = {
536 "secrets": [
537 {
538 "name": f"kubeconfig-{cluster_name}",
539 "namespace": "managed-resources",
540 },
541 ]
542 }
543
544 try:
545 await self.clean_items(items)
546 return True, "OK"
547 except Exception as e:
548 return False, f"Error while cleaning items: {e}"