/*
 * Copyright 1&1 Internet AG, https://github.com/1and1/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.oneandone.stool.server.kubernetes;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.Configuration;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.models.V1Pod;
import io.kubernetes.client.openapi.models.V1PodList;
import io.kubernetes.client.openapi.models.V1Service;
import io.kubernetes.client.openapi.models.V1ServiceList;
import io.kubernetes.client.util.Config;

import java.io.IOException;

@SuppressWarnings("checkstyle:HideUtilityClassConstructor")
public class Engine {
    public static void main(String[] args) throws IOException, ApiException{
        ApiClient client = Config.defaultClient();
        Configuration.setDefaultApiClient(client);
        CoreV1Api api;
        V1PodList pods;
        V1ServiceList services;

        api = new CoreV1Api();
        pods = api.listNamespacedPod("default", null, null, null, null, null, null, null, null, null);
        for (V1Pod item : pods.getItems()) {
            System.out.println("pod: " + item.getMetadata().getName());
        }
        services = api.listNamespacedService("default", null, null, null, null, null, null, null, null, null);
        for (V1Service item : services.getItems()) {
            System.out.println("service: " + item.getMetadata().getName());
        }
    }
}

@@ -661,16 +661,71 @@
 rnetes;%0A
+import ch.qos.logback.classic.util.ContextInitializer;%0A
 import i
@@ -916,16 +916,129 @@
 eV1Api;%0A
+import io.kubernetes.client.openapi.models.V1Container;%0Aimport io.kubernetes.client.openapi.models.V1ObjectMeta;%0A
 import i
@@ -1129,24 +1129,78 @@
 .V1PodList;%0A
+import io.kubernetes.client.openapi.models.V1PodSpec;%0A
 import io.ku
@@ -1517,23 +1517,183 @@
 tion
-, ApiException%7B
+ %7B%0A        System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, %22/Users/mhm/Projects/github.com/net/oneandone/stool/stool/server/src/test/resources/logback-test.xml%22);%0A
 %0A   
@@ -1831,27 +1831,23 @@
 1Pod
-List
  pod
-s
 ;%0A
+%0A
         
 V1Se
@@ -1846,64 +1846,175 @@
     
-V1ServiceList services;%0A%0A        api = new CoreV1Api();%0A
+api = new CoreV1Api();%0A%0A        pod = pod(%22pod%22, %22contargo.server.lan/cisoops-public/hellowar:1.0.0%22);%0A        System.out.println(%22before: %22 + pod);%0A        try %7B%0A    
     
@@ -2020,28 +2020,29 @@
      pod
-s
  = api.
-list
+create
 Namespac
@@ -2048,30 +2048,27 @@
 cedPod(%22
-default%22, null
+stool%22, pod
 , null, 
@@ -2081,405 +2081,787 @@
 null
-, null, null, null, null, null);%0A        for (V1Pod item : pods.getItems()) %7B%0A            System.out.println(%22pod: %22 + item.getMetadata().getName());%0A        %7D%0A        services = api.listNamespacedService(%22default%22, null, null, null, null, null, null, null, null, null);%0A        for (V1Service item : services.getItems()) %7B%0A            System.out.println(%22service: %22 + item.getMetadata().g
+);%0A        %7D catch (ApiException e) %7B%0A            throw new IOException(%22apiException: %22 + e.getMessage() + %22 %22 + e.getResponseBody(), e);%0A        %7D%0A        System.out.println(%22after: %22 + pod);%0A    %7D%0A%0A    private static V1Pod pod(String name, String image) %7B%0A        V1PodSpec spec;%0A        V1Container container;%0A        V1Pod pod;%0A%0A        container = new V1Container();%0A        container.setName(name + %22-container%22);%0A        container.setImage(image);%0A        spec = new V1PodSpec();%0A        spec.addContainersItem(container);%0A        pod = new V1Pod();%0A        pod.setMetadata(md(name));%0A        pod.setSpec(spec);%0A        return pod;%0A    %7D%0A%0A    private static V1ObjectMeta md(String name) %7B%0A        V1ObjectMeta md;%0A%0A        md = new V1ObjectMeta();%0A        md.s
 etName(
-)
+name
 );%0A 
@@ -2863,22 +2863,31 @@
 e);%0A        
-%7D
+return md;
 %0A    %7D%0A%7D%0A

create a prod