|
20 | 20 | */ |
21 | 21 | package eu.openanalytics.containerproxy.backend.kubernetes; |
22 | 22 |
|
| 23 | +import java.io.ByteArrayInputStream; |
| 24 | +import java.io.File; |
| 25 | +import java.io.FileWriter; |
23 | 26 | import java.io.IOException; |
24 | 27 | import java.io.OutputStream; |
25 | 28 | import java.net.URI; |
|
36 | 39 | import java.util.stream.Collectors; |
37 | 40 |
|
38 | 41 | import javax.inject.Inject; |
| 42 | +import javax.json.JsonValue; |
39 | 43 |
|
40 | 44 | import org.apache.commons.io.IOUtils; |
41 | 45 |
|
|
52 | 56 | import io.fabric8.kubernetes.api.model.ContainerPortBuilder; |
53 | 57 | import io.fabric8.kubernetes.api.model.EnvVar; |
54 | 58 | import io.fabric8.kubernetes.api.model.EnvVarSourceBuilder; |
| 59 | +import io.fabric8.kubernetes.api.model.HasMetadata; |
55 | 60 | import io.fabric8.kubernetes.api.model.LocalObjectReference; |
56 | 61 | import io.fabric8.kubernetes.api.model.Pod; |
57 | 62 | import io.fabric8.kubernetes.api.model.PodBuilder; |
@@ -134,6 +139,16 @@ protected Container startContainer(ContainerSpec spec, Proxy proxy) throws Excep |
134 | 139 |
|
135 | 140 | String kubeNamespace = getProperty(PROPERTY_NAMESPACE, DEFAULT_NAMESPACE); |
136 | 141 | String apiVersion = getProperty(PROPERTY_API_VERSION, DEFAULT_API_VERSION); |
| 142 | + |
| 143 | + // create additional manifests |
| 144 | + for (String manifest : proxy.getSpec().getKubernetesAdditionalManifests()) { |
| 145 | + List<HasMetadata> objects = kubeClient.load(new ByteArrayInputStream(manifest.getBytes())).get(); |
| 146 | + for (HasMetadata object : objects) { |
| 147 | + if (kubeClient.resource(object).fromServer().get() == null) { |
| 148 | + kubeClient.resource(object).createOrReplace(); |
| 149 | + } |
| 150 | + } |
| 151 | + } |
137 | 152 |
|
138 | 153 | String[] volumeStrings = Optional.ofNullable(spec.getVolumes()).orElse(new String[] {}); |
139 | 154 | List<Volume> volumes = new ArrayList<>(); |
@@ -287,6 +302,7 @@ protected Container startContainer(ContainerSpec spec, Proxy proxy) throws Excep |
287 | 302 | proxy.getTargets().put(mapping, target); |
288 | 303 | } |
289 | 304 |
|
| 305 | + |
290 | 306 | return container; |
291 | 307 | } |
292 | 308 |
|
@@ -334,6 +350,14 @@ protected void doStopProxy(Proxy proxy) throws Exception { |
334 | 350 | if (pod != null) kubeClient.pods().inNamespace(kubeNamespace).delete(pod); |
335 | 351 | Service service = Service.class.cast(container.getParameters().get(PARAM_SERVICE)); |
336 | 352 | if (service != null) kubeClient.services().inNamespace(kubeNamespace).delete(service); |
| 353 | + |
| 354 | + // delete additional manifests |
| 355 | + for (String manifest : proxy.getSpec().getKubernetesAdditionalManifests()) { |
| 356 | + List<HasMetadata> objects = kubeClient.load(new ByteArrayInputStream(manifest.getBytes())).get(); |
| 357 | + for (HasMetadata object : objects) { |
| 358 | + kubeClient.resource(object).delete(); |
| 359 | + } |
| 360 | + } |
337 | 361 | } |
338 | 362 | } |
339 | 363 |
|
|
0 commit comments