Search in sources :

Example 36 with V1Pod

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

the class CoreV1Api method deleteNamespacedPodAsync.

/**
 * (asynchronously) delete a Pod
 *
 * @param name name of the Pod (required)
 * @param namespace object name and auth scope, such as for teams and projects (required)
 * @param pretty If 'true', then the output is pretty printed. (optional)
 * @param dryRun When present, indicates that modifications should not be persisted. An invalid or
 *     unrecognized dryRun directive will result in an error response and no further processing of
 *     the request. Valid values are: - All: all dry run stages will be processed (optional)
 * @param gracePeriodSeconds The duration in seconds before the object should be deleted. Value
 *     must be non-negative integer. The value zero indicates delete immediately. If this value is
 *     nil, the default grace period for the specified type will be used. Defaults to a per object
 *     value if not specified. zero means delete immediately. (optional)
 * @param orphanDependents Deprecated: please use the PropagationPolicy, this field will be
 *     deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the
 *     \"orphan\" finalizer will be added to/removed from the object's finalizers
 *     list. Either this field or PropagationPolicy may be set, but not both. (optional)
 * @param propagationPolicy Whether and how garbage collection will be performed. Either this
 *     field or OrphanDependents may be set, but not both. The default policy is decided by the
 *     existing finalizer set in the metadata.finalizers and the resource-specific default policy.
 *     Acceptable values are: 'Orphan' - orphan the dependents; 'Background' -
 *     allow the garbage collector to delete the dependents in the background;
 *     'Foreground' - a cascading policy that deletes all dependents in the foreground.
 *     (optional)
 * @param body (optional)
 * @param _callback The callback to be executed when the API call finishes
 * @return The request call
 * @throws ApiException If fail to process the API call, e.g. serializing the request body object
 * @http.response.details
 *     <table summary="Response Details" border="1">
 * <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
 * <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
 * <tr><td> 202 </td><td> Accepted </td><td>  -  </td></tr>
 * <tr><td> 401 </td><td> Unauthorized </td><td>  -  </td></tr>
 * </table>
 */
public okhttp3.Call deleteNamespacedPodAsync(String name, String namespace, String pretty, String dryRun, Integer gracePeriodSeconds, Boolean orphanDependents, String propagationPolicy, V1DeleteOptions body, final ApiCallback<V1Pod> _callback) throws ApiException {
    okhttp3.Call localVarCall = deleteNamespacedPodValidateBeforeCall(name, namespace, pretty, dryRun, gracePeriodSeconds, orphanDependents, propagationPolicy, body, _callback);
    Type localVarReturnType = new TypeToken<V1Pod>() {
    }.getType();
    localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
    return localVarCall;
}
Also used : Type(java.lang.reflect.Type) V1Pod(io.kubernetes.client.openapi.models.V1Pod)

Example 37 with V1Pod

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

the class CoreV1Api method patchNamespacedPodEphemeralcontainersAsync.

/**
 * (asynchronously) partially update ephemeralcontainers of the specified Pod
 *
 * @param name name of the Pod (required)
 * @param namespace object name and auth scope, such as for teams and projects (required)
 * @param body (required)
 * @param pretty If &#39;true&#39;, then the output is pretty printed. (optional)
 * @param dryRun When present, indicates that modifications should not be persisted. An invalid or
 *     unrecognized dryRun directive will result in an error response and no further processing of
 *     the request. Valid values are: - All: all dry run stages will be processed (optional)
 * @param fieldManager fieldManager is a name associated with the actor or entity that is making
 *     these changes. The value must be less than or 128 characters long, and only contain
 *     printable characters, as defined by https://golang.org/pkg/unicode/#IsPrint. This field is
 *     required for apply requests (application/apply-patch) but optional for non-apply patch
 *     types (JsonPatch, MergePatch, StrategicMergePatch). (optional)
 * @param fieldValidation fieldValidation determines how the server should respond to
 *     unknown/duplicate fields in the object in the request. Introduced as alpha in 1.23, older
 *     servers or servers with the &#x60;ServerSideFieldValidation&#x60; feature disabled will
 *     discard valid values specified in this param and not perform any server side field
 *     validation. Valid values are: - Ignore: ignores unknown/duplicate fields. - Warn: responds
 *     with a warning for each unknown/duplicate field, but successfully serves the request. -
 *     Strict: fails the request on unknown/duplicate fields. (optional)
 * @param force Force is going to \&quot;force\&quot; Apply requests. It means user will
 *     re-acquire conflicting fields owned by other people. Force flag must be unset for non-apply
 *     patch requests. (optional)
 * @param _callback The callback to be executed when the API call finishes
 * @return The request call
 * @throws ApiException If fail to process the API call, e.g. serializing the request body object
 * @http.response.details
 *     <table summary="Response Details" border="1">
 * <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
 * <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
 * <tr><td> 201 </td><td> Created </td><td>  -  </td></tr>
 * <tr><td> 401 </td><td> Unauthorized </td><td>  -  </td></tr>
 * </table>
 */
