io.fabric8.kubernetes.api.model.ReplicationControllerBuilder Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.ReplicationControllerBuilder. 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: ReplicationControllerTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() {
 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/repl1").andReturn(200, new ReplicationControllerBuilder().build()).once();
 server.expect().withPath("/api/v1/namespaces/ns1/replicationcontrollers/repl2").andReturn(200, new ReplicationControllerBuilder().build()).once();

  KubernetesClient client = server.getClient();

  ReplicationController repl1 = client.replicationControllers().withName("repl1").get();
  assertNotNull(repl1);

  repl1 = client.replicationControllers().withName("repl2").get();
  assertNull(repl1);

  repl1 = client.replicationControllers().inNamespace("ns1").withName("repl2").get();
  assertNotNull(repl1);
}
 
Example #2
Source File: PropagationPolicyTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("Should delete a ReplicationController with explicitly specified PropagationPolicy")
void testDeleteReplicationControllerWithExplicitPropagationPolicy() throws InterruptedException {
  // Given
  server.expect().delete().withPath("/api/v1/namespaces/ns1/replicationcontrollers/myreplicationcontroller")
    .andReturn(HttpURLConnection.HTTP_OK, new ReplicationControllerBuilder().build())
    .once();
  KubernetesClient client = server.getClient();

  // When
  Boolean isDeleted = client.replicationControllers().inNamespace("ns1").withName("myreplicationcontroller").withPropagationPolicy(DeletionPropagation.ORPHAN).delete();

  // Then
  assertTrue(isDeleted);
  assertDeleteOptionsInLastRecordedRequest(DeletionPropagation.ORPHAN.toString(), server.getLastRequest());
}
 
Example #3
Source File: ReplicationControllerTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testScale() {
 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/repl1").andReturn(200, new ReplicationControllerBuilder()
    .withNewMetadata()
    .withName("repl1")
    .withResourceVersion("1")
    .endMetadata()
    .withNewSpec()
    .withReplicas(5)
    .endSpec()
    .withNewStatus()
      .withReplicas(1)
    .endStatus()
    .build()).always();

  KubernetesClient client = server.getClient();
  ReplicationController repl = client.replicationControllers().withName("repl1").scale(5);
  assertNotNull(repl);
  assertNotNull(repl.getSpec());
  assertEquals(5, repl.getSpec().getReplicas().intValue());
  assertEquals(1, repl.getStatus().getReplicas().intValue());
}
 
Example #4
Source File: PropagationPolicyTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("Should delete a ReplicationController with PropagationPolicy=Background")
void testDeleteReplicationController() throws InterruptedException {
  // Given
  server.expect().delete().withPath("/api/v1/namespaces/ns1/replicationcontrollers/myreplicationcontroller")
    .andReturn(HttpURLConnection.HTTP_OK, new ReplicationControllerBuilder().build())
    .once();
  KubernetesClient client = server.getClient();

  // When
  Boolean isDeleted = client.replicationControllers().inNamespace("ns1").withName("myreplicationcontroller").delete();

  // Then
  assertTrue(isDeleted);
  assertDeleteOptionsInLastRecordedRequest(DeletionPropagation.BACKGROUND.toString(), server.getLastRequest());
}
 
