Search in sources :

Example 1 with V1Deployment

use of io.kubernetes.client.openapi.models.V1Deployment in project pravega by pravega.

the class K8sClient method createDeployment.

/**
 * Create a deployment on KUBERNETES, if the deployment is already present then it is ignored.
 * @param namespace Namespace.
 * @param deploy Deployment object.
 * @return A future which represents the creation of the Deployment.
 */
@SneakyThrows(ApiException.class)
public CompletableFuture<V1Deployment> createDeployment(final String namespace, final V1Deployment deploy) {
    AppsV1Api api = new AppsV1Api();
    K8AsyncCallback<V1Deployment> callback = new K8AsyncCallback<>("deployment-" + deploy.getMetadata().getName());
    api.createNamespacedDeploymentAsync(namespace, deploy, PRETTY_PRINT, DRY_RUN, FIELD_MANAGER, callback);
    return exceptionallyExpecting(callback.getFuture(), isConflict, null);
}
Also used : V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) SneakyThrows(lombok.SneakyThrows)

Example 2 with V1Deployment

use of io.kubernetes.client.openapi.models.V1Deployment in project pravega by pravega.

the class K8sClient method getDeploymentStatus.

/**
 * Fetch the deployment status.
 * @param deploymentName Name of the deployment
 * @param namespace Namespace where the deployment exists.
 * @return Future representing the Deployement.
 */
@SneakyThrows(ApiException.class)
public CompletableFuture<V1Deployment> getDeploymentStatus(final String deploymentName, final String namespace) {
    AppsV1Api api = new AppsV1Api();
    K8AsyncCallback<V1Deployment> callback = new K8AsyncCallback<>("readNamespacedDeployment-" + deploymentName);
    api.readNamespacedDeploymentStatusAsync(deploymentName, namespace, PRETTY_PRINT, callback);
    return callback.getFuture();
}
Also used : V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) SneakyThrows(lombok.SneakyThrows)

Example 3 with V1Deployment

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

the class DeploymentHelperTest method testGetAllReplicaSetsShouldWork.

@Test
public void testGetAllReplicaSetsShouldWork() throws IOException, ApiException {
    wireMockRule.stubFor(get(urlPathEqualTo("/apis/apps/v1/namespaces/default/replicasets")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(REPLICASET_LIST))))));
    AppsV1Api api = new AppsV1Api(this.apiClient);
    V1Deployment deployment = new JSON().deserialize(new String(Files.readAllBytes(Paths.get(DEPLOYMENT))), V1Deployment.class);
    List<V1ReplicaSet> oldRSes = new ArrayList<>();
    List<V1ReplicaSet> allOldRSes = new ArrayList<>();
    V1ReplicaSet newRs = DeploymentHelper.getAllReplicaSets(deployment, api, oldRSes, allOldRSes);
    wireMockRule.verify(1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/replicasets"))).withQueryParam("labelSelector", new EqualToPattern("app = bar")));
    Assert.assertNotNull(newRs);
    Assert.assertEquals(1, oldRSes.size());
    Assert.assertEquals(2, allOldRSes.size());
}
Also used : V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) ArrayList(java.util.ArrayList) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) JSON(io.kubernetes.client.openapi.JSON) V1ReplicaSet(io.kubernetes.client.openapi.models.V1ReplicaSet) Test(org.junit.Test)

Example 4 with V1Deployment

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

the class DeploymentHelper method listReplicaSets.

/**
 * listReplicaSets returns a list of RSes the given deployment targets. Note that this does NOT
 * attempt to reconcile ControllerRef (adopt/orphan), because only the controller itself should do
 * that. However, it does filter out anything whose ControllerRef doesn't match.
 */
private static List<V1ReplicaSet> listReplicaSets(V1Deployment deployment, AppsV1Api api) throws ApiException {
    String namespace = deployment.getMetadata().getNamespace();
    LabelSelector selector = LabelSelector.parse(deployment.getSpec().getSelector());
    List<V1ReplicaSet> all = rsListFromClient(namespace, selector.toString(), api);
    List<V1ReplicaSet> owned = new ArrayList<>(all.size());
    for (V1ReplicaSet rs : all) {
        List<V1OwnerReference> refs = rs.getMetadata().getOwnerReferences();
        Optional<V1OwnerReference> ref = refs.stream().filter(o -> o.getController() != null && o.getController()).findAny();
        // Only include those whose ControllerRef matches the Deployment.
        if (ref.isPresent() && ref.get().getUid().equals(deployment.getMetadata().getUid())) {
            owned.add(rs);
        }
    }
    return owned;
}
Also used : V1ReplicaSet(io.kubernetes.client.openapi.models.V1ReplicaSet) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) Yaml(io.kubernetes.client.util.Yaml) LabelSelector(io.kubernetes.client.util.labels.LabelSelector) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) ArrayList(java.util.ArrayList) Objects(java.util.Objects) ApiException(io.kubernetes.client.openapi.ApiException) List(java.util.List) V1ReplicaSetList(io.kubernetes.client.openapi.models.V1ReplicaSetList) V1OwnerReference(io.kubernetes.client.openapi.models.V1OwnerReference) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) Optional(java.util.Optional) V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) ArrayList(java.util.ArrayList) LabelSelector(io.kubernetes.client.util.labels.LabelSelector) V1OwnerReference(io.kubernetes.client.openapi.models.V1OwnerReference) V1ReplicaSet(io.kubernetes.client.openapi.models.V1ReplicaSet)

Example 5 with V1Deployment

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

the class AppsV1Api method patchNamespacedDeploymentStatusWithHttpInfo.

/**
 * partially update status of the specified Deployment
 *
 * @param name name of the Deployment (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)
 * @return ApiResponse&lt;V1Deployment&gt;
 * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the
 *     response body
 * @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 ApiResponse<V1Deployment> patchNamespacedDeploymentStatusWithHttpInfo(String name, String namespace, V1Patch body, String pretty, String dryRun, String fieldManager, String fieldValidation, Boolean force) throws ApiException {
    okhttp3.Call localVarCall = patchNamespacedDeploymentStatusValidateBeforeCall(name, namespace, body, pretty, dryRun, fieldManager, fieldValidation, force, null);
    Type localVarReturnType = new TypeToken<V1Deployment>() {
    }.getType();
    return localVarApiClient.execute(localVarCall, localVarReturnType);
}
Also used : V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) Type(java.lang.reflect.Type)

Aggregations

V1Deployment (io.kubernetes.client.openapi.models.V1Deployment)23 Type (java.lang.reflect.Type)14 AppsV1Api (io.kubernetes.client.openapi.apis.AppsV1Api)7 ApiException (io.kubernetes.client.openapi.ApiException)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 V1Patch (io.kubernetes.client.custom.V1Patch)2 V1DeploymentSpec (io.kubernetes.client.openapi.models.V1DeploymentSpec)2 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)2 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)2 V1ReplicaSet (io.kubernetes.client.openapi.models.V1ReplicaSet)2 SneakyThrows (lombok.SneakyThrows)2 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)1 KubernetesType (io.kubernetes.client.common.KubernetesType)1 ApiClient (io.kubernetes.client.openapi.ApiClient)1 JSON (io.kubernetes.client.openapi.JSON)1 V1Container (io.kubernetes.client.openapi.models.V1Container)1 V1DeploymentBuilder (io.kubernetes.client.openapi.models.V1DeploymentBuilder)1 V1DeploymentList (io.kubernetes.client.openapi.models.V1DeploymentList)1 V1LabelSelector (io.kubernetes.client.openapi.models.V1LabelSelector)1