Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skip crd capture when related api not deployed for support bundle #316

Merged
merged 11 commits into from
Aug 23, 2024
4 changes: 1 addition & 3 deletions azext_edge/edge/providers/edge_api/akri.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ class AkriResourceKinds(ListableEnum):
CONFIGURATION = "configuration"


AKRI_API_V0 = EdgeResourceApi(
group="akri.sh", version="v0", moniker="akri", label="microsoft-iotoperations-akri"
)
AKRI_API_V0 = EdgeResourceApi(group="akri.sh", version="v0", moniker="akri", label="microsoft-iotoperations-akri")
2 changes: 1 addition & 1 deletion azext_edge/edge/providers/edge_api/dataflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class DataflowResourceKinds(ListableEnum):
group="connectivity.iotoperations.azure.com",
version="v1beta1",
moniker="dataflow",
label="microsoft-iotoperations-dataflows"
label="microsoft-iotoperations-dataflows",
)
5 changes: 1 addition & 4 deletions azext_edge/edge/providers/edge_api/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ class MetaResourceKinds(ListableEnum):


META_API_V1B1 = EdgeResourceApi(
group="iotoperations.azure.com",
version="v1beta1",
moniker="meta",
label="microsoft-iotoperations"
group="iotoperations.azure.com", version="v1beta1", moniker="meta", label="microsoft-iotoperations"
)
2 changes: 1 addition & 1 deletion azext_edge/edge/providers/edge_api/mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MqResourceKinds(ListableEnum):


MQTT_BROKER_API_V1B1 = EdgeResourceApi(
group="mqttbroker.iotoperations.azure.com",
group="mqtt.iotoperations.azure.com",
version="v1beta1",
moniker="broker",
label="microsoft-iotoperations-mqttbroker",
Expand Down
4 changes: 2 additions & 2 deletions azext_edge/edge/providers/edge_api/opcua.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class OpcuaResourceKinds(ListableEnum):


OPCUA_API_V1 = EdgeResourceApi(
group="opcuabroker.iotoperations.azure.com",
group="opcuabroker2.iotoperations.azure.com",
version="v1beta1",
moniker="opcua",
label="microsoft-iotoperations-opcuabroker"
label="microsoft-iotoperations-opcuabroker",
)
23 changes: 11 additions & 12 deletions azext_edge/edge/providers/support/akri.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ----------------------------------------------------------------------------------------------

from functools import partial
from typing import Iterable
from typing import Iterable, Optional

from knack.log import get_logger

Expand Down Expand Up @@ -100,9 +100,7 @@ def fetch_daemonsets():
)
)

processed.extend(
process_daemonsets(directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2)
)
processed.extend(process_daemonsets(directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2))
return processed


Expand All @@ -121,9 +119,7 @@ def fetch_services():
)
)

processed.extend(
process_services(directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2)
)
processed.extend(process_services(directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2))
return processed


Expand All @@ -142,9 +138,7 @@ def fetch_replicasets():
)
)

processed.extend(
process_replicasets(directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2)
)
processed.extend(process_replicasets(directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2))
return processed


Expand All @@ -156,9 +150,14 @@ def fetch_replicasets():
}


def prepare_bundle(apis: Iterable[EdgeResourceApi], log_age_seconds: int = DAY_IN_SECONDS) -> dict:
def prepare_bundle(
log_age_seconds: int = DAY_IN_SECONDS,
apis: Optional[Iterable[EdgeResourceApi]] = None,
) -> dict:
akri_to_run = {}
akri_to_run.update(assemble_crd_work(apis))

if apis:
akri_to_run.update(assemble_crd_work(apis))

support_runtime_elements["pods"] = partial(fetch_pods, since_seconds=log_age_seconds)
akri_to_run.update(support_runtime_elements)
Expand Down
8 changes: 5 additions & 3 deletions azext_edge/edge/providers/support/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ----------------------------------------------------------------------------------------------

from functools import partial
from typing import Iterable
from typing import Iterable, Optional

from knack.log import get_logger

Expand Down Expand Up @@ -107,11 +107,13 @@ def fetch_services():


def prepare_bundle(
apis: Iterable[EdgeResourceApi],
log_age_seconds: int = DAY_IN_SECONDS,
apis: Optional[Iterable[EdgeResourceApi]] = None,
) -> dict:
billing_to_run = {}
billing_to_run.update(assemble_crd_work(apis=apis, directory_path=ARC_BILLING_DIRECTORY_PATH))