Example #5
Source File: ReplicationControllerTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
private ReplicationControllerBuilder getReplicationControllerBuilder() {
  return new ReplicationControllerBuilder()
    .withNewMetadata()
    .withName("replicationcontroller1")
    .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 #6
Source File: ReplicationControllerTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Disabled
@Test
public void testUpdate() {
  ReplicationController repl1 = new ReplicationControllerBuilder()
    .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("/api/v1/namespaces/test/replicationcontrollers/repl1").andReturn(200, repl1).once();
 server.expect().put().withPath("/api/v1/namespaces/test/replicationcontrollers/repl1").andReturn(200, repl1).once();
 server.expect().get().withPath("/api/v1/namespaces/test/replicationcontrollers").andReturn(200, new ReplicationControllerListBuilder().withItems(repl1).build()).once();
 server.expect().post().withPath("/api/v1/namespaces/test/replicationcontrollers").andReturn(201, repl1).once();
 server.expect().withPath("/api/v1/namespaces/test/pods").andReturn(200, new KubernetesListBuilder().build()).once();
  KubernetesClient client = server.getClient();

  repl1 = client.replicationControllers().withName("repl1")
    .rolling()
    .withTimeout(5, TimeUnit.MINUTES)
    .updateImage("");
  assertNotNull(repl1);
}
 
Example #7
Source File: ResourceCompareTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testResourceCompareEqualsFalse() throws Exception {
  final ReplicationController rc = new ReplicationControllerBuilder()
    .withNewMetadata().withName("repl1").withNamespace("test").endMetadata()
    .withNewSpec().withReplicas(2).endSpec()
    .build();
  final KubernetesList kubeList2 =
    new KubernetesListBuilder(kubeList).withItems(pod, service, rc).build();
  assertThat(ResourceCompare.equals(kubeList, kubeList2), is(false));
}
 
Example #8
Source File: ResourceCompareTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup() {
  pod = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").withLabels(Collections.singletonMap("label", "value")).and().build();
  service = new ServiceBuilder()
    .withNewMetadata().withName("service1").withNamespace("test").and()
    .build();
  final ReplicationController rc = new ReplicationControllerBuilder()
    .withNewMetadata().withName("repl1").withNamespace("test").endMetadata()
    .withNewSpec().withReplicas(1).endSpec()
    .build();

  kubeList = new KubernetesListBuilder().withItems(pod, service, rc).build();
}
 
Example #9
Source File: ReplicationControllerRollingUpdater.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
protected ReplicationController createClone(ReplicationController obj, String newName, String newDeploymentHash) {
  return new ReplicationControllerBuilder(obj)
    .editMetadata()
    .withResourceVersion(null)
    .withName(newName)
    .endMetadata()
    .editSpec()
    .withReplicas(0).addToSelector(DEPLOYMENT_KEY, newDeploymentHash)
    .editTemplate().editMetadata().addToLabels(DEPLOYMENT_KEY, newDeploymentHash).endMetadata().endTemplate()
    .endSpec()
    .build();
}
 
Example #10
Source File: KubernetesListTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelete() {
 server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, pod1).always();
 server.expect().withPath("/api/v1/namespaces/test/services/service1").andReturn(200, service1).always();
 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/repl1").andReturn(200, replicationController1).once();
 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/repl1").andReturn(200, new ReplicationControllerBuilder(replicationController1)
    .editSpec().withReplicas(0).and()
    .editStatus().withReplicas(0).and().build()
  ).times(5);

  KubernetesClient client = server.getClient();
  Boolean result = client.lists().delete(list);

  assertTrue(result);
}
 
Example #11
Source File: ReplicationControllerTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testScaleAndWait() {
 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/repl1").andReturn(200, new ReplicationControllerBuilder()
    .withNewMetadata()
    .withName("repl1")
    .withResourceVersion("1")
    .endMetadata()
    .withNewSpec()
    .withReplicas(5)
    .endSpec()
    .withNewStatus()
      .withReplicas(1)
    .endStatus()
    .build()).once();

  server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/repl1").andReturn(200, new ReplicationControllerBuilder()
      .withNewMetadata()
      .withName("repl1")
      .withResourceVersion("1")
      .endMetadata()
      .withNewSpec()
      .withReplicas(5)
      .endSpec()
      .withNewStatus()
      .withReplicas(5)
      .endStatus()
      .build()).always();

  KubernetesClient client = server.getClient();
  ReplicationController repl = client.replicationControllers().withName("repl1").scale(5, true);
  assertNotNull(repl);
  assertNotNull(repl.getSpec());
  assertEquals(5, repl.getSpec().getReplicas().intValue());
  assertEquals(5, repl.getStatus().getReplicas().intValue());
}
 
Example #12
Source File: KubernetesOperationTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteWithAdapt() {
 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/rc1").andReturn(200, new ReplicationControllerBuilder().build()).once();
 server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, new PodBuilder().build()).once();
 server.expect().withPath("/apis").andReturn(200, new APIGroupListBuilder()
    .addNewGroup()
    .withApiVersion("v1")
    .withName("autoscaling.k8s.io")
    .endGroup()
    .addNewGroup()
    .withApiVersion("v1")
    .withName("security.openshift.io")
    .endGroup()
    .build()).once();
 server.expect().withPath("/apis/build.openshift.io/v1/namespaces/test/buildconfigs/bc1").andReturn(200, new BuildConfigBuilder().build()).once();
 server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, new PodBuilder().build()).once();

  try (KubernetesClient client = server.getKubernetesClient()) {
    Boolean deleted = client.replicationControllers().withName("rc1").cascading(false).delete();
    assertTrue(deleted);

    deleted = client.pods().withName("pod1").cascading(false).delete();
    assertTrue(deleted);

    OpenShiftClient oclient = client.adapt(OpenShiftClient.class);

    deleted = oclient.buildConfigs().withName("bc1").cascading(false).delete();
    assertTrue(deleted);

    deleted = oclient.pods().withName("pod1").cascading(false).delete();
    assertTrue(deleted);
  }
}
 
