From 8a489df50c9abdb573a2335e93077aa0d40726b3 Mon Sep 17 00:00:00 2001 From: Elsie4ever <3467996@gmail.com> Date: Fri, 10 May 2024 15:21:28 -0700 Subject: [PATCH 1/9] refator support bundle for kube resource not specific to EdgeResourceApi --- azext_edge/edge/commands_edge.py | 2 + azext_edge/edge/params.py | 6 + azext_edge/edge/providers/support/akri.py | 20 +- azext_edge/edge/providers/support/base.py | 48 ++--- .../support/clusterconfig/billing.py | 14 +- .../edge/providers/support/dataprocessor.py | 24 +-- azext_edge/edge/providers/support/lnm.py | 12 +- azext_edge/edge/providers/support/mq.py | 24 +-- azext_edge/edge/providers/support/opcua.py | 26 +-- azext_edge/edge/providers/support/orc.py | 8 +- azext_edge/edge/providers/support/otel.py | 8 +- azext_edge/edge/providers/support_bundle.py | 28 +++ .../create_bundle_int/test_akri_int.py | 2 +- .../tests/edge/support/test_support_unit.py | 192 +++++++++--------- 14 files changed, 224 insertions(+), 190 deletions(-) diff --git a/azext_edge/edge/commands_edge.py b/azext_edge/edge/commands_edge.py index bd5b2cfc3..faabe11b6 100644 --- a/azext_edge/edge/commands_edge.py +++ b/azext_edge/edge/commands_edge.py @@ -35,6 +35,7 @@ def support_bundle( log_age_seconds: int = 60 * 60 * 24, ops_service: str = OpsServiceType.auto.value, bundle_dir: Optional[str] = None, + include_arc_agent: Optional[bool] = None, include_mq_traces: Optional[bool] = None, context_name: Optional[str] = None, ) -> Union[Dict[str, Any], None]: @@ -46,6 +47,7 @@ def support_bundle( ops_service=ops_service, bundle_path=str(bundle_path), log_age_seconds=log_age_seconds, + include_arc_agent=include_arc_agent, include_mq_traces=include_mq_traces, ) diff --git a/azext_edge/edge/params.py b/azext_edge/edge/params.py index 58552acaf..ef4b4af8f 100644 --- a/azext_edge/edge/params.py +++ b/azext_edge/edge/params.py @@ -74,6 +74,12 @@ def load_iotops_arguments(self, _): arg_type=get_three_state_flag(), help="Include mq traces in the support bundle. Usage may add considerable size to the produced bundle.", ) + context.argument( + "include_arc_agent", + options_list=["--arc-agent"], + arg_type=get_three_state_flag(), + help="Include arc agent logs in the support bundle. Usage may add considerable size to the produced bundle.", + ) with self.argument_context("iot ops check") as context: context.argument( diff --git a/azext_edge/edge/providers/support/akri.py b/azext_edge/edge/providers/support/akri.py index 511ab861d..1854f1720 100644 --- a/azext_edge/edge/providers/support/akri.py +++ b/azext_edge/edge/providers/support/akri.py @@ -45,7 +45,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for pod_name_label in pod_name_labels: processed.extend( process_v1_pods( - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, label_selector=pod_name_label, since_seconds=since_seconds, ) @@ -53,7 +53,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): processed.extend( process_v1_pods( - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2, since_seconds=since_seconds, ) @@ -71,14 +71,14 @@ def fetch_deployments(): for deployment_name_label in deployment_name_labels: processed.extend( process_deployments( - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, label_selector=deployment_name_label, ) ) processed.extend( process_deployments( - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2, ) ) @@ -94,13 +94,13 @@ def fetch_daemonsets(): for daemonset_name_label in daemonset_name_labels: processed.extend( process_daemonsets( - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, label_selector=daemonset_name_label, ) ) processed.extend( - process_daemonsets(resource_api=AKRI_API_V0, label_selector=AKRI_NAME_LABEL_V2) + process_daemonsets(moniker=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) ) return processed @@ -115,13 +115,13 @@ def fetch_services(): for service_name_label in service_name_labels: processed.extend( process_services( - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, label_selector=service_name_label, ) ) processed.extend( - process_services(resource_api=AKRI_API_V0, label_selector=AKRI_NAME_LABEL_V2) + process_services(moniker=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) ) return processed @@ -136,13 +136,13 @@ def fetch_replicasets(): for replicaset_name_label in replicaset_name_labels: processed.extend( process_replicasets( - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, label_selector=replicaset_name_label, ) ) processed.extend( - process_replicasets(resource_api=AKRI_API_V0, label_selector=AKRI_NAME_LABEL_V2) + process_replicasets(moniker=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) ) return processed diff --git a/azext_edge/edge/providers/support/base.py b/azext_edge/edge/providers/support/base.py index a8b837ae2..f0f82196a 100644 --- a/azext_edge/edge/providers/support/base.py +++ b/azext_edge/edge/providers/support/base.py @@ -61,7 +61,7 @@ def process_crd( def process_v1_pods( - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, capture_previous_logs: bool = True, include_metrics: bool = False, @@ -100,7 +100,7 @@ def process_v1_pods( p.api_version = pods.api_version p.kind = "Pod" zinfo = _process_zinfo( - prefix=f"{pod_namespace}/{resource_api.moniker}", + prefix=f"{pod_namespace}/{moniker}", suffix=f"pod.{pod_name}.yaml", sub_group=sub_group, ) @@ -124,7 +124,7 @@ def process_v1_pods( pod_containers=pod_containers, pod_name=pod_name, pod_namespace=pod_namespace, - resource_api=resource_api, + moniker=moniker, v1_api=v1_api, since_seconds=since_seconds, capture_previous_logs=capture_previous_logs, @@ -140,7 +140,7 @@ def process_v1_pods( ) if metric: zinfo = _process_zinfo( - prefix=f"{pod_namespace}/{resource_api.moniker}", + prefix=f"{pod_namespace}/{moniker}", suffix=f"pod.{pod_name}.metric.yaml", sub_group=sub_group, ) @@ -157,7 +157,7 @@ def process_v1_pods( def process_deployments( - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, return_namespaces: bool = False, field_selector: Optional[str] = None, @@ -175,7 +175,7 @@ def process_deployments( processed = _process_kubernetes_resources( sub_group=sub_group, resources=deployments, - resource_api=resource_api, + moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.deployment.value, ) @@ -193,7 +193,7 @@ def process_deployments( def process_statefulset( - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, field_selector: Optional[str] = None, label_selector: Optional[str] = None, @@ -208,13 +208,13 @@ def process_statefulset( return _process_kubernetes_resources( sub_group=sub_group, resources=statefulsets, - resource_api=resource_api, + moniker=moniker, kind=BundleResourceKind.statefulset.value, ) def process_services( - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, field_selector: Optional[str] = None, label_selector: Optional[str] = None, @@ -230,14 +230,14 @@ def process_services( return _process_kubernetes_resources( sub_group=sub_group, resources=services, - resource_api=resource_api, + moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.service.value, ) def process_replicasets( - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -250,14 +250,14 @@ def process_replicasets( return _process_kubernetes_resources( sub_group=sub_group, resources=replicasets, - resource_api=resource_api, + moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.replicaset.value, ) def process_daemonsets( - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, field_selector: Optional[str] = None, label_selector: Optional[str] = None, @@ -273,7 +273,7 @@ def process_daemonsets( return _process_kubernetes_resources( sub_group=sub_group, resources=daemonsets, - resource_api=resource_api, + moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.daemonset.value, ) @@ -326,7 +326,7 @@ def process_storage_classes() -> List[dict]: def process_persistent_volume_claims( - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, field_selector: Optional[str] = None, label_selector: Optional[str] = None, @@ -342,14 +342,14 @@ def process_persistent_volume_claims( return _process_kubernetes_resources( sub_group=sub_group, resources=pvcs, - resource_api=resource_api, + moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.pvc.value, ) def process_jobs( - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, field_selector: Optional[str] = None, label_selector: Optional[str] = None, @@ -365,14 +365,14 @@ def process_jobs( return _process_kubernetes_resources( sub_group=sub_group, resources=jobs, - resource_api=resource_api, + moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.job.value, ) def process_cron_jobs( - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, field_selector: Optional[str] = None, label_selector: Optional[str] = None, @@ -388,7 +388,7 @@ def process_cron_jobs( return _process_kubernetes_resources( sub_group=sub_group, resources=cron_jobs, - resource_api=resource_api, + moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.cronjob.value, ) @@ -436,7 +436,7 @@ def _capture_pod_container_logs( pod_containers: List[V1Container], pod_name: str, pod_namespace: str, - resource_api: EdgeResourceApi, + moniker: str, v1_api: client.CoreV1Api, capture_previous_logs: bool = True, since_seconds: int = DAY_IN_SECONDS, @@ -463,7 +463,7 @@ def _capture_pod_container_logs( ) zinfo_previous_segment = "previous." if capture_previous else "" zinfo = _process_zinfo( - prefix=f"{pod_namespace}/{resource_api.moniker}", + prefix=f"{pod_namespace}/{moniker}", suffix=f"pod.{pod_name}.{container.name}.{zinfo_previous_segment}log", sub_group=sub_group, ) @@ -481,7 +481,7 @@ def _capture_pod_container_logs( def _process_kubernetes_resources( resources: object, - resource_api: EdgeResourceApi, + moniker: str, kind: str, sub_group: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -512,7 +512,7 @@ def _process_kubernetes_resources( resource_type = kind.lower() zinfo = _process_zinfo( - prefix=f"{resource_namespace}/{resource_api.moniker}", + prefix=f"{resource_namespace}/{moniker}", suffix=f"{resource_type}.{resource_name}.yaml", sub_group=sub_group, ) diff --git a/azext_edge/edge/providers/support/clusterconfig/billing.py b/azext_edge/edge/providers/support/clusterconfig/billing.py index 15d321c32..26e5af865 100644 --- a/azext_edge/edge/providers/support/clusterconfig/billing.py +++ b/azext_edge/edge/providers/support/clusterconfig/billing.py @@ -33,7 +33,7 @@ def fetch_pods( ): # capture billing pods for aio usage billing_pods = process_v1_pods( - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, label_selector=AIO_BILLING_USAGE_NAME_LABEL, since_seconds=since_seconds, sub_group=BILLING_RESOURCE_KIND, @@ -42,7 +42,7 @@ def fetch_pods( # capture billing pods for arc extension billing_pods.extend( process_v1_pods( - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, since_seconds=since_seconds, sub_group=BILLING_RESOURCE_KIND, @@ -54,7 +54,7 @@ def fetch_pods( def fetch_jobs(): processed = process_jobs( - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, label_selector=AIO_BILLING_USAGE_NAME_LABEL, sub_group=BILLING_RESOURCE_KIND, ) @@ -64,7 +64,7 @@ def fetch_jobs(): def fetch_cron_jobs(): processed = process_cron_jobs( - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, label_selector=AIO_BILLING_USAGE_NAME_LABEL, sub_group=BILLING_RESOURCE_KIND, ) @@ -74,7 +74,7 @@ def fetch_cron_jobs(): def fetch_deployments(): processed = process_deployments( - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, sub_group=BILLING_RESOURCE_KIND, ) @@ -84,7 +84,7 @@ def fetch_deployments(): def fetch_replicasets(): return process_replicasets( - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, sub_group=BILLING_RESOURCE_KIND, ) @@ -92,7 +92,7 @@ def fetch_replicasets(): def fetch_services(): return process_services( - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, sub_group=BILLING_RESOURCE_KIND, ) diff --git a/azext_edge/edge/providers/support/dataprocessor.py b/azext_edge/edge/providers/support/dataprocessor.py index e61c8c03a..2cefe83c6 100644 --- a/azext_edge/edge/providers/support/dataprocessor.py +++ b/azext_edge/edge/providers/support/dataprocessor.py @@ -54,7 +54,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): dataprocessor_pods = process_v1_pods( - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL, since_seconds=since_seconds, pod_prefix_for_init_container_logs=[ @@ -65,7 +65,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): dataprocessor_pods.extend( process_v1_pods( - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, since_seconds=since_seconds, pod_prefix_for_init_container_logs=[ @@ -79,9 +79,9 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): - processed = process_deployments(resource_api=DATA_PROCESSOR_API_V1, label_selector=DATA_PROCESSOR_LABEL) + processed = process_deployments(moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL) processed.extend( - process_deployments(resource_api=DATA_PROCESSOR_API_V1, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_deployments(moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -89,12 +89,12 @@ def fetch_deployments(): def fetch_statefulsets(): processed = process_statefulset( - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL, ) processed.extend( process_statefulset( - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, ) ) @@ -103,9 +103,9 @@ def fetch_statefulsets(): def fetch_replicasets(): - processed = process_replicasets(resource_api=DATA_PROCESSOR_API_V1, label_selector=DATA_PROCESSOR_LABEL) + processed = process_replicasets(moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL) processed.extend( - process_replicasets(resource_api=DATA_PROCESSOR_API_V1, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_replicasets(moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -120,13 +120,13 @@ def fetch_services(): for service_name_label in service_name_labels: processed.extend( process_services( - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=service_name_label, ) ) processed.extend( - process_services(resource_api=DATA_PROCESSOR_API_V1, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_services(moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -143,14 +143,14 @@ def fetch_persistent_volume_claims(): for persistent_volume_claims_name_label in persistent_volume_claims_name_labels: processed.extend( process_persistent_volume_claims( - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=persistent_volume_claims_name_label, ) ) processed.extend( process_persistent_volume_claims( - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2 ) ) diff --git a/azext_edge/edge/providers/support/lnm.py b/azext_edge/edge/providers/support/lnm.py index ac5d0f55c..c58c60e1a 100644 --- a/azext_edge/edge/providers/support/lnm.py +++ b/azext_edge/edge/providers/support/lnm.py @@ -29,7 +29,7 @@ def fetch_replicasets(): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) return process_replicasets( - resource_api=LNM_API_V1B1, + moniker=LNM_API_V1B1.moniker, label_selector=lnm_labels, ) @@ -38,13 +38,13 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) processed = process_v1_pods( - resource_api=LNM_API_V1B1, + moniker=LNM_API_V1B1.moniker, label_selector=lnm_labels, since_seconds=since_seconds, ) processed.extend( process_v1_pods( - resource_api=LNM_API_V1B1, + moniker=LNM_API_V1B1.moniker, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"], since_seconds=since_seconds, @@ -57,19 +57,19 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_services(): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) - return process_services(resource_api=LNM_API_V1B1, label_selector=lnm_labels) + return process_services(moniker=LNM_API_V1B1.moniker, label_selector=lnm_labels) def fetch_lnm_deployments(): deployment_prefixes = [f"{LNM_LABEL_PREFIX}-{name}" for name in _fetch_lnm_instance_names()] deployment_prefixes.extend(LNM_APP_LABELS) - return process_deployments(resource_api=LNM_API_V1B1, label_selector=None, prefix_names=deployment_prefixes) + return process_deployments(moniker=LNM_API_V1B1.moniker, label_selector=None, prefix_names=deployment_prefixes) def fetch_daemonsets(): return process_daemonsets( - resource_api=LNM_API_V1B1, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"] + moniker=LNM_API_V1B1.moniker, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"] ) diff --git a/azext_edge/edge/providers/support/mq.py b/azext_edge/edge/providers/support/mq.py index 45c6dadf0..05b84fce1 100644 --- a/azext_edge/edge/providers/support/mq.py +++ b/azext_edge/edge/providers/support/mq.py @@ -88,16 +88,16 @@ def fetch_diagnostic_traces(): def fetch_deployments(): processed, namespaces = process_deployments( - resource_api=MQ_ACTIVE_API, label_selector=MQ_LABEL, return_namespaces=True + moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, return_namespaces=True ) # aio-mq-operator deployment has no app label operators, operator_namespaces = process_deployments( - resource_api=MQ_ACTIVE_API, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", return_namespaces=True + moniker=MQ_ACTIVE_API.moniker, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", return_namespaces=True ) processed.extend(operators) operators_v2, operator_namespaces_v2 = process_deployments( - resource_api=MQ_ACTIVE_API, label_selector=MQ_NAME_LABEL, return_namespaces=True + moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, return_namespaces=True ) processed.extend(operators_v2) @@ -122,12 +122,12 @@ def fetch_deployments(): def fetch_statefulsets(): processed = process_statefulset( - resource_api=MQ_ACTIVE_API, + moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, ) processed.extend( process_statefulset( - resource_api=MQ_ACTIVE_API, + moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, ) ) @@ -144,7 +144,7 @@ def fetch_statefulsets(): for connector in connectors: connector_name = connector.get("metadata", {}).get("name") stateful_set = process_statefulset( - resource_api=MQ_ACTIVE_API, + moniker=MQ_ACTIVE_API.moniker, field_selector=f"metadata.name={AIO_MQ_RESOURCE_PREFIX}{connector_name}", ) processed.extend(stateful_set) @@ -154,12 +154,12 @@ def fetch_statefulsets(): def fetch_services(): processed = process_services( - resource_api=MQ_ACTIVE_API, + moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, ) processed.extend( process_services( - resource_api=MQ_ACTIVE_API, + moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, ) ) @@ -169,12 +169,12 @@ def fetch_services(): def fetch_replicasets(): processed = process_replicasets( - resource_api=MQ_ACTIVE_API, + moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, ) processed.extend( process_replicasets( - resource_api=MQ_ACTIVE_API, + moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, ) ) @@ -184,13 +184,13 @@ def fetch_replicasets(): def fetch_pods(since_seconds: int = DAY_IN_SECONDS): processed = process_v1_pods( - resource_api=MQ_ACTIVE_API, + moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, since_seconds=since_seconds, ) processed.extend( process_v1_pods( - resource_api=MQ_ACTIVE_API, + moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, since_seconds=since_seconds, ) diff --git a/azext_edge/edge/providers/support/opcua.py b/azext_edge/edge/providers/support/opcua.py index 667587024..85f235e32 100644 --- a/azext_edge/edge/providers/support/opcua.py +++ b/azext_edge/edge/providers/support/opcua.py @@ -44,7 +44,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for pod_name_label in pod_name_labels: opcua_pods.extend( process_v1_pods( - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, label_selector=pod_name_label, since_seconds=since_seconds, include_metrics=True, @@ -53,7 +53,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): opcua_pods.extend( process_v1_pods( - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL, since_seconds=since_seconds, include_metrics=True, @@ -63,34 +63,34 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): - processed = process_deployments(resource_api=OPCUA_API_V1, prefix_names=[OPC_PREFIX, SIMULATOR_PREFIX]) - processed.extend(process_deployments(resource_api=OPCUA_API_V1, label_selector=OPC_NAME_LABEL)) - processed.extend(process_deployments(resource_api=OPCUA_API_V1, label_selector=OPCUA_NAME_LABEL)) + processed = process_deployments(moniker=OPCUA_API_V1.moniker, prefix_names=[OPC_PREFIX, SIMULATOR_PREFIX]) + processed.extend(process_deployments(moniker=OPCUA_API_V1.moniker, label_selector=OPC_NAME_LABEL)) + processed.extend(process_deployments(moniker=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_replicasets(): - processed = process_replicasets(resource_api=OPCUA_API_V1, label_selector=OPC_APP_LABEL) - processed.extend(process_replicasets(resource_api=OPCUA_API_V1, label_selector=OPC_NAME_LABEL)) - processed.extend(process_replicasets(resource_api=OPCUA_API_V1, label_selector=OPCUA_NAME_LABEL)) + processed = process_replicasets(moniker=OPCUA_API_V1.moniker, label_selector=OPC_APP_LABEL) + processed.extend(process_replicasets(moniker=OPCUA_API_V1.moniker, label_selector=OPC_NAME_LABEL)) + processed.extend(process_replicasets(moniker=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_services(): - processed = process_services(resource_api=OPCUA_API_V1, label_selector=OPC_APP_LABEL) - processed.extend(process_services(resource_api=OPCUA_API_V1, prefix_names=[SIMULATOR_PREFIX])) - processed.extend(process_services(resource_api=OPCUA_API_V1, label_selector=OPCUA_NAME_LABEL)) + processed = process_services(moniker=OPCUA_API_V1.moniker, label_selector=OPC_APP_LABEL) + processed.extend(process_services(moniker=OPCUA_API_V1.moniker, prefix_names=[SIMULATOR_PREFIX])) + processed.extend(process_services(moniker=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_daemonsets(): processed = process_daemonsets( - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, field_selector="metadata.name==aio-opc-asset-discovery", ) processed.extend( process_daemonsets( - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL, ) ) diff --git a/azext_edge/edge/providers/support/orc.py b/azext_edge/edge/providers/support/orc.py index 2e5b15bef..b9bba066b 100644 --- a/azext_edge/edge/providers/support/orc.py +++ b/azext_edge/edge/providers/support/orc.py @@ -34,7 +34,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: processed.extend( process_v1_pods( - resource_api=ORC_API_V1, + moniker=ORC_API_V1.moniker, label_selector=label, since_seconds=since_seconds, ) @@ -46,7 +46,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_deployments(resource_api=ORC_API_V1, label_selector=label)) + processed.extend(process_deployments(moniker=ORC_API_V1.moniker, label_selector=label)) return processed @@ -54,7 +54,7 @@ def fetch_deployments(): def fetch_services(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_services(resource_api=ORC_API_V1, label_selector=label)) + processed.extend(process_services(moniker=ORC_API_V1.moniker, label_selector=label)) return processed @@ -62,7 +62,7 @@ def fetch_services(): def fetch_replicasets(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_replicasets(resource_api=ORC_API_V1, label_selector=label)) + processed.extend(process_replicasets(moniker=ORC_API_V1.moniker, label_selector=label)) return processed diff --git a/azext_edge/edge/providers/support/otel.py b/azext_edge/edge/providers/support/otel.py index 8d1bdbed0..062d40f2f 100644 --- a/azext_edge/edge/providers/support/otel.py +++ b/azext_edge/edge/providers/support/otel.py @@ -22,19 +22,19 @@ def fetch_otel_pods(since_seconds: int = DAY_IN_SECONDS): - return process_v1_pods(resource_api=OTEL_API, label_selector=OTEL_NAME_LABEL, since_seconds=since_seconds) + return process_v1_pods(moniker=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL, since_seconds=since_seconds) def fetch_otel_deployments(): - return process_deployments(resource_api=OTEL_API, label_selector=OTEL_NAME_LABEL) + return process_deployments(moniker=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) def fetch_otel_replicasets(): - return process_replicasets(resource_api=OTEL_API, label_selector=OTEL_NAME_LABEL) + return process_replicasets(moniker=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) def fetch_otel_services(): - return process_services(resource_api=OTEL_API, label_selector=OTEL_NAME_LABEL) + return process_services(moniker=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) support_runtime_elements = { diff --git a/azext_edge/edge/providers/support_bundle.py b/azext_edge/edge/providers/support_bundle.py index 497d481af..8c5d8b0a0 100644 --- a/azext_edge/edge/providers/support_bundle.py +++ b/azext_edge/edge/providers/support_bundle.py @@ -42,6 +42,7 @@ def build_bundle( ops_service: str, bundle_path: str, log_age_seconds: Optional[int] = None, + include_arc_agent: Optional[bool] = None, include_mq_traces: Optional[bool] = None, ): from rich.live import Live @@ -58,6 +59,18 @@ def build_bundle( from .support.shared import prepare_bundle as prepare_shared_bundle from .support.akri import prepare_bundle as prepare_akri_bundle from .support.otel import prepare_bundle as prepare_otel_bundle + from .support.arck8sagent.flux_log_agent import prepare_bundle as prepare_fluxlogagent_bundle + from .support.arck8sagent.meta_data_operator import prepare_bundle as prepare_metadataoperator_bundle + from .support.arck8sagent.controller_manager import prepare_bundle as prepare_controllermanager_bundle + from .support.arck8sagent.log_collector import prepare_bundle as prepare_logcollector_bundle + from .support.arck8sagent.cluster_identity_operator import prepare_bundle as prepare_clusteridentityoperator_bundle + from .support.arck8sagent.kube_aad_proxy import prepare_bundle as prepare_kubeaadproxy_bundle + from .support.arck8sagent.clusterconnect_agent import prepare_bundle as prepare_clusterconnectagent_bundle + from .support.arck8sagent.extension_events_collector import prepare_bundle as prepare_extensioneventscollector_bundle + from .support.arck8sagent.metrics_agent import prepare_bundle as prepare_metricsagent_bundle + from .support.arck8sagent.config_agent import prepare_bundle as prepare_configagent_bundle + from .support.arck8sagent.extension_manager import prepare_bundle as prepare_extensionmanager_bundle + from .support.arck8sagent.resource_sync_agent import prepare_bundle as prepare_resourcesyncagent_bundle pending_work = {k: {} for k in OpsServiceType.list()} pending_work.pop(OpsServiceType.auto.value) @@ -105,6 +118,21 @@ def build_bundle( bundle = bundle_method(deployed_apis, log_age_seconds) pending_work[service_moniker].update(bundle) + + # arc agent resources + if include_arc_agent: + pending_work["fluxlogagent"] = prepare_fluxlogagent_bundle(log_age_seconds) + pending_work["metadataoperator"] = prepare_metadataoperator_bundle(log_age_seconds) + pending_work["controllermanager"] = prepare_controllermanager_bundle(log_age_seconds) + pending_work["logcollector"] = prepare_logcollector_bundle(log_age_seconds) + pending_work["clusteridentityoperator"] = prepare_clusteridentityoperator_bundle(log_age_seconds) + pending_work["kubeaadproxy"] = prepare_kubeaadproxy_bundle(log_age_seconds) + pending_work["clusterconnectagent"] = prepare_clusterconnectagent_bundle(log_age_seconds) + pending_work["extensioneventscollector"] = prepare_extensioneventscollector_bundle(log_age_seconds) + pending_work["metricsagnet"] = prepare_metricsagent_bundle(log_age_seconds) + pending_work["configagent"] = prepare_configagent_bundle(log_age_seconds) + pending_work["extensionmanager"] = prepare_extensionmanager_bundle(log_age_seconds) + pending_work["resourcesyncagent"] = prepare_resourcesyncagent_bundle(log_age_seconds) # @digimaun - consider combining this work check with work count. if not any(v for _, v in pending_work.items()): diff --git a/azext_edge/tests/edge/support/create_bundle_int/test_akri_int.py b/azext_edge/tests/edge/support/create_bundle_int/test_akri_int.py index d080ff351..41aa71ea6 100644 --- a/azext_edge/tests/edge/support/create_bundle_int/test_akri_int.py +++ b/azext_edge/tests/edge/support/create_bundle_int/test_akri_int.py @@ -21,7 +21,7 @@ def test_create_bundle_akri(init_setup, tracked_files): check_custom_resource_files( file_objs=file_map, - resource_api=AKRI_API_V0 + resource_api=AKRI_API_V0, ) expected_workload_types = ["daemonset", "deployment", "pod", "replicaset", "service"] diff --git a/azext_edge/tests/edge/support/test_support_unit.py b/azext_edge/tests/edge/support/test_support_unit.py index 80254e311..2592b2f0f 100644 --- a/azext_edge/tests/edge/support/test_support_unit.py +++ b/azext_edge/tests/edge/support/test_support_unit.py @@ -158,7 +158,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, since_seconds=since_seconds, sub_group=sub_group, ) @@ -166,35 +166,35 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=AIO_BILLING_USAGE_NAME_LABEL, - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, sub_group=sub_group, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, sub_group=sub_group, ) assert_list_jobs( mocked_client, mocked_zipfile, label_selector=AIO_BILLING_USAGE_NAME_LABEL, - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, sub_group=sub_group, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, sub_group=sub_group, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - resource_api=CLUSTER_CONFIG_API_V1, + moniker=CLUSTER_CONFIG_API_V1.moniker, sub_group=sub_group, ) @@ -204,7 +204,7 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, - resource_api=MQ_API_V1B1, + moniker=MQ_API_V1B1.moniker, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", ) assert_list_pods( @@ -212,7 +212,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=MQ_LABEL, - resource_api=MQ_API_V1B1, + moniker=MQ_API_V1B1.moniker, since_seconds=since_seconds, ) assert_list_pods( @@ -220,25 +220,25 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=MQ_NAME_LABEL, - resource_api=MQ_API_V1B1, + moniker=MQ_API_V1B1.moniker, since_seconds=since_seconds, ) - assert_list_replica_sets(mocked_client, mocked_zipfile, label_selector=MQ_LABEL, resource_api=MQ_API_V1B1) + assert_list_replica_sets(mocked_client, mocked_zipfile, label_selector=MQ_LABEL, moniker=MQ_API_V1B1.moniker) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, resource_api=MQ_API_V1B1 + mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, moniker=MQ_API_V1B1.moniker ) assert_list_stateful_sets( - mocked_client, mocked_zipfile, label_selector=MQ_LABEL, field_selector=None, resource_api=MQ_API_V1B1 + mocked_client, mocked_zipfile, label_selector=MQ_LABEL, field_selector=None, moniker=MQ_API_V1B1.moniker ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, field_selector=None, - resource_api=MQ_API_V1B1, + moniker=MQ_API_V1B1.moniker, ) - assert_list_services(mocked_client, mocked_zipfile, label_selector=MQ_LABEL, resource_api=MQ_API_V1B1) - assert_list_services(mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, resource_api=MQ_API_V1B1) + assert_list_services(mocked_client, mocked_zipfile, label_selector=MQ_LABEL,moniker=MQ_API_V1B1.moniker) + assert_list_services(mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, moniker=MQ_API_V1B1.moniker) assert_mq_stats(mocked_zipfile) if api in [OPCUA_API_V1]: @@ -248,7 +248,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_APP_LABEL, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, since_seconds=since_seconds, include_metrics=True, ) @@ -257,7 +257,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_NAME_LABEL, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, since_seconds=since_seconds, include_metrics=True, ) @@ -266,7 +266,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_NAME_VAR_LABEL, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, since_seconds=since_seconds, include_metrics=True, ) @@ -275,7 +275,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPCUA_NAME_LABEL, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, since_seconds=since_seconds, include_metrics=True, ) @@ -283,64 +283,64 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=None, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, mock_names=["aio-opc-admission-controller", "aio-opc-supervisor", "aio-opc-opc", "opcplc-0000000"], ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=OPC_NAME_LABEL, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPC_NAME_LABEL, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=None, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, mock_names=["opcplc-0000000"], ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, resource_api=OPCUA_API_V1 + mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, moniker=OPCUA_API_V1.moniker ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, resource_api=OPCUA_API_V1 + mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, moniker=OPCUA_API_V1.moniker ) # TODO: one-off field selector remove after label assert_list_daemon_sets( mocked_client, mocked_zipfile, field_selector="metadata.name==aio-opc-asset-discovery", - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, ) if api in [DATA_PROCESSOR_API_V1]: @@ -350,13 +350,13 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_pods( @@ -364,7 +364,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=DATA_PROCESSOR_LABEL, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, since_seconds=since_seconds, pod_prefix_for_init_container_logs=["aio-"], ) @@ -373,79 +373,79 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, since_seconds=since_seconds, pod_prefix_for_init_container_logs=["aio-"], ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, resource_api=DATA_PROCESSOR_API_V1 + mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, moniker=DATA_PROCESSOR_API_V1.moniker ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, resource_api=DATA_PROCESSOR_API_V1 + mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, moniker=DATA_PROCESSOR_API_V1.moniker ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_INSTANCE_LABEL, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_PVC_APP_LABEL, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_ONEOFF_LABEL, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - resource_api=DATA_PROCESSOR_API_V1, + moniker=DATA_PROCESSOR_API_V1.moniker, ) if api in [ORC_API_V1]: @@ -455,16 +455,16 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=orc_label, - resource_api=ORC_API_V1, + moniker=ORC_API_V1.moniker, since_seconds=since_seconds, ) assert_list_deployments( - mocked_client, mocked_zipfile, label_selector=orc_label, resource_api=ORC_API_V1 + mocked_client, mocked_zipfile, label_selector=orc_label, moniker=ORC_API_V1.moniker ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=orc_label, resource_api=ORC_API_V1 + mocked_client, mocked_zipfile, label_selector=orc_label, moniker=ORC_API_V1.moniker ) - assert_list_services(mocked_client, mocked_zipfile, label_selector=orc_label, resource_api=ORC_API_V1) + assert_list_services(mocked_client, mocked_zipfile, label_selector=orc_label, moniker=ORC_API_V1.moniker) if api in [AKRI_API_V0]: assert_list_pods( @@ -472,7 +472,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_INSTANCE_LABEL, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, since_seconds=since_seconds, ) assert_list_pods( @@ -480,7 +480,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_APP_LABEL, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, since_seconds=since_seconds, ) assert_list_pods( @@ -488,7 +488,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=NAME_LABEL_FORMAT.format(label=f"{AKRI_AGENT_LABEL}, {AKRI_WEBHOOK_LABEL}"), - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, since_seconds=since_seconds, ) assert_list_pods( @@ -496,83 +496,83 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_NAME_LABEL_V2, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, since_seconds=since_seconds, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_APP_LABEL, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_APP_LABEL, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_WEBHOOK_LABEL), - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_SERVICE_LABEL, resource_api=AKRI_API_V0 + mocked_client, mocked_zipfile, label_selector=AKRI_SERVICE_LABEL, moniker=AKRI_API_V0.moniker ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, resource_api=AKRI_API_V0 + mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, moniker=AKRI_API_V0.moniker ) assert_list_services( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_WEBHOOK_LABEL), - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, resource_api=AKRI_API_V0 + mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, moniker=AKRI_API_V0.moniker ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_AGENT_LABEL), - resource_api=OPCUA_API_V1, + moniker=OPCUA_API_V1.moniker, ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - resource_api=AKRI_API_V0, + moniker=AKRI_API_V0.moniker, ) if api in [LNM_API_V1B1]: @@ -582,7 +582,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=lnm_app_label, - resource_api=LNM_API_V1B1, + moniker=LNM_API_V1B1.moniker, since_seconds=since_seconds, ) assert_list_pods( @@ -590,7 +590,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=None, - resource_api=LNM_API_V1B1, + moniker=LNM_API_V1B1.moniker, since_seconds=since_seconds, mock_names=["svclb-aio-lnm-operator"], ) @@ -598,21 +598,21 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=None, - resource_api=LNM_API_V1B1, + moniker=LNM_API_V1B1.moniker, mock_names=["aio-lnm-operator"], ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=lnm_app_label, resource_api=LNM_API_V1B1 + mocked_client, mocked_zipfile, label_selector=lnm_app_label, moniker=LNM_API_V1B1.moniker ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=lnm_app_label, resource_api=LNM_API_V1B1 + mocked_client, mocked_zipfile, label_selector=lnm_app_label, moniker=LNM_API_V1B1.moniker ) # TODO: test both without or with lnm instance assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=None, - resource_api=LNM_API_V1B1, + moniker=LNM_API_V1B1.moniker, mock_names=["svclb-aio-lnm-operator"], ) @@ -663,7 +663,7 @@ def assert_list_cron_jobs( mocked_client, mocked_zipfile, label_selector: str, - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, ): mocked_client.BatchV1Api().list_cron_job_for_all_namespaces.assert_any_call( @@ -673,7 +673,7 @@ def assert_list_cron_jobs( assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{resource_api.moniker}/{sub_group}cronjob.mock_cron_job.yaml", + zinfo=f"mock_namespace/{moniker}/{sub_group}cronjob.mock_cron_job.yaml", data="kind: CronJob\nmetadata:\n name: mock_cron_job\n namespace: mock_namespace\n", ) @@ -682,15 +682,13 @@ def assert_list_deployments( mocked_client, mocked_zipfile, label_selector: str, - resource_api: EdgeResourceApi, + moniker: str, field_selector: str = None, mock_names: List[str] = None, sub_group: Optional[str] = None, ): - moniker = resource_api.moniker - if resource_api in COMPAT_MQ_APIS.resource_apis: + if moniker == MQ_API_V1B1.moniker: # regardless of MQ API, MQ_ACTIVE_API.moniker is used for support/mq/fetch_diagnostic_metrics - moniker = MQ_ACTIVE_API.moniker from unittest.mock import call mocked_client.AppsV1Api().list_deployment_for_all_namespaces.assert_has_calls( @@ -723,7 +721,7 @@ def assert_list_jobs( mocked_client, mocked_zipfile, label_selector: str, - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, ): mocked_client.BatchV1Api().list_job_for_all_namespaces.assert_any_call( @@ -734,7 +732,7 @@ def assert_list_jobs( assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{resource_api.moniker}/{sub_group}job.mock_job.yaml", + zinfo=f"mock_namespace/{moniker}/{sub_group}job.mock_job.yaml", data="kind: Job\nmetadata:\n name: mock_job\n namespace: mock_namespace\n", ) @@ -744,7 +742,7 @@ def assert_list_pods( mocked_zipfile, mocked_list_pods, label_selector: str, - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, **kwargs, ): @@ -772,7 +770,7 @@ def assert_list_pods( ) assert_zipfile_write( mocked_zipfile, - zinfo=f"{namespace}/{resource_api.moniker}/pod.{pod_name}.metric.yaml", + zinfo=f"{namespace}/{moniker}/pod.{pod_name}.metric.yaml", data="apiVersion: metrics.k8s.io/v1beta1\nkind: PodMetrics\nmetadata:\n " "creationTimestamp: '0000-00-00T00:00:00Z'\n name: mock_custom_object\n " "namespace: namespace\ntimestamp: '0000-00-00T00:00:00Z'\n", @@ -787,7 +785,7 @@ def assert_list_pods( assert_zipfile_write( mocked_zipfile, - zinfo=f"{namespace}/{resource_api.moniker}/{sub_group}pod.{pod_name}.yaml", + zinfo=f"{namespace}/{moniker}/{sub_group}pod.{pod_name}.yaml", data=data, ) @@ -803,7 +801,7 @@ def assert_list_pods( previous_segment = ".previous" if previous_logs else "" assert_zipfile_write( mocked_zipfile, - zinfo=f"{namespace}/{resource_api.moniker}/" + zinfo=f"{namespace}/{moniker}/" f"{sub_group}pod.{pod_name}.{container_name}{previous_segment}.log", data=pods_with_container[namespace][pod_name][container_name], ) @@ -813,7 +811,7 @@ def assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector: str, - resource_api: EdgeResourceApi, + moniker: str, sub_group: Optional[str] = None, mock_names: Optional[List[str]] = None, ): @@ -824,7 +822,7 @@ def assert_list_replica_sets( for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{resource_api.moniker}/{sub_group}replicaset.{name}.yaml", + zinfo=f"mock_namespace/{moniker}/{sub_group}replicaset.{name}.yaml", data=f"kind: Replicaset\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -832,7 +830,7 @@ def assert_list_replica_sets( def assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, - resource_api: EdgeResourceApi, + moniker: str, label_selector: str = None, field_selector: str = None, sub_group: Optional[str] = None, @@ -844,7 +842,7 @@ def assert_list_persistent_volume_claims( assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{resource_api.moniker}/{sub_group}pvc.mock_pvc.yaml", + zinfo=f"mock_namespace/{moniker}/{sub_group}pvc.mock_pvc.yaml", data="kind: PersistentVolumeClaim\nmetadata:\n name: mock_pvc\n namespace: mock_namespace\n", ) @@ -852,7 +850,7 @@ def assert_list_persistent_volume_claims( def assert_list_stateful_sets( mocked_client, mocked_zipfile, - resource_api: EdgeResourceApi, + moniker: str, label_selector: Optional[str] = None, field_selector: Optional[str] = None, ): @@ -862,7 +860,7 @@ def assert_list_stateful_sets( assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{resource_api.moniker}/statefulset.mock_statefulset.yaml", + zinfo=f"mock_namespace/{moniker}/statefulset.mock_statefulset.yaml", data="kind: Statefulset\nmetadata:\n name: mock_statefulset\n namespace: mock_namespace\n", ) @@ -870,7 +868,7 @@ def assert_list_stateful_sets( def assert_list_services( mocked_client, mocked_zipfile, - resource_api: EdgeResourceApi, + moniker: str, label_selector: Optional[str] = None, field_selector: Optional[str] = None, mock_names: Optional[List[str]] = None, @@ -885,7 +883,7 @@ def assert_list_services( for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{resource_api.moniker}/{sub_group}service.{name}.yaml", + zinfo=f"mock_namespace/{moniker}/{sub_group}service.{name}.yaml", data=f"kind: Service\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -893,7 +891,7 @@ def assert_list_services( def assert_list_daemon_sets( mocked_client, mocked_zipfile, - resource_api: EdgeResourceApi, + moniker: str, label_selector: Optional[str] = None, field_selector: Optional[str] = None, mock_names: Optional[List[str]] = None, @@ -908,7 +906,7 @@ def assert_list_daemon_sets( for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{resource_api.moniker}/{sub_group}daemonset.{name}.yaml", + zinfo=f"mock_namespace/{moniker}/{sub_group}daemonset.{name}.yaml", data=f"kind: Daemonset\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -927,7 +925,7 @@ def assert_otel_kpis( "mocked_client": mocked_client, "mocked_zipfile": mocked_zipfile, "label_selector": OTEL_NAME_LABEL, - "resource_api": OTEL_API, + "moniker": OTEL_API.moniker, } if assert_func == assert_list_pods: kwargs["mocked_list_pods"] = mocked_list_pods From 6f1602013b97486cca8e13dc2e3f1eb82165327e Mon Sep 17 00:00:00 2001 From: Elsie4ever <3467996@gmail.com> Date: Fri, 10 May 2024 15:25:33 -0700 Subject: [PATCH 2/9] remove things --- azext_edge/edge/commands_edge.py | 2 -- azext_edge/edge/params.py | 6 ----- azext_edge/edge/providers/support_bundle.py | 28 --------------------- 3 files changed, 36 deletions(-) diff --git a/azext_edge/edge/commands_edge.py b/azext_edge/edge/commands_edge.py index faabe11b6..bd5b2cfc3 100644 --- a/azext_edge/edge/commands_edge.py +++ b/azext_edge/edge/commands_edge.py @@ -35,7 +35,6 @@ def support_bundle( log_age_seconds: int = 60 * 60 * 24, ops_service: str = OpsServiceType.auto.value, bundle_dir: Optional[str] = None, - include_arc_agent: Optional[bool] = None, include_mq_traces: Optional[bool] = None, context_name: Optional[str] = None, ) -> Union[Dict[str, Any], None]: @@ -47,7 +46,6 @@ def support_bundle( ops_service=ops_service, bundle_path=str(bundle_path), log_age_seconds=log_age_seconds, - include_arc_agent=include_arc_agent, include_mq_traces=include_mq_traces, ) diff --git a/azext_edge/edge/params.py b/azext_edge/edge/params.py index ef4b4af8f..58552acaf 100644 --- a/azext_edge/edge/params.py +++ b/azext_edge/edge/params.py @@ -74,12 +74,6 @@ def load_iotops_arguments(self, _): arg_type=get_three_state_flag(), help="Include mq traces in the support bundle. Usage may add considerable size to the produced bundle.", ) - context.argument( - "include_arc_agent", - options_list=["--arc-agent"], - arg_type=get_three_state_flag(), - help="Include arc agent logs in the support bundle. Usage may add considerable size to the produced bundle.", - ) with self.argument_context("iot ops check") as context: context.argument( diff --git a/azext_edge/edge/providers/support_bundle.py b/azext_edge/edge/providers/support_bundle.py index 8c5d8b0a0..497d481af 100644 --- a/azext_edge/edge/providers/support_bundle.py +++ b/azext_edge/edge/providers/support_bundle.py @@ -42,7 +42,6 @@ def build_bundle( ops_service: str, bundle_path: str, log_age_seconds: Optional[int] = None, - include_arc_agent: Optional[bool] = None, include_mq_traces: Optional[bool] = None, ): from rich.live import Live @@ -59,18 +58,6 @@ def build_bundle( from .support.shared import prepare_bundle as prepare_shared_bundle from .support.akri import prepare_bundle as prepare_akri_bundle from .support.otel import prepare_bundle as prepare_otel_bundle - from .support.arck8sagent.flux_log_agent import prepare_bundle as prepare_fluxlogagent_bundle - from .support.arck8sagent.meta_data_operator import prepare_bundle as prepare_metadataoperator_bundle - from .support.arck8sagent.controller_manager import prepare_bundle as prepare_controllermanager_bundle - from .support.arck8sagent.log_collector import prepare_bundle as prepare_logcollector_bundle - from .support.arck8sagent.cluster_identity_operator import prepare_bundle as prepare_clusteridentityoperator_bundle - from .support.arck8sagent.kube_aad_proxy import prepare_bundle as prepare_kubeaadproxy_bundle - from .support.arck8sagent.clusterconnect_agent import prepare_bundle as prepare_clusterconnectagent_bundle - from .support.arck8sagent.extension_events_collector import prepare_bundle as prepare_extensioneventscollector_bundle - from .support.arck8sagent.metrics_agent import prepare_bundle as prepare_metricsagent_bundle - from .support.arck8sagent.config_agent import prepare_bundle as prepare_configagent_bundle - from .support.arck8sagent.extension_manager import prepare_bundle as prepare_extensionmanager_bundle - from .support.arck8sagent.resource_sync_agent import prepare_bundle as prepare_resourcesyncagent_bundle pending_work = {k: {} for k in OpsServiceType.list()} pending_work.pop(OpsServiceType.auto.value) @@ -118,21 +105,6 @@ def build_bundle( bundle = bundle_method(deployed_apis, log_age_seconds) pending_work[service_moniker].update(bundle) - - # arc agent resources - if include_arc_agent: - pending_work["fluxlogagent"] = prepare_fluxlogagent_bundle(log_age_seconds) - pending_work["metadataoperator"] = prepare_metadataoperator_bundle(log_age_seconds) - pending_work["controllermanager"] = prepare_controllermanager_bundle(log_age_seconds) - pending_work["logcollector"] = prepare_logcollector_bundle(log_age_seconds) - pending_work["clusteridentityoperator"] = prepare_clusteridentityoperator_bundle(log_age_seconds) - pending_work["kubeaadproxy"] = prepare_kubeaadproxy_bundle(log_age_seconds) - pending_work["clusterconnectagent"] = prepare_clusterconnectagent_bundle(log_age_seconds) - pending_work["extensioneventscollector"] = prepare_extensioneventscollector_bundle(log_age_seconds) - pending_work["metricsagnet"] = prepare_metricsagent_bundle(log_age_seconds) - pending_work["configagent"] = prepare_configagent_bundle(log_age_seconds) - pending_work["extensionmanager"] = prepare_extensionmanager_bundle(log_age_seconds) - pending_work["resourcesyncagent"] = prepare_resourcesyncagent_bundle(log_age_seconds) # @digimaun - consider combining this work check with work count. if not any(v for _, v in pending_work.items()): From ec5d20fca62df4b64b29bead680534fe2c31265b Mon Sep 17 00:00:00 2001 From: Elsie4ever <3467996@gmail.com> Date: Fri, 10 May 2024 16:01:04 -0700 Subject: [PATCH 3/9] lint --- .../tests/edge/support/test_support_unit.py | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/azext_edge/tests/edge/support/test_support_unit.py b/azext_edge/tests/edge/support/test_support_unit.py index 2592b2f0f..c87c5f59f 100644 --- a/azext_edge/tests/edge/support/test_support_unit.py +++ b/azext_edge/tests/edge/support/test_support_unit.py @@ -223,7 +223,12 @@ def test_create_bundle( moniker=MQ_API_V1B1.moniker, since_seconds=since_seconds, ) - assert_list_replica_sets(mocked_client, mocked_zipfile, label_selector=MQ_LABEL, moniker=MQ_API_V1B1.moniker) + assert_list_replica_sets( + mocked_client, + mocked_zipfile, + label_selector=MQ_LABEL, + moniker=MQ_API_V1B1.moniker + ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, moniker=MQ_API_V1B1.moniker ) @@ -237,8 +242,18 @@ def test_create_bundle( field_selector=None, moniker=MQ_API_V1B1.moniker, ) - assert_list_services(mocked_client, mocked_zipfile, label_selector=MQ_LABEL,moniker=MQ_API_V1B1.moniker) - assert_list_services(mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, moniker=MQ_API_V1B1.moniker) + assert_list_services( + mocked_client, + mocked_zipfile, + label_selector=MQ_LABEL, + moniker=MQ_API_V1B1.moniker + ) + assert_list_services( + mocked_client, + mocked_zipfile, + label_selector=MQ_NAME_LABEL, + moniker=MQ_API_V1B1.moniker + ) assert_mq_stats(mocked_zipfile) if api in [OPCUA_API_V1]: @@ -379,7 +394,10 @@ def test_create_bundle( ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, moniker=DATA_PROCESSOR_API_V1.moniker + mocked_client, + mocked_zipfile, + label_selector=DATA_PROCESSOR_LABEL, + moniker=DATA_PROCESSOR_API_V1.moniker ) assert_list_replica_sets( mocked_client, @@ -402,7 +420,10 @@ def test_create_bundle( ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, moniker=DATA_PROCESSOR_API_V1.moniker + mocked_client, + mocked_zipfile, + label_selector=DATA_PROCESSOR_LABEL, + moniker=DATA_PROCESSOR_API_V1.moniker ) assert_list_services( mocked_client, @@ -464,7 +485,12 @@ def test_create_bundle( assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=orc_label, moniker=ORC_API_V1.moniker ) - assert_list_services(mocked_client, mocked_zipfile, label_selector=orc_label, moniker=ORC_API_V1.moniker) + assert_list_services( + mocked_client, + mocked_zipfile, + label_selector=orc_label, + moniker=ORC_API_V1.moniker + ) if api in [AKRI_API_V0]: assert_list_pods( From 4164500caae0fb097c6de3aeaefe4e4134a7d67f Mon Sep 17 00:00:00 2001 From: Elsie4ever <3467996@gmail.com> Date: Fri, 31 May 2024 09:33:56 -0700 Subject: [PATCH 4/9] combine moniker and subgroup for process_func in support bundle --- azext_edge/edge/providers/support/akri.py | 20 +- azext_edge/edge/providers/support/base.py | 116 +++------ .../support/{clusterconfig => }/billing.py | 26 +- .../support/clusterconfig/__init__.py | 5 - .../edge/providers/support/dataprocessor.py | 24 +- azext_edge/edge/providers/support/lnm.py | 12 +- azext_edge/edge/providers/support/mq.py | 24 +- azext_edge/edge/providers/support/opcua.py | 26 +- azext_edge/edge/providers/support/orc.py | 8 +- azext_edge/edge/providers/support/otel.py | 8 +- azext_edge/edge/providers/support_bundle.py | 2 +- azext_edge/tests/edge/support/conftest.py | 9 +- .../tests/edge/support/test_support_unit.py | 229 ++++++++---------- 13 files changed, 207 insertions(+), 302 deletions(-) rename azext_edge/edge/providers/support/{clusterconfig => }/billing.py (78%) delete mode 100644 azext_edge/edge/providers/support/clusterconfig/__init__.py diff --git a/azext_edge/edge/providers/support/akri.py b/azext_edge/edge/providers/support/akri.py index 1854f1720..64b4b6ecd 100644 --- a/azext_edge/edge/providers/support/akri.py +++ b/azext_edge/edge/providers/support/akri.py @@ -45,7 +45,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for pod_name_label in pod_name_labels: processed.extend( process_v1_pods( - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, label_selector=pod_name_label, since_seconds=since_seconds, ) @@ -53,7 +53,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): processed.extend( process_v1_pods( - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2, since_seconds=since_seconds, ) @@ -71,14 +71,14 @@ def fetch_deployments(): for deployment_name_label in deployment_name_labels: processed.extend( process_deployments( - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, label_selector=deployment_name_label, ) ) processed.extend( process_deployments( - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2, ) ) @@ -94,13 +94,13 @@ def fetch_daemonsets(): for daemonset_name_label in daemonset_name_labels: processed.extend( process_daemonsets( - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, label_selector=daemonset_name_label, ) ) processed.extend( - process_daemonsets(moniker=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) + process_daemonsets(file_path=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) ) return processed @@ -115,13 +115,13 @@ def fetch_services(): for service_name_label in service_name_labels: processed.extend( process_services( - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, label_selector=service_name_label, ) ) processed.extend( - process_services(moniker=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) + process_services(file_path=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) ) return processed @@ -136,13 +136,13 @@ def fetch_replicasets(): for replicaset_name_label in replicaset_name_labels: processed.extend( process_replicasets( - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, label_selector=replicaset_name_label, ) ) processed.extend( - process_replicasets(moniker=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) + process_replicasets(file_path=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) ) return processed diff --git a/azext_edge/edge/providers/support/base.py b/azext_edge/edge/providers/support/base.py index f0f82196a..cbaf6c308 100644 --- a/azext_edge/edge/providers/support/base.py +++ b/azext_edge/edge/providers/support/base.py @@ -28,8 +28,7 @@ def process_crd( version: str, kind: str, plural: str, - api_moniker: str, - sub_group: Optional[str] = None, + file_path: str, file_prefix: Optional[str] = None, ) -> List[dict]: result: dict = get_custom_objects( @@ -47,22 +46,16 @@ def process_crd( namespace = r["metadata"]["namespace"] namespaces.append(namespace) name = r["metadata"]["name"] - zinfo = _process_zinfo( - prefix=f"{namespace}/{api_moniker}", - suffix=f"{file_prefix}.{version}.{name}.yaml", - sub_group=sub_group, - ) processed.append({ "data": r, - "zinfo": zinfo, + "zinfo": f"{namespace}/{file_path}/{file_prefix}.{version}.{name}.yaml", }) return processed def process_v1_pods( - moniker: str, - sub_group: Optional[str] = None, + file_path: str, capture_previous_logs: bool = True, include_metrics: bool = False, since_seconds: int = DAY_IN_SECONDS, @@ -99,15 +92,10 @@ def process_v1_pods( # TODO: Workaround p.api_version = pods.api_version p.kind = "Pod" - zinfo = _process_zinfo( - prefix=f"{pod_namespace}/{moniker}", - suffix=f"pod.{pod_name}.yaml", - sub_group=sub_group, - ) processed.append( { "data": generic.sanitize_for_serialization(obj=p), - "zinfo": zinfo, + "zinfo": f"{pod_namespace}/{file_path}/pod.{pod_name}.yaml", } ) pod_spec: V1PodSpec = p.spec @@ -121,14 +109,13 @@ def process_v1_pods( processed.extend( _capture_pod_container_logs( + file_path=file_path, pod_containers=pod_containers, pod_name=pod_name, pod_namespace=pod_namespace, - moniker=moniker, v1_api=v1_api, since_seconds=since_seconds, capture_previous_logs=capture_previous_logs, - sub_group=sub_group, ) ) @@ -139,15 +126,10 @@ def process_v1_pods( "metrics.k8s.io", "v1beta1", pod_namespace, "pods", pod_name ) if metric: - zinfo = _process_zinfo( - prefix=f"{pod_namespace}/{moniker}", - suffix=f"pod.{pod_name}.metric.yaml", - sub_group=sub_group, - ) processed.append( { "data": metric, - "zinfo": zinfo, + "zinfo": f"{pod_namespace}/{file_path}/pod.{pod_name}.metric.yaml" } ) except ApiException as e: @@ -157,8 +139,7 @@ def process_v1_pods( def process_deployments( - moniker: str, - sub_group: Optional[str] = None, + file_path: str, return_namespaces: bool = False, field_selector: Optional[str] = None, label_selector: Optional[str] = None, @@ -173,9 +154,8 @@ def process_deployments( namespace_pods_work = {} processed = _process_kubernetes_resources( - sub_group=sub_group, + file_path=file_path, resources=deployments, - moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.deployment.value, ) @@ -193,8 +173,7 @@ def process_deployments( def process_statefulset( - moniker: str, - sub_group: Optional[str] = None, + file_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, ) -> List[dict]: @@ -206,16 +185,14 @@ def process_statefulset( ) return _process_kubernetes_resources( - sub_group=sub_group, + file_path=file_path, resources=statefulsets, - moniker=moniker, kind=BundleResourceKind.statefulset.value, ) def process_services( - moniker: str, - sub_group: Optional[str] = None, + file_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -228,17 +205,15 @@ def process_services( ) return _process_kubernetes_resources( - sub_group=sub_group, + file_path=file_path, resources=services, - moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.service.value, ) def process_replicasets( - moniker: str, - sub_group: Optional[str] = None, + file_path: str, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, ) -> List[dict]: @@ -248,17 +223,15 @@ def process_replicasets( replicasets: V1ReplicaSetList = v1_apps.list_replica_set_for_all_namespaces(label_selector=label_selector) return _process_kubernetes_resources( - sub_group=sub_group, + file_path=file_path, resources=replicasets, - moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.replicaset.value, ) def process_daemonsets( - moniker: str, - sub_group: Optional[str] = None, + file_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -271,9 +244,8 @@ def process_daemonsets( ) return _process_kubernetes_resources( - sub_group=sub_group, + file_path=file_path, resources=daemonsets, - moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.daemonset.value, ) @@ -326,8 +298,7 @@ def process_storage_classes() -> List[dict]: def process_persistent_volume_claims( - moniker: str, - sub_group: Optional[str] = None, + file_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -340,17 +311,15 @@ def process_persistent_volume_claims( ) return _process_kubernetes_resources( - sub_group=sub_group, + file_path=file_path, resources=pvcs, - moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.pvc.value, ) def process_jobs( - moniker: str, - sub_group: Optional[str] = None, + file_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -363,17 +332,15 @@ def process_jobs( ) return _process_kubernetes_resources( - sub_group=sub_group, + file_path=file_path, resources=jobs, - moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.job.value, ) def process_cron_jobs( - moniker: str, - sub_group: Optional[str] = None, + file_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -386,9 +353,8 @@ def process_cron_jobs( ) return _process_kubernetes_resources( - sub_group=sub_group, + file_path=file_path, resources=cron_jobs, - moniker=moniker, prefix_names=prefix_names, kind=BundleResourceKind.cronjob.value, ) @@ -396,8 +362,8 @@ def process_cron_jobs( def assemble_crd_work( apis: Iterable[EdgeResourceApi], - sub_group: Optional[str] = None, file_prefix_map: Optional[Dict[str, str]] = None, + sub_group: Optional[str] = None, ) -> dict: if not file_prefix_map: file_prefix_map = {} @@ -405,15 +371,15 @@ def assemble_crd_work( result = {} for api in apis: for kind in api.kinds: + file_path = api.moniker if not sub_group else f"{api.moniker}/{sub_group}" file_prefix = file_prefix_map.get(kind) result[f"{api.moniker} {api.version} {kind}"] = partial( process_crd, - sub_group=sub_group, group=api.group, version=api.version, kind=kind, plural=api._kinds[kind], # TODO: optimize - api_moniker=api.moniker, + file_path=file_path, file_prefix=file_prefix, ) @@ -433,14 +399,13 @@ def default_bundle_name(system_name: str) -> str: def _capture_pod_container_logs( + file_path: str, pod_containers: List[V1Container], pod_name: str, pod_namespace: str, - moniker: str, v1_api: client.CoreV1Api, capture_previous_logs: bool = True, since_seconds: int = DAY_IN_SECONDS, - sub_group: Optional[str] = None, ) -> List[dict]: processed = [] @@ -462,11 +427,7 @@ def _capture_pod_container_logs( previous=capture_previous, ) zinfo_previous_segment = "previous." if capture_previous else "" - zinfo = _process_zinfo( - prefix=f"{pod_namespace}/{moniker}", - suffix=f"pod.{pod_name}.{container.name}.{zinfo_previous_segment}log", - sub_group=sub_group, - ) + zinfo = f"{pod_namespace}/{file_path}/pod.{pod_name}.{container.name}.{zinfo_previous_segment}log" processed.append( { "data": log, @@ -480,10 +441,9 @@ def _capture_pod_container_logs( def _process_kubernetes_resources( + file_path: str, resources: object, - moniker: str, kind: str, - sub_group: Optional[str] = None, prefix_names: Optional[List[str]] = None, ) -> List[dict]: processed = [] @@ -511,29 +471,11 @@ def _process_kubernetes_resources( else: resource_type = kind.lower() - zinfo = _process_zinfo( - prefix=f"{resource_namespace}/{moniker}", - suffix=f"{resource_type}.{resource_name}.yaml", - sub_group=sub_group, - ) processed.append( { "data": generic.sanitize_for_serialization(obj=r), - "zinfo": zinfo, + "zinfo": f"{resource_namespace}/{file_path}/{resource_type}.{resource_name}.yaml", } ) return processed - - -def _process_zinfo( - prefix: str, - suffix: str, - sub_group: Optional[str] = None, -) -> str: - if not sub_group: - sub_group = "" - else: - sub_group = f"{sub_group}/" - - return f"{prefix}/{sub_group}{suffix}" diff --git a/azext_edge/edge/providers/support/clusterconfig/billing.py b/azext_edge/edge/providers/support/billing.py similarity index 78% rename from azext_edge/edge/providers/support/clusterconfig/billing.py rename to azext_edge/edge/providers/support/billing.py index 26e5af865..f175b1a92 100644 --- a/azext_edge/edge/providers/support/clusterconfig/billing.py +++ b/azext_edge/edge/providers/support/billing.py @@ -9,8 +9,8 @@ from knack.log import get_logger -from ...edge_api import CLUSTER_CONFIG_API_V1, EdgeResourceApi -from ..base import ( +from ..edge_api import CLUSTER_CONFIG_API_V1, EdgeResourceApi +from .base import ( DAY_IN_SECONDS, assemble_crd_work, process_cron_jobs, @@ -26,6 +26,7 @@ AIO_BILLING_USAGE_NAME_LABEL = "app.kubernetes.io/name in (microsoft-iotoperations)" ARC_BILLING_EXTENSION_COMP_LABEL = "app.kubernetes.io/component in (billing-operator)" BILLING_RESOURCE_KIND = "billing" +ARC_BILLING_FILE_PATH = f"{CLUSTER_CONFIG_API_V1.moniker}/{BILLING_RESOURCE_KIND}" def fetch_pods( @@ -33,19 +34,17 @@ def fetch_pods( ): # capture billing pods for aio usage billing_pods = process_v1_pods( - moniker=CLUSTER_CONFIG_API_V1.moniker, + file_path=ARC_BILLING_FILE_PATH, label_selector=AIO_BILLING_USAGE_NAME_LABEL, since_seconds=since_seconds, - sub_group=BILLING_RESOURCE_KIND, ) # capture billing pods for arc extension billing_pods.extend( process_v1_pods( - moniker=CLUSTER_CONFIG_API_V1.moniker, + file_path=ARC_BILLING_FILE_PATH, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, since_seconds=since_seconds, - sub_group=BILLING_RESOURCE_KIND, ) ) @@ -54,9 +53,8 @@ def fetch_pods( def fetch_jobs(): processed = process_jobs( - moniker=CLUSTER_CONFIG_API_V1.moniker, + file_path=ARC_BILLING_FILE_PATH, label_selector=AIO_BILLING_USAGE_NAME_LABEL, - sub_group=BILLING_RESOURCE_KIND, ) return processed @@ -64,9 +62,8 @@ def fetch_jobs(): def fetch_cron_jobs(): processed = process_cron_jobs( - moniker=CLUSTER_CONFIG_API_V1.moniker, + file_path=ARC_BILLING_FILE_PATH, label_selector=AIO_BILLING_USAGE_NAME_LABEL, - sub_group=BILLING_RESOURCE_KIND, ) return processed @@ -74,9 +71,8 @@ def fetch_cron_jobs(): def fetch_deployments(): processed = process_deployments( - moniker=CLUSTER_CONFIG_API_V1.moniker, + file_path=ARC_BILLING_FILE_PATH, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - sub_group=BILLING_RESOURCE_KIND, ) return processed @@ -84,17 +80,15 @@ def fetch_deployments(): def fetch_replicasets(): return process_replicasets( - moniker=CLUSTER_CONFIG_API_V1.moniker, + file_path=ARC_BILLING_FILE_PATH, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - sub_group=BILLING_RESOURCE_KIND, ) def fetch_services(): return process_services( - moniker=CLUSTER_CONFIG_API_V1.moniker, + file_path=ARC_BILLING_FILE_PATH, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - sub_group=BILLING_RESOURCE_KIND, ) diff --git a/azext_edge/edge/providers/support/clusterconfig/__init__.py b/azext_edge/edge/providers/support/clusterconfig/__init__.py deleted file mode 100644 index ced5cdf5b..000000000 --- a/azext_edge/edge/providers/support/clusterconfig/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# coding=utf-8 -# ---------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License file in the project root for license information. -# ---------------------------------------------------------------------------------------------- diff --git a/azext_edge/edge/providers/support/dataprocessor.py b/azext_edge/edge/providers/support/dataprocessor.py index 2cefe83c6..44a3cd0de 100644 --- a/azext_edge/edge/providers/support/dataprocessor.py +++ b/azext_edge/edge/providers/support/dataprocessor.py @@ -54,7 +54,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): dataprocessor_pods = process_v1_pods( - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL, since_seconds=since_seconds, pod_prefix_for_init_container_logs=[ @@ -65,7 +65,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): dataprocessor_pods.extend( process_v1_pods( - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, since_seconds=since_seconds, pod_prefix_for_init_container_logs=[ @@ -79,9 +79,9 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): - processed = process_deployments(moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL) + processed = process_deployments(file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL) processed.extend( - process_deployments(moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_deployments(file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -89,12 +89,12 @@ def fetch_deployments(): def fetch_statefulsets(): processed = process_statefulset( - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL, ) processed.extend( process_statefulset( - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, ) ) @@ -103,9 +103,9 @@ def fetch_statefulsets(): def fetch_replicasets(): - processed = process_replicasets(moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL) + processed = process_replicasets(file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL) processed.extend( - process_replicasets(moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_replicasets(file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -120,13 +120,13 @@ def fetch_services(): for service_name_label in service_name_labels: processed.extend( process_services( - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=service_name_label, ) ) processed.extend( - process_services(moniker=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_services(file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -143,14 +143,14 @@ def fetch_persistent_volume_claims(): for persistent_volume_claims_name_label in persistent_volume_claims_name_labels: processed.extend( process_persistent_volume_claims( - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=persistent_volume_claims_name_label, ) ) processed.extend( process_persistent_volume_claims( - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2 ) ) diff --git a/azext_edge/edge/providers/support/lnm.py b/azext_edge/edge/providers/support/lnm.py index c58c60e1a..9faa02fe7 100644 --- a/azext_edge/edge/providers/support/lnm.py +++ b/azext_edge/edge/providers/support/lnm.py @@ -29,7 +29,7 @@ def fetch_replicasets(): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) return process_replicasets( - moniker=LNM_API_V1B1.moniker, + file_path=LNM_API_V1B1.moniker, label_selector=lnm_labels, ) @@ -38,13 +38,13 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) processed = process_v1_pods( - moniker=LNM_API_V1B1.moniker, + file_path=LNM_API_V1B1.moniker, label_selector=lnm_labels, since_seconds=since_seconds, ) processed.extend( process_v1_pods( - moniker=LNM_API_V1B1.moniker, + file_path=LNM_API_V1B1.moniker, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"], since_seconds=since_seconds, @@ -57,19 +57,19 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_services(): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) - return process_services(moniker=LNM_API_V1B1.moniker, label_selector=lnm_labels) + return process_services(file_path=LNM_API_V1B1.moniker, label_selector=lnm_labels) def fetch_lnm_deployments(): deployment_prefixes = [f"{LNM_LABEL_PREFIX}-{name}" for name in _fetch_lnm_instance_names()] deployment_prefixes.extend(LNM_APP_LABELS) - return process_deployments(moniker=LNM_API_V1B1.moniker, label_selector=None, prefix_names=deployment_prefixes) + return process_deployments(file_path=LNM_API_V1B1.moniker, label_selector=None, prefix_names=deployment_prefixes) def fetch_daemonsets(): return process_daemonsets( - moniker=LNM_API_V1B1.moniker, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"] + file_path=LNM_API_V1B1.moniker, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"] ) diff --git a/azext_edge/edge/providers/support/mq.py b/azext_edge/edge/providers/support/mq.py index 05b84fce1..2801f853a 100644 --- a/azext_edge/edge/providers/support/mq.py +++ b/azext_edge/edge/providers/support/mq.py @@ -88,16 +88,16 @@ def fetch_diagnostic_traces(): def fetch_deployments(): processed, namespaces = process_deployments( - moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, return_namespaces=True + file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, return_namespaces=True ) # aio-mq-operator deployment has no app label operators, operator_namespaces = process_deployments( - moniker=MQ_ACTIVE_API.moniker, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", return_namespaces=True + file_path=MQ_ACTIVE_API.moniker, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", return_namespaces=True ) processed.extend(operators) operators_v2, operator_namespaces_v2 = process_deployments( - moniker=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, return_namespaces=True + file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, return_namespaces=True ) processed.extend(operators_v2) @@ -122,12 +122,12 @@ def fetch_deployments(): def fetch_statefulsets(): processed = process_statefulset( - moniker=MQ_ACTIVE_API.moniker, + file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, ) processed.extend( process_statefulset( - moniker=MQ_ACTIVE_API.moniker, + file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, ) ) @@ -144,7 +144,7 @@ def fetch_statefulsets(): for connector in connectors: connector_name = connector.get("metadata", {}).get("name") stateful_set = process_statefulset( - moniker=MQ_ACTIVE_API.moniker, + file_path=MQ_ACTIVE_API.moniker, field_selector=f"metadata.name={AIO_MQ_RESOURCE_PREFIX}{connector_name}", ) processed.extend(stateful_set) @@ -154,12 +154,12 @@ def fetch_statefulsets(): def fetch_services(): processed = process_services( - moniker=MQ_ACTIVE_API.moniker, + file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, ) processed.extend( process_services( - moniker=MQ_ACTIVE_API.moniker, + file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, ) ) @@ -169,12 +169,12 @@ def fetch_services(): def fetch_replicasets(): processed = process_replicasets( - moniker=MQ_ACTIVE_API.moniker, + file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, ) processed.extend( process_replicasets( - moniker=MQ_ACTIVE_API.moniker, + file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, ) ) @@ -184,13 +184,13 @@ def fetch_replicasets(): def fetch_pods(since_seconds: int = DAY_IN_SECONDS): processed = process_v1_pods( - moniker=MQ_ACTIVE_API.moniker, + file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, since_seconds=since_seconds, ) processed.extend( process_v1_pods( - moniker=MQ_ACTIVE_API.moniker, + file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, since_seconds=since_seconds, ) diff --git a/azext_edge/edge/providers/support/opcua.py b/azext_edge/edge/providers/support/opcua.py index 85f235e32..89ab49beb 100644 --- a/azext_edge/edge/providers/support/opcua.py +++ b/azext_edge/edge/providers/support/opcua.py @@ -44,7 +44,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for pod_name_label in pod_name_labels: opcua_pods.extend( process_v1_pods( - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, label_selector=pod_name_label, since_seconds=since_seconds, include_metrics=True, @@ -53,7 +53,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): opcua_pods.extend( process_v1_pods( - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL, since_seconds=since_seconds, include_metrics=True, @@ -63,34 +63,34 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): - processed = process_deployments(moniker=OPCUA_API_V1.moniker, prefix_names=[OPC_PREFIX, SIMULATOR_PREFIX]) - processed.extend(process_deployments(moniker=OPCUA_API_V1.moniker, label_selector=OPC_NAME_LABEL)) - processed.extend(process_deployments(moniker=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) + processed = process_deployments(file_path=OPCUA_API_V1.moniker, prefix_names=[OPC_PREFIX, SIMULATOR_PREFIX]) + processed.extend(process_deployments(file_path=OPCUA_API_V1.moniker, label_selector=OPC_NAME_LABEL)) + processed.extend(process_deployments(file_path=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_replicasets(): - processed = process_replicasets(moniker=OPCUA_API_V1.moniker, label_selector=OPC_APP_LABEL) - processed.extend(process_replicasets(moniker=OPCUA_API_V1.moniker, label_selector=OPC_NAME_LABEL)) - processed.extend(process_replicasets(moniker=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) + processed = process_replicasets(file_path=OPCUA_API_V1.moniker, label_selector=OPC_APP_LABEL) + processed.extend(process_replicasets(file_path=OPCUA_API_V1.moniker, label_selector=OPC_NAME_LABEL)) + processed.extend(process_replicasets(file_path=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_services(): - processed = process_services(moniker=OPCUA_API_V1.moniker, label_selector=OPC_APP_LABEL) - processed.extend(process_services(moniker=OPCUA_API_V1.moniker, prefix_names=[SIMULATOR_PREFIX])) - processed.extend(process_services(moniker=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) + processed = process_services(file_path=OPCUA_API_V1.moniker, label_selector=OPC_APP_LABEL) + processed.extend(process_services(file_path=OPCUA_API_V1.moniker, prefix_names=[SIMULATOR_PREFIX])) + processed.extend(process_services(file_path=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_daemonsets(): processed = process_daemonsets( - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, field_selector="metadata.name==aio-opc-asset-discovery", ) processed.extend( process_daemonsets( - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL, ) ) diff --git a/azext_edge/edge/providers/support/orc.py b/azext_edge/edge/providers/support/orc.py index b9bba066b..c1da71387 100644 --- a/azext_edge/edge/providers/support/orc.py +++ b/azext_edge/edge/providers/support/orc.py @@ -34,7 +34,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: processed.extend( process_v1_pods( - moniker=ORC_API_V1.moniker, + file_path=ORC_API_V1.moniker, label_selector=label, since_seconds=since_seconds, ) @@ -46,7 +46,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_deployments(moniker=ORC_API_V1.moniker, label_selector=label)) + processed.extend(process_deployments(file_path=ORC_API_V1.moniker, label_selector=label)) return processed @@ -54,7 +54,7 @@ def fetch_deployments(): def fetch_services(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_services(moniker=ORC_API_V1.moniker, label_selector=label)) + processed.extend(process_services(file_path=ORC_API_V1.moniker, label_selector=label)) return processed @@ -62,7 +62,7 @@ def fetch_services(): def fetch_replicasets(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_replicasets(moniker=ORC_API_V1.moniker, label_selector=label)) + processed.extend(process_replicasets(file_path=ORC_API_V1.moniker, label_selector=label)) return processed diff --git a/azext_edge/edge/providers/support/otel.py b/azext_edge/edge/providers/support/otel.py index 062d40f2f..28133450b 100644 --- a/azext_edge/edge/providers/support/otel.py +++ b/azext_edge/edge/providers/support/otel.py @@ -22,19 +22,19 @@ def fetch_otel_pods(since_seconds: int = DAY_IN_SECONDS): - return process_v1_pods(moniker=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL, since_seconds=since_seconds) + return process_v1_pods(file_path=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL, since_seconds=since_seconds) def fetch_otel_deployments(): - return process_deployments(moniker=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) + return process_deployments(file_path=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) def fetch_otel_replicasets(): - return process_replicasets(moniker=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) + return process_replicasets(file_path=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) def fetch_otel_services(): - return process_services(moniker=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) + return process_services(file_path=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) support_runtime_elements = { diff --git a/azext_edge/edge/providers/support_bundle.py b/azext_edge/edge/providers/support_bundle.py index 497d481af..68ecab8c8 100644 --- a/azext_edge/edge/providers/support_bundle.py +++ b/azext_edge/edge/providers/support_bundle.py @@ -48,7 +48,7 @@ def build_bundle( from rich.progress import Progress from rich.table import Table - from .support.clusterconfig.billing import prepare_bundle as prepare_billing_bundle + from .support.billing import prepare_bundle as prepare_billing_bundle from .support.dataprocessor import prepare_bundle as prepare_dataprocessor_bundle from .support.mq import prepare_bundle as prepare_mq_bundle from .support.lnm import prepare_bundle as prepare_lnm_bundle diff --git a/azext_edge/tests/edge/support/conftest.py b/azext_edge/tests/edge/support/conftest.py index 1df72064f..21d797933 100644 --- a/azext_edge/tests/edge/support/conftest.py +++ b/azext_edge/tests/edge/support/conftest.py @@ -5,7 +5,7 @@ # ---------------------------------------------------------------------------------------------- from functools import partial -from typing import List, Optional +from typing import List from ...generators import generate_random_string import pytest @@ -46,13 +46,6 @@ def add_pod_to_mocked_pods( mocked_client.CoreV1Api().read_namespaced_pod_log.return_value = mock_log -def process_sub_group(sub_group: Optional[str]): - if not sub_group: - return "" - - return f"{sub_group}/" - - @pytest.fixture def mocked_client(mocker, mocked_client): patched = mocker.patch("azext_edge.edge.providers.support.base.client", autospec=True) diff --git a/azext_edge/tests/edge/support/test_support_unit.py b/azext_edge/tests/edge/support/test_support_unit.py index c87c5f59f..fc8149a53 100644 --- a/azext_edge/tests/edge/support/test_support_unit.py +++ b/azext_edge/tests/edge/support/test_support_unit.py @@ -36,9 +36,10 @@ AKRI_WEBHOOK_LABEL, ) from azext_edge.edge.providers.support.base import get_bundle_path -from azext_edge.edge.providers.support.clusterconfig.billing import ( +from azext_edge.edge.providers.support.billing import ( AIO_BILLING_USAGE_NAME_LABEL, ARC_BILLING_EXTENSION_COMP_LABEL, + ARC_BILLING_FILE_PATH, BILLING_RESOURCE_KIND, ) from azext_edge.edge.providers.support.dataprocessor import ( @@ -66,7 +67,7 @@ from azext_edge.edge.providers.support_bundle import COMPAT_MQ_APIS from ...generators import generate_random_string -from .conftest import add_pod_to_mocked_pods, process_sub_group +from .conftest import add_pod_to_mocked_pods a_bundle_dir = f"support_test_{generate_random_string()}" @@ -158,44 +159,38 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - moniker=CLUSTER_CONFIG_API_V1.moniker, + file_path=ARC_BILLING_FILE_PATH, since_seconds=since_seconds, - sub_group=sub_group, ) assert_list_cron_jobs( mocked_client, mocked_zipfile, label_selector=AIO_BILLING_USAGE_NAME_LABEL, - moniker=CLUSTER_CONFIG_API_V1.moniker, - sub_group=sub_group, + file_path=ARC_BILLING_FILE_PATH, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - moniker=CLUSTER_CONFIG_API_V1.moniker, - sub_group=sub_group, + file_path=ARC_BILLING_FILE_PATH, ) assert_list_jobs( mocked_client, mocked_zipfile, label_selector=AIO_BILLING_USAGE_NAME_LABEL, - moniker=CLUSTER_CONFIG_API_V1.moniker, - sub_group=sub_group, + file_path=ARC_BILLING_FILE_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - moniker=CLUSTER_CONFIG_API_V1.moniker, - sub_group=sub_group, + file_path=ARC_BILLING_FILE_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - moniker=CLUSTER_CONFIG_API_V1.moniker, - sub_group=sub_group, + file_path=ARC_BILLING_FILE_PATH, ) if api in COMPAT_MQ_APIS.resource_apis: @@ -204,7 +199,7 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, - moniker=MQ_API_V1B1.moniker, + file_path=MQ_API_V1B1.moniker, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", ) assert_list_pods( @@ -212,7 +207,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=MQ_LABEL, - moniker=MQ_API_V1B1.moniker, + file_path=MQ_API_V1B1.moniker, since_seconds=since_seconds, ) assert_list_pods( @@ -220,39 +215,43 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=MQ_NAME_LABEL, - moniker=MQ_API_V1B1.moniker, + file_path=MQ_API_V1B1.moniker, since_seconds=since_seconds, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, - moniker=MQ_API_V1B1.moniker + file_path=MQ_API_V1B1.moniker ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, moniker=MQ_API_V1B1.moniker + mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, file_path=MQ_API_V1B1.moniker ) assert_list_stateful_sets( - mocked_client, mocked_zipfile, label_selector=MQ_LABEL, field_selector=None, moniker=MQ_API_V1B1.moniker + mocked_client, + mocked_zipfile, + label_selector=MQ_LABEL, + field_selector=None, + file_path=MQ_API_V1B1.moniker ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, field_selector=None, - moniker=MQ_API_V1B1.moniker, + file_path=MQ_API_V1B1.moniker, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, - moniker=MQ_API_V1B1.moniker + file_path=MQ_API_V1B1.moniker ) assert_list_services( mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, - moniker=MQ_API_V1B1.moniker + file_path=MQ_API_V1B1.moniker ) assert_mq_stats(mocked_zipfile) @@ -263,7 +262,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_APP_LABEL, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, since_seconds=since_seconds, include_metrics=True, ) @@ -272,7 +271,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_NAME_LABEL, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, since_seconds=since_seconds, include_metrics=True, ) @@ -281,7 +280,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_NAME_VAR_LABEL, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, since_seconds=since_seconds, include_metrics=True, ) @@ -290,7 +289,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPCUA_NAME_LABEL, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, since_seconds=since_seconds, include_metrics=True, ) @@ -298,64 +297,64 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=None, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, mock_names=["aio-opc-admission-controller", "aio-opc-supervisor", "aio-opc-opc", "opcplc-0000000"], ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=OPC_NAME_LABEL, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPC_NAME_LABEL, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=None, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, mock_names=["opcplc-0000000"], ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, moniker=OPCUA_API_V1.moniker + mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, file_path=OPCUA_API_V1.moniker ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, moniker=OPCUA_API_V1.moniker + mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, file_path=OPCUA_API_V1.moniker ) # TODO: one-off field selector remove after label assert_list_daemon_sets( mocked_client, mocked_zipfile, field_selector="metadata.name==aio-opc-asset-discovery", - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, ) if api in [DATA_PROCESSOR_API_V1]: @@ -365,13 +364,13 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_pods( @@ -379,7 +378,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=DATA_PROCESSOR_LABEL, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, since_seconds=since_seconds, pod_prefix_for_init_container_logs=["aio-"], ) @@ -388,7 +387,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, since_seconds=since_seconds, pod_prefix_for_init_container_logs=["aio-"], ) @@ -397,76 +396,76 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - moniker=DATA_PROCESSOR_API_V1.moniker + file_path=DATA_PROCESSOR_API_V1.moniker ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - moniker=DATA_PROCESSOR_API_V1.moniker + file_path=DATA_PROCESSOR_API_V1.moniker ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_INSTANCE_LABEL, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_PVC_APP_LABEL, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_ONEOFF_LABEL, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - moniker=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_API_V1.moniker, ) if api in [ORC_API_V1]: @@ -476,20 +475,20 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=orc_label, - moniker=ORC_API_V1.moniker, + file_path=ORC_API_V1.moniker, since_seconds=since_seconds, ) assert_list_deployments( - mocked_client, mocked_zipfile, label_selector=orc_label, moniker=ORC_API_V1.moniker + mocked_client, mocked_zipfile, label_selector=orc_label, file_path=ORC_API_V1.moniker ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=orc_label, moniker=ORC_API_V1.moniker + mocked_client, mocked_zipfile, label_selector=orc_label, file_path=ORC_API_V1.moniker ) assert_list_services( mocked_client, mocked_zipfile, label_selector=orc_label, - moniker=ORC_API_V1.moniker + file_path=ORC_API_V1.moniker ) if api in [AKRI_API_V0]: @@ -498,7 +497,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_INSTANCE_LABEL, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, since_seconds=since_seconds, ) assert_list_pods( @@ -506,7 +505,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_APP_LABEL, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, since_seconds=since_seconds, ) assert_list_pods( @@ -514,7 +513,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=NAME_LABEL_FORMAT.format(label=f"{AKRI_AGENT_LABEL}, {AKRI_WEBHOOK_LABEL}"), - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, since_seconds=since_seconds, ) assert_list_pods( @@ -522,83 +521,83 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_NAME_LABEL_V2, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, since_seconds=since_seconds, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_APP_LABEL, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_APP_LABEL, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_WEBHOOK_LABEL), - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_SERVICE_LABEL, moniker=AKRI_API_V0.moniker + mocked_client, mocked_zipfile, label_selector=AKRI_SERVICE_LABEL, file_path=AKRI_API_V0.moniker ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, moniker=AKRI_API_V0.moniker + mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, file_path=AKRI_API_V0.moniker ) assert_list_services( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_WEBHOOK_LABEL), - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, moniker=AKRI_API_V0.moniker + mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, file_path=AKRI_API_V0.moniker ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_AGENT_LABEL), - moniker=OPCUA_API_V1.moniker, + file_path=OPCUA_API_V1.moniker, ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - moniker=AKRI_API_V0.moniker, + file_path=AKRI_API_V0.moniker, ) if api in [LNM_API_V1B1]: @@ -608,7 +607,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=lnm_app_label, - moniker=LNM_API_V1B1.moniker, + file_path=LNM_API_V1B1.moniker, since_seconds=since_seconds, ) assert_list_pods( @@ -616,7 +615,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=None, - moniker=LNM_API_V1B1.moniker, + file_path=LNM_API_V1B1.moniker, since_seconds=since_seconds, mock_names=["svclb-aio-lnm-operator"], ) @@ -624,21 +623,21 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=None, - moniker=LNM_API_V1B1.moniker, + file_path=LNM_API_V1B1.moniker, mock_names=["aio-lnm-operator"], ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=lnm_app_label, moniker=LNM_API_V1B1.moniker + mocked_client, mocked_zipfile, label_selector=lnm_app_label, file_path=LNM_API_V1B1.moniker ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=lnm_app_label, moniker=LNM_API_V1B1.moniker + mocked_client, mocked_zipfile, label_selector=lnm_app_label, file_path=LNM_API_V1B1.moniker ) # TODO: test both without or with lnm instance assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=None, - moniker=LNM_API_V1B1.moniker, + file_path=LNM_API_V1B1.moniker, mock_names=["svclb-aio-lnm-operator"], ) @@ -676,7 +675,7 @@ def assert_get_custom_resources( if not file_prefix: file_prefix = kind - sub_group = process_sub_group(sub_group) + sub_group = f"{sub_group}/" if sub_group else "" assert_zipfile_write( mocked_zipfile, @@ -689,17 +688,15 @@ def assert_list_cron_jobs( mocked_client, mocked_zipfile, label_selector: str, - moniker: str, - sub_group: Optional[str] = None, + file_path: str, ): mocked_client.BatchV1Api().list_cron_job_for_all_namespaces.assert_any_call( label_selector=label_selector, field_selector=None ) - sub_group = process_sub_group(sub_group) assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{moniker}/{sub_group}cronjob.mock_cron_job.yaml", + zinfo=f"mock_namespace/{file_path}/cronjob.mock_cron_job.yaml", data="kind: CronJob\nmetadata:\n name: mock_cron_job\n namespace: mock_namespace\n", ) @@ -708,12 +705,11 @@ def assert_list_deployments( mocked_client, mocked_zipfile, label_selector: str, - moniker: str, + file_path: str, field_selector: str = None, mock_names: List[str] = None, - sub_group: Optional[str] = None, ): - if moniker == MQ_API_V1B1.moniker: + if MQ_API_V1B1.moniker in file_path: # regardless of MQ API, MQ_ACTIVE_API.moniker is used for support/mq/fetch_diagnostic_metrics from unittest.mock import call @@ -731,14 +727,12 @@ def assert_list_deployments( label_selector=label_selector, field_selector=field_selector ) - sub_group = process_sub_group(sub_group) - # @jiacju - no label for lnm mock_names = mock_names or ["mock_deployment"] for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{moniker}/{sub_group}deployment.{name}.yaml", + zinfo=f"mock_namespace/{file_path}/deployment.{name}.yaml", data=f"kind: Deployment\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -747,18 +741,15 @@ def assert_list_jobs( mocked_client, mocked_zipfile, label_selector: str, - moniker: str, - sub_group: Optional[str] = None, + file_path: str, ): mocked_client.BatchV1Api().list_job_for_all_namespaces.assert_any_call( label_selector=label_selector, field_selector=None ) - sub_group = process_sub_group(sub_group) - assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{moniker}/{sub_group}job.mock_job.yaml", + zinfo=f"mock_namespace/{file_path}/job.mock_job.yaml", data="kind: Job\nmetadata:\n name: mock_job\n namespace: mock_namespace\n", ) @@ -768,12 +759,10 @@ def assert_list_pods( mocked_zipfile, mocked_list_pods, label_selector: str, - moniker: str, - sub_group: Optional[str] = None, + file_path: str, **kwargs, ): mocked_client.CoreV1Api().list_pod_for_all_namespaces.assert_any_call(label_selector=label_selector) - sub_group = process_sub_group(sub_group) for namespace in mocked_list_pods: for pod_name in mocked_list_pods[namespace]: @@ -796,7 +785,7 @@ def assert_list_pods( ) assert_zipfile_write( mocked_zipfile, - zinfo=f"{namespace}/{moniker}/pod.{pod_name}.metric.yaml", + zinfo=f"{namespace}/{file_path}/pod.{pod_name}.metric.yaml", data="apiVersion: metrics.k8s.io/v1beta1\nkind: PodMetrics\nmetadata:\n " "creationTimestamp: '0000-00-00T00:00:00Z'\n name: mock_custom_object\n " "namespace: namespace\ntimestamp: '0000-00-00T00:00:00Z'\n", @@ -811,7 +800,7 @@ def assert_list_pods( assert_zipfile_write( mocked_zipfile, - zinfo=f"{namespace}/{moniker}/{sub_group}pod.{pod_name}.yaml", + zinfo=f"{namespace}/{file_path}/pod.{pod_name}.yaml", data=data, ) @@ -827,8 +816,8 @@ def assert_list_pods( previous_segment = ".previous" if previous_logs else "" assert_zipfile_write( mocked_zipfile, - zinfo=f"{namespace}/{moniker}/" - f"{sub_group}pod.{pod_name}.{container_name}{previous_segment}.log", + zinfo=f"{namespace}/{file_path}/" + f"pod.{pod_name}.{container_name}{previous_segment}.log", data=pods_with_container[namespace][pod_name][container_name], ) @@ -837,18 +826,16 @@ def assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector: str, - moniker: str, - sub_group: Optional[str] = None, + file_path: str, mock_names: Optional[List[str]] = None, ): mocked_client.AppsV1Api().list_replica_set_for_all_namespaces.assert_any_call(label_selector=label_selector) mock_names = mock_names or ["mock_replicaset"] - sub_group = process_sub_group(sub_group) for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{moniker}/{sub_group}replicaset.{name}.yaml", + zinfo=f"mock_namespace/{file_path}/replicaset.{name}.yaml", data=f"kind: Replicaset\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -856,19 +843,17 @@ def assert_list_replica_sets( def assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, - moniker: str, + file_path: str, label_selector: str = None, field_selector: str = None, - sub_group: Optional[str] = None, ): mocked_client.CoreV1Api().list_persistent_volume_claim_for_all_namespaces.assert_any_call( label_selector=label_selector, field_selector=field_selector ) - sub_group = process_sub_group(sub_group) assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{moniker}/{sub_group}pvc.mock_pvc.yaml", + zinfo=f"mock_namespace/{file_path}/pvc.mock_pvc.yaml", data="kind: PersistentVolumeClaim\nmetadata:\n name: mock_pvc\n namespace: mock_namespace\n", ) @@ -876,7 +861,7 @@ def assert_list_persistent_volume_claims( def assert_list_stateful_sets( mocked_client, mocked_zipfile, - moniker: str, + file_path: str, label_selector: Optional[str] = None, field_selector: Optional[str] = None, ): @@ -886,7 +871,7 @@ def assert_list_stateful_sets( assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{moniker}/statefulset.mock_statefulset.yaml", + zinfo=f"mock_namespace/{file_path}/statefulset.mock_statefulset.yaml", data="kind: Statefulset\nmetadata:\n name: mock_statefulset\n namespace: mock_namespace\n", ) @@ -894,22 +879,20 @@ def assert_list_stateful_sets( def assert_list_services( mocked_client, mocked_zipfile, - moniker: str, + file_path: str, label_selector: Optional[str] = None, field_selector: Optional[str] = None, mock_names: Optional[List[str]] = None, - sub_group: Optional[str] = None, ): mocked_client.CoreV1Api().list_service_for_all_namespaces.assert_any_call( label_selector=label_selector, field_selector=field_selector ) mock_names = mock_names or ["mock_service"] - sub_group = process_sub_group(sub_group) for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{moniker}/{sub_group}service.{name}.yaml", + zinfo=f"mock_namespace/{file_path}/service.{name}.yaml", data=f"kind: Service\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -917,22 +900,20 @@ def assert_list_services( def assert_list_daemon_sets( mocked_client, mocked_zipfile, - moniker: str, + file_path: str, label_selector: Optional[str] = None, field_selector: Optional[str] = None, mock_names: Optional[List[str]] = None, - sub_group: Optional[str] = None, ): mocked_client.AppsV1Api().list_daemon_set_for_all_namespaces.assert_any_call( label_selector=label_selector, field_selector=field_selector ) mock_names = mock_names or ["mock_daemonset"] - sub_group = process_sub_group(sub_group) for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{moniker}/{sub_group}daemonset.{name}.yaml", + zinfo=f"mock_namespace/{file_path}/daemonset.{name}.yaml", data=f"kind: Daemonset\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -951,7 +932,7 @@ def assert_otel_kpis( "mocked_client": mocked_client, "mocked_zipfile": mocked_zipfile, "label_selector": OTEL_NAME_LABEL, - "moniker": OTEL_API.moniker, + "file_path": OTEL_API.moniker, } if assert_func == assert_list_pods: kwargs["mocked_list_pods"] = mocked_list_pods From 52d2fe4f3c9d4bacbb9bf2d3a3b39694f7f59c72 Mon Sep 17 00:00:00 2001 From: Elsie4ever <3467996@gmail.com> Date: Fri, 31 May 2024 11:59:58 -0700 Subject: [PATCH 5/9] address comment --- azext_edge/edge/providers/support/akri.py | 21 +++++------ .../edge/providers/support/dataprocessor.py | 25 ++++++------- azext_edge/edge/providers/support/lnm.py | 13 +++---- azext_edge/edge/providers/support/mq.py | 29 +++++++-------- azext_edge/edge/providers/support/opcua.py | 27 +++++++------- azext_edge/edge/providers/support/orc.py | 9 ++--- azext_edge/edge/providers/support/otel.py | 9 ++--- .../tests/edge/support/test_support_unit.py | 35 ++++++++++--------- 8 files changed, 88 insertions(+), 80 deletions(-) diff --git a/azext_edge/edge/providers/support/akri.py b/azext_edge/edge/providers/support/akri.py index 64b4b6ecd..0bd9a63f2 100644 --- a/azext_edge/edge/providers/support/akri.py +++ b/azext_edge/edge/providers/support/akri.py @@ -33,6 +33,7 @@ AKRI_NAME_LABEL_V2 = NAME_LABEL_FORMAT.format(label=AKRI_API_V0.label) AKRI_POD_NAME_LABEL = NAME_LABEL_FORMAT.format(label=f"{AKRI_AGENT_LABEL}, {AKRI_WEBHOOK_LABEL}") +AKRI_FILE_PATH = AKRI_API_V0.moniker def fetch_pods(since_seconds: int = DAY_IN_SECONDS): @@ -45,7 +46,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for pod_name_label in pod_name_labels: processed.extend( process_v1_pods( - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, label_selector=pod_name_label, since_seconds=since_seconds, ) @@ -53,7 +54,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): processed.extend( process_v1_pods( - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, label_selector=AKRI_NAME_LABEL_V2, since_seconds=since_seconds, ) @@ -71,14 +72,14 @@ def fetch_deployments(): for deployment_name_label in deployment_name_labels: processed.extend( process_deployments( - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, label_selector=deployment_name_label, ) ) processed.extend( process_deployments( - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, label_selector=AKRI_NAME_LABEL_V2, ) ) @@ -94,13 +95,13 @@ def fetch_daemonsets(): for daemonset_name_label in daemonset_name_labels: processed.extend( process_daemonsets( - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, label_selector=daemonset_name_label, ) ) processed.extend( - process_daemonsets(file_path=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) + process_daemonsets(file_path=AKRI_FILE_PATH, label_selector=AKRI_NAME_LABEL_V2) ) return processed @@ -115,13 +116,13 @@ def fetch_services(): for service_name_label in service_name_labels: processed.extend( process_services( - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, label_selector=service_name_label, ) ) processed.extend( - process_services(file_path=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) + process_services(file_path=AKRI_FILE_PATH, label_selector=AKRI_NAME_LABEL_V2) ) return processed @@ -136,13 +137,13 @@ def fetch_replicasets(): for replicaset_name_label in replicaset_name_labels: processed.extend( process_replicasets( - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, label_selector=replicaset_name_label, ) ) processed.extend( - process_replicasets(file_path=AKRI_API_V0.moniker, label_selector=AKRI_NAME_LABEL_V2) + process_replicasets(file_path=AKRI_FILE_PATH, label_selector=AKRI_NAME_LABEL_V2) ) return processed diff --git a/azext_edge/edge/providers/support/dataprocessor.py b/azext_edge/edge/providers/support/dataprocessor.py index 44a3cd0de..50506aa2f 100644 --- a/azext_edge/edge/providers/support/dataprocessor.py +++ b/azext_edge/edge/providers/support/dataprocessor.py @@ -50,11 +50,12 @@ # TODO: @jiacju - will remove once the nats issue the fixed DATA_PROCESSOR_ONEOFF_LABEL = NAME_LABEL_FORMAT.format(label=DATA_PROCESSOR_NATS_APP_LABEL) DATA_PROCESSOR_NAME_LABEL_V2 = NAME_LABEL_FORMAT.format(label=DATA_PROCESSOR_API_V1.label) +DATA_PROCESSOR_FILE_PATH = DATA_PROCESSOR_API_V1.moniker def fetch_pods(since_seconds: int = DAY_IN_SECONDS): dataprocessor_pods = process_v1_pods( - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_LABEL, since_seconds=since_seconds, pod_prefix_for_init_container_logs=[ @@ -65,7 +66,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): dataprocessor_pods.extend( process_v1_pods( - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, since_seconds=since_seconds, pod_prefix_for_init_container_logs=[ @@ -79,9 +80,9 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): - processed = process_deployments(file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL) + processed = process_deployments(file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_LABEL) processed.extend( - process_deployments(file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_deployments(file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -89,12 +90,12 @@ def fetch_deployments(): def fetch_statefulsets(): processed = process_statefulset( - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_LABEL, ) processed.extend( process_statefulset( - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, ) ) @@ -103,9 +104,9 @@ def fetch_statefulsets(): def fetch_replicasets(): - processed = process_replicasets(file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_LABEL) + processed = process_replicasets(file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_LABEL) processed.extend( - process_replicasets(file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_replicasets(file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -120,13 +121,13 @@ def fetch_services(): for service_name_label in service_name_labels: processed.extend( process_services( - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, label_selector=service_name_label, ) ) processed.extend( - process_services(file_path=DATA_PROCESSOR_API_V1.moniker, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_services(file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -143,14 +144,14 @@ def fetch_persistent_volume_claims(): for persistent_volume_claims_name_label in persistent_volume_claims_name_labels: processed.extend( process_persistent_volume_claims( - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, label_selector=persistent_volume_claims_name_label, ) ) processed.extend( process_persistent_volume_claims( - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2 ) ) diff --git a/azext_edge/edge/providers/support/lnm.py b/azext_edge/edge/providers/support/lnm.py index 9faa02fe7..c892be9fe 100644 --- a/azext_edge/edge/providers/support/lnm.py +++ b/azext_edge/edge/providers/support/lnm.py @@ -23,13 +23,14 @@ ] LNM_APP_LABEL_TYPE = 'app' LNM_LABEL_PREFIX = "aio-lnm" +LNM_FILE_PATH = LNM_API_V1B1.moniker def fetch_replicasets(): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) return process_replicasets( - file_path=LNM_API_V1B1.moniker, + file_path=LNM_FILE_PATH, label_selector=lnm_labels, ) @@ -38,13 +39,13 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) processed = process_v1_pods( - file_path=LNM_API_V1B1.moniker, + file_path=LNM_FILE_PATH, label_selector=lnm_labels, since_seconds=since_seconds, ) processed.extend( process_v1_pods( - file_path=LNM_API_V1B1.moniker, + file_path=LNM_FILE_PATH, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"], since_seconds=since_seconds, @@ -57,19 +58,19 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_services(): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) - return process_services(file_path=LNM_API_V1B1.moniker, label_selector=lnm_labels) + return process_services(file_path=LNM_FILE_PATH, label_selector=lnm_labels) def fetch_lnm_deployments(): deployment_prefixes = [f"{LNM_LABEL_PREFIX}-{name}" for name in _fetch_lnm_instance_names()] deployment_prefixes.extend(LNM_APP_LABELS) - return process_deployments(file_path=LNM_API_V1B1.moniker, label_selector=None, prefix_names=deployment_prefixes) + return process_deployments(file_path=LNM_FILE_PATH, label_selector=None, prefix_names=deployment_prefixes) def fetch_daemonsets(): return process_daemonsets( - file_path=LNM_API_V1B1.moniker, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"] + file_path=LNM_FILE_PATH, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"] ) diff --git a/azext_edge/edge/providers/support/mq.py b/azext_edge/edge/providers/support/mq.py index 2801f853a..e5b5b82dd 100644 --- a/azext_edge/edge/providers/support/mq.py +++ b/azext_edge/edge/providers/support/mq.py @@ -44,6 +44,7 @@ MQ_LABEL = f"app in ({','.join(MQ_APP_LABELS)})" MQ_NAME_LABEL = NAME_LABEL_FORMAT.format(label=MQ_ACTIVE_API.label) +MQ_FILE_PATH = MQ_ACTIVE_API.moniker def fetch_diagnostic_metrics(namespace: str): @@ -52,7 +53,7 @@ def fetch_diagnostic_metrics(namespace: str): stats_raw = get_stats(namespace=namespace, raw_response=True) return { "data": stats_raw, - "zinfo": f"{namespace}/{MQ_ACTIVE_API.moniker}/diagnostic_metrics.txt", + "zinfo": f"{namespace}/{MQ_FILE_PATH}/diagnostic_metrics.txt", } except Exception: logger.debug(f"Unable to process diagnostics pod metrics against namespace {namespace}.") @@ -67,7 +68,7 @@ def fetch_diagnostic_traces(): if traces: for trace in traces: zinfo = ZipInfo( - filename=f"{namespace}/{MQ_ACTIVE_API.moniker}/traces/{trace[0].filename}", + filename=f"{namespace}/{MQ_FILE_PATH}/traces/{trace[0].filename}", date_time=trace[0].date_time, ) # Fixed in Py 3.9 https://github.com/python/cpython/issues/70373 @@ -88,16 +89,16 @@ def fetch_diagnostic_traces(): def fetch_deployments(): processed, namespaces = process_deployments( - file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_LABEL, return_namespaces=True + file_path=MQ_FILE_PATH, label_selector=MQ_LABEL, return_namespaces=True ) # aio-mq-operator deployment has no app label operators, operator_namespaces = process_deployments( - file_path=MQ_ACTIVE_API.moniker, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", return_namespaces=True + file_path=MQ_FILE_PATH, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", return_namespaces=True ) processed.extend(operators) operators_v2, operator_namespaces_v2 = process_deployments( - file_path=MQ_ACTIVE_API.moniker, label_selector=MQ_NAME_LABEL, return_namespaces=True + file_path=MQ_FILE_PATH, label_selector=MQ_NAME_LABEL, return_namespaces=True ) processed.extend(operators_v2) @@ -122,12 +123,12 @@ def fetch_deployments(): def fetch_statefulsets(): processed = process_statefulset( - file_path=MQ_ACTIVE_API.moniker, + file_path=MQ_FILE_PATH, label_selector=MQ_LABEL, ) processed.extend( process_statefulset( - file_path=MQ_ACTIVE_API.moniker, + file_path=MQ_FILE_PATH, label_selector=MQ_NAME_LABEL, ) ) @@ -144,7 +145,7 @@ def fetch_statefulsets(): for connector in connectors: connector_name = connector.get("metadata", {}).get("name") stateful_set = process_statefulset( - file_path=MQ_ACTIVE_API.moniker, + file_path=MQ_FILE_PATH, field_selector=f"metadata.name={AIO_MQ_RESOURCE_PREFIX}{connector_name}", ) processed.extend(stateful_set) @@ -154,12 +155,12 @@ def fetch_statefulsets(): def fetch_services(): processed = process_services( - file_path=MQ_ACTIVE_API.moniker, + file_path=MQ_FILE_PATH, label_selector=MQ_LABEL, ) processed.extend( process_services( - file_path=MQ_ACTIVE_API.moniker, + file_path=MQ_FILE_PATH, label_selector=MQ_NAME_LABEL, ) ) @@ -169,12 +170,12 @@ def fetch_services(): def fetch_replicasets(): processed = process_replicasets( - file_path=MQ_ACTIVE_API.moniker, + file_path=MQ_FILE_PATH, label_selector=MQ_LABEL, ) processed.extend( process_replicasets( - file_path=MQ_ACTIVE_API.moniker, + file_path=MQ_FILE_PATH, label_selector=MQ_NAME_LABEL, ) ) @@ -184,13 +185,13 @@ def fetch_replicasets(): def fetch_pods(since_seconds: int = DAY_IN_SECONDS): processed = process_v1_pods( - file_path=MQ_ACTIVE_API.moniker, + file_path=MQ_FILE_PATH, label_selector=MQ_LABEL, since_seconds=since_seconds, ) processed.extend( process_v1_pods( - file_path=MQ_ACTIVE_API.moniker, + file_path=MQ_FILE_PATH, label_selector=MQ_NAME_LABEL, since_seconds=since_seconds, ) diff --git a/azext_edge/edge/providers/support/opcua.py b/azext_edge/edge/providers/support/opcua.py index 89ab49beb..e417528aa 100644 --- a/azext_edge/edge/providers/support/opcua.py +++ b/azext_edge/edge/providers/support/opcua.py @@ -29,6 +29,7 @@ OPC_APP_LABEL = "app in (aio-opc-supervisor, aio-opc-admission-controller)" OPC_NAME_LABEL = NAME_LABEL_FORMAT.format(label="aio-opc-opcua-connector, opcplc") OPC_NAME_VAR_LABEL = "name in (aio-opc-asset-discovery)" +OPC_FILE_PATH = OPCUA_API_V1.moniker # TODO: once this label is stabled, we can remove the other labels OPCUA_NAME_LABEL = NAME_LABEL_FORMAT.format(label=OPCUA_API_V1.label) @@ -44,7 +45,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for pod_name_label in pod_name_labels: opcua_pods.extend( process_v1_pods( - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, label_selector=pod_name_label, since_seconds=since_seconds, include_metrics=True, @@ -53,7 +54,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): opcua_pods.extend( process_v1_pods( - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, label_selector=OPCUA_NAME_LABEL, since_seconds=since_seconds, include_metrics=True, @@ -63,34 +64,34 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): - processed = process_deployments(file_path=OPCUA_API_V1.moniker, prefix_names=[OPC_PREFIX, SIMULATOR_PREFIX]) - processed.extend(process_deployments(file_path=OPCUA_API_V1.moniker, label_selector=OPC_NAME_LABEL)) - processed.extend(process_deployments(file_path=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) + processed = process_deployments(file_path=OPC_FILE_PATH, prefix_names=[OPC_PREFIX, SIMULATOR_PREFIX]) + processed.extend(process_deployments(file_path=OPC_FILE_PATH, label_selector=OPC_NAME_LABEL)) + processed.extend(process_deployments(file_path=OPC_FILE_PATH, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_replicasets(): - processed = process_replicasets(file_path=OPCUA_API_V1.moniker, label_selector=OPC_APP_LABEL) - processed.extend(process_replicasets(file_path=OPCUA_API_V1.moniker, label_selector=OPC_NAME_LABEL)) - processed.extend(process_replicasets(file_path=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) + processed = process_replicasets(file_path=OPC_FILE_PATH, label_selector=OPC_APP_LABEL) + processed.extend(process_replicasets(file_path=OPC_FILE_PATH, label_selector=OPC_NAME_LABEL)) + processed.extend(process_replicasets(file_path=OPC_FILE_PATH, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_services(): - processed = process_services(file_path=OPCUA_API_V1.moniker, label_selector=OPC_APP_LABEL) - processed.extend(process_services(file_path=OPCUA_API_V1.moniker, prefix_names=[SIMULATOR_PREFIX])) - processed.extend(process_services(file_path=OPCUA_API_V1.moniker, label_selector=OPCUA_NAME_LABEL)) + processed = process_services(file_path=OPC_FILE_PATH, label_selector=OPC_APP_LABEL) + processed.extend(process_services(file_path=OPC_FILE_PATH, prefix_names=[SIMULATOR_PREFIX])) + processed.extend(process_services(file_path=OPC_FILE_PATH, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_daemonsets(): processed = process_daemonsets( - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, field_selector="metadata.name==aio-opc-asset-discovery", ) processed.extend( process_daemonsets( - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, label_selector=OPCUA_NAME_LABEL, ) ) diff --git a/azext_edge/edge/providers/support/orc.py b/azext_edge/edge/providers/support/orc.py index c1da71387..f4851d0c0 100644 --- a/azext_edge/edge/providers/support/orc.py +++ b/azext_edge/edge/providers/support/orc.py @@ -24,6 +24,7 @@ ORC_APP_LABEL = "app in (aio-orc-api, cert-manager, cainjector, webhook)" ORC_CONTROLLER_LABEL = "control-plane in (aio-orc-controller-manager)" +ORC_FILE_PATH = ORC_API_V1.moniker # TODO: @jiacju - this label will be used near future for consistency # META_AIO_NAME_LABEL = "app.kubernetes.io/name in (microsoft-iotoperations)" @@ -34,7 +35,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: processed.extend( process_v1_pods( - file_path=ORC_API_V1.moniker, + file_path=ORC_FILE_PATH, label_selector=label, since_seconds=since_seconds, ) @@ -46,7 +47,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_deployments(file_path=ORC_API_V1.moniker, label_selector=label)) + processed.extend(process_deployments(file_path=ORC_FILE_PATH, label_selector=label)) return processed @@ -54,7 +55,7 @@ def fetch_deployments(): def fetch_services(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_services(file_path=ORC_API_V1.moniker, label_selector=label)) + processed.extend(process_services(file_path=ORC_FILE_PATH, label_selector=label)) return processed @@ -62,7 +63,7 @@ def fetch_services(): def fetch_replicasets(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_replicasets(file_path=ORC_API_V1.moniker, label_selector=label)) + processed.extend(process_replicasets(file_path=ORC_FILE_PATH, label_selector=label)) return processed diff --git a/azext_edge/edge/providers/support/otel.py b/azext_edge/edge/providers/support/otel.py index 28133450b..07901f169 100644 --- a/azext_edge/edge/providers/support/otel.py +++ b/azext_edge/edge/providers/support/otel.py @@ -19,22 +19,23 @@ # Defined here as this is not an IoT Operations API OTEL_API = EdgeResourceApi(group="otel", version="v1", moniker="otel") +OTEL_FILE_PATH = OTEL_API.moniker def fetch_otel_pods(since_seconds: int = DAY_IN_SECONDS): - return process_v1_pods(file_path=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL, since_seconds=since_seconds) + return process_v1_pods(file_path=OTEL_FILE_PATH, label_selector=OTEL_NAME_LABEL, since_seconds=since_seconds) def fetch_otel_deployments(): - return process_deployments(file_path=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) + return process_deployments(file_path=OTEL_FILE_PATH, label_selector=OTEL_NAME_LABEL) def fetch_otel_replicasets(): - return process_replicasets(file_path=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) + return process_replicasets(file_path=OTEL_FILE_PATH, label_selector=OTEL_NAME_LABEL) def fetch_otel_services(): - return process_services(file_path=OTEL_API.moniker, label_selector=OTEL_NAME_LABEL) + return process_services(file_path=OTEL_FILE_PATH, label_selector=OTEL_NAME_LABEL) support_runtime_elements = { diff --git a/azext_edge/tests/edge/support/test_support_unit.py b/azext_edge/tests/edge/support/test_support_unit.py index fc8149a53..44d15aa3e 100644 --- a/azext_edge/tests/edge/support/test_support_unit.py +++ b/azext_edge/tests/edge/support/test_support_unit.py @@ -30,6 +30,7 @@ from azext_edge.edge.providers.support.akri import ( AKRI_AGENT_LABEL, AKRI_APP_LABEL, + AKRI_FILE_PATH, AKRI_INSTANCE_LABEL, AKRI_NAME_LABEL_V2, AKRI_SERVICE_LABEL, @@ -497,7 +498,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_INSTANCE_LABEL, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, since_seconds=since_seconds, ) assert_list_pods( @@ -505,7 +506,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_APP_LABEL, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, since_seconds=since_seconds, ) assert_list_pods( @@ -513,7 +514,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=NAME_LABEL_FORMAT.format(label=f"{AKRI_AGENT_LABEL}, {AKRI_WEBHOOK_LABEL}"), - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, since_seconds=since_seconds, ) assert_list_pods( @@ -521,71 +522,71 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_NAME_LABEL_V2, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, since_seconds=since_seconds, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_APP_LABEL, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_APP_LABEL, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_WEBHOOK_LABEL), - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_SERVICE_LABEL, file_path=AKRI_API_V0.moniker + mocked_client, mocked_zipfile, label_selector=AKRI_SERVICE_LABEL, file_path=AKRI_FILE_PATH ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, file_path=AKRI_API_V0.moniker + mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, file_path=AKRI_FILE_PATH ) assert_list_services( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_WEBHOOK_LABEL), - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, file_path=AKRI_API_V0.moniker + mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, file_path=AKRI_FILE_PATH ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, ) assert_list_daemon_sets( mocked_client, @@ -597,7 +598,7 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - file_path=AKRI_API_V0.moniker, + file_path=AKRI_FILE_PATH, ) if api in [LNM_API_V1B1]: From cca12f6f6e8f1ca5a34c800c0fd68d60a78d9677 Mon Sep 17 00:00:00 2001 From: Elsie4ever <3467996@gmail.com> Date: Fri, 31 May 2024 12:24:19 -0700 Subject: [PATCH 6/9] test --- .../tests/edge/support/test_support_unit.py | 111 +++++++++--------- 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/azext_edge/tests/edge/support/test_support_unit.py b/azext_edge/tests/edge/support/test_support_unit.py index 44d15aa3e..54e4cf997 100644 --- a/azext_edge/tests/edge/support/test_support_unit.py +++ b/azext_edge/tests/edge/support/test_support_unit.py @@ -44,6 +44,7 @@ BILLING_RESOURCE_KIND, ) from azext_edge.edge.providers.support.dataprocessor import ( + DATA_PROCESSOR_FILE_PATH, DATA_PROCESSOR_INSTANCE_LABEL, DATA_PROCESSOR_LABEL, DATA_PROCESSOR_NAME_LABEL, @@ -51,15 +52,17 @@ DATA_PROCESSOR_ONEOFF_LABEL, DATA_PROCESSOR_PVC_APP_LABEL, ) -from azext_edge.edge.providers.support.lnm import LNM_APP_LABELS -from azext_edge.edge.providers.support.mq import MQ_LABEL, MQ_NAME_LABEL +from azext_edge.edge.providers.support.lnm import LNM_APP_LABELS, LNM_FILE_PATH +from azext_edge.edge.providers.support.mq import MQ_FILE_PATH, MQ_LABEL, MQ_NAME_LABEL from azext_edge.edge.providers.support.opcua import ( OPC_APP_LABEL, + OPC_FILE_PATH, OPC_NAME_LABEL, OPC_NAME_VAR_LABEL, OPCUA_NAME_LABEL, ) from azext_edge.edge.providers.support.orc import ( + ORC_FILE_PATH, ORC_APP_LABEL, ORC_CONTROLLER_LABEL, ) @@ -200,7 +203,7 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, - file_path=MQ_API_V1B1.moniker, + file_path=MQ_FILE_PATH, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", ) assert_list_pods( @@ -208,7 +211,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=MQ_LABEL, - file_path=MQ_API_V1B1.moniker, + file_path=MQ_FILE_PATH, since_seconds=since_seconds, ) assert_list_pods( @@ -216,43 +219,43 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=MQ_NAME_LABEL, - file_path=MQ_API_V1B1.moniker, + file_path=MQ_FILE_PATH, since_seconds=since_seconds, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, - file_path=MQ_API_V1B1.moniker + file_path=MQ_FILE_PATH ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, file_path=MQ_API_V1B1.moniker + mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, file_path=MQ_FILE_PATH ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, field_selector=None, - file_path=MQ_API_V1B1.moniker + file_path=MQ_FILE_PATH ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, field_selector=None, - file_path=MQ_API_V1B1.moniker, + file_path=MQ_FILE_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, - file_path=MQ_API_V1B1.moniker + file_path=MQ_FILE_PATH ) assert_list_services( mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, - file_path=MQ_API_V1B1.moniker + file_path=MQ_FILE_PATH ) assert_mq_stats(mocked_zipfile) @@ -263,7 +266,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_APP_LABEL, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, since_seconds=since_seconds, include_metrics=True, ) @@ -272,7 +275,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_NAME_LABEL, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, since_seconds=since_seconds, include_metrics=True, ) @@ -281,7 +284,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_NAME_VAR_LABEL, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, since_seconds=since_seconds, include_metrics=True, ) @@ -290,7 +293,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPCUA_NAME_LABEL, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, since_seconds=since_seconds, include_metrics=True, ) @@ -298,64 +301,64 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=None, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, mock_names=["aio-opc-admission-controller", "aio-opc-supervisor", "aio-opc-opc", "opcplc-0000000"], ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=OPC_NAME_LABEL, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPC_NAME_LABEL, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=None, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, mock_names=["opcplc-0000000"], ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, file_path=OPCUA_API_V1.moniker + mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, file_path=OPC_FILE_PATH ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, file_path=OPCUA_API_V1.moniker + mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, file_path=OPC_FILE_PATH ) # TODO: one-off field selector remove after label assert_list_daemon_sets( mocked_client, mocked_zipfile, field_selector="metadata.name==aio-opc-asset-discovery", - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, ) if api in [DATA_PROCESSOR_API_V1]: @@ -365,13 +368,13 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_pods( @@ -379,7 +382,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=DATA_PROCESSOR_LABEL, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, since_seconds=since_seconds, pod_prefix_for_init_container_logs=["aio-"], ) @@ -388,7 +391,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, since_seconds=since_seconds, pod_prefix_for_init_container_logs=["aio-"], ) @@ -397,76 +400,76 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - file_path=DATA_PROCESSOR_API_V1.moniker + file_path=DATA_PROCESSOR_FILE_PATH ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - file_path=DATA_PROCESSOR_API_V1.moniker + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_INSTANCE_LABEL, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_PVC_APP_LABEL, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_ONEOFF_LABEL, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_API_V1.moniker, + file_path=DATA_PROCESSOR_FILE_PATH, ) if api in [ORC_API_V1]: @@ -476,20 +479,20 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=orc_label, - file_path=ORC_API_V1.moniker, + file_path=ORC_FILE_PATH, since_seconds=since_seconds, ) assert_list_deployments( - mocked_client, mocked_zipfile, label_selector=orc_label, file_path=ORC_API_V1.moniker + mocked_client, mocked_zipfile, label_selector=orc_label, file_path=ORC_FILE_PATH ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=orc_label, file_path=ORC_API_V1.moniker + mocked_client, mocked_zipfile, label_selector=orc_label, file_path=ORC_FILE_PATH ) assert_list_services( mocked_client, mocked_zipfile, label_selector=orc_label, - file_path=ORC_API_V1.moniker + file_path=ORC_FILE_PATH ) if api in [AKRI_API_V0]: @@ -592,7 +595,7 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_AGENT_LABEL), - file_path=OPCUA_API_V1.moniker, + file_path=OPC_FILE_PATH, ) assert_list_daemon_sets( mocked_client, @@ -608,7 +611,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=lnm_app_label, - file_path=LNM_API_V1B1.moniker, + file_path=LNM_FILE_PATH, since_seconds=since_seconds, ) assert_list_pods( @@ -616,7 +619,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=None, - file_path=LNM_API_V1B1.moniker, + file_path=LNM_FILE_PATH, since_seconds=since_seconds, mock_names=["svclb-aio-lnm-operator"], ) @@ -624,21 +627,21 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=None, - file_path=LNM_API_V1B1.moniker, + file_path=LNM_FILE_PATH, mock_names=["aio-lnm-operator"], ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=lnm_app_label, file_path=LNM_API_V1B1.moniker + mocked_client, mocked_zipfile, label_selector=lnm_app_label, file_path=LNM_FILE_PATH ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=lnm_app_label, file_path=LNM_API_V1B1.moniker + mocked_client, mocked_zipfile, label_selector=lnm_app_label, file_path=LNM_FILE_PATH ) # TODO: test both without or with lnm instance assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=None, - file_path=LNM_API_V1B1.moniker, + file_path=LNM_FILE_PATH, mock_names=["svclb-aio-lnm-operator"], ) @@ -710,7 +713,7 @@ def assert_list_deployments( field_selector: str = None, mock_names: List[str] = None, ): - if MQ_API_V1B1.moniker in file_path: + if MQ_FILE_PATH in file_path: # regardless of MQ API, MQ_ACTIVE_API.moniker is used for support/mq/fetch_diagnostic_metrics from unittest.mock import call From 8663273dbe26f3de63fd7ef9186b04363513aae0 Mon Sep 17 00:00:00 2001 From: Elsie4ever <3467996@gmail.com> Date: Mon, 3 Jun 2024 09:40:08 -0700 Subject: [PATCH 7/9] address comment: change to directory_path --- azext_edge/edge/providers/support/akri.py | 22 +- azext_edge/edge/providers/support/base.py | 56 ++--- azext_edge/edge/providers/support/billing.py | 16 +- .../edge/providers/support/dataprocessor.py | 26 +-- azext_edge/edge/providers/support/lnm.py | 14 +- azext_edge/edge/providers/support/mq.py | 30 +-- azext_edge/edge/providers/support/opcua.py | 28 +-- azext_edge/edge/providers/support/orc.py | 10 +- azext_edge/edge/providers/support/otel.py | 10 +- .../tests/edge/support/test_support_unit.py | 206 +++++++++--------- 10 files changed, 209 insertions(+), 209 deletions(-) diff --git a/azext_edge/edge/providers/support/akri.py b/azext_edge/edge/providers/support/akri.py index 0bd9a63f2..a6099ae04 100644 --- a/azext_edge/edge/providers/support/akri.py +++ b/azext_edge/edge/providers/support/akri.py @@ -33,7 +33,7 @@ AKRI_NAME_LABEL_V2 = NAME_LABEL_FORMAT.format(label=AKRI_API_V0.label) AKRI_POD_NAME_LABEL = NAME_LABEL_FORMAT.format(label=f"{AKRI_AGENT_LABEL}, {AKRI_WEBHOOK_LABEL}") -AKRI_FILE_PATH = AKRI_API_V0.moniker +AKRI_DIRECTORY_PATH = AKRI_API_V0.moniker def fetch_pods(since_seconds: int = DAY_IN_SECONDS): @@ -46,7 +46,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for pod_name_label in pod_name_labels: processed.extend( process_v1_pods( - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, label_selector=pod_name_label, since_seconds=since_seconds, ) @@ -54,7 +54,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): processed.extend( process_v1_pods( - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2, since_seconds=since_seconds, ) @@ -72,14 +72,14 @@ def fetch_deployments(): for deployment_name_label in deployment_name_labels: processed.extend( process_deployments( - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, label_selector=deployment_name_label, ) ) processed.extend( process_deployments( - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2, ) ) @@ -95,13 +95,13 @@ def fetch_daemonsets(): for daemonset_name_label in daemonset_name_labels: processed.extend( process_daemonsets( - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, label_selector=daemonset_name_label, ) ) processed.extend( - process_daemonsets(file_path=AKRI_FILE_PATH, label_selector=AKRI_NAME_LABEL_V2) + process_daemonsets(directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2) ) return processed @@ -116,13 +116,13 @@ def fetch_services(): for service_name_label in service_name_labels: processed.extend( process_services( - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, label_selector=service_name_label, ) ) processed.extend( - process_services(file_path=AKRI_FILE_PATH, label_selector=AKRI_NAME_LABEL_V2) + process_services(directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2) ) return processed @@ -137,13 +137,13 @@ def fetch_replicasets(): for replicaset_name_label in replicaset_name_labels: processed.extend( process_replicasets( - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, label_selector=replicaset_name_label, ) ) processed.extend( - process_replicasets(file_path=AKRI_FILE_PATH, label_selector=AKRI_NAME_LABEL_V2) + process_replicasets(directory_path=AKRI_DIRECTORY_PATH, label_selector=AKRI_NAME_LABEL_V2) ) return processed diff --git a/azext_edge/edge/providers/support/base.py b/azext_edge/edge/providers/support/base.py index cbaf6c308..9a1e2d6de 100644 --- a/azext_edge/edge/providers/support/base.py +++ b/azext_edge/edge/providers/support/base.py @@ -28,7 +28,7 @@ def process_crd( version: str, kind: str, plural: str, - file_path: str, + directory_path: str, file_prefix: Optional[str] = None, ) -> List[dict]: result: dict = get_custom_objects( @@ -48,14 +48,14 @@ def process_crd( name = r["metadata"]["name"] processed.append({ "data": r, - "zinfo": f"{namespace}/{file_path}/{file_prefix}.{version}.{name}.yaml", + "zinfo": f"{namespace}/{directory_path}/{file_prefix}.{version}.{name}.yaml", }) return processed def process_v1_pods( - file_path: str, + directory_path: str, capture_previous_logs: bool = True, include_metrics: bool = False, since_seconds: int = DAY_IN_SECONDS, @@ -95,7 +95,7 @@ def process_v1_pods( processed.append( { "data": generic.sanitize_for_serialization(obj=p), - "zinfo": f"{pod_namespace}/{file_path}/pod.{pod_name}.yaml", + "zinfo": f"{pod_namespace}/{directory_path}/pod.{pod_name}.yaml", } ) pod_spec: V1PodSpec = p.spec @@ -109,7 +109,7 @@ def process_v1_pods( processed.extend( _capture_pod_container_logs( - file_path=file_path, + directory_path=directory_path, pod_containers=pod_containers, pod_name=pod_name, pod_namespace=pod_namespace, @@ -129,7 +129,7 @@ def process_v1_pods( processed.append( { "data": metric, - "zinfo": f"{pod_namespace}/{file_path}/pod.{pod_name}.metric.yaml" + "zinfo": f"{pod_namespace}/{directory_path}/pod.{pod_name}.metric.yaml" } ) except ApiException as e: @@ -139,7 +139,7 @@ def process_v1_pods( def process_deployments( - file_path: str, + directory_path: str, return_namespaces: bool = False, field_selector: Optional[str] = None, label_selector: Optional[str] = None, @@ -154,7 +154,7 @@ def process_deployments( namespace_pods_work = {} processed = _process_kubernetes_resources( - file_path=file_path, + directory_path=directory_path, resources=deployments, prefix_names=prefix_names, kind=BundleResourceKind.deployment.value, @@ -173,7 +173,7 @@ def process_deployments( def process_statefulset( - file_path: str, + directory_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, ) -> List[dict]: @@ -185,14 +185,14 @@ def process_statefulset( ) return _process_kubernetes_resources( - file_path=file_path, + directory_path=directory_path, resources=statefulsets, kind=BundleResourceKind.statefulset.value, ) def process_services( - file_path: str, + directory_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -205,7 +205,7 @@ def process_services( ) return _process_kubernetes_resources( - file_path=file_path, + directory_path=directory_path, resources=services, prefix_names=prefix_names, kind=BundleResourceKind.service.value, @@ -213,7 +213,7 @@ def process_services( def process_replicasets( - file_path: str, + directory_path: str, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, ) -> List[dict]: @@ -223,7 +223,7 @@ def process_replicasets( replicasets: V1ReplicaSetList = v1_apps.list_replica_set_for_all_namespaces(label_selector=label_selector) return _process_kubernetes_resources( - file_path=file_path, + directory_path=directory_path, resources=replicasets, prefix_names=prefix_names, kind=BundleResourceKind.replicaset.value, @@ -231,7 +231,7 @@ def process_replicasets( def process_daemonsets( - file_path: str, + directory_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -244,7 +244,7 @@ def process_daemonsets( ) return _process_kubernetes_resources( - file_path=file_path, + directory_path=directory_path, resources=daemonsets, prefix_names=prefix_names, kind=BundleResourceKind.daemonset.value, @@ -298,7 +298,7 @@ def process_storage_classes() -> List[dict]: def process_persistent_volume_claims( - file_path: str, + directory_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -311,7 +311,7 @@ def process_persistent_volume_claims( ) return _process_kubernetes_resources( - file_path=file_path, + directory_path=directory_path, resources=pvcs, prefix_names=prefix_names, kind=BundleResourceKind.pvc.value, @@ -319,7 +319,7 @@ def process_persistent_volume_claims( def process_jobs( - file_path: str, + directory_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -332,7 +332,7 @@ def process_jobs( ) return _process_kubernetes_resources( - file_path=file_path, + directory_path=directory_path, resources=jobs, prefix_names=prefix_names, kind=BundleResourceKind.job.value, @@ -340,7 +340,7 @@ def process_jobs( def process_cron_jobs( - file_path: str, + directory_path: str, field_selector: Optional[str] = None, label_selector: Optional[str] = None, prefix_names: Optional[List[str]] = None, @@ -353,7 +353,7 @@ def process_cron_jobs( ) return _process_kubernetes_resources( - file_path=file_path, + directory_path=directory_path, resources=cron_jobs, prefix_names=prefix_names, kind=BundleResourceKind.cronjob.value, @@ -371,7 +371,7 @@ def assemble_crd_work( result = {} for api in apis: for kind in api.kinds: - file_path = api.moniker if not sub_group else f"{api.moniker}/{sub_group}" + directory_path = api.moniker if not sub_group else f"{api.moniker}/{sub_group}" file_prefix = file_prefix_map.get(kind) result[f"{api.moniker} {api.version} {kind}"] = partial( process_crd, @@ -379,7 +379,7 @@ def assemble_crd_work( version=api.version, kind=kind, plural=api._kinds[kind], # TODO: optimize - file_path=file_path, + directory_path=directory_path, file_prefix=file_prefix, ) @@ -399,7 +399,7 @@ def default_bundle_name(system_name: str) -> str: def _capture_pod_container_logs( - file_path: str, + directory_path: str, pod_containers: List[V1Container], pod_name: str, pod_namespace: str, @@ -427,7 +427,7 @@ def _capture_pod_container_logs( previous=capture_previous, ) zinfo_previous_segment = "previous." if capture_previous else "" - zinfo = f"{pod_namespace}/{file_path}/pod.{pod_name}.{container.name}.{zinfo_previous_segment}log" + zinfo = f"{pod_namespace}/{directory_path}/pod.{pod_name}.{container.name}.{zinfo_previous_segment}log" processed.append( { "data": log, @@ -441,7 +441,7 @@ def _capture_pod_container_logs( def _process_kubernetes_resources( - file_path: str, + directory_path: str, resources: object, kind: str, prefix_names: Optional[List[str]] = None, @@ -474,7 +474,7 @@ def _process_kubernetes_resources( processed.append( { "data": generic.sanitize_for_serialization(obj=r), - "zinfo": f"{resource_namespace}/{file_path}/{resource_type}.{resource_name}.yaml", + "zinfo": f"{resource_namespace}/{directory_path}/{resource_type}.{resource_name}.yaml", } ) diff --git a/azext_edge/edge/providers/support/billing.py b/azext_edge/edge/providers/support/billing.py index f175b1a92..394d3ae7a 100644 --- a/azext_edge/edge/providers/support/billing.py +++ b/azext_edge/edge/providers/support/billing.py @@ -26,7 +26,7 @@ AIO_BILLING_USAGE_NAME_LABEL = "app.kubernetes.io/name in (microsoft-iotoperations)" ARC_BILLING_EXTENSION_COMP_LABEL = "app.kubernetes.io/component in (billing-operator)" BILLING_RESOURCE_KIND = "billing" -ARC_BILLING_FILE_PATH = f"{CLUSTER_CONFIG_API_V1.moniker}/{BILLING_RESOURCE_KIND}" +ARC_BILLING_DIRECTORY_PATH = f"{CLUSTER_CONFIG_API_V1.moniker}/{BILLING_RESOURCE_KIND}" def fetch_pods( @@ -34,7 +34,7 @@ def fetch_pods( ): # capture billing pods for aio usage billing_pods = process_v1_pods( - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, label_selector=AIO_BILLING_USAGE_NAME_LABEL, since_seconds=since_seconds, ) @@ -42,7 +42,7 @@ def fetch_pods( # capture billing pods for arc extension billing_pods.extend( process_v1_pods( - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, since_seconds=since_seconds, ) @@ -53,7 +53,7 @@ def fetch_pods( def fetch_jobs(): processed = process_jobs( - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, label_selector=AIO_BILLING_USAGE_NAME_LABEL, ) @@ -62,7 +62,7 @@ def fetch_jobs(): def fetch_cron_jobs(): processed = process_cron_jobs( - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, label_selector=AIO_BILLING_USAGE_NAME_LABEL, ) @@ -71,7 +71,7 @@ def fetch_cron_jobs(): def fetch_deployments(): processed = process_deployments( - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, ) @@ -80,14 +80,14 @@ def fetch_deployments(): def fetch_replicasets(): return process_replicasets( - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, ) def fetch_services(): return process_services( - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, ) diff --git a/azext_edge/edge/providers/support/dataprocessor.py b/azext_edge/edge/providers/support/dataprocessor.py index 50506aa2f..de8486fb0 100644 --- a/azext_edge/edge/providers/support/dataprocessor.py +++ b/azext_edge/edge/providers/support/dataprocessor.py @@ -50,12 +50,12 @@ # TODO: @jiacju - will remove once the nats issue the fixed DATA_PROCESSOR_ONEOFF_LABEL = NAME_LABEL_FORMAT.format(label=DATA_PROCESSOR_NATS_APP_LABEL) DATA_PROCESSOR_NAME_LABEL_V2 = NAME_LABEL_FORMAT.format(label=DATA_PROCESSOR_API_V1.label) -DATA_PROCESSOR_FILE_PATH = DATA_PROCESSOR_API_V1.moniker +DATA_PROCESSOR_DIRECTORY_PATH = DATA_PROCESSOR_API_V1.moniker def fetch_pods(since_seconds: int = DAY_IN_SECONDS): dataprocessor_pods = process_v1_pods( - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=DATA_PROCESSOR_LABEL, since_seconds=since_seconds, pod_prefix_for_init_container_logs=[ @@ -66,7 +66,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): dataprocessor_pods.extend( process_v1_pods( - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, since_seconds=since_seconds, pod_prefix_for_init_container_logs=[ @@ -80,9 +80,9 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): - processed = process_deployments(file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_LABEL) + processed = process_deployments(directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=DATA_PROCESSOR_LABEL) processed.extend( - process_deployments(file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_deployments(directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -90,12 +90,12 @@ def fetch_deployments(): def fetch_statefulsets(): processed = process_statefulset( - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=DATA_PROCESSOR_LABEL, ) processed.extend( process_statefulset( - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, ) ) @@ -104,9 +104,9 @@ def fetch_statefulsets(): def fetch_replicasets(): - processed = process_replicasets(file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_LABEL) + processed = process_replicasets(directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=DATA_PROCESSOR_LABEL) processed.extend( - process_replicasets(file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_replicasets(directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -121,13 +121,13 @@ def fetch_services(): for service_name_label in service_name_labels: processed.extend( process_services( - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=service_name_label, ) ) processed.extend( - process_services(file_path=DATA_PROCESSOR_FILE_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) + process_services(directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2) ) return processed @@ -144,14 +144,14 @@ def fetch_persistent_volume_claims(): for persistent_volume_claims_name_label in persistent_volume_claims_name_labels: processed.extend( process_persistent_volume_claims( - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=persistent_volume_claims_name_label, ) ) processed.extend( process_persistent_volume_claims( - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, label_selector=DATA_PROCESSOR_NAME_LABEL_V2 ) ) diff --git a/azext_edge/edge/providers/support/lnm.py b/azext_edge/edge/providers/support/lnm.py index c892be9fe..37b2ac149 100644 --- a/azext_edge/edge/providers/support/lnm.py +++ b/azext_edge/edge/providers/support/lnm.py @@ -23,14 +23,14 @@ ] LNM_APP_LABEL_TYPE = 'app' LNM_LABEL_PREFIX = "aio-lnm" -LNM_FILE_PATH = LNM_API_V1B1.moniker +LNM_DIRECTORY_PATH = LNM_API_V1B1.moniker def fetch_replicasets(): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) return process_replicasets( - file_path=LNM_FILE_PATH, + directory_path=LNM_DIRECTORY_PATH, label_selector=lnm_labels, ) @@ -39,13 +39,13 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) processed = process_v1_pods( - file_path=LNM_FILE_PATH, + directory_path=LNM_DIRECTORY_PATH, label_selector=lnm_labels, since_seconds=since_seconds, ) processed.extend( process_v1_pods( - file_path=LNM_FILE_PATH, + directory_path=LNM_DIRECTORY_PATH, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"], since_seconds=since_seconds, @@ -58,19 +58,19 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_services(): lnm_labels = _generate_lnm_labels(prefix=LNM_LABEL_PREFIX, label_type=LNM_APP_LABEL_TYPE) - return process_services(file_path=LNM_FILE_PATH, label_selector=lnm_labels) + return process_services(directory_path=LNM_DIRECTORY_PATH, label_selector=lnm_labels) def fetch_lnm_deployments(): deployment_prefixes = [f"{LNM_LABEL_PREFIX}-{name}" for name in _fetch_lnm_instance_names()] deployment_prefixes.extend(LNM_APP_LABELS) - return process_deployments(file_path=LNM_FILE_PATH, label_selector=None, prefix_names=deployment_prefixes) + return process_deployments(directory_path=LNM_DIRECTORY_PATH, label_selector=None, prefix_names=deployment_prefixes) def fetch_daemonsets(): return process_daemonsets( - file_path=LNM_FILE_PATH, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"] + directory_path=LNM_DIRECTORY_PATH, label_selector=None, prefix_names=[f"svclb-{LNM_LABEL_PREFIX}"] ) diff --git a/azext_edge/edge/providers/support/mq.py b/azext_edge/edge/providers/support/mq.py index e5b5b82dd..eaaaf4294 100644 --- a/azext_edge/edge/providers/support/mq.py +++ b/azext_edge/edge/providers/support/mq.py @@ -44,7 +44,7 @@ MQ_LABEL = f"app in ({','.join(MQ_APP_LABELS)})" MQ_NAME_LABEL = NAME_LABEL_FORMAT.format(label=MQ_ACTIVE_API.label) -MQ_FILE_PATH = MQ_ACTIVE_API.moniker +MQ_DIRECTORY_PATH = MQ_ACTIVE_API.moniker def fetch_diagnostic_metrics(namespace: str): @@ -53,7 +53,7 @@ def fetch_diagnostic_metrics(namespace: str): stats_raw = get_stats(namespace=namespace, raw_response=True) return { "data": stats_raw, - "zinfo": f"{namespace}/{MQ_FILE_PATH}/diagnostic_metrics.txt", + "zinfo": f"{namespace}/{MQ_DIRECTORY_PATH}/diagnostic_metrics.txt", } except Exception: logger.debug(f"Unable to process diagnostics pod metrics against namespace {namespace}.") @@ -68,7 +68,7 @@ def fetch_diagnostic_traces(): if traces: for trace in traces: zinfo = ZipInfo( - filename=f"{namespace}/{MQ_FILE_PATH}/traces/{trace[0].filename}", + filename=f"{namespace}/{MQ_DIRECTORY_PATH}/traces/{trace[0].filename}", date_time=trace[0].date_time, ) # Fixed in Py 3.9 https://github.com/python/cpython/issues/70373 @@ -89,16 +89,16 @@ def fetch_diagnostic_traces(): def fetch_deployments(): processed, namespaces = process_deployments( - file_path=MQ_FILE_PATH, label_selector=MQ_LABEL, return_namespaces=True + directory_path=MQ_DIRECTORY_PATH, label_selector=MQ_LABEL, return_namespaces=True ) # aio-mq-operator deployment has no app label operators, operator_namespaces = process_deployments( - file_path=MQ_FILE_PATH, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", return_namespaces=True + directory_path=MQ_DIRECTORY_PATH, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", return_namespaces=True ) processed.extend(operators) operators_v2, operator_namespaces_v2 = process_deployments( - file_path=MQ_FILE_PATH, label_selector=MQ_NAME_LABEL, return_namespaces=True + directory_path=MQ_DIRECTORY_PATH, label_selector=MQ_NAME_LABEL, return_namespaces=True ) processed.extend(operators_v2) @@ -123,12 +123,12 @@ def fetch_deployments(): def fetch_statefulsets(): processed = process_statefulset( - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, label_selector=MQ_LABEL, ) processed.extend( process_statefulset( - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, label_selector=MQ_NAME_LABEL, ) ) @@ -145,7 +145,7 @@ def fetch_statefulsets(): for connector in connectors: connector_name = connector.get("metadata", {}).get("name") stateful_set = process_statefulset( - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, field_selector=f"metadata.name={AIO_MQ_RESOURCE_PREFIX}{connector_name}", ) processed.extend(stateful_set) @@ -155,12 +155,12 @@ def fetch_statefulsets(): def fetch_services(): processed = process_services( - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, label_selector=MQ_LABEL, ) processed.extend( process_services( - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, label_selector=MQ_NAME_LABEL, ) ) @@ -170,12 +170,12 @@ def fetch_services(): def fetch_replicasets(): processed = process_replicasets( - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, label_selector=MQ_LABEL, ) processed.extend( process_replicasets( - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, label_selector=MQ_NAME_LABEL, ) ) @@ -185,13 +185,13 @@ def fetch_replicasets(): def fetch_pods(since_seconds: int = DAY_IN_SECONDS): processed = process_v1_pods( - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, label_selector=MQ_LABEL, since_seconds=since_seconds, ) processed.extend( process_v1_pods( - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, label_selector=MQ_NAME_LABEL, since_seconds=since_seconds, ) diff --git a/azext_edge/edge/providers/support/opcua.py b/azext_edge/edge/providers/support/opcua.py index e417528aa..b197ea097 100644 --- a/azext_edge/edge/providers/support/opcua.py +++ b/azext_edge/edge/providers/support/opcua.py @@ -29,7 +29,7 @@ OPC_APP_LABEL = "app in (aio-opc-supervisor, aio-opc-admission-controller)" OPC_NAME_LABEL = NAME_LABEL_FORMAT.format(label="aio-opc-opcua-connector, opcplc") OPC_NAME_VAR_LABEL = "name in (aio-opc-asset-discovery)" -OPC_FILE_PATH = OPCUA_API_V1.moniker +OPC_DIRECTORY_PATH = OPCUA_API_V1.moniker # TODO: once this label is stabled, we can remove the other labels OPCUA_NAME_LABEL = NAME_LABEL_FORMAT.format(label=OPCUA_API_V1.label) @@ -45,7 +45,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for pod_name_label in pod_name_labels: opcua_pods.extend( process_v1_pods( - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, label_selector=pod_name_label, since_seconds=since_seconds, include_metrics=True, @@ -54,7 +54,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): opcua_pods.extend( process_v1_pods( - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, label_selector=OPCUA_NAME_LABEL, since_seconds=since_seconds, include_metrics=True, @@ -64,34 +64,34 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): - processed = process_deployments(file_path=OPC_FILE_PATH, prefix_names=[OPC_PREFIX, SIMULATOR_PREFIX]) - processed.extend(process_deployments(file_path=OPC_FILE_PATH, label_selector=OPC_NAME_LABEL)) - processed.extend(process_deployments(file_path=OPC_FILE_PATH, label_selector=OPCUA_NAME_LABEL)) + processed = process_deployments(directory_path=OPC_DIRECTORY_PATH, prefix_names=[OPC_PREFIX, SIMULATOR_PREFIX]) + processed.extend(process_deployments(directory_path=OPC_DIRECTORY_PATH, label_selector=OPC_NAME_LABEL)) + processed.extend(process_deployments(directory_path=OPC_DIRECTORY_PATH, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_replicasets(): - processed = process_replicasets(file_path=OPC_FILE_PATH, label_selector=OPC_APP_LABEL) - processed.extend(process_replicasets(file_path=OPC_FILE_PATH, label_selector=OPC_NAME_LABEL)) - processed.extend(process_replicasets(file_path=OPC_FILE_PATH, label_selector=OPCUA_NAME_LABEL)) + processed = process_replicasets(directory_path=OPC_DIRECTORY_PATH, label_selector=OPC_APP_LABEL) + processed.extend(process_replicasets(directory_path=OPC_DIRECTORY_PATH, label_selector=OPC_NAME_LABEL)) + processed.extend(process_replicasets(directory_path=OPC_DIRECTORY_PATH, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_services(): - processed = process_services(file_path=OPC_FILE_PATH, label_selector=OPC_APP_LABEL) - processed.extend(process_services(file_path=OPC_FILE_PATH, prefix_names=[SIMULATOR_PREFIX])) - processed.extend(process_services(file_path=OPC_FILE_PATH, label_selector=OPCUA_NAME_LABEL)) + processed = process_services(directory_path=OPC_DIRECTORY_PATH, label_selector=OPC_APP_LABEL) + processed.extend(process_services(directory_path=OPC_DIRECTORY_PATH, prefix_names=[SIMULATOR_PREFIX])) + processed.extend(process_services(directory_path=OPC_DIRECTORY_PATH, label_selector=OPCUA_NAME_LABEL)) return processed def fetch_daemonsets(): processed = process_daemonsets( - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, field_selector="metadata.name==aio-opc-asset-discovery", ) processed.extend( process_daemonsets( - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, label_selector=OPCUA_NAME_LABEL, ) ) diff --git a/azext_edge/edge/providers/support/orc.py b/azext_edge/edge/providers/support/orc.py index f4851d0c0..09ad349cb 100644 --- a/azext_edge/edge/providers/support/orc.py +++ b/azext_edge/edge/providers/support/orc.py @@ -24,7 +24,7 @@ ORC_APP_LABEL = "app in (aio-orc-api, cert-manager, cainjector, webhook)" ORC_CONTROLLER_LABEL = "control-plane in (aio-orc-controller-manager)" -ORC_FILE_PATH = ORC_API_V1.moniker +ORC_DIRECTORY_PATH = ORC_API_V1.moniker # TODO: @jiacju - this label will be used near future for consistency # META_AIO_NAME_LABEL = "app.kubernetes.io/name in (microsoft-iotoperations)" @@ -35,7 +35,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: processed.extend( process_v1_pods( - file_path=ORC_FILE_PATH, + directory_path=ORC_DIRECTORY_PATH, label_selector=label, since_seconds=since_seconds, ) @@ -47,7 +47,7 @@ def fetch_pods(since_seconds: int = DAY_IN_SECONDS): def fetch_deployments(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_deployments(file_path=ORC_FILE_PATH, label_selector=label)) + processed.extend(process_deployments(directory_path=ORC_DIRECTORY_PATH, label_selector=label)) return processed @@ -55,7 +55,7 @@ def fetch_deployments(): def fetch_services(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_services(file_path=ORC_FILE_PATH, label_selector=label)) + processed.extend(process_services(directory_path=ORC_DIRECTORY_PATH, label_selector=label)) return processed @@ -63,7 +63,7 @@ def fetch_services(): def fetch_replicasets(): processed = [] for label in [ORC_APP_LABEL, ORC_CONTROLLER_LABEL]: - processed.extend(process_replicasets(file_path=ORC_FILE_PATH, label_selector=label)) + processed.extend(process_replicasets(directory_path=ORC_DIRECTORY_PATH, label_selector=label)) return processed diff --git a/azext_edge/edge/providers/support/otel.py b/azext_edge/edge/providers/support/otel.py index 07901f169..30a14fa79 100644 --- a/azext_edge/edge/providers/support/otel.py +++ b/azext_edge/edge/providers/support/otel.py @@ -19,23 +19,23 @@ # Defined here as this is not an IoT Operations API OTEL_API = EdgeResourceApi(group="otel", version="v1", moniker="otel") -OTEL_FILE_PATH = OTEL_API.moniker +OTEL_DIRECTORY_PATH = OTEL_API.moniker def fetch_otel_pods(since_seconds: int = DAY_IN_SECONDS): - return process_v1_pods(file_path=OTEL_FILE_PATH, label_selector=OTEL_NAME_LABEL, since_seconds=since_seconds) + return process_v1_pods(directory_path=OTEL_DIRECTORY_PATH, label_selector=OTEL_NAME_LABEL, since_seconds=since_seconds) def fetch_otel_deployments(): - return process_deployments(file_path=OTEL_FILE_PATH, label_selector=OTEL_NAME_LABEL) + return process_deployments(directory_path=OTEL_DIRECTORY_PATH, label_selector=OTEL_NAME_LABEL) def fetch_otel_replicasets(): - return process_replicasets(file_path=OTEL_FILE_PATH, label_selector=OTEL_NAME_LABEL) + return process_replicasets(directory_path=OTEL_DIRECTORY_PATH, label_selector=OTEL_NAME_LABEL) def fetch_otel_services(): - return process_services(file_path=OTEL_FILE_PATH, label_selector=OTEL_NAME_LABEL) + return process_services(directory_path=OTEL_DIRECTORY_PATH, label_selector=OTEL_NAME_LABEL) support_runtime_elements = { diff --git a/azext_edge/tests/edge/support/test_support_unit.py b/azext_edge/tests/edge/support/test_support_unit.py index 54e4cf997..0eb3a8cc2 100644 --- a/azext_edge/tests/edge/support/test_support_unit.py +++ b/azext_edge/tests/edge/support/test_support_unit.py @@ -30,7 +30,7 @@ from azext_edge.edge.providers.support.akri import ( AKRI_AGENT_LABEL, AKRI_APP_LABEL, - AKRI_FILE_PATH, + AKRI_DIRECTORY_PATH, AKRI_INSTANCE_LABEL, AKRI_NAME_LABEL_V2, AKRI_SERVICE_LABEL, @@ -40,11 +40,11 @@ from azext_edge.edge.providers.support.billing import ( AIO_BILLING_USAGE_NAME_LABEL, ARC_BILLING_EXTENSION_COMP_LABEL, - ARC_BILLING_FILE_PATH, + ARC_BILLING_DIRECTORY_PATH, BILLING_RESOURCE_KIND, ) from azext_edge.edge.providers.support.dataprocessor import ( - DATA_PROCESSOR_FILE_PATH, + DATA_PROCESSOR_DIRECTORY_PATH, DATA_PROCESSOR_INSTANCE_LABEL, DATA_PROCESSOR_LABEL, DATA_PROCESSOR_NAME_LABEL, @@ -52,17 +52,17 @@ DATA_PROCESSOR_ONEOFF_LABEL, DATA_PROCESSOR_PVC_APP_LABEL, ) -from azext_edge.edge.providers.support.lnm import LNM_APP_LABELS, LNM_FILE_PATH -from azext_edge.edge.providers.support.mq import MQ_FILE_PATH, MQ_LABEL, MQ_NAME_LABEL +from azext_edge.edge.providers.support.lnm import LNM_APP_LABELS, LNM_DIRECTORY_PATH +from azext_edge.edge.providers.support.mq import MQ_DIRECTORY_PATH, MQ_LABEL, MQ_NAME_LABEL from azext_edge.edge.providers.support.opcua import ( OPC_APP_LABEL, - OPC_FILE_PATH, + OPC_DIRECTORY_PATH, OPC_NAME_LABEL, OPC_NAME_VAR_LABEL, OPCUA_NAME_LABEL, ) from azext_edge.edge.providers.support.orc import ( - ORC_FILE_PATH, + ORC_DIRECTORY_PATH, ORC_APP_LABEL, ORC_CONTROLLER_LABEL, ) @@ -163,38 +163,38 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, since_seconds=since_seconds, ) assert_list_cron_jobs( mocked_client, mocked_zipfile, label_selector=AIO_BILLING_USAGE_NAME_LABEL, - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, ) assert_list_jobs( mocked_client, mocked_zipfile, label_selector=AIO_BILLING_USAGE_NAME_LABEL, - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=ARC_BILLING_EXTENSION_COMP_LABEL, - file_path=ARC_BILLING_FILE_PATH, + directory_path=ARC_BILLING_DIRECTORY_PATH, ) if api in COMPAT_MQ_APIS.resource_apis: @@ -203,7 +203,7 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, field_selector=f"metadata.name={AIO_MQ_OPERATOR}", ) assert_list_pods( @@ -211,7 +211,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=MQ_LABEL, - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, since_seconds=since_seconds, ) assert_list_pods( @@ -219,43 +219,43 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=MQ_NAME_LABEL, - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, since_seconds=since_seconds, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, - file_path=MQ_FILE_PATH + directory_path=MQ_DIRECTORY_PATH ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, file_path=MQ_FILE_PATH + mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, directory_path=MQ_DIRECTORY_PATH ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, field_selector=None, - file_path=MQ_FILE_PATH + directory_path=MQ_DIRECTORY_PATH ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, field_selector=None, - file_path=MQ_FILE_PATH, + directory_path=MQ_DIRECTORY_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=MQ_LABEL, - file_path=MQ_FILE_PATH + directory_path=MQ_DIRECTORY_PATH ) assert_list_services( mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, - file_path=MQ_FILE_PATH + directory_path=MQ_DIRECTORY_PATH ) assert_mq_stats(mocked_zipfile) @@ -266,7 +266,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_APP_LABEL, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, since_seconds=since_seconds, include_metrics=True, ) @@ -275,7 +275,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_NAME_LABEL, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, since_seconds=since_seconds, include_metrics=True, ) @@ -284,7 +284,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPC_NAME_VAR_LABEL, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, since_seconds=since_seconds, include_metrics=True, ) @@ -293,7 +293,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=OPCUA_NAME_LABEL, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, since_seconds=since_seconds, include_metrics=True, ) @@ -301,64 +301,64 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=None, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, mock_names=["aio-opc-admission-controller", "aio-opc-supervisor", "aio-opc-opc", "opcplc-0000000"], ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=OPC_NAME_LABEL, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPC_NAME_LABEL, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=None, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, mock_names=["opcplc-0000000"], ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, file_path=OPC_FILE_PATH + mocked_client, mocked_zipfile, label_selector=OPC_APP_LABEL, directory_path=OPC_DIRECTORY_PATH ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, file_path=OPC_FILE_PATH + mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, directory_path=OPC_DIRECTORY_PATH ) # TODO: one-off field selector remove after label assert_list_daemon_sets( mocked_client, mocked_zipfile, field_selector="metadata.name==aio-opc-asset-discovery", - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=OPCUA_NAME_LABEL, - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, ) if api in [DATA_PROCESSOR_API_V1]: @@ -368,13 +368,13 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_pods( @@ -382,7 +382,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=DATA_PROCESSOR_LABEL, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, since_seconds=since_seconds, pod_prefix_for_init_container_logs=["aio-"], ) @@ -391,7 +391,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, since_seconds=since_seconds, pod_prefix_for_init_container_logs=["aio-"], ) @@ -400,76 +400,76 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - file_path=DATA_PROCESSOR_FILE_PATH + directory_path=DATA_PROCESSOR_DIRECTORY_PATH ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_stateful_sets( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_LABEL, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_services( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_INSTANCE_LABEL, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_PVC_APP_LABEL, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_ONEOFF_LABEL, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, label_selector=DATA_PROCESSOR_NAME_LABEL_V2, - file_path=DATA_PROCESSOR_FILE_PATH, + directory_path=DATA_PROCESSOR_DIRECTORY_PATH, ) if api in [ORC_API_V1]: @@ -479,20 +479,20 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=orc_label, - file_path=ORC_FILE_PATH, + directory_path=ORC_DIRECTORY_PATH, since_seconds=since_seconds, ) assert_list_deployments( - mocked_client, mocked_zipfile, label_selector=orc_label, file_path=ORC_FILE_PATH + mocked_client, mocked_zipfile, label_selector=orc_label, directory_path=ORC_DIRECTORY_PATH ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=orc_label, file_path=ORC_FILE_PATH + mocked_client, mocked_zipfile, label_selector=orc_label, directory_path=ORC_DIRECTORY_PATH ) assert_list_services( mocked_client, mocked_zipfile, label_selector=orc_label, - file_path=ORC_FILE_PATH + directory_path=ORC_DIRECTORY_PATH ) if api in [AKRI_API_V0]: @@ -501,7 +501,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_INSTANCE_LABEL, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, since_seconds=since_seconds, ) assert_list_pods( @@ -509,7 +509,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_APP_LABEL, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, since_seconds=since_seconds, ) assert_list_pods( @@ -517,7 +517,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=NAME_LABEL_FORMAT.format(label=f"{AKRI_AGENT_LABEL}, {AKRI_WEBHOOK_LABEL}"), - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, since_seconds=since_seconds, ) assert_list_pods( @@ -525,83 +525,83 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=AKRI_NAME_LABEL_V2, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, since_seconds=since_seconds, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_APP_LABEL, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, ) assert_list_deployments( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_APP_LABEL, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_WEBHOOK_LABEL), - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, ) assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_SERVICE_LABEL, file_path=AKRI_FILE_PATH + mocked_client, mocked_zipfile, label_selector=AKRI_SERVICE_LABEL, directory_path=AKRI_DIRECTORY_PATH ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, file_path=AKRI_FILE_PATH + mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, directory_path=AKRI_DIRECTORY_PATH ) assert_list_services( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_WEBHOOK_LABEL), - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, file_path=AKRI_FILE_PATH + mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, directory_path=AKRI_DIRECTORY_PATH ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=AKRI_INSTANCE_LABEL, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=NAME_LABEL_FORMAT.format(label=AKRI_AGENT_LABEL), - file_path=OPC_FILE_PATH, + directory_path=OPC_DIRECTORY_PATH, ) assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=AKRI_NAME_LABEL_V2, - file_path=AKRI_FILE_PATH, + directory_path=AKRI_DIRECTORY_PATH, ) if api in [LNM_API_V1B1]: @@ -611,7 +611,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=lnm_app_label, - file_path=LNM_FILE_PATH, + directory_path=LNM_DIRECTORY_PATH, since_seconds=since_seconds, ) assert_list_pods( @@ -619,7 +619,7 @@ def test_create_bundle( mocked_zipfile, mocked_list_pods, label_selector=None, - file_path=LNM_FILE_PATH, + directory_path=LNM_DIRECTORY_PATH, since_seconds=since_seconds, mock_names=["svclb-aio-lnm-operator"], ) @@ -627,21 +627,21 @@ def test_create_bundle( mocked_client, mocked_zipfile, label_selector=None, - file_path=LNM_FILE_PATH, + directory_path=LNM_DIRECTORY_PATH, mock_names=["aio-lnm-operator"], ) assert_list_replica_sets( - mocked_client, mocked_zipfile, label_selector=lnm_app_label, file_path=LNM_FILE_PATH + mocked_client, mocked_zipfile, label_selector=lnm_app_label, directory_path=LNM_DIRECTORY_PATH ) assert_list_services( - mocked_client, mocked_zipfile, label_selector=lnm_app_label, file_path=LNM_FILE_PATH + mocked_client, mocked_zipfile, label_selector=lnm_app_label, directory_path=LNM_DIRECTORY_PATH ) # TODO: test both without or with lnm instance assert_list_daemon_sets( mocked_client, mocked_zipfile, label_selector=None, - file_path=LNM_FILE_PATH, + directory_path=LNM_DIRECTORY_PATH, mock_names=["svclb-aio-lnm-operator"], ) @@ -692,7 +692,7 @@ def assert_list_cron_jobs( mocked_client, mocked_zipfile, label_selector: str, - file_path: str, + directory_path: str, ): mocked_client.BatchV1Api().list_cron_job_for_all_namespaces.assert_any_call( label_selector=label_selector, field_selector=None @@ -700,7 +700,7 @@ def assert_list_cron_jobs( assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{file_path}/cronjob.mock_cron_job.yaml", + zinfo=f"mock_namespace/{directory_path}/cronjob.mock_cron_job.yaml", data="kind: CronJob\nmetadata:\n name: mock_cron_job\n namespace: mock_namespace\n", ) @@ -709,11 +709,11 @@ def assert_list_deployments( mocked_client, mocked_zipfile, label_selector: str, - file_path: str, + directory_path: str, field_selector: str = None, mock_names: List[str] = None, ): - if MQ_FILE_PATH in file_path: + if MQ_DIRECTORY_PATH in directory_path: # regardless of MQ API, MQ_ACTIVE_API.moniker is used for support/mq/fetch_diagnostic_metrics from unittest.mock import call @@ -736,7 +736,7 @@ def assert_list_deployments( for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{file_path}/deployment.{name}.yaml", + zinfo=f"mock_namespace/{directory_path}/deployment.{name}.yaml", data=f"kind: Deployment\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -745,7 +745,7 @@ def assert_list_jobs( mocked_client, mocked_zipfile, label_selector: str, - file_path: str, + directory_path: str, ): mocked_client.BatchV1Api().list_job_for_all_namespaces.assert_any_call( label_selector=label_selector, field_selector=None @@ -753,7 +753,7 @@ def assert_list_jobs( assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{file_path}/job.mock_job.yaml", + zinfo=f"mock_namespace/{directory_path}/job.mock_job.yaml", data="kind: Job\nmetadata:\n name: mock_job\n namespace: mock_namespace\n", ) @@ -763,7 +763,7 @@ def assert_list_pods( mocked_zipfile, mocked_list_pods, label_selector: str, - file_path: str, + directory_path: str, **kwargs, ): mocked_client.CoreV1Api().list_pod_for_all_namespaces.assert_any_call(label_selector=label_selector) @@ -789,7 +789,7 @@ def assert_list_pods( ) assert_zipfile_write( mocked_zipfile, - zinfo=f"{namespace}/{file_path}/pod.{pod_name}.metric.yaml", + zinfo=f"{namespace}/{directory_path}/pod.{pod_name}.metric.yaml", data="apiVersion: metrics.k8s.io/v1beta1\nkind: PodMetrics\nmetadata:\n " "creationTimestamp: '0000-00-00T00:00:00Z'\n name: mock_custom_object\n " "namespace: namespace\ntimestamp: '0000-00-00T00:00:00Z'\n", @@ -804,7 +804,7 @@ def assert_list_pods( assert_zipfile_write( mocked_zipfile, - zinfo=f"{namespace}/{file_path}/pod.{pod_name}.yaml", + zinfo=f"{namespace}/{directory_path}/pod.{pod_name}.yaml", data=data, ) @@ -820,7 +820,7 @@ def assert_list_pods( previous_segment = ".previous" if previous_logs else "" assert_zipfile_write( mocked_zipfile, - zinfo=f"{namespace}/{file_path}/" + zinfo=f"{namespace}/{directory_path}/" f"pod.{pod_name}.{container_name}{previous_segment}.log", data=pods_with_container[namespace][pod_name][container_name], ) @@ -830,7 +830,7 @@ def assert_list_replica_sets( mocked_client, mocked_zipfile, label_selector: str, - file_path: str, + directory_path: str, mock_names: Optional[List[str]] = None, ): mocked_client.AppsV1Api().list_replica_set_for_all_namespaces.assert_any_call(label_selector=label_selector) @@ -839,7 +839,7 @@ def assert_list_replica_sets( for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{file_path}/replicaset.{name}.yaml", + zinfo=f"mock_namespace/{directory_path}/replicaset.{name}.yaml", data=f"kind: Replicaset\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -847,7 +847,7 @@ def assert_list_replica_sets( def assert_list_persistent_volume_claims( mocked_client, mocked_zipfile, - file_path: str, + directory_path: str, label_selector: str = None, field_selector: str = None, ): @@ -857,7 +857,7 @@ def assert_list_persistent_volume_claims( assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{file_path}/pvc.mock_pvc.yaml", + zinfo=f"mock_namespace/{directory_path}/pvc.mock_pvc.yaml", data="kind: PersistentVolumeClaim\nmetadata:\n name: mock_pvc\n namespace: mock_namespace\n", ) @@ -865,7 +865,7 @@ def assert_list_persistent_volume_claims( def assert_list_stateful_sets( mocked_client, mocked_zipfile, - file_path: str, + directory_path: str, label_selector: Optional[str] = None, field_selector: Optional[str] = None, ): @@ -875,7 +875,7 @@ def assert_list_stateful_sets( assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{file_path}/statefulset.mock_statefulset.yaml", + zinfo=f"mock_namespace/{directory_path}/statefulset.mock_statefulset.yaml", data="kind: Statefulset\nmetadata:\n name: mock_statefulset\n namespace: mock_namespace\n", ) @@ -883,7 +883,7 @@ def assert_list_stateful_sets( def assert_list_services( mocked_client, mocked_zipfile, - file_path: str, + directory_path: str, label_selector: Optional[str] = None, field_selector: Optional[str] = None, mock_names: Optional[List[str]] = None, @@ -896,7 +896,7 @@ def assert_list_services( for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{file_path}/service.{name}.yaml", + zinfo=f"mock_namespace/{directory_path}/service.{name}.yaml", data=f"kind: Service\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -904,7 +904,7 @@ def assert_list_services( def assert_list_daemon_sets( mocked_client, mocked_zipfile, - file_path: str, + directory_path: str, label_selector: Optional[str] = None, field_selector: Optional[str] = None, mock_names: Optional[List[str]] = None, @@ -917,7 +917,7 @@ def assert_list_daemon_sets( for name in mock_names: assert_zipfile_write( mocked_zipfile, - zinfo=f"mock_namespace/{file_path}/daemonset.{name}.yaml", + zinfo=f"mock_namespace/{directory_path}/daemonset.{name}.yaml", data=f"kind: Daemonset\nmetadata:\n name: {name}\n namespace: mock_namespace\n", ) @@ -936,7 +936,7 @@ def assert_otel_kpis( "mocked_client": mocked_client, "mocked_zipfile": mocked_zipfile, "label_selector": OTEL_NAME_LABEL, - "file_path": OTEL_API.moniker, + "directory_path": OTEL_API.moniker, } if assert_func == assert_list_pods: kwargs["mocked_list_pods"] = mocked_list_pods From 284c5500dd9734799a335f54af93adb22d9d275b Mon Sep 17 00:00:00 2001 From: Elsie4ever <3467996@gmail.com> Date: Mon, 3 Jun 2024 10:08:15 -0700 Subject: [PATCH 8/9] lint --- azext_edge/edge/providers/support/otel.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/azext_edge/edge/providers/support/otel.py b/azext_edge/edge/providers/support/otel.py index 30a14fa79..b3d115877 100644 --- a/azext_edge/edge/providers/support/otel.py +++ b/azext_edge/edge/providers/support/otel.py @@ -23,7 +23,11 @@ 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) + return process_v1_pods( + directory_path=OTEL_DIRECTORY_PATH, + label_selector=OTEL_NAME_LABEL, + since_seconds=since_seconds + ) def fetch_otel_deployments(): From cb2ab8086e6a4a8b85a8de4498c2d8a7438f333b Mon Sep 17 00:00:00 2001 From: Elsie4ever <3467996@gmail.com> Date: Mon, 3 Jun 2024 17:16:38 -0700 Subject: [PATCH 9/9] address comment --- azext_edge/edge/providers/support/base.py | 5 +++-- azext_edge/edge/providers/support/billing.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/azext_edge/edge/providers/support/base.py b/azext_edge/edge/providers/support/base.py index 9a1e2d6de..e9dc1a541 100644 --- a/azext_edge/edge/providers/support/base.py +++ b/azext_edge/edge/providers/support/base.py @@ -363,15 +363,16 @@ def process_cron_jobs( def assemble_crd_work( apis: Iterable[EdgeResourceApi], file_prefix_map: Optional[Dict[str, str]] = None, - sub_group: Optional[str] = None, + directory_path: Optional[str] = None, ) -> dict: if not file_prefix_map: file_prefix_map = {} result = {} for api in apis: + if not directory_path: + directory_path = api.moniker for kind in api.kinds: - directory_path = api.moniker if not sub_group else f"{api.moniker}/{sub_group}" file_prefix = file_prefix_map.get(kind) result[f"{api.moniker} {api.version} {kind}"] = partial( process_crd, diff --git a/azext_edge/edge/providers/support/billing.py b/azext_edge/edge/providers/support/billing.py index 394d3ae7a..776b6a22b 100644 --- a/azext_edge/edge/providers/support/billing.py +++ b/azext_edge/edge/providers/support/billing.py @@ -106,7 +106,7 @@ def prepare_bundle( log_age_seconds: int = DAY_IN_SECONDS, ) -> dict: billing_to_run = {} - billing_to_run.update(assemble_crd_work(apis=apis, sub_group=BILLING_RESOURCE_KIND)) + 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)