Search in sources :

Example 51 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class Apply method main.

public static void main(String... args) {
    if (args.length < 1) {
        System.out.println("Usage jsonFileToApply");
        return;
    }
    try {
        KubernetesClient kube = new DefaultKubernetesClient();
        File file = new File(args[0]);
        System.out.println("Applying file: " + file);
        if (!file.exists() || !file.isFile()) {
            System.out.println("File does not exist! " + file.getAbsolutePath());
            return;
        }
        Controller controller = new Controller(kube);
        String answer = controller.apply(file);
        System.out.println("Applied!: " + answer);
    } catch (Exception e) {
        System.out.println("FAILED: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) File(java.io.File)

Example 52 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class CreateBuildConfig method main.

public static void main(String... args) {
    if (args.length < 1) {
        System.out.println("Usage nameOfBuildConfig");
        return;
    }
    try {
        KubernetesClient kube = new DefaultKubernetesClient();
        String name = args[0];
        String namespace = kube.getNamespace();
        if (Strings.isNullOrBlank(namespace)) {
            namespace = KubernetesHelper.defaultNamespace();
        }
        if (Strings.isNullOrBlank(namespace)) {
            namespace = "default";
        }
        System.out.println("Creating a BuildConfig for name: " + name + " in namespace: " + namespace);
        BuildConfig buildConfig = new BuildConfigBuilder().withNewMetadata().withName(name).withNamespace(namespace).endMetadata().withNewSpec().withNewSource().withType("Git").withNewGit().withUri("http://gogs.vagrant.f8/gogsadmin/" + name + ".git").endGit().endSource().endSpec().build();
        System.out.println("Creating BuildConfig: " + buildConfig);
        Controller controller = new Controller(kube);
        if (controller.getNamespace() == null) {
            controller.setNamespace(namespace);
        }
        controller.applyBuildConfig(buildConfig, "Generated!");
        System.out.println("Applied!: " + name);
    } catch (Exception e) {
        System.out.println("FAILED: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder)

Example 53 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class DeleteBuildConfig method main.

public static void main(String... args) {
    if (args.length < 1) {
        System.out.println("Usage nameOfBuildConfig");
        return;
    }
    try {
        String name = args[0];
        System.out.println("Deleting BuildConfig: " + name);
        KubernetesClient kube = new DefaultKubernetesClient();
        String namespace = kube.getNamespace();
        System.out.println("Using namespace: " + namespace);
        Controller controller = new Controller(kube);
        OpenShiftClient openshift = controller.getOpenShiftClientOrJenkinshift();
        if (openshift == null) {
            System.err.println("Cannot connect to OpenShift or Jenkinshift!");
            return;
        }
        BuildConfig buildConfig = openshift.buildConfigs().withName(name).get();
        if (buildConfig != null) {
            System.out.println("Managed to load BuildConfig with resourceVersion " + KubernetesHelper.getResourceVersion(buildConfig));
        } else {
            System.err.println("Could not find BuildConfig called: " + name);
            return;
        }
        Boolean result = openshift.buildConfigs().withName(name).delete();
        System.out.println("Deleted BuildConfig with name " + name + " result: " + result);
    } catch (Exception e) {
        System.out.println("FAILED: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 54 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class GetServiceURL method main.

public static void main(String... args) {
    if (args.length < 1) {
        System.out.println("Usage nameOfService");
        return;
    }
    try {
        String name = args[0];
        KubernetesClient kube = new DefaultKubernetesClient();
        String namespace = kube.getNamespace();
        if (Strings.isNullOrBlank(namespace)) {
            namespace = "default";
        }
        String url = KubernetesHelper.getServiceURL(kube, name, namespace, "http", true);
        System.out.println("Service " + name + " has external URL: " + url);
    } catch (Exception e) {
        System.out.println("FAILED: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 55 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project syndesis by syndesisio.

the class PodMetricsReaderTest method readTest.

@Test
@Ignore
public void readTest() {
    String podName = "dbtest1-2-3nvf3";
    String integration = "DBTest1";
    String integrationId = "-L5ApZneYNfmLWG-PKQt";
    String version = "1";
    PodMetricsReader reader = new PodMetricsReader(new DefaultKubernetesClient(), podName, integration, integrationId, version, new LogRawMetrics());
    reader.run();
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Ignore(org.junit.Ignore) Test(org.junit.Test)

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