-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow communication between sessions of same user
A requirement for the training mode is that a Jupyter session can talk to a Capella session. This PR adds network policies so that Pods can reach the ports of other Pods from the same user.
- Loading branch information
1 parent
d514394
commit 58638ad
Showing
5 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import logging | ||
|
||
from capellacollab.sessions import operators | ||
from capellacollab.sessions.operators import k8s | ||
from capellacollab.tools import models as tools_models | ||
from capellacollab.users import models as users_models | ||
|
||
from .. import models as sessions_models | ||
from . import interface | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class NetworkingIntegration(interface.HookRegistration): | ||
"""Allow sessions of the same user to talk to each other.""" | ||
|
||
def post_session_creation_hook( | ||
self, | ||
session_id: str, | ||
session: k8s.Session, | ||
db_session: sessions_models.DatabaseSession, | ||
operator: operators.KubernetesOperator, | ||
user: users_models.DatabaseUser, | ||
connection_method: tools_models.ToolSessionConnectionMethod, | ||
**kwargs, | ||
) -> interface.PostSessionCreationHookResult: | ||
"""Allow sessions of the user to talk to each other.""" | ||
|
||
operator.create_network_policy_from_pod_to_label( | ||
session_id, | ||
{"capellacollab/session-id": session_id}, | ||
{"capellacollab/owner-id": str(user.id)}, | ||
) | ||
|
||
return interface.PostSessionCreationHookResult() | ||
|
||
def pre_session_termination_hook( # type: ignore | ||
self, | ||
operator: operators.KubernetesOperator, | ||
session: sessions_models.DatabaseSession, | ||
**kwargs, | ||
): | ||
operator.delete_network_policy(session.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters