Search in sources :

Example 71 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.

the class ExampleTest method exactUrlOnly.

@Test
public void exactUrlOnly() throws IOException, ApiException {
    ApiClient client = new ApiClient();
    client.setBasePath("http://localhost:" + PORT);
    Configuration.setDefaultApiClient(client);
    V1Namespace ns1 = new V1Namespace().metadata(new V1ObjectMeta().name("name"));
    stubFor(get(urlEqualTo("/api/v1/namespaces/name")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(client.getJSON().serialize(ns1))));
    CoreV1Api api = new CoreV1Api();
    V1Namespace ns2 = api.readNamespace("name", null);
    assertEquals(ns1, ns2);
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Namespace(io.kubernetes.client.openapi.models.V1Namespace) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) Test(org.junit.Test)

Example 72 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.

the class ExecTest method testUrl.

@Test
public void testUrl() throws IOException, ApiException, InterruptedException {
    Exec exec = new Exec(client);
    V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(podName).namespace(namespace));
    Semaphore getCount = new Semaphore(2);
    Parameters getParams = new Parameters();
    getParams.put("semaphore", getCount);
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).withPostServeAction("semaphore", getParams).willReturn(aResponse().withStatus(404).withHeader("Content-Type", "application/json").withBody("{}")));
    Process p = exec.exec(pod, cmd, "container", true, false);
    p.waitFor();
    exec.newExecutionBuilder(pod.getMetadata().getNamespace(), pod.getMetadata().getName(), cmd).setContainer("container").setStdin(false).setStderr(false).execute().waitFor();
    // These will be released for each web call above.
    // There is a race between the above waitFor() and the request actually being recorded
    // by WireMock. This fixes it.
    getCount.acquire(2);
    wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).withQueryParam("stdin", equalTo("true")).withQueryParam("stdout", equalTo("true")).withQueryParam("stderr", equalTo("true")).withQueryParam("container", equalTo("container")).withQueryParam("tty", equalTo("false")).withQueryParam("command", equalTo("cmd")));
    wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).withQueryParam("stdin", equalTo("false")).withQueryParam("stdout", equalTo("true")).withQueryParam("stderr", equalTo("false")).withQueryParam("container", equalTo("container")).withQueryParam("tty", equalTo("false")).withQueryParam("command", equalTo("cmd")));
    assertEquals(-1975219, p.exitValue());
}
Also used : Parameters(com.github.tomakehurst.wiremock.extension.Parameters) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ExecProcess(io.kubernetes.client.Exec.ExecProcess) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Example 73 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.

the class ReflectorRunnable method watchHandler.

private void watchHandler(Watchable<ApiType> watch) {
    while (watch.hasNext()) {
        io.kubernetes.client.util.Watch.Response<ApiType> item = watch.next();
        Optional<EventType> eventType = EventType.findByType(item.type);
        if (!eventType.isPresent()) {
            log.error("unrecognized event {}", item);
            continue;
        }
        if (eventType.get() == EventType.ERROR) {
            if (item.status != null && item.status.getCode() == HttpURLConnection.HTTP_GONE) {
                log.info("ResourceVersion {} and Watch connection expired: {} , will retry w/o resourceVersion next time", getRelistResourceVersion(), item.status.getMessage());
                isLastSyncResourceVersionUnavailable = true;
                throw new WatchExpiredException();
            } else {
                String errorMessage = String.format("got ERROR event and its status: %s", item.status.toString());
                log.error(errorMessage);
                throw new RuntimeException(errorMessage);
            }
        }
        ApiType obj = item.object;
        V1ObjectMeta meta = obj.getMetadata();
        String newResourceVersion = meta.getResourceVersion();
        switch(eventType.get()) {
            case ADDED:
                store.add(obj);
                break;
            case MODIFIED:
                store.update(obj);
                break;
            case DELETED:
                store.delete(obj);
                break;
            case BOOKMARK:
                break;
        }
        lastSyncResourceVersion = newResourceVersion;
        if (log.isDebugEnabled()) {
            log.debug("{}#Receiving resourceVersion {}", apiTypeClass, lastSyncResourceVersion);
        }
    }
}
Also used : EventType(io.kubernetes.client.informer.EventType) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) WatchExpiredException(io.kubernetes.client.informer.exception.WatchExpiredException)