Example #13
Source File: KubernetesOperationTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelete() {
 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/rc1").andReturn(200, new ReplicationControllerBuilder().build()).once();
 server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, new PodBuilder().build()).once();

  OpenShiftClient client = server.getOpenshiftClient();

  Boolean deleted = client.replicationControllers().withName("rc1").cascading(false).delete();
  assertTrue(deleted);

  deleted = client.pods().withName("pod1").cascading(false).delete();
  assertTrue(deleted);
}
 
Example #14
Source File: ImageEnricher.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private void ensureTemplateSpecsInReplicationControllers(KubernetesListBuilder builder) {
    builder.accept(new TypedVisitor<ReplicationControllerBuilder>() {
        @Override
        public void visit(ReplicationControllerBuilder item) {
            ReplicationControllerFluent.SpecNested<ReplicationControllerBuilder> spec =
                item.buildSpec() == null ? item.withNewSpec() : item.editSpec();
            ReplicationControllerSpecFluent.TemplateNested<ReplicationControllerFluent.SpecNested<ReplicationControllerBuilder>>
                template =
                spec.buildTemplate() == null ? spec.withNewTemplate() : spec.editTemplate();
            template.endTemplate().endSpec();
        }
    });
}
 
Example #15
Source File: ReplicationControllerHandler.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public ReplicationController getReplicationController(ResourceConfig config,
                                                      List<ImageConfiguration> images) {
    return new ReplicationControllerBuilder()
        .withMetadata(createRcMetaData(config))
        .withSpec(createRcSpec(config, images))
        .build();
}
 
Example #16
Source File: MetadataVisitor.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ObjectMeta getOrCreateMetadata(ReplicationControllerBuilder item) {
    return addEmptyLabelsAndAnnotations(item::hasMetadata, item::withNewMetadata, item::editMetadata, item::buildMetadata)
            .endMetadata().buildMetadata();
}
 
Example #17
Source File: ReplicationControllerTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testDelete() {
 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/repl1").andReturn(200, new ReplicationControllerBuilder() .withNewMetadata()
    .withName("repl1")
    .withResourceVersion("1")
    .endMetadata()
    .withNewSpec()
    .withReplicas(0)
    .endSpec()
    .withNewStatus()
    .withReplicas(1)
    .endStatus()
    .build()).once();

 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/repl1").andReturn(200, new ReplicationControllerBuilder() .withNewMetadata()
    .withName("repl1")
    .withResourceVersion("1")
    .endMetadata()
    .withNewSpec()
    .withReplicas(0)
    .endSpec()
    .withNewStatus()
    .withReplicas(0)
    .endStatus()
    .build()).times(5);

 server.expect().withPath("/api/v1/namespaces/ns1/replicationcontrollers/repl2").andReturn(200, new ReplicationControllerBuilder() .withNewMetadata()
    .withName("repl2")
    .withResourceVersion("1")
    .endMetadata()
    .withNewSpec()
    .withReplicas(0)
    .endSpec()
    .withNewStatus()
    .withReplicas(1)
    .endStatus()
    .build()).once();

 server.expect().withPath("/api/v1/namespaces/ns1/replicationcontrollers/repl2").andReturn(200, new ReplicationControllerBuilder() .withNewMetadata()
    .withName("repl2")
    .withResourceVersion("1")
    .endMetadata()
    .withNewSpec()
    .withReplicas(0)
    .endSpec()
    .withNewStatus()
    .withReplicas(0)
    .endStatus()
    .build()).times(5);

  KubernetesClient client = server.getClient();

  Boolean deleted = client.replicationControllers().withName("repl1").delete();
  assertTrue(deleted);

  deleted = client.replicationControllers().withName("repl2").delete();
  assertFalse(deleted);

  deleted = client.replicationControllers().inNamespace("ns1").withName("repl2").delete();
  assertTrue(deleted);
}
 
Example #18
Source File: ReplicationControllerRollingUpdater.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
protected ReplicationController setReplicas(ReplicationController obj, int replicas) {
  return new ReplicationControllerBuilder(obj).editSpec().withReplicas(replicas).endSpec().build();
}