use of io.kubernetes.client.openapi.models.V1ReplicaSet 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.models.V1ReplicaSet in project java by kubernetes-client.
the class DeploymentHelperTest method testRevisionShouldWork.
@Test
public void testRevisionShouldWork() throws IOException {
V1ReplicaSetList replicaSetList = new JSON().deserialize(new String(Files.readAllBytes(Paths.get(REPLICASET_LIST))), V1ReplicaSetList.class);
List<Long> revisions = new ArrayList<>();
for (V1ReplicaSet rs : replicaSetList.getItems()) {
revisions.add(DeploymentHelper.revision(rs.getMetadata()));
}
revisions.sort(Long::compareTo);
List<Long> exceptRevisions = Arrays.asList(1L, 2L, 2L, 3L, 4L);
Assert.assertEquals(exceptRevisions, revisions);
}
use of io.kubernetes.client.openapi.models.V1ReplicaSet 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.models.V1ReplicaSet in project java by kubernetes-client.
the class DeploymentHelper method getAllReplicaSets.
/**
* getAllReplicaSets get the old replica sets and return new replica targeted by the given
* Deployment. It gets PodList and ReplicaSetList from client interface. Note that the first set
* of old replica sets doesn't include the ones with no pods, and the second set of old replica
* sets include all old replica sets. The returned value is the new replica set, and it may be nil
* if it doesn't exist yet.
*
* @param deployment the given deployment
* @param api the client interface
* @param oldRSes container of all old ReplicaSet exclude the ones with no pods
* @param allOldRSes container of all old ReplicaSet
* @return the new replica set
*/
public static V1ReplicaSet getAllReplicaSets(V1Deployment deployment, AppsV1Api api, List<V1ReplicaSet> oldRSes, List<V1ReplicaSet> allOldRSes) throws ApiException {
List<V1ReplicaSet> rsList = listReplicaSets(deployment, api);
V1ReplicaSet newRs = findNewReplicaSet(deployment, rsList);
findOldReplicaSets(rsList, newRs, oldRSes, allOldRSes);
return newRs;
}
use of io.kubernetes.client.openapi.models.V1ReplicaSet in project java by kubernetes-client.
the class KubectlScaleTest method testKubectlScaleReplicaSetShouldWork.
@Test
public void testKubectlScaleReplicaSetShouldWork() throws KubectlException {
wireMockRule.stubFor(patch(urlPathEqualTo("/apis/apps/v1/namespaces/default/replicasets/foo")).willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"foo\",\"namespace\":\"default\"}}")));
V1ReplicaSet scaled = Kubectl.scale(V1ReplicaSet.class).apiClient(apiClient).replicas(4).name("foo").namespace("default").execute();
wireMockRule.verify(1, patchRequestedFor(urlPathEqualTo("/apis/apps/v1/namespaces/default/replicasets/foo")).withRequestBody(equalToJson("[{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":4}]")));
assertNotNull(scaled);
}
Aggregations