if apis:
billing_to_run.update(assemble_crd_work(apis=apis, directory_path=ARC_BILLING_DIRECTORY_PATH))

support_runtime_elements["pods"] = partial(fetch_pods, since_seconds=log_age_seconds)
billing_to_run.update(support_runtime_elements)
Expand Down
9 changes: 6 additions & 3 deletions azext_edge/edge/providers/support/dataflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ----------------------------------------------------------------------------------------------

from functools import partial
from typing import Iterable
from typing import Iterable, Optional

from knack.log import get_logger

Expand Down Expand Up @@ -64,10 +64,13 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS):


def prepare_bundle(
apis: Iterable[EdgeResourceApi], log_age_seconds: int = DAY_IN_SECONDS
log_age_seconds: int = DAY_IN_SECONDS,
apis: Optional[Iterable[EdgeResourceApi]] = None,
) -> dict:
dataflow_to_run = {}
dataflow_to_run.update(assemble_crd_work(apis))

if apis:
dataflow_to_run.update(assemble_crd_work(apis))

support_runtime_elements["pods"] = partial(fetch_pods, since_seconds=log_age_seconds)
dataflow_to_run.update(support_runtime_elements)
Expand Down
8 changes: 5 additions & 3 deletions azext_edge/edge/providers/support/deviceregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Licensed under the MIT License. See License file in the project root for license information.
# ----------------------------------------------------------------------------------------------

from typing import Iterable
from typing import Iterable, Optional

from knack.log import get_logger

Expand All @@ -14,8 +14,10 @@
logger = get_logger(__name__)


def prepare_bundle(apis: Iterable[EdgeResourceApi]) -> dict:
def prepare_bundle(apis: Optional[Iterable[EdgeResourceApi]] = None) -> dict:
deviceregistry_to_run = {}
deviceregistry_to_run.update(assemble_crd_work(apis))

if apis:
deviceregistry_to_run.update(assemble_crd_work(apis))

return deviceregistry_to_run
10 changes: 5 additions & 5 deletions azext_edge/edge/providers/support/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ----------------------------------------------------------------------------------------------

from functools import partial
from typing import Iterable
from typing import Iterable, Optional

from knack.log import get_logger

Expand Down Expand Up @@ -80,11 +80,11 @@ def fetch_jobs():
}


def prepare_bundle(
apis: Iterable[EdgeResourceApi], log_age_seconds: int = DAY_IN_SECONDS
) -> dict:
def prepare_bundle(log_age_seconds: int = DAY_IN_SECONDS, apis: Optional[Iterable[EdgeResourceApi]] = None) -> dict:
meta_to_run = {}
meta_to_run.update(assemble_crd_work(apis))

if apis:
meta_to_run.update(assemble_crd_work(apis))

support_runtime_elements["pods"] = partial(fetch_pods, since_seconds=log_age_seconds)
meta_to_run.update(support_runtime_elements)
Expand Down
9 changes: 7 additions & 2 deletions azext_edge/edge/providers/support/mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS):


def prepare_bundle(
apis: Iterable[EdgeResourceApi], log_age_seconds: int = DAY_IN_SECONDS, include_mq_traces: Optional[bool] = None
log_age_seconds: int = DAY_IN_SECONDS,
apis: Optional[Iterable[EdgeResourceApi]] = None,
include_mq_traces: Optional[bool] = None,
) -> dict:
mq_to_run = {}
mq_to_run.update(assemble_crd_work(apis))

# when apis not found, still try to fetch other resources
if apis:
mq_to_run.update(assemble_crd_work(apis))

support_runtime_elements["pods"] = partial(fetch_pods, since_seconds=log_age_seconds)
if include_mq_traces:
Expand Down
11 changes: 8 additions & 3 deletions azext_edge/edge/providers/support/opcua.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ----------------------------------------------------------------------------------------------

from functools import partial
from typing import Iterable
from typing import Iterable, Optional

from knack.log import get_logger

Expand Down Expand Up @@ -106,9 +106,14 @@ def fetch_daemonsets():
}


def prepare_bundle(apis: Iterable[EdgeResourceApi], log_age_seconds: int = DAY_IN_SECONDS) -> dict:
def prepare_bundle(
log_age_seconds: int = DAY_IN_SECONDS,
apis: Optional[Iterable[EdgeResourceApi]] = None,
) -> dict:
opcua_to_run = {}
opcua_to_run.update(assemble_crd_work(apis))

if apis:
opcua_to_run.update(assemble_crd_work(apis))

