Search in sources :

Example 71 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.

the class KubernetesAssert method getServiceSpec.

protected ServiceSpec getServiceSpec(String serviceId, String namespace) {
    Service service = getService(serviceId, namespace);
    ServiceSpec spec = service.getSpec();
    assertThat(spec).isNotNull();
    return spec;
}
Also used : ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service)

Example 72 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.

the class KubernetesAssert method hasServicePort.

/**
 * Asserts that the service can be found for the given name and has a port of the given value
 */
public void hasServicePort(String serviceId, int port) {
    ServiceSpec spec = getServiceSpec(serviceId, namespace());
    boolean found = false;
    List<ServicePort> ports = spec.getPorts();
    List<Integer> portNumbers = new ArrayList<>();
    if (ports != null) {
        for (ServicePort servicePort : ports) {
            Integer aPort = servicePort.getPort();
            if (aPort != null) {
                if (aPort == port) {
                    found = true;
                    break;
                } else {
                    portNumbers.add(aPort);
                }
            }
        }
    }
    assertThat(found).describedAs("No port found for " + port + " but found ports: " + portNumbers).isTrue();
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) ArrayList(java.util.ArrayList)

Example 73 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.

the class KubernetesAssert method getPod.

protected Pod getPod(String podId, String namespace) {
    assertThat(podId).isNotNull();
    Pod pod = null;
    try {
        pod = client.pods().inNamespace(namespace).withName(podId).get();
    } catch (Exception e) {
        fail("Could not find pod for '" + podId + "'");
    }
    assertThat(pod).isNotNull();
    return pod;
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException)

Example 74 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.

the class PodIdToReplicationControllerIDExample method main.

public static void main(String[] args) {
    if (args.length < 3) {
        System.out.println("Arguments: kuberneteMasterUrl namespace podID");
        return;
    }
    String kuberneteMasterUrl = args[0];
    String namespace = args[1];
    String podID = args[2];
    System.out.println("Looking up ReplicationController for pod ID: " + podID);
    KubernetesClient client = new DefaultKubernetesClient(new ConfigBuilder().withMasterUrl(kuberneteMasterUrl).build());
    Pod pod = (Pod) client.pods().inNamespace(namespace).withName(podID);
    pod.getMetadata().getLabels();
    List<ReplicationController> replicationControllers = client.replicationControllers().inNamespace(namespace).withLabels(pod.getMetadata().getLabels()).list().getItems();
    if (replicationControllers.size() == 1) {
        ReplicationController replicationController = replicationControllers.get(0);
        String id = KubernetesHelper.getName(replicationController);
        System.out.println("Found replication controller: " + id);
    } else {
        System.out.println("Could not find replication controller!");
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 75 with Namespace

use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.

the class PipelineConfiguration method savePipelineConfiguration.

/**
 * Saves the {@link PipelineConfiguration} into a {@link ConfigMap} in the given namespace
 */
public static void savePipelineConfiguration(KubernetesClient kubernetesClient, String namespace, PipelineConfiguration configuration) {
    ConfigMap configMap = configuration.createConfigMap();
    kubernetesClient.configMaps().inNamespace(namespace).withName(FABRIC8_PIPELINES).createOrReplace(configMap);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap)

Aggregations

IOException (java.io.IOException)81 Test (org.junit.Test)78 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)74 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)65 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)60 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)59 HashMap (java.util.HashMap)59 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)58 FileNotFoundException (java.io.FileNotFoundException)49 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)48 OpenShiftNotAvailableException (io.fabric8.openshift.client.OpenShiftNotAvailableException)48 JSONObject (org.json.JSONObject)44 Service (io.fabric8.kubernetes.api.model.Service)38 Pod (io.fabric8.kubernetes.api.model.Pod)36 ArrayList (java.util.ArrayList)32 File (java.io.File)25 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)24 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)24 Map (java.util.Map)22 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)21