io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReplicaSetTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testGet() { server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, new ReplicaSetBuilder().build()).once(); server.expect().withPath("/apis/apps/v1/namespaces/ns1/replicasets/repl2").andReturn(200, new ReplicaSetBuilder().build()).once(); KubernetesClient client = server.getClient(); ReplicaSet repl1 = client.apps().replicaSets().withName("repl1").get(); assertNotNull(repl1); repl1 = client.apps().replicaSets().withName("repl2").get(); assertNull(repl1); repl1 = client.apps().replicaSets().inNamespace("ns1").withName("repl2").get(); assertNotNull(repl1); }
Example #2
Source File: ReplicaSetTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testScale() { server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, new ReplicaSetBuilder() .withNewMetadata() .withName("repl1") .withResourceVersion("1") .endMetadata() .withNewSpec() .withReplicas(5) .endSpec() .withNewStatus() .withReplicas(1) .endStatus() .build()).always(); KubernetesClient client = server.getClient(); ReplicaSet repl = client.apps().replicaSets().withName("repl1").scale(5); assertNotNull(repl); assertNotNull(repl.getSpec()); assertEquals(5, repl.getSpec().getReplicas().intValue()); assertEquals(1, repl.getStatus().getReplicas().intValue()); }
Example #3
Source File: ReplicaSetTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
private ReplicaSetBuilder getReplicaSetBuilder() { return new ReplicaSetBuilder() .withNewMetadata() .withName("replicaset1") .addToLabels("app", "nginx") .addToAnnotations("app", "nginx") .endMetadata() .withNewSpec() .withReplicas(1) .withNewTemplate() .withNewMetadata().addToLabels("app", "nginx").endMetadata() .withNewSpec() .addNewContainer() .withName("nginx") .withImage("nginx:1.7.9") .addNewPort().withContainerPort(80).endPort() .endContainer() .endSpec() .endTemplate() .endSpec(); }
Example #4
Source File: ReplicaSetHandler.java From jkube with Eclipse Public License 2.0 | 5 votes |
public ReplicaSet getReplicaSet(ResourceConfig config, List<ImageConfiguration> images) { return new ReplicaSetBuilder() .withMetadata(createRsMetaData(config)) .withSpec(createRsSpec(config, images)) .build(); }
Example #5
Source File: ImageEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void ensureTemplateSpecsInRelicaSet(KubernetesListBuilder builder) { builder.accept(new TypedVisitor<ReplicaSetBuilder>() { @Override public void visit(ReplicaSetBuilder item) { ReplicaSetFluent.SpecNested<ReplicaSetBuilder> spec = item.buildSpec() == null ? item.withNewSpec() : item.editSpec(); ReplicaSetSpecFluent.TemplateNested<ReplicaSetFluent.SpecNested<ReplicaSetBuilder>> template = spec.buildTemplate() == null ? spec.withNewTemplate() : spec.editTemplate(); template.endTemplate().endSpec(); } }); }
Example #6
Source File: TriggersAnnotationEnricherTest.java From jkube with Eclipse Public License 2.0 | 5 votes |
@Test public void testReplicaSetEnrichment() throws IOException { KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new ReplicaSetBuilder() .withNewSpec() .withNewTemplate() .withNewSpec() .withContainers(createContainers( "c1", "is", "c2", "a-docker-user/is:latest" )) .endSpec() .endTemplate() .endSpec() .build()); TriggersAnnotationEnricher enricher = new TriggersAnnotationEnricher(context); enricher.enrich(PlatformMode.kubernetes, builder); ReplicaSet res = (ReplicaSet) builder.build().getItems().get(0); String triggers = res.getMetadata().getAnnotations().get("image.openshift.io/triggers"); assertNotNull(triggers); List<ImageChangeTrigger> triggerList = OBJECT_MAPPER.readValue(triggers, OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, ImageChangeTrigger.class)); assertEquals(1, triggerList.size()); ImageChangeTrigger trigger = triggerList.get(0); assertEquals("ImageStreamTag", trigger.getFrom().getKind()); assertEquals("is:latest", trigger.getFrom().getName()); assertTrue(trigger.getAdditionalProperties().containsKey("fieldPath")); }
Example #7
Source File: ImageEnricherTest.java From jkube with Eclipse Public License 2.0 | 5 votes |
@Test public void checkEnrichReplicaSet() throws Exception { KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new ReplicaSetBuilder().build()); imageEnricher.create(PlatformMode.kubernetes, builder); assertCorrectlyGeneratedResources(builder.build(), "ReplicaSet"); }
Example #8
Source File: ReplicaSetRollingUpdater.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Override protected ReplicaSet createClone(ReplicaSet obj, String newName, String newDeploymentHash) { return new ReplicaSetBuilder(obj) .editMetadata() .withResourceVersion(null) .withName(newName) .endMetadata() .editSpec() .withReplicas(0) .editSelector().addToMatchLabels(DEPLOYMENT_KEY, newDeploymentHash).endSelector() .editTemplate().editMetadata().addToLabels(DEPLOYMENT_KEY, newDeploymentHash).endMetadata().endTemplate() .endSpec() .build(); }
Example #9
Source File: ReplicaSetTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void testScaleAndWait() { server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, new ReplicaSetBuilder() .withNewMetadata() .withName("repl1") .withResourceVersion("1") .endMetadata() .withNewSpec() .withReplicas(5) .endSpec() .withNewStatus() .withReplicas(1) .endStatus() .build()).once(); server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, new ReplicaSetBuilder() .withNewMetadata() .withName("repl1") .withResourceVersion("1") .endMetadata() .withNewSpec() .withReplicas(5) .endSpec() .withNewStatus() .withReplicas(5) .endStatus() .build()).always(); KubernetesClient client = server.getClient(); ReplicaSet repl = client.apps().replicaSets().withName("repl1").scale(5, true); assertNotNull(repl); assertNotNull(repl.getSpec()); assertEquals(5, repl.getSpec().getReplicas().intValue()); assertEquals(5, repl.getStatus().getReplicas().intValue()); }
Example #10
Source File: ReplicaSetTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Disabled @Test public void testUpdate() { ReplicaSet repl1 = new ReplicaSetBuilder() .withNewMetadata() .withName("repl1") .withNamespace("test") .endMetadata() .withNewSpec() .withReplicas(1) .withNewTemplate() .withNewMetadata().withLabels(new HashMap<String, String>()).endMetadata() .withNewSpec() .addNewContainer() .withImage("img1") .endContainer() .endSpec() .endTemplate() .endSpec() .withNewStatus().withReplicas(1).endStatus() .build(); server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, repl1).once(); server.expect().put().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, repl1).once(); server.expect().get().withPath("/apis/apps/v1/namespaces/test/replicasets").andReturn(200, new ReplicaSetListBuilder().withItems(repl1).build()).once(); server.expect().post().withPath("/apis/apps/v1/namespaces/test/replicasets").andReturn(201, repl1).once(); server.expect().withPath("/apis/apps/v1/namespaces/test/pods").andReturn(200, new KubernetesListBuilder().build()).once(); KubernetesClient client = server.getClient(); repl1 = client.apps().replicaSets().withName("repl1") .rolling() .withTimeout(5, TimeUnit.MINUTES) .updateImage(""); assertNotNull(repl1); }
Example #11
Source File: ReplicaSetTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void testDeprecatedApiVersion() { io.fabric8.kubernetes.api.model.extensions.ReplicaSet repl1 = new io.fabric8.kubernetes.api.model.extensions.ReplicaSetBuilder() .withApiVersion("extensions/v1beta1") .withNewMetadata() .withName("repl1") .withNamespace("test") .endMetadata() .withNewSpec() .withReplicas(1) .withNewTemplate() .withNewMetadata().withLabels(new HashMap<String, String>()).endMetadata() .withNewSpec() .addNewContainer() .withImage("img1") .endContainer() .endSpec() .endTemplate() .endSpec() .withNewStatus().withReplicas(1).endStatus() .build(); server.expect().withPath("/apis/extensions/v1beta1/namespaces/test/replicasets").andReturn(200, repl1).once(); KubernetesClient client = server.getClient(); client.resource(repl1).inNamespace("test").createOrReplace(); }
Example #12
Source File: ReplicaSetIT.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Before public void init() { currentNamespace = session.getNamespace(); Map<String, Quantity> requests = new HashMap<>(); requests.put("cpu", new Quantity("100m")); requests.put("memory", new Quantity("100Mi")); List<EnvVar> envVarList = new ArrayList<>(); envVarList.add(new EnvVar("name", "GET_HOSTS_FROM", null)); envVarList.add(new EnvVar("value", "dns", null)); replicaset1 = new ReplicaSetBuilder() .withNewMetadata() .withName("replicaset1") .addToLabels("app", "guestbook") .addToLabels("tier", "frontend") .endMetadata() .withNewSpec() .withReplicas(1) .withNewSelector() .withMatchLabels(Collections.singletonMap("tier", "frontend")) .endSelector() .withNewTemplate() .withNewMetadata() .addToLabels("app", "guestbook") .addToLabels("tier", "frontend") .endMetadata() .withNewSpec() .addNewContainer() .withName("busybox") .withImage("busybox") .withCommand("sleep","36000") .withNewResources() .withRequests(requests) .endResources() .withEnv(envVarList) .endContainer() .endSpec() .endTemplate() .endSpec() .build(); client.apps().replicaSets().inNamespace(currentNamespace).createOrReplace(replicaset1); }
Example #13
Source File: MetadataVisitor.java From jkube with Eclipse Public License 2.0 | 4 votes |
@Override protected ObjectMeta getOrCreateMetadata(ReplicaSetBuilder item) { return addEmptyLabelsAndAnnotations(item::hasMetadata, item::withNewMetadata, item::editMetadata, item::buildMetadata) .endMetadata().buildMetadata(); }
Example #14
Source File: ReplicaSetRollingUpdater.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override protected ReplicaSet setReplicas(ReplicaSet obj, int replicas) { return new ReplicaSetBuilder(obj).editSpec().withReplicas(replicas).endSpec().build(); }
Example #15
Source File: ReplicaSetTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test public void testDelete() { server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, new ReplicaSetBuilder() .withNewMetadata() .withName("repl1") .withResourceVersion("1") .endMetadata() .withNewSpec() .withReplicas(0) .endSpec() .withNewStatus() .withReplicas(1) .endStatus() .build()).once(); server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, new ReplicaSetBuilder() .withNewMetadata() .withName("repl1") .withResourceVersion("1") .endMetadata() .withNewSpec() .withReplicas(0) .endSpec() .withNewStatus() .withReplicas(0) .endStatus() .build()).times(5); server.expect().withPath("/apis/apps/v1/namespaces/ns1/replicasets/repl2").andReturn(200, new ReplicaSetBuilder() .withNewMetadata() .withName("repl2") .withResourceVersion("1") .endMetadata() .withNewSpec() .withReplicas(0) .endSpec() .withNewStatus() .withReplicas(1) .endStatus() .build()).once(); server.expect().withPath("/apis/apps/v1/namespaces/ns1/replicasets/repl2").andReturn(200, new ReplicaSetBuilder() .withNewMetadata() .withName("repl2") .withResourceVersion("1") .endMetadata() .withNewSpec() .withReplicas(0) .endSpec() .withNewStatus() .withReplicas(0) .endStatus() .build()).times(5); KubernetesClient client = server.getClient(); Boolean deleted = client.apps().replicaSets().withName("repl1").delete(); assertTrue(deleted); deleted = client.apps().replicaSets().withName("repl2").delete(); assertFalse(deleted); deleted = client.apps().replicaSets().inNamespace("ns1").withName("repl2").delete(); assertTrue(deleted); }
Example #16
Source File: DeploymentTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test @DisplayName("Should undo rollout") void testRolloutUndo() throws InterruptedException { // Given ReplicaSet replicaSetRevision1 = new ReplicaSetBuilder() .withNewMetadata() .addToAnnotations("deployment.kubernetes.io/revision", "1") .withName("rs1") .endMetadata() .withNewSpec() .withReplicas(0) .withNewSelector().addToMatchLabels("app", "nginx").endSelector() .withNewTemplate() .withNewMetadata() .addToAnnotations("kubectl.kubernetes.io/restartedAt", "2020-06-08T11:52:50.022") .addToAnnotations("app", "rs1") .addToLabels("app", "nginx") .endMetadata() .withNewSpec() .addNewContainer() .withName("nginx") .withImage("nginx:perl") .addNewPort().withContainerPort(80).endPort() .endContainer() .endSpec() .endTemplate() .endSpec() .build(); ReplicaSet replicaSetRevision2 = new ReplicaSetBuilder() .withNewMetadata() .addToAnnotations("deployment.kubernetes.io/revision", "2") .withName("rs2") .endMetadata() .withNewSpec() .withReplicas(1) .withNewSelector().addToMatchLabels("app", "nginx").endSelector() .withNewTemplate() .withNewMetadata() .addToAnnotations("kubectl.kubernetes.io/restartedAt", "2020-06-08T11:52:50.022") .addToAnnotations("app", "rs2") .addToLabels("app", "nginx") .endMetadata() .withNewSpec() .addNewContainer() .withName("nginx") .withImage("nginx:1.19") .addNewPort().withContainerPort(80).endPort() .endContainer() .endSpec() .endTemplate() .endSpec() .build(); server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/replicasets?labelSelector=" + Utils.toUrlEncoded("app=nginx")) .andReturn(HttpURLConnection.HTTP_OK, new ReplicaSetListBuilder().withItems(replicaSetRevision1, replicaSetRevision2).build()).once(); server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/deployments/deploy1") .andReturn(HttpURLConnection.HTTP_OK, getDeploymentBuilder().build()).times(3); server.expect().patch().withPath("/apis/apps/v1/namespaces/ns1/deployments/deploy1") .andReturn(HttpURLConnection.HTTP_OK, getDeploymentBuilder().build()).once(); KubernetesClient client = server.getClient(); // When Deployment deployment = client.apps().deployments().inNamespace("ns1").withName("deploy1") .rolling().undo(); // Then RecordedRequest recordedRequest = server.getLastRequest(); assertNotNull(deployment); assertEquals("PATCH", recordedRequest.getMethod()); assertTrue(recordedRequest.getBody().readUtf8().contains("\"app\":\"rs1\"")); }
Example #17
Source File: DeploymentTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test public void testDelete() { Deployment deployment1 = new DeploymentBuilder().withNewMetadata() .withName("deployment1") .addToLabels("key1", "value1") .withResourceVersion("1") .withGeneration(1L) .endMetadata() .withNewSpec() .withNewSelector() .addToMatchLabels("key1", "value1") .endSelector() .withReplicas(0) .endSpec() .withNewStatus() .withReplicas(1) .withObservedGeneration(1L) .endStatus() .build(); ReplicaSet replicaSet1 = new ReplicaSetBuilder().withNewMetadata() .withName("rs1") .addToLabels("key1", "value1") .withResourceVersion("1") .withGeneration(1L) .endMetadata() .withNewSpec() .withNewSelector() .addToMatchLabels("key1", "value1") .endSelector() .withReplicas(0) .endSpec() .withNewStatus() .withReplicas(1) .withObservedGeneration(1L) .endStatus() .build(); Deployment deployment2 = new DeploymentBuilder().withNewMetadata() .withName("deployment2") .addToLabels("key2", "value2") .withResourceVersion("1") .withGeneration(1L) .endMetadata() .withNewSpec() .withNewSelector() .addToMatchLabels("key2", "value2") .endSelector() .withReplicas(0) .endSpec() .withNewStatus() .withReplicas(1) .withObservedGeneration(1L) .endStatus() .build(); server.expect().withPath("/apis/apps/v1/namespaces/test/deployments/deployment1").andReturn(200, deployment1).once(); server.expect().withPath("/apis/apps/v1/namespaces/test/deployments/deployment1").andReturn(200, new DeploymentBuilder(deployment1).editSpec().withReplicas(0).endSpec().build()).times(5); server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets?labelSelector=key1%3Dvalue1").andReturn(200, new ReplicaSetListBuilder().addToItems(replicaSet1).build()).once(); server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/rs1").andReturn(200, replicaSet1).once(); server.expect().withPath("/apis/apps/v1/namespaces/ns1/deployments/deployment2").andReturn(200, deployment2).once(); server.expect().withPath("/apis/apps/v1/namespaces/ns1/deployments/deployment2").andReturn(200, new DeploymentBuilder(deployment2).editSpec().withReplicas(0).endSpec().build()).times(5); KubernetesClient client = server.getClient(); Boolean deleted = client.apps().deployments().withName("deployment1").delete(); assertTrue(deleted); deleted = client.apps().deployments().withName("deployment2").delete(); assertFalse(deleted); deleted = client.apps().deployments().inNamespace("ns1").withName("deployment2").delete(); assertTrue(deleted); }