| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 1 | ####################################################################################### |
| 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 | |
| 19 | import yaml |
| 20 | |
| 21 | |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 22 | MAP_PROFILE = { |
| 23 | "infra_controller_profiles": "infra-controllers", |
| 24 | "infra_config_profiles": "infra-controllers", |
| 25 | "resource_profiles": "managed_resources", |
| 26 | "app_profiles": "apps", |
| 27 | } |
| 28 | |
| 29 | |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 30 | async def create_ksus(self, op_id, op_params_list, content_list): |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 31 | self.logger.info(f"create_ksus Enter. Operation {op_id}. Params: {op_params_list}") |
| 32 | # self.logger.debug(f"Content: {content_list}") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 33 | |
| 34 | if len(content_list) > 1: |
| 35 | raise Exception("There is no ODU workflow yet able to manage multiple KSUs") |
| 36 | db_ksu = content_list[0] |
| 37 | ksu_params = op_params_list[0] |
| 38 | oka_list = ksu_params["oka"] |
| 39 | if len(oka_list) > 1: |
| 40 | raise Exception( |
| 41 | "There is no ODU workflow yet able to manage multiple OKAs for a KSU" |
| 42 | ) |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 43 | oka_item = oka_list[0] |
| garciadeblas | 1b2933c | 2024-10-16 11:43:36 +0200 | [diff] [blame] | 44 | oka_params = oka_item.get("transformation", {}) |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 45 | if "sw_catalog_path" in oka_item: |
| 46 | oka_path = oka_item["sw_catalog_path"] |
| 47 | else: |
| 48 | oka_type = "infra-controllers" |
| 49 | oka_name = oka_item["git_name"] |
| 50 | oka_path = f"{oka_type}/{oka_name}/templates" |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 51 | |
| 52 | workflow_template = "launcher-create-ksu-hr.j2" |
| 53 | workflow_name = f"create-ksus-{op_id}" |
| 54 | ksu_name = db_ksu["git_name"].lower() |
| 55 | |
| 56 | # Additional params for the workflow |
| 57 | osm_project_name = "osm_admin" # TODO: get project name from db_ksu |
| 58 | kustomization_name = ksu_name |
| 59 | helmrelease_name = ksu_name |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 60 | profile_type = ksu_params.get("profile", {}).get("profile_type") |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 61 | profile_type = MAP_PROFILE[profile_type] |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 62 | profile_name = ksu_params.get("profile", {}).get("name") |
| 63 | age_public_key = ksu_params.get("profile", {}).get("age_pubkey") |
| garciadeblas | 1b2933c | 2024-10-16 11:43:36 +0200 | [diff] [blame] | 64 | target_ns = oka_params.get("namespace", "default") |
| 65 | substitute_environment = oka_params.get("substitute_environment", "false") |
| 66 | substitution_filter = oka_params.get("substitution_filter", "") |
| 67 | custom_env_vars = oka_params.get("custom_env_vars", "") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 68 | if custom_env_vars: |
| 69 | custom_env_vars = "|\n" + "\n".join( |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 70 | [" " * 10 + f"{k}={v}" for k, v in custom_env_vars.items()] |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 71 | ) |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 72 | else: |
| 73 | custom_env_vars = '""' |
| garciadeblas | 1b2933c | 2024-10-16 11:43:36 +0200 | [diff] [blame] | 74 | inline_values = oka_params.get("inline_values", "") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 75 | if inline_values: |
| 76 | yaml_string = yaml.safe_dump( |
| 77 | inline_values, sort_keys=False, default_flow_style=False |
| 78 | ) |
| 79 | inline_values = "|\n" + "\n".join( |
| 80 | [" " * 8 + line for line in yaml_string.splitlines()] |
| 81 | ) |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 82 | else: |
| 83 | inline_values = '""' |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 84 | is_preexisting_cm = "false" |
| garciadeblas | 1b2933c | 2024-10-16 11:43:36 +0200 | [diff] [blame] | 85 | cm_values = oka_params.get("configmap_values", "") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 86 | if cm_values: |
| 87 | yaml_string = yaml.safe_dump( |
| 88 | cm_values, sort_keys=False, default_flow_style=False |
| 89 | ) |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 90 | cm_values = "|\n" + "\n".join( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 91 | [" " * 8 + line for line in yaml_string.splitlines()] |
| 92 | ) |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 93 | values_configmap_name = f"cm-{ksu_name}" |
| 94 | cm_key = "values.yaml" |
| 95 | else: |
| 96 | values_configmap_name = "" |
| 97 | cm_key = "" |
| 98 | cm_values = '""' |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 99 | is_preexisting_secret = "false" |
| garciadeblas | 1b2933c | 2024-10-16 11:43:36 +0200 | [diff] [blame] | 100 | secret_values = oka_params.get("secret_values", "") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 101 | if secret_values: |
| 102 | values_secret_name = f"secret-{ksu_name}" |
| 103 | reference_secret_for_values = f"ref-secret-{ksu_name}" |
| 104 | reference_key_for_values = f"ref-key-{ksu_name}" |
| 105 | secret_values = yaml.safe_dump( |
| 106 | secret_values, sort_keys=False, default_flow_style=False |
| 107 | ) |
| 108 | else: |
| 109 | values_secret_name = "" |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 110 | reference_secret_for_values = "this-secret-does-not-exist" |
| 111 | reference_key_for_values = "this-key-does-not-exist" |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 112 | sync = "true" |
| 113 | |
| 114 | if secret_values: |
| 115 | secret_namespace = "osm-workflows" |
| 116 | # Create secret |
| 117 | await self.create_secret( |
| 118 | reference_secret_for_values, |
| 119 | secret_namespace, |
| 120 | reference_key_for_values, |
| 121 | secret_values, |
| 122 | ) |
| 123 | |
| 124 | # Render workflow |
| 125 | manifest = self.render_jinja_template( |
| 126 | workflow_template, |
| 127 | output_file=None, |
| 128 | workflow_name=workflow_name, |
| 129 | git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git", |
| 130 | git_sw_catalogs_url=f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git", |
| 131 | templates_path=oka_path, |
| 132 | substitute_environment=substitute_environment, |
| 133 | substitution_filter=substitution_filter, |
| 134 | custom_env_vars=custom_env_vars, |
| 135 | kustomization_name=kustomization_name, |
| 136 | helmrelease_name=helmrelease_name, |
| 137 | inline_values=inline_values, |
| 138 | is_preexisting_secret=is_preexisting_secret, |
| 139 | target_ns=target_ns, |
| 140 | age_public_key=age_public_key, |
| 141 | values_secret_name=values_secret_name, |
| 142 | reference_secret_for_values=reference_secret_for_values, |
| 143 | reference_key_for_values=reference_key_for_values, |
| 144 | is_preexisting_cm=is_preexisting_cm, |
| 145 | values_configmap_name=values_configmap_name, |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 146 | cm_key=cm_key, |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 147 | cm_values=cm_values, |
| 148 | ksu_name=ksu_name, |
| 149 | profile_name=profile_name, |
| 150 | profile_type=profile_type, |
| 151 | osm_project_name=osm_project_name, |
| 152 | sync=sync, |
| 153 | workflow_debug=self._workflow_debug, |
| 154 | workflow_dry_run=self._workflow_dry_run, |
| 155 | ) |
| 156 | self.logger.debug(f"Workflow manifest: {manifest}") |
| 157 | |
| 158 | # Submit workflow |
| 159 | self._kubectl.create_generic_object( |
| 160 | namespace="osm-workflows", |
| 161 | manifest_dict=yaml.safe_load(manifest), |
| 162 | api_group="argoproj.io", |
| 163 | api_plural="workflows", |
| 164 | api_version="v1alpha1", |
| 165 | ) |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 166 | return True, workflow_name |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 167 | |
| 168 | |
| 169 | async def update_ksus(self, op_id, op_params_list, content_list): |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 170 | self.logger.info(f"update_ksus Enter. Operation {op_id}. Params: {op_params_list}") |
| 171 | # self.logger.debug(f"Content: {content_list}") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 172 | |
| 173 | if len(content_list) > 1: |
| 174 | raise Exception("There is no ODU workflow yet able to manage multiple KSUs") |
| 175 | db_ksu = content_list[0] |
| 176 | ksu_params = op_params_list[0] |
| 177 | oka_list = ksu_params["oka"] |
| 178 | if len(oka_list) > 1: |
| 179 | raise Exception( |
| 180 | "There is no ODU workflow yet able to manage multiple OKAs for a KSU" |
| 181 | ) |
| garciadeblas | 1b2933c | 2024-10-16 11:43:36 +0200 | [diff] [blame] | 182 | oka_item = oka_list[0] |
| 183 | oka_params = oka_item.get("transformation", {}) |
| 184 | if "sw_catalog_path" in oka_item: |
| 185 | oka_path = oka_item["sw_catalog_path"] |
| 186 | else: |
| 187 | oka_type = "infra-controllers" |
| 188 | oka_name = oka_item["git_name"] |
| 189 | oka_path = f"{oka_type}/{oka_name}/templates" |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 190 | |
| 191 | workflow_template = "launcher-update-ksu-hr.j2" |
| 192 | workflow_name = f"update-ksus-{op_id}" |
| 193 | ksu_name = db_ksu["git_name"].lower() |
| 194 | |
| 195 | # Additional params for the workflow |
| 196 | osm_project_name = "osm_admin" # TODO: get project name from db_ksu |
| 197 | kustomization_name = ksu_name |
| 198 | helmrelease_name = ksu_name |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 199 | profile_type = ksu_params.get("profile", {}).get("profile_type") |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 200 | profile_type = MAP_PROFILE[profile_type] |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 201 | profile_name = ksu_params.get("profile", {}).get("name") |
| 202 | age_public_key = ksu_params.get("profile", {}).get("age_pubkey") |
| garciadeblas | 1b2933c | 2024-10-16 11:43:36 +0200 | [diff] [blame] | 203 | target_ns = oka_params.get("namespace", "default") |
| 204 | substitute_environment = oka_params.get("substitute_environment", "false") |
| 205 | substitution_filter = oka_params.get("substitution_filter", "") |
| 206 | custom_env_vars = oka_params.get("custom_env_vars", "") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 207 | if custom_env_vars: |
| 208 | custom_env_vars = "|\n" + "\n".join( |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 209 | [" " * 10 + f"{k}={v}" for k, v in custom_env_vars.items()] |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 210 | ) |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 211 | else: |
| 212 | custom_env_vars = '""' |
| garciadeblas | 1b2933c | 2024-10-16 11:43:36 +0200 | [diff] [blame] | 213 | inline_values = oka_params.get("inline_values", "") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 214 | if inline_values: |
| 215 | yaml_string = yaml.safe_dump( |
| 216 | inline_values, sort_keys=False, default_flow_style=False |
| 217 | ) |
| 218 | inline_values = "|\n" + "\n".join( |
| 219 | [" " * 8 + line for line in yaml_string.splitlines()] |
| 220 | ) |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 221 | else: |
| 222 | inline_values = '""' |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 223 | is_preexisting_cm = "false" |
| garciadeblas | 1b2933c | 2024-10-16 11:43:36 +0200 | [diff] [blame] | 224 | cm_values = oka_params.get("configmap_values", "") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 225 | if cm_values: |
| 226 | yaml_string = yaml.safe_dump( |
| 227 | cm_values, sort_keys=False, default_flow_style=False |
| 228 | ) |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 229 | cm_values = "|\n" + "\n".join( |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 230 | [" " * 8 + line for line in yaml_string.splitlines()] |
| 231 | ) |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 232 | values_configmap_name = f"cm-{ksu_name}" |
| 233 | cm_key = "values.yaml" |
| 234 | else: |
| 235 | values_configmap_name = "" |
| 236 | cm_key = "" |
| 237 | cm_values = '""' |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 238 | is_preexisting_secret = "false" |
| garciadeblas | 1b2933c | 2024-10-16 11:43:36 +0200 | [diff] [blame] | 239 | secret_values = oka_params.get("secret_values", "") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 240 | if secret_values: |
| 241 | values_secret_name = f"secret-{ksu_name}" |
| 242 | reference_secret_for_values = f"ref-secret-{ksu_name}" |
| 243 | reference_key_for_values = f"ref-key-{ksu_name}" |
| 244 | secret_values = yaml.safe_dump( |
| 245 | secret_values, sort_keys=False, default_flow_style=False |
| 246 | ) |
| 247 | else: |
| 248 | values_secret_name = "" |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 249 | reference_secret_for_values = "this-secret-does-not-exist" |
| 250 | reference_key_for_values = "this-key-does-not-exist" |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 251 | |
| 252 | if secret_values: |
| 253 | secret_namespace = "osm-workflows" |
| 254 | # Create secret |
| 255 | await self.create_secret( |
| 256 | reference_secret_for_values, |
| 257 | secret_namespace, |
| 258 | reference_key_for_values, |
| 259 | secret_values, |
| 260 | ) |
| 261 | |
| 262 | # Render workflow |
| 263 | manifest = self.render_jinja_template( |
| 264 | workflow_template, |
| 265 | output_file=None, |
| 266 | workflow_name=workflow_name, |
| 267 | git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git", |
| 268 | git_sw_catalogs_url=f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git", |
| 269 | templates_path=oka_path, |
| 270 | substitute_environment=substitute_environment, |
| 271 | substitution_filter=substitution_filter, |
| 272 | custom_env_vars=custom_env_vars, |
| 273 | kustomization_name=kustomization_name, |
| 274 | helmrelease_name=helmrelease_name, |
| 275 | inline_values=inline_values, |
| 276 | is_preexisting_secret=is_preexisting_secret, |
| 277 | target_ns=target_ns, |
| 278 | age_public_key=age_public_key, |
| 279 | values_secret_name=values_secret_name, |
| 280 | reference_secret_for_values=reference_secret_for_values, |
| 281 | reference_key_for_values=reference_key_for_values, |
| 282 | is_preexisting_cm=is_preexisting_cm, |
| 283 | values_configmap_name=values_configmap_name, |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 284 | cm_key=cm_key, |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 285 | cm_values=cm_values, |
| 286 | ksu_name=ksu_name, |
| 287 | profile_name=profile_name, |
| 288 | profile_type=profile_type, |
| 289 | osm_project_name=osm_project_name, |
| 290 | workflow_debug=self._workflow_debug, |
| 291 | workflow_dry_run=self._workflow_dry_run, |
| 292 | ) |
| 293 | self.logger.debug(f"Workflow manifest: {manifest}") |
| 294 | |
| 295 | # Submit workflow |
| 296 | self._kubectl.create_generic_object( |
| 297 | namespace="osm-workflows", |
| 298 | manifest_dict=yaml.safe_load(manifest), |
| 299 | api_group="argoproj.io", |
| 300 | api_plural="workflows", |
| 301 | api_version="v1alpha1", |
| 302 | ) |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 303 | return True, workflow_name |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 304 | |
| 305 | |
| 306 | async def delete_ksus(self, op_id, op_params_list, content_list): |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 307 | self.logger.info(f"delete_ksus Enter. Operation {op_id}. Params: {op_params_list}") |
| 308 | # self.logger.debug(f"Content: {content_list}") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 309 | |
| 310 | if len(content_list) > 1: |
| 311 | raise Exception("There is no ODU workflow yet able to manage multiple KSUs") |
| 312 | db_ksu = content_list[0] |
| 313 | ksu_params = op_params_list[0] |
| 314 | |
| 315 | workflow_template = "launcher-delete-ksu.j2" |
| 316 | workflow_name = f"delete-ksus-{op_id}" |
| 317 | ksu_name = db_ksu["git_name"].lower() |
| 318 | |
| 319 | # Additional params for the workflow |
| 320 | osm_project_name = "osm_admin" # TODO: get project name from db_ksu |
| 321 | profile_name = ksu_params.get("profile", {}).get("name") |
| 322 | profile_type = ksu_params.get("profile", {}).get("profile_type") |
| garciadeblas | f7dfdb7 | 2024-09-25 12:15:40 +0200 | [diff] [blame] | 323 | profile_type = MAP_PROFILE[profile_type] |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 324 | |
| 325 | # Render workflow |
| 326 | manifest = self.render_jinja_template( |
| 327 | workflow_template, |
| 328 | output_file=None, |
| 329 | workflow_name=workflow_name, |
| 330 | git_fleet_url=f"{self._repo_base_url}/{self._repo_user}/fleet-osm.git", |
| 331 | git_sw_catalogs_url=f"{self._repo_base_url}/{self._repo_user}/sw-catalogs-osm.git", |
| 332 | ksu_name=ksu_name, |
| 333 | profile_name=profile_name, |
| 334 | profile_type=profile_type, |
| 335 | osm_project_name=osm_project_name, |
| 336 | workflow_debug=self._workflow_debug, |
| 337 | workflow_dry_run=self._workflow_dry_run, |
| 338 | ) |
| 339 | self.logger.debug(f"Workflow manifest: {manifest}") |
| 340 | |
| 341 | # Submit workflow |
| 342 | self._kubectl.create_generic_object( |
| 343 | namespace="osm-workflows", |
| 344 | manifest_dict=yaml.safe_load(manifest), |
| 345 | api_group="argoproj.io", |
| 346 | api_plural="workflows", |
| 347 | api_version="v1alpha1", |
| 348 | ) |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 349 | return True, workflow_name |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 350 | |
| 351 | |
| 352 | async def clone_ksu(self, op_id, op_params, content): |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 353 | self.logger.info(f"clone_ksu Enter. Operation {op_id}. Params: {op_params}") |
| 354 | # self.logger.debug(f"Content: {content}") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 355 | workflow_name = f"clone-ksu-{content['_id']}" |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 356 | return True, workflow_name |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 357 | |
| 358 | |
| 359 | async def move_ksu(self, op_id, op_params, content): |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 360 | self.logger.info(f"move_ksu Enter. Operation {op_id}. Params: {op_params}") |
| 361 | # self.logger.debug(f"Content: {content}") |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 362 | workflow_name = f"move-ksu-{content['_id']}" |
| garciadeblas | adb81e8 | 2024-11-08 01:11:46 +0100 | [diff] [blame] | 363 | return True, workflow_name |
| garciadeblas | 96b94f5 | 2024-07-08 16:18:21 +0200 | [diff] [blame] | 364 | |
| 365 | |
| garciadeblas | d842985 | 2024-10-17 15:30:30 +0200 | [diff] [blame] | 366 | async def clean_items_ksu_create(self, op_id, op_params_list, content_list): |
| garciadeblas | d842985 | 2024-10-17 15:30:30 +0200 | [diff] [blame] | 367 | self.logger.info( |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 368 | f"clean_items_ksu_create Enter. Operation {op_id}. Params: {op_params_list}" |
| garciadeblas | d842985 | 2024-10-17 15:30:30 +0200 | [diff] [blame] | 369 | ) |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 370 | # self.logger.debug(f"Content: {content_list}") |
| garciadeblas | d842985 | 2024-10-17 15:30:30 +0200 | [diff] [blame] | 371 | try: |
| 372 | if len(content_list) > 1: |
| 373 | raise Exception("There is no ODU workflow yet able to manage multiple KSUs") |
| 374 | db_ksu = content_list[0] |
| 375 | ksu_name = db_ksu["git_name"].lower() |
| 376 | ksu_params = op_params_list[0] |
| 377 | oka_list = ksu_params["oka"] |
| 378 | if len(oka_list) > 1: |
| 379 | raise Exception( |
| 380 | "There is no ODU workflow yet able to manage multiple OKAs for a KSU" |
| 381 | ) |
| 382 | oka_item = oka_list[0] |
| 383 | oka_params = oka_item.get("transformation", {}) |
| 384 | secret_values = oka_params.get("secret_values", "") |
| 385 | if secret_values: |
| 386 | items = { |
| 387 | "secrets": [ |
| 388 | { |
| 389 | "name": f"ref-secret-{ksu_name}", |
| 390 | "namespace": "osm-workflows", |
| 391 | } |
| 392 | ] |
| 393 | } |
| 394 | await self.clean_items(items) |
| 395 | return True, "OK" |
| 396 | except Exception as e: |
| 397 | return False, f"Error while cleaning items: {e}" |
| 398 | |
| 399 | |
| 400 | async def clean_items_ksu_update(self, op_id, op_params_list, content_list): |
| garciadeblas | d842985 | 2024-10-17 15:30:30 +0200 | [diff] [blame] | 401 | self.logger.info( |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 402 | f"clean_items_ksu_update Enter. Operation {op_id}. Params: {op_params_list}" |
| garciadeblas | d842985 | 2024-10-17 15:30:30 +0200 | [diff] [blame] | 403 | ) |
| garciadeblas | 9e53281 | 2024-10-22 14:04:36 +0200 | [diff] [blame] | 404 | # self.logger.debug(f"Content: {content_list}") |
| garciadeblas | d842985 | 2024-10-17 15:30:30 +0200 | [diff] [blame] | 405 | return await self.clean_items_ksu_create(op_id, op_params_list, content_list) |