Search in sources :

Example 76 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.

the class ViewPipeline method main.

public static void main(String[] args) {
    if (args.length == 0) {
        System.err.println("Usage: ViewPipeline jobName [branchName] [gitUrl]");
        return;
    }
    String jobName = args[0];
    String branchName = "master";
    String gitUrl = null;
    if (args.length > 1) {
        branchName = args[1];
    }
    if (args.length > 2) {
        gitUrl = args[2];
    }
    try {
        JobEnvironment environment = new JobEnvironment();
        environment.setJobName(jobName);
        environment.setBranchName(branchName);
        environment.setGitUrl(gitUrl);
        KubernetesClient kubernetesClient = new DefaultKubernetesClient();
        String namespace = kubernetesClient.getNamespace();
        if (Strings.isNullOrBlank(namespace)) {
            namespace = KubernetesHelper.defaultNamespace();
        }
        Pipeline pipeline = Pipelines.getPipeline(kubernetesClient, namespace, environment);
        System.out.println("Found pipeline for job: " + pipeline.getJobName() + " of kind: " + pipeline.getKind());
    } catch (IntrospectionException e) {
        System.out.println("Failed with: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) IntrospectionException(java.beans.IntrospectionException) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 77 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.

the class WatchServicesExample method main.

public static void main(String... args) throws Exception {
    KubernetesClient client = new DefaultKubernetesClient();
    client.services().watch(new io.fabric8.kubernetes.client.Watcher<Service>() {

        @Override
        public void eventReceived(Action action, Service service) {
            System.out.println(action + ": " + service);
        }

        @Override
        public void onClose(KubernetesClientException e) {
            System.out.println("Closed: " + e);
        }
    });
    client.close();
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Service(io.fabric8.kubernetes.api.model.Service) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 78 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.

the class ListEnvironments method main.

public static void main(String[] args) {
    KubernetesClient kubernetesClient = new DefaultKubernetesClient();
    Environments environments;
    if (args.length > 0) {
        String namespace = args[0];
        System.out.println("Listing environments for namespace: " + namespace);
        environments = Environments.load(namespace);
    } else {
        environments = Environments.load();
    }
    String environmentKey = "testing";
    if (args.length > 1) {
        environmentKey = args[1];
    }
    System.out.println("Space namespace: " + environments.getNamespace());
    SortedSet<Environment> set = environments.getEnvironmentSet();
    for (Environment environment : set) {
        String onCluster = "";
        String clusterAPiServer = environment.getClusterAPiServer();
        if (Strings.isNotBlank(clusterAPiServer)) {
            onCluster += " on API server: " + clusterAPiServer;
        }
        System.out.println("Environment " + environment.getName() + " maps to namespace: " + environment.getNamespace() + onCluster);
    }
    System.out.println("Namespace for environment key: " + environmentKey + " is " + Environments.namespaceForEnvironment(environmentKey));
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 79 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project jbosstools-openshift by jbosstools.

the class ClusterHelper method getClusterInfo.

public static ClusterInfo getClusterInfo(KubernetesClient client) throws KubernetesClientException {
    if (client instanceof OpenShiftClient || client.isAdaptable(OpenShiftClient.class)) {
        VersionInfo oClientVersionInfo;
        VersionInfo kClientVersionInfo;
        if (client instanceof OpenShiftClient) {
            oClientVersionInfo = ((OpenShiftClient) client).getVersion();
            kClientVersionInfo = new DefaultKubernetesClient(client.getConfiguration()).getVersion();
        } else {
            oClientVersionInfo = client.adapt(OpenShiftClient.class).getVersion();
            kClientVersionInfo = client.getVersion();
        }
        return new ClusterInfo(kClientVersionInfo != null ? kClientVersionInfo.getGitVersion() : "", true, oClientVersionInfo != null && oClientVersionInfo.getMajor() != null ? assemble(oClientVersionInfo.getMajor(), oClientVersionInfo.getMinor()) : "");
    }
    VersionInfo kClientVersionInfo = client.getVersion();
    return new ClusterInfo(kClientVersionInfo != null ? kClientVersionInfo.getGitVersion() : "", false, "");
}
Also used : VersionInfo(io.fabric8.kubernetes.client.VersionInfo) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Aggregations

DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)79 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)55 HashMap (java.util.HashMap)13 Config (io.fabric8.kubernetes.client.Config)11 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)7 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)6 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)6 TaskAction (org.gradle.api.tasks.TaskAction)6 Pod (io.fabric8.kubernetes.api.model.Pod)5 IOException (java.io.IOException)5 Map (java.util.Map)5 Test (org.junit.Test)5 KubernetesModelGenerator (com.github.isdream.chameleon.container.kubernetes.KubernetesModelGenerator)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 File (java.io.File)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 Service (io.fabric8.kubernetes.api.model.Service)3 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)3 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)3