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: exclude meta resource job from billing support bundle using prefix name #293

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions azext_edge/edge/providers/support/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def fetch_jobs():
processed = process_jobs(
directory_path=BILLING_RESOURCE_KIND,
label_selector=AIO_BILLING_USAGE_NAME_LABEL,
prefix_names=[AIO_USAGE_PREFIX],
)

return processed
Expand Down
12 changes: 10 additions & 2 deletions azext_edge/tests/edge/support/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from functools import partial
from typing import List

from azext_edge.edge.providers.support.billing import AIO_BILLING_USAGE_NAME_LABEL
from ...generators import generate_random_string

import pytest
Expand Down Expand Up @@ -241,8 +243,14 @@ def mocked_list_jobs(mocked_client):
from kubernetes.client.models import V1JobList, V1Job, V1ObjectMeta

def _handle_list_jobs(*args, **kwargs):
job = V1Job(metadata=V1ObjectMeta(namespace="mock_namespace", name="mock_job"))
job_list = V1JobList(items=[job])
names = ["mock_job"]
if "label_selector" in kwargs and kwargs["label_selector"] == AIO_BILLING_USAGE_NAME_LABEL:
names.append("aio-usage-job")

job_list = []
for name in names:
job_list.append(V1Job(metadata=V1ObjectMeta(namespace="mock_namespace", name=name)))
job_list = V1JobList(items=job_list)

return job_list

Expand Down
14 changes: 9 additions & 5 deletions azext_edge/tests/edge/support/test_support_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def test_create_bundle(
mocked_zipfile,
label_selector=AIO_BILLING_USAGE_NAME_LABEL,
directory_path=BILLING_RESOURCE_KIND,
mock_names=["aio-usage-job"],
)
assert_list_replica_sets(
mocked_client,
Expand Down Expand Up @@ -599,16 +600,19 @@ def assert_list_jobs(
mocked_zipfile,
label_selector: str,
directory_path: str,
mock_names: Optional[List[str]] = None,
):
mocked_client.BatchV1Api().list_job_for_all_namespaces.assert_any_call(
label_selector=label_selector, field_selector=None
)

assert_zipfile_write(
mocked_zipfile,
zinfo=f"mock_namespace/{directory_path}/job.mock_job.yaml",
data="kind: Job\nmetadata:\n name: mock_job\n namespace: mock_namespace\n",
)
mock_names = mock_names or ["mock_job"]
for name in mock_names:
assert_zipfile_write(
mocked_zipfile,
zinfo=f"mock_namespace/{directory_path}/job.{name}.yaml",
data=f"kind: Job\nmetadata:\n name: {name}\n namespace: mock_namespace\n",
)


def assert_list_pods(
Expand Down