Skip to content

Commit

Permalink
Simplify implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nsklikas committed Apr 21, 2023
1 parent d3f5a2f commit 3301bd4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 2 additions & 4 deletions lib/charms/kratos/v0/kubernetes_network_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def to_resource(self):


Port = Union[str, int]
IngressPolicyDefinition = Union[Tuple[Port], Tuple[int, str], Tuple[int, str, int]]
IngressPolicyDefinition = Tuple[PortDefinition, List[Relation]]
IngressPolicyDefinition = Tuple[Port, List[Relation]]


class KubernetesNetworkPoliciesHandler:
Expand Down Expand Up @@ -130,7 +129,7 @@ def apply_ingress_policy(
ingress.append(
NetworkPolicyIngressRule(
from_=selectors,
ports=[port.to_resource()],
ports=[NetworkPolicyPort(port=port, protocol="TCP")],
),
)

Expand All @@ -144,7 +143,6 @@ def apply_ingress_policy(
),
policyTypes=["Ingress", "Egress"],
ingress=ingress,
egress=[NetworkPolicyEgressRule()],
),
)

Expand Down
10 changes: 4 additions & 6 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,10 @@ def _apply_network_policies(self, event: HookEvent) -> None:
try:
self.network_policy_handler.apply_ingress_policy(
[
# (PortDefinition(1, KRATOS_PUBLIC_PORT - 1), []),
(PortDefinition(KRATOS_PUBLIC_PORT), [self.public_ingress.relation]),
(PortDefinition(KRATOS_ADMIN_PORT), [self.admin_ingress.relation]),
(PortDefinition(38812), []),
(PortDefinition(38813), []),
# (PortDefinition(KRATOS_ADMIN_PORT + 1, 65535), []),
(KRATOS_PUBLIC_PORT, [self.public_ingress.relation]),
(KRATOS_ADMIN_PORT, [self.admin_ingress.relation]),
(38812, []),
(38813, []),
]
)
except NetworkPoliciesHandlerError:
Expand Down

0 comments on commit 3301bd4

Please sign in to comment.