item=checking["item"],
name=checking["name"],
namespace=checking["namespace"],
- flag=checking.get("flag"),
+ condition=checking.get("condition"),
deleted=checking.get("deleted", False),
timeout=checking["timeout"],
kubectl=kubectl,
"item": "kustomization",
"name": cluster_kustomization_name,
"namespace": "managed-resources",
- "flag": "Ready",
+ "condition": {
+ "jsonpath_filter": "status.conditions[?(@.type=='Ready')].status",
+ "value": "True",
+ },
"timeout": 1500,
"enable": True,
"resourceState": "IN_PROGRESS.KUSTOMIZATION_READY",
"item": f"cluster_{cloud_type}",
"name": cluster_name,
"namespace": "",
- "flag": "Synced",
+ "condition": {
+ "jsonpath_filter": "status.conditions[?(@.type=='Synced')].status",
+ "value": "True",
+ },
"timeout": self._checkloop_resource_timeout,
"enable": True,
"resourceState": "IN_PROGRESS.RESOURCE_SYNCED.CLUSTER",
"item": f"cluster_{cloud_type}",
"name": cluster_name,
"namespace": "",
- "flag": "Ready",
+ "condition": {
+ "jsonpath_filter": "status.conditions[?(@.type=='Ready')].status",
+ "value": "True",
+ },
"timeout": self._checkloop_resource_timeout,
"enable": True,
"resourceState": "IN_PROGRESS.RESOURCE_READY.CLUSTER",
"item": "kustomization",
"name": f"{cluster_kustomization_name}-bstrp-fluxctrl",
"namespace": "managed-resources",
- "flag": "Ready",
+ "condition": {
+ "jsonpath_filter": "status.conditions[?(@.type=='Ready')].status",
+ "value": "True",
+ },
"timeout": self._checkloop_resource_timeout,
"enable": bootstrap,
"resourceState": "IN_PROGRESS.BOOTSTRAP_OK",
"item": f"nodepool_{cloud_type}",
"name": nodepool_name,
"namespace": "",
- "flag": "Ready",
+ "condition": {
+ "jsonpath_filter": "status.conditions[?(@.type=='Ready')].status",
+ "value": "True",
+ },
"timeout": self._checkloop_resource_timeout,
"enable": True,
"resourceState": "IN_PROGRESS.RESOURCE_READY.NODEPOOL",
"item": "kustomization",
"name": f"{cluster_kustomization_name}-bstrp-fluxctrl",
"namespace": "managed-resources",
- "flag": "Ready",
+ "condition": {
+ "jsonpath_filter": "status.conditions[?(@.type=='Ready')].status",
+ "value": "True",
+ },
"timeout": self._checkloop_kustomization_timeout,
"enable": bootstrap,
"resourceState": "IN_PROGRESS.BOOTSTRAP_OK",
db_cluster["operatingState"] = "IDLE"
# self.logger.info("db_cluster: {}".format(db_cluster))
- # TODO: verify enxtcondition
+ # TODO: verify condition
# For the moment, if the workflow completed successfully, then we update the db accordingly.
if workflow_status:
if "k8s_version" in op_params:
# "item": "kustomization",
# "name": cluster_kustomization_name,
# "namespace": "managed-resources",
- # "flag": "Ready",
+ # "condition": {
+ # "jsonpath_filter": "status.conditions[?(@.type=='Ready')].status",
+ # "value": "True",
+ # },
# "timeout": self._checkloop_kustomization_timeout,
# "enable": True,
# "resourceState": "IN_PROGRESS.KUSTOMIZATION_READY",
"item": "kustomization",
"name": kustomization_name,
"namespace": target_ns,
- "flag": "Ready",
+ "condition": {
+ "jsonpath_filter": "status.conditions[?(@.type=='Ready')].status",
+ "value": "True",
+ },
"timeout": self._checkloop_kustomization_timeout,
"enable": True,
"resourceState": "IN_PROGRESS.KUSTOMIZATION_READY",
import asyncio
from math import ceil
+from jsonpath_ng.ext import parse
async def check_workflow_status(self, workflow_name):
item="workflow",
name=workflow_name,
namespace="osm-workflows",
- flag="Completed",
+ condition={
+ "jsonpath_filter": "status.conditions[?(@.type=='Completed')].status",
+ "value": "True",
+ },
deleted=False,
timeout=300,
)
async def readiness_loop(
- self, item, name, namespace, flag, deleted, timeout, kubectl=None
+ self, item, name, namespace, condition, deleted, timeout, kubectl=None
):
if kubectl is None:
kubectl = self._kubectl
self.logger.info("readiness_loop Enter")
self.logger.info(
- f"{item} {name}. Namespace: '{namespace}'. Flag: {flag}. Deleted: {deleted}. Timeout: {timeout}"
+ f"{item} {name}. Namespace: '{namespace}'. Condition: {condition}. Deleted: {deleted}. Timeout: {timeout}"
)
item_api_map = {
"workflow": {
)
return True, "COMPLETED"
else:
- if not flag:
+ if not condition:
return True, "Nothing to check"
if generic_object:
# self.logger.debug(f"{yaml.safe_dump(generic_object)}")
f"Could not find {api_plural}. Name: {name}. Namespace: '{namespace}'. API: {api_group}/{api_version}"
)
conditions = []
- result = next((item for item in conditions if item["type"] == flag), {})
- if result.get("status", "False") == "True":
- self.logger.info(
- f"{item} {name} reached the status {flag} in {counter} iterations (aprox {counter*retry_time} seconds)"
- )
- return True, "COMPLETED"
- # TODO: Implement generic condition with jsonpath filter
- # jsonpath_expr = parse(condition["jsonpath_filter"])
- # match = jsonpath_expr.find(generic_object)
- # if match:
- # value = match[0].value
- # if condition["function"](value, condition["value"]):
- # return True, "COMPLETED"
+ jsonpath_expr = parse(condition["jsonpath_filter"])
+ match = jsonpath_expr.find(generic_object)
+ if match:
+ value = match[0].value
+ condition_function = condition.get("function", lambda x, y: x == y)
+ if condition_function(condition["value"], value):
+ self.logger.info(
+ f"{item} {name} met the condition {condition} in {counter} iterations (aprox {counter*retry_time} seconds)"
+ )
+ return True, "COMPLETED"
except Exception as e:
self.logger.error(f"Exception: {e}")
await asyncio.sleep(retry_time)