opcua_to_run["pods"] = partial(fetch_pods, since_seconds=log_age_seconds)
opcua_to_run.update(support_runtime_elements)
Expand Down
11 changes: 8 additions & 3 deletions azext_edge/edge/providers/support/orc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ----------------------------------------------------------------------------------------------

from functools import partial
from typing import Iterable
from typing import Iterable, Optional

from knack.log import get_logger

Expand Down Expand Up @@ -75,9 +75,14 @@ def fetch_replicasets():
}


def prepare_bundle(apis: Iterable[EdgeResourceApi], log_age_seconds: int = DAY_IN_SECONDS) -> dict:
def prepare_bundle(
log_age_seconds: int = DAY_IN_SECONDS,
apis: Optional[Iterable[EdgeResourceApi]] = None,
) -> dict:
symphony_to_run = {}
symphony_to_run.update(assemble_crd_work(apis))

if apis:
symphony_to_run.update(assemble_crd_work(apis))

support_runtime_elements["pods"] = partial(fetch_pods, since_seconds=log_age_seconds)
symphony_to_run.update(support_runtime_elements)
Expand Down
4 changes: 1 addition & 3 deletions azext_edge/edge/providers/support/otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

def fetch_otel_pods(since_seconds: int = DAY_IN_SECONDS):
return process_v1_pods(
directory_path=OTEL_DIRECTORY_PATH,
label_selector=OTEL_NAME_LABEL,
since_seconds=since_seconds
directory_path=OTEL_DIRECTORY_PATH, label_selector=OTEL_NAME_LABEL, since_seconds=since_seconds
)


Expand Down
39 changes: 20 additions & 19 deletions azext_edge/edge/providers/support_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,29 @@ def build_bundle(
OpsServiceType.dataflow.value: {"apis": COMPAT_DATAFLOW_APIS, "prepare_bundle": prepare_dataflow_bundle},
}

raise_on_404 = not (ops_service == OpsServiceType.auto.value)

for service_moniker, api_info in api_map.items():
if ops_service in [OpsServiceType.auto.value, service_moniker]:
deployed_apis = api_info["apis"].get_deployed(raise_on_404)
if deployed_apis:
bundle_method = api_info["prepare_bundle"]
# Check if the function takes a second argument
# TODO: Change to kwargs based pattern
if service_moniker == OpsServiceType.deviceregistry.value:
bundle = bundle_method(deployed_apis)
elif service_moniker == OpsServiceType.mq.value:
bundle = bundle_method(deployed_apis, log_age_seconds, include_mq_traces)
else:
bundle = bundle_method(deployed_apis, log_age_seconds)
deployed_apis = api_info["apis"].get_deployed()

if not deployed_apis:
expected_api_version = api_info["apis"].as_str()
logger.warning(
Elsie4ever marked this conversation as resolved.
Show resolved Hide resolved
f"Skip capturing CRD for {service_moniker} since {expected_api_version} is not deployed, "
Elsie4ever marked this conversation as resolved.
Show resolved Hide resolved
"will try to get rest of the resources..."
)

pending_work[service_moniker].update(bundle)
# still try fetching other resources even crds are not available due to api version mismatch
bundle_method = api_info["prepare_bundle"]
# Check if the function takes a second argument
# TODO: Change to kwargs based pattern
if service_moniker == OpsServiceType.deviceregistry.value:
bundle = bundle_method(deployed_apis)
elif service_moniker == OpsServiceType.mq.value:
bundle = bundle_method(log_age_seconds, deployed_apis, include_mq_traces)
else:
bundle = bundle_method(log_age_seconds, deployed_apis)

# @digimaun - consider combining this work check with work count.
if not any(v for _, v in pending_work.items()):
logger.warning("No known IoT Operations services discovered on cluster.")
return
pending_work[service_moniker].update(bundle)

if ops_service == OpsServiceType.auto.value:
# Only attempt to collect otel resources if any AIO service is deployed AND auto is used.
Expand All @@ -117,7 +118,7 @@ def build_bundle(

Elsie4ever marked this conversation as resolved.
Show resolved Hide resolved
# Collect meta resources if any AIO service is deployed with any service selected.
deployed_meta_apis = COMPAT_META_APIS.get_deployed()
pending_work["meta"] = prepare_meta_bundle(deployed_meta_apis, log_age_seconds)
pending_work["meta"] = prepare_meta_bundle(log_age_seconds, deployed_meta_apis)

total_work_count = 0
for service in pending_work:
Expand Down
Loading