-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
org.eclipse.theia.cloud.common.util.LabelsUtil is added to encapsulate creation of labels. To indicate that a pod is a user session, its 'app.kubernetes.io/component' label is set to 'session'. For custom labels, we use the prefix 'theia-cloud.io'. This is currently used for: - Identifying a session pods associated with a user: 'theia-cloud.io/user' = '$username' - Identifying a session pod by appdefinition name: 'theia-cloud.io/app-definition' = $appdefinitionname Signed-off-by: Olaf Lessenich <[email protected]> Co-authored-by: Johannes Faltermeier <[email protected]> Co-authored-by: Lucas Koehler <[email protected]>
- Loading branch information
1 parent
84d00f6
commit 518c317
Showing
5 changed files
with
135 additions
and
33 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...ipse.theia.cloud.common/src/main/java/org/eclipse/theia/cloud/common/util/LabelsUtil.java
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,31 @@ | ||
package org.eclipse.theia.cloud.common.util; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.theia.cloud.common.k8s.resource.appdefinition.AppDefinitionSpec; | ||
import org.eclipse.theia.cloud.common.k8s.resource.session.SessionSpec; | ||
|
||
public class LabelsUtil { | ||
public static final String LABEL_CUSTOM_PREFIX = "theia-cloud.io"; | ||
|
||
public static final String LABEL_KEY_SESSION = "app.kubernetes.io/component"; | ||
public static final String LABEL_VALUE_SESSION = "session"; | ||
|
||
public static final String LABEL_KEY_THEIACLOUD = "app.kubernetes.io/part-of"; | ||
public static final String LABEL_VALUE_THEIACLOUD = "theia-cloud"; | ||
|
||
public static final String LABEL_KEY_USER = LABEL_CUSTOM_PREFIX + "/user"; | ||
public static final String LABEL_KEY_APPDEF = LABEL_CUSTOM_PREFIX + "/app-definition"; | ||
|
||
public static Map<String, String> createSessionLabels(SessionSpec sessionSpec, | ||
AppDefinitionSpec appDefinitionSpec) { | ||
Map<String, String> labels = new HashMap<>(); | ||
labels.put(LABEL_KEY_SESSION, LABEL_VALUE_SESSION); | ||
labels.put(LABEL_KEY_THEIACLOUD, LABEL_VALUE_THEIACLOUD); | ||
String sanitizedUser = sessionSpec.getUser().replaceAll("@", "_at_").replaceAll("[^a-zA-Z0-9]", "_"); | ||
labels.put(LABEL_KEY_USER, sanitizedUser); | ||
labels.put(LABEL_KEY_APPDEF, appDefinitionSpec.getName()); | ||
return labels; | ||
} | ||
} |
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
Oops, something went wrong.