public okhttp3.Call patchNamespacedPodEphemeralcontainersAsync(String name, String namespace, V1Patch body, String pretty, String dryRun, String fieldManager, String fieldValidation, Boolean force, final ApiCallback<V1Pod> _callback) throws ApiException {
    okhttp3.Call localVarCall = patchNamespacedPodEphemeralcontainersValidateBeforeCall(name, namespace, body, pretty, dryRun, fieldManager, fieldValidation, force, _callback);
    Type localVarReturnType = new TypeToken<V1Pod>() {
    }.getType();
    localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
    return localVarCall;
}
Also used : Type(java.lang.reflect.Type) V1Pod(io.kubernetes.client.openapi.models.V1Pod)

Example 38 with V1Pod

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

the class DefaultSharedIndexInformerWireMockTest method testAllNamespacedPodInformerNormalBehavior.

@Test
public void testAllNamespacedPodInformerNormalBehavior() throws InterruptedException {
    CoreV1Api coreV1Api = new CoreV1Api(client);
    String startRV = "1000";
    String endRV = "1001";
    V1PodList podList = new V1PodList().metadata(new V1ListMeta().resourceVersion(startRV)).items(Arrays.asList());
    stubFor(get(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(new JSON().serialize(podList))));
    Watch.Response<V1Pod> watchResponse = new Watch.Response<>(EventType.ADDED.name(), new V1Pod().metadata(new V1ObjectMeta().namespace(namespace).name(podName).resourceVersion(endRV).labels(Collections.singletonMap("foo", "bar")).annotations(Collections.singletonMap("foo", "bar"))));
    stubFor(get(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(new JSON().serialize(watchResponse))));
    SharedInformerFactory factory = new SharedInformerFactory();
    SharedIndexInformer<V1Pod> podInformer = factory.sharedIndexInformerFor((CallGeneratorParams params) -> {
        try {
            return coreV1Api.listPodForAllNamespacesCall(null, null, null, null, null, null, params.resourceVersion, null, params.timeoutSeconds, params.watch, null);
        } catch (ApiException e) {
            throw new RuntimeException(e);
        }
    }, V1Pod.class, V1PodList.class);
    podInformer.setTransform((obj) -> {
        // deepcopy
        String json = new JSON().serialize(obj);
        V1Pod pod = new JSON().deserialize(json, V1Pod.class);
        // remove pod annotations
        pod.getMetadata().setAnnotations(null);
        return pod;
    });
    AtomicBoolean foundExistingPod = new AtomicBoolean(false);
    AtomicBoolean transformed = new AtomicBoolean(false);
    AtomicBoolean setTransformAfterStarted = new AtomicBoolean(false);
    podInformer.addEventHandler(new ResourceEventHandler<V1Pod>() {

        @Override
        public void onAdd(V1Pod obj) {
            if (podName.equals(obj.getMetadata().getName()) && namespace.equals(obj.getMetadata().getNamespace())) {
                foundExistingPod.set(true);
            }
            V1ObjectMeta metadata = obj.getMetadata();
            // check if the object was transformed
            if (metadata.getLabels().get("foo").equals("bar") && metadata.getAnnotations() == null) {
                transformed.set(true);
            }
        }

        @Override
        public void onUpdate(V1Pod oldObj, V1Pod newObj) {
        }

        @Override
        public void onDelete(V1Pod obj, boolean deletedFinalStateUnknown) {
        }
    });
    factory.startAllRegisteredInformers();
    Thread.sleep(1000);
    // can not set transform func if the informer has started
    try {
        podInformer.setTransform((obj) -> new V1Pod());
        setTransformAfterStarted.set(true);
    } catch (IllegalStateException e) {
    }
    assertTrue(foundExistingPod.get());
    assertTrue(transformed.get());
    assertFalse(setTransformAfterStarted.get());
    assertEquals(endRV, podInformer.lastSyncResourceVersion());
    verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false")));
    verify(moreThan(1), getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("true")));
    factory.stopAllRegisteredInformers();
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) JSON(io.kubernetes.client.openapi.JSON) CallGeneratorParams(io.kubernetes.client.util.CallGeneratorParams) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) V1PodList(io.kubernetes.client.openapi.models.V1PodList) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SharedInformerFactory(io.kubernetes.client.informer.SharedInformerFactory) Watch(io.kubernetes.client.util.Watch) V1Pod(io.kubernetes.client.openapi.models.V1Pod) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Example 39 with V1Pod

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