Example 74 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project twister2 by DSC-SPIDAL.

the class JobMasterRequestObject method createJobMasterHeadlessServiceObject.

/**
 * create headless service for job master
 */
public static V1Service createJobMasterHeadlessServiceObject() {
    String serviceName = KubernetesUtils.createJobMasterServiceName(jobID);
    V1Service service = new V1Service();
    service.setKind("Service");
    service.setApiVersion("v1");
    // set labels for the jm service
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // construct and set metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(serviceName);
    meta.setLabels(labels);
    service.setMetadata(meta);
    // construct and set service spec
    V1ServiceSpec serviceSpec = new V1ServiceSpec();
    serviceSpec.setClusterIP("None");
    // set selector
    HashMap<String, String> selectors = new HashMap<String, String>();
    selectors.put("t2-mp", jobID);
    serviceSpec.setSelector(selectors);
    service.setSpec(serviceSpec);
    return service;
}
Also used : HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1ServiceSpec(io.kubernetes.client.openapi.models.V1ServiceSpec) V1Service(io.kubernetes.client.openapi.models.V1Service) IntOrString(io.kubernetes.client.custom.IntOrString)

Example 75 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project twister2 by DSC-SPIDAL.

the class JobMasterRequestObject method createJobMasterServiceObject.

/**
 * create regular service for job master
 */
public static V1Service createJobMasterServiceObject() {
    String serviceName = KubernetesUtils.createJobMasterServiceName(jobID);
    V1Service service = new V1Service();
    service.setKind("Service");
    service.setApiVersion("v1");
    // set labels for the jm service
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // construct and set metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(serviceName);
    meta.setLabels(labels);
    service.setMetadata(meta);
    // construct and set service spec
    V1ServiceSpec serviceSpec = new V1ServiceSpec();
    // set selector
    HashMap<String, String> selectors = new HashMap<String, String>();
    selectors.put("t2-mp", jobID);
    serviceSpec.setSelector(selectors);
    // set port
    V1ServicePort servicePort = new V1ServicePort();
    servicePort.setName("job-master-port");
    servicePort.setPort(JobMasterContext.jobMasterPort(config));
    servicePort.setTargetPort(new IntOrString(JobMasterContext.jobMasterPort(config)));
    servicePort.setProtocol("TCP");
    serviceSpec.setPorts(Arrays.asList(servicePort));
    service.setSpec(serviceSpec);
    return service;
}
Also used : V1ServicePort(io.kubernetes.client.openapi.models.V1ServicePort) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) IntOrString(io.kubernetes.client.custom.IntOrString) V1ServiceSpec(io.kubernetes.client.openapi.models.V1ServiceSpec) V1Service(io.kubernetes.client.openapi.models.V1Service) IntOrString(io.kubernetes.client.custom.IntOrString)

Aggregations

V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)78 Test (org.junit.Test)49 V1Pod (io.kubernetes.client.openapi.models.V1Pod)37 HashMap (java.util.HashMap)14 ApiException (io.kubernetes.client.openapi.ApiException)11 V1PodList (io.kubernetes.client.openapi.models.V1PodList)11 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)10 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)8 V1Container (io.kubernetes.client.openapi.models.V1Container)7 ApiClient (io.kubernetes.client.openapi.ApiClient)6 JSON (io.kubernetes.client.openapi.JSON)6 V1Job (io.kubernetes.client.openapi.models.V1Job)6 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)6 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)6 V1Patch (io.kubernetes.client.custom.V1Patch)5 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)5 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)5 V1Service (io.kubernetes.client.openapi.models.V1Service)5 V1ServiceSpec (io.kubernetes.client.openapi.models.V1ServiceSpec)5 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)5