Skip to content

Commit

Permalink
fix: Broker statefulsets support bundle fix (#271)
Browse files Browse the repository at this point in the history
* Removing MQTT Broker Connectors from support bundle

* Remove additional references to MQ_LABEL

---------

Co-authored-by: Ryan Kelly <rykelly@microsoft.com>
Co-authored-by: Ryan Kelly <ryan@UPX-M2.local>
  • Loading branch information
3 people authored Jul 17, 2024
1 parent 0247120 commit 8a8a669
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 95 deletions.
2 changes: 1 addition & 1 deletion azext_edge/edge/providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def retrieve_namespaced_service_from_cache(key: tuple):
def get_namespaced_pods_by_prefix(
prefix: str,
namespace: str,
label_selector: str = None,
label_selector: Optional[str] = None,
as_dict: bool = False,
) -> Union[List[V1Pod], List[dict], None]:
def filter_pods_by_prefix(pods: List[V1Pod], prefix: str) -> List[V1Pod]:
Expand Down
4 changes: 2 additions & 2 deletions azext_edge/edge/providers/check/base/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from knack.log import get_logger
from rich.padding import Padding
from kubernetes.client.models import V1Pod
from typing import List, Tuple
from typing import List, Optional, Tuple

from .check_manager import CheckManager
from .display import add_display_and_eval
Expand All @@ -32,7 +32,7 @@ def evaluate_pod_health(
target: str,
pod: str,
display_padding: int,
service_label: str,
service_label: Optional[str] = None,
detail_level: int = ResourceOutputDetailLevel.summary.value,
) -> None:
target_service_pod = f"pod/{pod}"
Expand Down
2 changes: 0 additions & 2 deletions azext_edge/edge/providers/check/cloud_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from ...common import AIO_MQ_RESOURCE_PREFIX, CheckTaskStatus
from ...providers.edge_api import MQ_ACTIVE_API, MqResourceKinds
from ..support.mq import MQ_LABEL
from .base import (
CheckManager,
evaluate_pod_health,
Expand Down Expand Up @@ -257,7 +256,6 @@ def _display_connector_runtime_health(
namespace=namespace,
pod=pod,
display_padding=padding,
service_label=MQ_LABEL,
detail_level=detail_level,
)

Expand Down
61 changes: 5 additions & 56 deletions azext_edge/edge/providers/support/mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

from knack.log import get_logger

from azext_edge.edge.common import AIO_MQ_RESOURCE_PREFIX
from azext_edge.edge.providers.edge_api.mq import MqResourceKinds

from ..edge_api import MQ_ACTIVE_API, EdgeResourceApi
from ..stats import get_stats, get_traces
from .base import (
Expand All @@ -28,14 +25,6 @@

logger = get_logger(__name__)

# TODO: @jiacju - will remove old labels once new labels are stabled
MQ_APP_LABELS = [
"aio-mq-mqttbridge",
"aio-mq-datalake",
"aio-mq-kafka-connector",
]

MQ_LABEL = f"app in ({','.join(MQ_APP_LABELS)})"
MQ_K8S_LABEL = "k8s-app in (aio-mq-fluent-bit)"

MQ_NAME_LABEL = NAME_LABEL_FORMAT.format(label=MQ_ACTIVE_API.label)
Expand Down Expand Up @@ -89,23 +78,6 @@ def fetch_statefulsets():
return_namespaces=True,
)

# bridge connector stateful sets have no labels
connectors = []
for kind in [
MqResourceKinds.DATALAKE_CONNECTOR,
MqResourceKinds.KAFKA_CONNECTOR,
MqResourceKinds.MQTT_BRIDGE_CONNECTOR,
]:
connectors.extend(MQ_ACTIVE_API.get_resources(kind=kind).get("items", []))

for connector in connectors:
connector_name = connector.get("metadata", {}).get("name")
stateful_set = process_statefulset(
directory_path=MQ_DIRECTORY_PATH,
field_selector=f"metadata.name={AIO_MQ_RESOURCE_PREFIX}{connector_name}",
)
processed.extend(stateful_set)

for namespace in namespaces:
metrics = fetch_diagnostic_metrics(namespace)
if metrics:
Expand All @@ -115,48 +87,25 @@ def fetch_statefulsets():


def fetch_services():
processed = process_services(
return process_services(
directory_path=MQ_DIRECTORY_PATH,
label_selector=MQ_LABEL,
)
processed.extend(
process_services(
directory_path=MQ_DIRECTORY_PATH,
label_selector=MQ_NAME_LABEL,
)
label_selector=MQ_NAME_LABEL,
)

return processed


def fetch_replicasets():
processed = process_replicasets(
return process_replicasets(
directory_path=MQ_DIRECTORY_PATH,
label_selector=MQ_LABEL,
)
processed.extend(
process_replicasets(
directory_path=MQ_DIRECTORY_PATH,
label_selector=MQ_NAME_LABEL,
)
label_selector=MQ_NAME_LABEL,
)

return processed


def fetch_pods(since_seconds: int = DAY_IN_SECONDS):
processed = process_v1_pods(
directory_path=MQ_DIRECTORY_PATH,
label_selector=MQ_LABEL,
label_selector=MQ_NAME_LABEL,
since_seconds=since_seconds,
)
processed.extend(
process_v1_pods(
directory_path=MQ_DIRECTORY_PATH,
label_selector=MQ_NAME_LABEL,
since_seconds=since_seconds,
)
)

# TODO: @jiacju - will remove once label decision is finalized
processed.extend(
Expand Down
35 changes: 1 addition & 34 deletions azext_edge/tests/edge/support/test_support_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from azure.cli.core.azclierror import ResourceNotFoundError

from azext_edge.edge.commands_edge import support_bundle
from azext_edge.edge.common import AIO_MQ_RESOURCE_PREFIX
from azext_edge.edge.providers.edge_api import (
AKRI_API_V0,
CLUSTER_CONFIG_API_V1,
Expand Down Expand Up @@ -44,7 +43,7 @@
BILLING_RESOURCE_KIND,
)
from azext_edge.edge.providers.support.meta import META_NAME_LABEL
from azext_edge.edge.providers.support.mq import MQ_DIRECTORY_PATH, MQ_K8S_LABEL, MQ_LABEL, MQ_NAME_LABEL
from azext_edge.edge.providers.support.mq import MQ_DIRECTORY_PATH, MQ_K8S_LABEL, MQ_NAME_LABEL
from azext_edge.edge.providers.support.opcua import (
OPC_APP_LABEL,
OPC_DIRECTORY_PATH,
Expand Down Expand Up @@ -197,14 +196,6 @@ def test_create_bundle(

if api in COMPAT_MQTT_BROKER_APIS.resource_apis:
# Assert runtime resources
assert_list_pods(
mocked_client,
mocked_zipfile,
mocked_list_pods,
label_selector=MQ_LABEL,
directory_path=MQ_DIRECTORY_PATH,
since_seconds=since_seconds,
)
assert_list_pods(
mocked_client,
mocked_zipfile,
Expand All @@ -221,12 +212,6 @@ def test_create_bundle(
directory_path=MQ_DIRECTORY_PATH,
since_seconds=since_seconds,
)
assert_list_replica_sets(
mocked_client,
mocked_zipfile,
label_selector=MQ_LABEL,
directory_path=MQ_DIRECTORY_PATH
)
assert_list_replica_sets(
mocked_client, mocked_zipfile, label_selector=MQ_NAME_LABEL, directory_path=MQ_DIRECTORY_PATH
)
Expand All @@ -237,12 +222,6 @@ def test_create_bundle(
field_selector=None,
directory_path=MQ_DIRECTORY_PATH,
)
assert_list_services(
mocked_client,
mocked_zipfile,
label_selector=MQ_LABEL,
directory_path=MQ_DIRECTORY_PATH
)
assert_list_services(
mocked_client,
mocked_zipfile,
Expand Down Expand Up @@ -590,8 +569,6 @@ def assert_list_deployments(

mocked_client.AppsV1Api().list_deployment_for_all_namespaces.assert_has_calls(
[
# MQ deployments
call(label_selector=MQ_LABEL, field_selector=None),
# Specific for `aio-mq-operator` (no app label)
call(label_selector=None, field_selector=field_selector),
call(label_selector=MQ_NAME_LABEL, field_selector=None),
Expand Down Expand Up @@ -949,16 +926,6 @@ def test_mq_list_stateful_sets(
# mocked_client.AppsV1Api().list_stateful_set_for_all_namespaces.assert_called_once()
mocked_client.AppsV1Api().list_stateful_set_for_all_namespaces.assert_called()

# assert secondary connector calls to list stateful sets
for item in custom_objects["items"]:
item_name = item["metadata"]["name"]
statefulset_name = f"{AIO_MQ_RESOURCE_PREFIX}{item_name}"
selector = f"metadata.name={statefulset_name}"
mocked_client.AppsV1Api().list_stateful_set_for_all_namespaces.assert_any_call(
label_selector=None, field_selector=selector
)
# TODO - assert zipfile write of individual connector statefulset


@pytest.mark.parametrize(
"mocked_cluster_resources",
Expand Down

0 comments on commit 8a8a669

Please sign in to comment.