Skip to content

Commit

Permalink
fix: Protect against load balancer service existing (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielArndt authored Oct 27, 2023
1 parent 4326796 commit dfc954e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
PFCP_PORT = 8805
REQUIRED_CPU_EXTENSIONS = ["avx2", "rdrand"]

# The default field manager set when using kubectl to create resources
DEFAULT_FIELD_MANAGER = "controller"


class IncompatibleCPUError(Exception):
"""Custom error to be raised when CPU doesn't support required instructions."""
Expand Down Expand Up @@ -168,8 +171,8 @@ def _create_external_upf_service(self) -> None:
),
)

client.create(service)
logger.info("Created external UPF service")
client.apply(service, field_manager=DEFAULT_FIELD_MANAGER)
logger.info("Created/asserted existence of the external UPF service")

def _on_remove(self, event: RemoveEvent) -> None:
self._delete_external_upf_service()
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,9 @@ def test_when_install_then_external_service_is_created(self, patch_client):
),
)

patch_client.return_value.create.assert_called_once_with(expected_service)
patch_client.return_value.apply.assert_called_once_with(
expected_service, field_manager="controller"
)

@patch("charm.Client")
def test_when_remove_then_external_service_is_deleted(self, patch_client):
Expand Down

0 comments on commit dfc954e

Please sign in to comment.