the class DefaultSharedIndexInformerWireMockTest method testInformerReListWatchOnWatchConflict.

@Test
public void testInformerReListWatchOnWatchConflict() throws InterruptedException {
    CoreV1Api coreV1Api = new CoreV1Api(client);
    String startRV = "1000";
    V1PodList podList = new V1PodList().metadata(new V1ListMeta().resourceVersion(startRV)).items(Arrays.asList());
    stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods")).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(new JSON().serialize(podList))));
    Watch.Response<V1Pod> watchResponse = new Watch.Response<>(EventType.ERROR.name(), new V1Status().apiVersion("v1").kind("Status").code(409));
    stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods")).withQueryParam("watch", equalTo("true")).withQueryParam("resourceVersion", equalTo(startRV)).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(new JSON().serialize(watchResponse))));
    SharedInformerFactory factory = new SharedInformerFactory();
    SharedIndexInformer<V1Pod> podInformer = factory.sharedIndexInformerFor((CallGeneratorParams params) -> {
        try {
            return coreV1Api.listNamespacedPodCall(namespace, null, null, null, null, null, null, params.resourceVersion, null, params.timeoutSeconds, params.watch, null);
        } catch (ApiException e) {
            throw new RuntimeException(e);
        }
    }, V1Pod.class, V1PodList.class);
    factory.startAllRegisteredInformers();
    // Sleep mroe than 1s so that informer can perform multiple rounds of list-watch
    Thread.sleep(3000);
    verify(moreThan(1), getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods")).withQueryParam("watch", equalTo("false")));
    verify(moreThan(1), getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods")).withQueryParam("watch", equalTo("true")));
    factory.stopAllRegisteredInformers();
}
Also used : V1Status(io.kubernetes.client.openapi.models.V1Status) JSON(io.kubernetes.client.openapi.JSON) CallGeneratorParams(io.kubernetes.client.util.CallGeneratorParams) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) V1PodList(io.kubernetes.client.openapi.models.V1PodList) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) SharedInformerFactory(io.kubernetes.client.informer.SharedInformerFactory) Watch(io.kubernetes.client.util.Watch) V1Pod(io.kubernetes.client.openapi.models.V1Pod) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Example 40 with V1Pod

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

the class CacheTest method testAddIndexers.

@Test
public void testAddIndexers() {
    Cache<V1Pod> podCache = new Cache<>();
    String nodeIndex = "node-index";
    String clusterIndex = "cluster-index";
    Map<String, Function<V1Pod, List<String>>> indexers = new HashMap<>();
    indexers.put(nodeIndex, (V1Pod pod) -> {
        return Arrays.asList(pod.getSpec().getNodeName());
    });
    indexers.put(clusterIndex, (V1Pod pod) -> {
        return Arrays.asList(pod.getMetadata().getClusterName());
    });
    podCache.addIndexers(indexers);
    V1Pod testPod = new V1Pod().metadata(new V1ObjectMeta().namespace("ns").name("n").clusterName("cluster1")).spec(new V1PodSpec().nodeName("node1"));
    podCache.add(testPod);
    List<V1Pod> namespaceIndexedPods = podCache.byIndex(Caches.NAMESPACE_INDEX, "ns");
    assertEquals(1, namespaceIndexedPods.size());
    List<V1Pod> nodeNameIndexedPods = podCache.byIndex(nodeIndex, "node1");
    assertEquals(1, nodeNameIndexedPods.size());
    List<V1Pod> clusterNameIndexedPods = podCache.byIndex(clusterIndex, "cluster1");
    assertEquals(1, clusterNameIndexedPods.size());
}
Also used : Function(java.util.function.Function) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) V1PodSpec(io.kubernetes.client.openapi.models.V1PodSpec) Test(org.junit.Test)

Aggregations

V1Pod (io.kubernetes.client.openapi.models.V1Pod)99 Test (org.junit.Test)55 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)38 V1PodList (io.kubernetes.client.openapi.models.V1PodList)33 Type (java.lang.reflect.Type)22 ApiException (io.kubernetes.client.openapi.ApiException)20 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)17 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)15 ApiClient (io.kubernetes.client.openapi.ApiClient)12 Watch (io.kubernetes.client.util.Watch)10 V1Status (io.kubernetes.client.openapi.models.V1Status)9 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)8 JSON (io.kubernetes.client.openapi.JSON)7 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)7 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)4 V1Patch (io.kubernetes.client.custom.V1Patch)4 V1Container (io.kubernetes.client.openapi.models.V1Container)4