Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: Broker statefulsets support bundle fix #271

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azext_edge/edge/providers/check/base/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def evaluate_pod_health(
target: str,
pod: str,
display_padding: int,
service_label: str,
service_label: str = None,
c-ryan-k marked this conversation as resolved.
Show resolved Hide resolved
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
53 changes: 3 additions & 50 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 @@ -117,13 +89,7 @@ def fetch_statefulsets():
def fetch_services():
processed = 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
Expand All @@ -132,13 +98,7 @@ def fetch_services():
def fetch_replicasets():
processed = process_replicasets(
c-ryan-k marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -147,16 +107,9 @@ def fetch_replicasets():
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