/*
 * Copyright 2017 Red Hat Inc.
 *
 * 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 io.enmasse.keycloak.controller;

import io.enmasse.k8s.api.AddressSpaceApi;
import io.enmasse.k8s.api.ConfigMapAddressSpaceApi;
import io.fabric8.openshift.client.DefaultOpenShiftClient;
import io.fabric8.openshift.client.OpenShiftClient;

public class Main {
    public static void main(String [] args) throws Exception {

        OpenShiftClient openShiftClient = new DefaultOpenShiftClient();
        AddressSpaceApi addressSpaceApi = new ConfigMapAddressSpaceApi(openShiftClient);
        KeycloakManager keycloakManager = new KeycloakManager(new Keycloak(KeycloakParams.fromEnv(System.getenv())));

        addressSpaceApi.watchAddressSpaces(keycloakManager);
    }
}

@@ -747,185 +747,740 @@
 ic8.
-openshift.client.DefaultOpenShiftClient;%0Aimport io.fabric8.openshift.client.OpenShiftClient;%0A%0Apublic class Main %7B%0A    public static void main(String %5B%5D args) throws Exception %7B%0A
+kubernetes.client.Config;%0Aimport io.fabric8.kubernetes.client.ConfigBuilder;%0Aimport io.fabric8.openshift.client.DefaultOpenShiftClient;%0Aimport io.fabric8.openshift.client.OpenShiftClient;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.nio.file.Files;%0Aimport java.util.Map;%0A%0Apublic class Main %7B%0A    public static void main(String %5B%5D args) throws Exception %7B%0A        Map%3CString, String%3E env = System.getenv();%0A%0A        String openshiftUri = String.format(%22https://%25s:%25s%22, getEnvOrThrow(env, %22KUBERNETES_SERVICE_HOST%22), getEnvOrThrow(env, %22KUBERNETES_SERVICE_PORT%22));%0A%0A        Config config = new ConfigBuilder().withMasterUrl(openshiftUri).withOauthToken(getAuthenticationToken()).withNamespace(getNamespace()).build();
 %0A   
@@ -1545,16 +1545,22 @@
 tClient(
+config
 );%0A     
@@ -1828,11 +1828,1150 @@
 );%0A    %7D
+%0A%0A    private static String getEnvOrThrow(Map%3CString, String%3E env, String envVar) %7B%0A        String var = env.get(envVar);%0A        if (var == null) %7B%0A            throw new IllegalArgumentException(String.format(%22Unable to find value for required environment var '%25s'%22, envVar));%0A        %7D%0A        return var;%0A    %7D%0A%0A    private static final String SERVICEACCOUNT_PATH = %22/var/run/secrets/kubernetes.io/serviceaccount%22;%0A%0A    private static String getNamespace() throws IOException %7B%0A        String namespace = System.getenv(%22KUBERNETES_NAMESPACE%22);%0A        if (namespace == null) %7B%0A            return readFile(new File(SERVICEACCOUNT_PATH, %22namespace%22));%0A        %7D else %7B%0A            return namespace;%0A        %7D%0A    %7D%0A%0A    private static String getAuthenticationToken() throws IOException %7B%0A        String token = System.getenv(%22KUBERNETES_TOKEN%22);%0A        if (token == null) %7B%0A            return readFile(new File(SERVICEACCOUNT_PATH, %22token%22));%0A        %7D else %7B%0A            return token;%0A        %7D%0A    %7D%0A%0A    private static String readFile(File file) throws IOException %7B%0A        return new String(Files.readAllBytes(file.toPath()));%0A    %7D
 %0A%7D%0A

Use environment variables to configure openshift client