blob: d9b2e785a8f2ea6efa042db992d45a931d101c6b [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
19import asyncio
20from time import time
21
22
23async def check_workflow_status(self, workflow_name):
24 self.logger.info(f"Async check workflow status Enter: {workflow_name}")
25 start_time = time()
26 timeout = 300
27 retry_time = 15
28 # TODO: Maybe it's better not to measure time, but controlling retries
29 # retries = 0
30 # total_retries = int(timeout/retry_time)
31 while time() <= start_time + timeout:
32 # workflow_list = await self._kubectl.list_generic_object(
33 # api_group="argoproj.io",
34 # api_plural="workflows",
35 # api_version="v1alpha1",
36 # namespace="osm-workflows",
37 # )
38 # self.logger.info(f"Workflow_list: { workflow_list }")
39 # kubectl get workflow/${WORKFLOW_NAME} -n osm-workflows -o jsonpath='{.status.conditions}' | jq -r '.[] | select(.type=="Completed").status'
40 workflow = await self._kubectl.get_generic_object(
41 api_group="argoproj.io",
42 api_plural="workflows",
43 api_version="v1alpha1",
44 namespace="osm-workflows",
45 name=workflow_name,
46 )
47 # self.logger.info(f"Workflow: {workflow}")
48 # self.logger.info(f"Workflow status: {workflow.get('status')}")
49 conditions = workflow.get("status", {}).get("conditions", [])
50 self.logger.info(f"Workflow status conditions: {conditions}")
51 result = next((item for item in conditions if item["type"] == "Completed"), {})
52 if result.get("status", "False") == "True":
53 self.logger.info(
54 f"Workflow {workflow_name} completed in {time() - start_time} seconds"
55 )
56 return True, "COMPLETED"
57 await asyncio.sleep(retry_time)
58 return False, "Workflow {workflow_name} did not complete in {timeout} seconds"