use of io.kubernetes.client.openapi.apis.AppsV1Api 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());
}
use of io.kubernetes.client.openapi.apis.AppsV1Api 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;
}
use of io.kubernetes.client.openapi.apis.AppsV1Api in project java by kubernetes-client.
the class KubectlScale method execute.
@Override
public ApiType execute() throws KubectlException {
validate();
String jsonPatchStr = String.format("[{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":%d}]", replicas);
AppsV1Api api = new AppsV1Api(this.apiClient);
try {
if (apiTypeClass.equals(V1Deployment.class)) {
return PatchUtils.patch(apiTypeClass, () -> api.patchNamespacedDeploymentCall(name, namespace, new V1Patch(jsonPatchStr), null, null, null, // field-manager is optional
null, null, null), V1Patch.PATCH_FORMAT_JSON_PATCH, this.apiClient);
} else if (apiTypeClass.equals(V1ReplicaSet.class)) {
return PatchUtils.patch(apiTypeClass, () -> api.patchNamespacedReplicaSetCall(name, namespace, new V1Patch(jsonPatchStr), null, null, null, null, null, null), V1Patch.PATCH_FORMAT_JSON_PATCH, this.apiClient);
} else if (apiTypeClass.equals(V1StatefulSet.class)) {
return PatchUtils.patch(apiTypeClass, () -> api.patchNamespacedStatefulSetCall(name, namespace, new V1Patch(jsonPatchStr), null, null, null, null, null, null), V1Patch.PATCH_FORMAT_JSON_PATCH, this.apiClient);
} else {
throw new KubectlException("Unsupported class for scale: " + apiTypeClass);
}
} catch (ApiException ex) {
throw new KubectlException(ex);
}
}
use of io.kubernetes.client.openapi.apis.AppsV1Api in project twister2 by DSC-SPIDAL.
the class KubernetesController method initApiInstances.
private static void initApiInstances() {
if (client == null) {
getApiClient();
}
Configuration.setDefaultApiClient(client);
coreApi = new CoreV1Api();
appsApi = new AppsV1Api(client);
}
Aggregations