Skip to content

Commit 60ba181

Browse files
committed
Add more labels to launched pods
1 parent 1f91b19 commit 60ba181

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/main/java/eu/openanalytics/containerproxy/backend/AbstractContainerBackend.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public abstract class AbstractContainerBackend implements IContainerBackend {
7070
protected static final String ENV_VAR_USER_GROUPS = "SHINYPROXY_USERGROUPS";
7171
protected static final String ENV_VAR_REALM_ID = "SHINYPROXY_REALM_ID";
7272

73+
protected static final String LABEL_PROXY_ID = "openanalytics.eu/sp-proxy-id";
74+
protected static final String LABEL_USER_ID = "openanalytics.eu/sp-user-id";
75+
protected static final String LABEL_PROXY_SPEC_ID = "openanalytics.eu/sp-spec-id";
76+
protected static final String LABEL_STARTUP_TIMESTAMP = "openanalytics.eu/sp-proxy-startup-timestamp";
77+
7378
protected final Logger log = LogManager.getLogger(getClass());
7479

7580
private boolean useInternalNetwork;
@@ -126,9 +131,23 @@ public void startProxy(Proxy proxy) throws ContainerProxyException {
126131
protected void doStartProxy(Proxy proxy) throws Exception {
127132
for (ContainerSpec spec: proxy.getSpec().getContainerSpecs()) {
128133
if (authBackend != null) authBackend.customizeContainer(spec);
134+
135+
// add labels need for App Recovery and maintenance
136+
spec.addLabel(LABEL_PROXY_ID, proxy.getId());
137+
spec.addLabel(LABEL_USER_ID, proxy.getUserId());
138+
spec.addLabel(LABEL_PROXY_SPEC_ID, proxy.getSpec().getId());
139+
spec.addLabel(LABEL_STARTUP_TIMESTAMP, String.valueOf(proxy.getStartupTimestamp()));
140+
129141
ExpressionAwareContainerSpec eSpec = new ExpressionAwareContainerSpec(spec, proxy, expressionResolver);
130142
Container c = startContainer(eSpec, proxy);
131143
c.setSpec(spec);
144+
145+
// remove labels needed for App Recovery since they do not really belong to the spec
146+
spec.removeLabel(LABEL_PROXY_ID);
147+
spec.removeLabel(LABEL_USER_ID);
148+
spec.removeLabel(LABEL_PROXY_SPEC_ID);
149+
spec.removeLabel(LABEL_STARTUP_TIMESTAMP);
150+
132151
proxy.getContainers().add(c);
133152
}
134153
}

src/main/java/eu/openanalytics/containerproxy/backend/kubernetes/KubernetesBackend.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public class KubernetesBackend extends AbstractContainerBackend {
109109

110110
private static final String SECRET_KEY_REF = "secretKeyRef";
111111

112-
private static final String LABEL_PROXIED_APP = "openanalytics.eu/containerproxy-proxied-app";
112+
private static final String LABEL_PROXIED_APP = "openanalytics.eu/containerproxy-proxied-app"; // TODO rename to "sp-proxied-app" ?
113113
private static final String LABEL_INSTANCE = "openanalytics.eu/sp-instance";
114114

115115

src/main/java/eu/openanalytics/containerproxy/model/spec/ContainerSpec.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,24 @@ public Map<String, String> getLabels() {
133133
public void setLabels(Map<String, String> labels) {
134134
this.labels = labels;
135135
}
136+
137+
public void addLabel(String key, String value) {
138+
if (this.labels.containsKey(key)) {
139+
throw new IllegalStateException("Cannot add duplicate label with key " + key);
140+
} else {
141+
labels.put(key, value);
142+
}
143+
}
144+
145+
public void removeLabel(String key) {
146+
labels.remove(key);
147+
}
148+
149+
136150
public Map<String, String> getSettings() {
137151
return settings;
138152
}
153+
139154
public void setSettings(Map<String, String> settings) {
140155
this.settings = settings;
141156
}

0 commit comments

Comments
 (0)