Search in sources :

Example 96 with KubernetesClient

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

the class Services method toServiceUrl.

public static String toServiceUrl(String serviceName, String serviceProtocol, String servicePortName, String servicePath, boolean serviceExternal) {
    KubernetesClient client = KubernetesHolder.getClient();
    String serviceNamespace = client.getNamespace();
    String actualProtocol = Strings.isNullOrBlank(serviceProtocol) ? DEFAULT_PROTO : serviceProtocol;
    return URLUtils.pathJoin(KubernetesHelper.getServiceURL(client, serviceName, serviceNamespace, actualProtocol, servicePortName, serviceExternal), servicePath);
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient)

Example 97 with KubernetesClient

use of io.fabric8.kubernetes.client.KubernetesClient 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 98 with KubernetesClient

use of io.fabric8.kubernetes.client.KubernetesClient 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 99 with KubernetesClient

use of io.fabric8.kubernetes.client.KubernetesClient 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 100 with KubernetesClient

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

the class Example method listServiceAccounts.

protected static void listServiceAccounts(KubernetesClient kube) {
    System.out.println("\n\nLooking up service accounts");
    System.out.println("=========================================================================");
    ServiceAccountList serviceAccounts = kube.serviceAccounts().list();
    List<ServiceAccount> serviceAccountItems = serviceAccounts.getItems();
    for (ServiceAccount serviceAccount : serviceAccountItems) {
        System.out.println("Service Account " + KubernetesHelper.getName(serviceAccount) + " labels: " + serviceAccount.getMetadata().getLabels());
    }
    System.out.println();
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) ServiceAccountList(io.fabric8.kubernetes.api.model.ServiceAccountList)

Aggregations

KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)62 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)40 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)21 HashMap (java.util.HashMap)19 Pod (io.fabric8.kubernetes.api.model.Pod)17 Service (io.fabric8.kubernetes.api.model.Service)16 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)14 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)13 IOException (java.io.IOException)12 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)10 File (java.io.File)10 ArrayList (java.util.ArrayList)9 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)8 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)8 Test (org.junit.Test)8 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)7 Map (java.util.Map)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 Controller (io.fabric8.kubernetes.api.Controller)6