io.fabric8.openshift.api.model.DeploymentConfigBuilder Java Examples

The following examples show how to use io.fabric8.openshift.api.model.DeploymentConfigBuilder. 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: DeploymentConfigIT.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
  currentNamespace = session.getNamespace();
  deploymentConfig1 = new DeploymentConfigBuilder()
    .withNewMetadata().withName("deploymentconfig1").endMetadata()
    .withNewSpec()
    .withReplicas(2)
    .withNewTemplate()
    .withNewMetadata()
    .addToLabels("app", "database")
    .endMetadata()
    .withNewSpec()
    .addNewContainer()
    .withName("mysql")
    .withImage("openshift/mysql-55-centos7")
    .endContainer()
    .endSpec()
    .endTemplate()
    .endSpec()
    .build();

  client.deploymentConfigs().inNamespace(currentNamespace).create(deploymentConfig1);
}
 
Example #2
Source File: DeploymentConfigTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployingLatestHandlesMissingLatestVersion() {
  server.expect().withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs/dc1")
    .andReturn(200, new DeploymentConfigBuilder().withNewMetadata().withName("dc1").endMetadata()
      .withNewStatus().endStatus().build())
    .always();

  server.expect().patch().withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs/dc1")
    .andReturn(200, new DeploymentConfigBuilder().withNewMetadata().withName("dc1").endMetadata()
      .withNewStatus().withLatestVersion(1L).endStatus().build())
    .once();

  OpenShiftClient client = server.getOpenshiftClient();

  DeploymentConfig deploymentConfig = client.deploymentConfigs().withName("dc1").deployLatest();
  assertNotNull(deploymentConfig);
  assertEquals(new Long(1), deploymentConfig.getStatus().getLatestVersion());
}
 
Example #3
Source File: DeploymentConfigTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployingLatest() {
	server.expect().withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs/dc1")
			.andReturn(200, new DeploymentConfigBuilder().withNewMetadata().withName("dc1").endMetadata()
					.withNewStatus().withLatestVersion(1L).endStatus().build())
			.always();

	server.expect().patch().withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs/dc1")
			.andReturn(200, new DeploymentConfigBuilder().withNewMetadata().withName("dc1").endMetadata()
					.withNewStatus().withLatestVersion(2L).endStatus().build())
			.once();

	OpenShiftClient client = server.getOpenshiftClient();

	DeploymentConfig deploymentConfig = client.deploymentConfigs().withName("dc1").deployLatest();
	assertNotNull(deploymentConfig);
	assertEquals(new Long(2), deploymentConfig.getStatus().getLatestVersion());
}
 
Example #4
Source File: DeploymentConfigTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() {
 server.expect().withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs/dc1").andReturn(200, new DeploymentConfigBuilder()
    .withNewMetadata().withName("dc1").endMetadata()
    .build()).once();

 server.expect().withPath("/apis/apps.openshift.io/v1/namespaces/ns1/deploymentconfigs/dc2").andReturn(200, new DeploymentConfigBuilder()
    .withNewMetadata().withName("dc2").endMetadata()
    .build()).once();

  OpenShiftClient client = server.getOpenshiftClient();

  DeploymentConfig buildConfig = client.deploymentConfigs().withName("dc1").get();
  assertNotNull(buildConfig);
  assertEquals("dc1", buildConfig.getMetadata().getName());

  buildConfig = client.deploymentConfigs().withName("dc2").get();
  assertNull(buildConfig);

  buildConfig = client.deploymentConfigs().inNamespace("ns1").withName("dc2").get();
  assertNotNull(buildConfig);
  assertEquals("dc2", buildConfig.getMetadata().getName());
}
 
Example #5
Source File: OpenShiftServiceImpl.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
public void scale(String name, Map<String, String> labels, int desiredReplicas, long amount, TimeUnit timeUnit) {
    String sName = openshiftName(name);
    getDeploymentsByLabel(labels)
        .stream()
        .filter(d -> d.getMetadata().getName().equals(sName))
        .map(d -> new DeploymentConfigBuilder(d)
                // record the previous, possibly user defined custom number of replicas
                .editSpec()
                    .withReplicas(desiredReplicas)
                    .editTemplate()
                        .editMetadata()
                            .addToAnnotations(OpenShiftService.DEPLOYMENT_REPLICAS_ANNOTATION, d.getSpec().getReplicas().toString())
                        .endMetadata()
                    .endTemplate()
                .endSpec()
                .build())
        .findAny().ifPresent(d -> openShiftClient.deploymentConfigs().createOrReplace(d));
}
 
Example #6
Source File: OpenshiftHandler.java    From dekorate with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link DeploymentConfig} for the {@link OpenshiftConfig}.
 * @param config   The sesssion.
 * @return          The deployment config.
 */
public DeploymentConfig createDeploymentConfig(OpenshiftConfig config, ImageConfiguration imageConfig)  {
  Map<String, String> labels = Labels.createLabels(config);

  return new DeploymentConfigBuilder()
    .withNewMetadata()
    .withName(config.getName())
    .withLabels(labels)
    .endMetadata()
    .withNewSpec()
    .withReplicas(1)
    .withTemplate(createPodTemplateSpec(config, imageConfig, labels))
    .withSelector(labels)
    .endSpec()
    .build();
}
 
Example #7
Source File: OpenShiftServiceImplTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
void expectDeploymentOf(final String name, final DeploymentConfig expectedDeploymentConfig) {
    final DeploymentConfig deployed = new DeploymentConfigBuilder(expectedDeploymentConfig)
        .withNewStatus()
            .withLatestVersion(1L)
        .endStatus()
        .build();
    server.expect()
        .get()
        .withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs/" + openshiftName(name))
        .andReturn(404, new StatusBuilder().withCode(404).build())
        .times(1);
    server.expect()
        .get()
        .withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs/" + openshiftName(name))
        .andReturn(200, deployed)
        .always();
    server.expect()
        .patch()
        .withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs/" + openshiftName(name))
        .andReturn(200, deployed)
        .always();
    server.expect()
        .post()
        .withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs")
        .andReturn(200, expectedDeploymentConfig)
        .always();
}
 
Example #8
Source File: DeploymentConfigTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteWithPropagationPolicy() throws InterruptedException {
  server.expect().delete()
    .withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs/dc1")
    .andReturn(200, new DeploymentConfigBuilder().build())
    .once();
  OpenShiftClient client = server.getOpenshiftClient();

  Boolean isDeleted = client.deploymentConfigs().inNamespace("test").withName("dc1").withPropagationPolicy(DeletionPropagation.ORPHAN).delete();
  assertTrue(isDeleted);
  RecordedRequest recordedRequest = server.getLastRequest();
  assertEquals("{\"apiVersion\":\"v1\",\"kind\":\"DeleteOptions\",\"propagationPolicy\":\"Orphan\"}", recordedRequest.getBody().readUtf8());
}
 
Example #9
Source File: DeploymentConfigOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
protected DeploymentConfig resource() {
    return new DeploymentConfigBuilder().withNewMetadata()
            .withNamespace(NAMESPACE)
            .withName(RESOURCE_NAME)
        .endMetadata()
        .withNewSpec()
            .withNewTemplate()
                .withNewSpec()
                    .addToContainers(new ContainerBuilder().withImage("img").build())
                .endSpec()
            .endTemplate()
        .endSpec().build();
}
 
Example #10
Source File: ImageEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void checkEnrichDeploymentConfig() throws Exception {
    KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new DeploymentConfigBuilder().build());

    imageEnricher.create(PlatformMode.kubernetes, builder);
    assertCorrectlyGeneratedResources(builder.build(), "DeploymentConfig");
}
 
Example #11
Source File: ImageEnricher.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private void ensureTemplateSpecsInDeploymentConfig(KubernetesListBuilder builder) {
    builder.accept(new TypedVisitor<DeploymentConfigBuilder>() {
        @Override
        public void visit(DeploymentConfigBuilder item) {
            DeploymentConfigFluent.SpecNested<DeploymentConfigBuilder> spec =
                    item.buildSpec() == null ? item.withNewSpec() : item.editSpec();
            DeploymentConfigSpecFluent.TemplateNested<DeploymentConfigFluent.SpecNested<DeploymentConfigBuilder>> template =
                    spec.buildTemplate() == null ? spec.withNewTemplate() : spec.editTemplate();
            template.endTemplate().endSpec();
        }
    });
}
 
Example #12
Source File: DeploymentConfigEnricher.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private DeploymentConfig convertFromExtensionsV1Beta1Deployment(HasMetadata item) {
    io.fabric8.kubernetes.api.model.extensions.Deployment resource = (io.fabric8.kubernetes.api.model.extensions.Deployment) item;
    DeploymentConfigBuilder builder = new DeploymentConfigBuilder();
    builder.withMetadata(resource.getMetadata());
    io.fabric8.kubernetes.api.model.extensions.DeploymentSpec spec = resource.getSpec();
    if (spec != null) {
        builder.withSpec(getDeploymentConfigSpec(spec.getReplicas(), spec.getRevisionHistoryLimit(), spec.getSelector(), spec.getTemplate(), spec.getStrategy() != null ? spec.getStrategy().getType() : null));
    }
    return builder.build();
}
 
Example #13
Source File: DeploymentConfigEnricher.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private DeploymentConfig convertFromAppsV1Deployment(HasMetadata item) {
    Deployment resource = (Deployment) item;
    DeploymentConfigBuilder builder = new DeploymentConfigBuilder();
    builder.withMetadata(resource.getMetadata());
    DeploymentSpec spec = resource.getSpec();
    if (spec != null) {
        builder.withSpec(getDeploymentConfigSpec(spec.getReplicas(), spec.getRevisionHistoryLimit(), spec.getSelector(), spec.getTemplate(), spec.getStrategy() != null ? spec.getStrategy().getType() : null));
    }
    return builder.build();
}
 
Example #14
Source File: DeploymentConfigHandler.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public DeploymentConfig getDeploymentConfig(ResourceConfig config,
                                            List<ImageConfiguration> images, Long openshiftDeployTimeoutSeconds, Boolean imageChangeTrigger, Boolean enableAutomaticTrigger, Boolean isOpenshiftBuildStrategy, List<String> generatedContainers) {

    DeploymentConfig deploymentConfig = new DeploymentConfigBuilder()
            .withMetadata(createDeploymentConfigMetaData(config))
            .withSpec(createDeploymentConfigSpec(config, images, openshiftDeployTimeoutSeconds, imageChangeTrigger, enableAutomaticTrigger, isOpenshiftBuildStrategy, generatedContainers))
            .build();

    return deploymentConfig;
}
 
Example #15
Source File: OpenShiftServiceImplTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
DeploymentConfigBuilder baseDeploymentFor(final String name, final DeploymentData deploymentData) {
    return new DeploymentConfigBuilder()
        .withNewMetadata()
            .withName(openshiftName(name))
            .addToAnnotations(deploymentData.getAnnotations())
            .addToLabels(deploymentData.getLabels())
        .endMetadata()
        .withNewSpec()
            .withReplicas(1)
            .addToSelector("syndesis.io/integration", openshiftName(name))
            .withNewStrategy()
                .withType("Recreate")
                .withNewResources()
                   .addToLimits("memory", new Quantity(config.getDeploymentMemoryLimitMi()  + "Mi"))
                   .addToRequests("memory", new Quantity(config.getDeploymentMemoryRequestMi() +  "Mi"))
                .endResources()
            .endStrategy()
            .withRevisionHistoryLimit(0)
            .withNewTemplate()
                .withNewMetadata()
                    .addToLabels("syndesis.io/integration", openshiftName(name))
                    .addToLabels(OpenShiftServiceImpl.COMPONENT_LABEL, "integration")
                    .addToLabels(deploymentData.getLabels())
                    .addToAnnotations(deploymentData.getAnnotations())
                    .addToAnnotations("prometheus.io/scrape", "true")
                    .addToAnnotations("prometheus.io/port", "9779")
                .endMetadata()
                .withNewSpec()
                    .addNewContainer()
                        .withImage(deploymentData.getImage())
                        .withImagePullPolicy("Always")
                        .withName(openshiftName(name))
                        .addToEnv(new EnvVarBuilder().withName("LOADER_HOME").withValue(config.getIntegrationDataPath()).build())
                        .addToEnv(new EnvVarBuilder().withName("AB_JMX_EXPORTER_CONFIG").withValue("/tmp/src/prometheus-config.yml").build())
                        .addToEnv(new EnvVarBuilder().withName("JAEGER_ENDPOINT").withValue("http://syndesis-jaeger-collector:14268/api/traces").build())
                        .addToEnv(new EnvVarBuilder().withName("JAEGER_TAGS").withValue("integration.version="+deploymentData.getVersion()).build())
                        .addToEnv(new EnvVarBuilder().withName("JAEGER_SAMPLER_TYPE").withValue("const").build())
                        .addToEnv(new EnvVarBuilder().withName("JAEGER_SAMPLER_PARAM").withValue("1").build())
                        .addNewPort()
                            .withName("jolokia")
                            .withContainerPort(8778)
                        .endPort()
                        .addNewPort()
                            .withName("metrics")
                            .withContainerPort(9779)
                        .endPort()
                        .addNewPort()
                            .withName("management")
                            .withContainerPort(8081)
                        .endPort()
                        .addNewVolumeMount()
                            .withName("secret-volume")
                            .withMountPath("/deployments/config")
                            .withReadOnly(false)
                        .endVolumeMount()
                        .withLivenessProbe(new ProbeBuilder()
                            .withInitialDelaySeconds(config.getIntegrationLivenessProbeInitialDelaySeconds())
                            .withNewHttpGet()
                                .withPath("/actuator/health")
                                .withNewPort(8081)
                            .endHttpGet()
                            .build())
                    .endContainer()
                    .addNewVolume()
                        .withName("secret-volume")
                        .withNewSecret()
                            .withSecretName(openshiftName(name))
                        .endSecret()
                    .endVolume()
                .endSpec()
            .endTemplate()
            .addNewTrigger()
                .withNewImageChangeParams()
                    .withAutomatic(true)
                    .withContainerNames(openshiftName(name))
                    .withNewFrom()
                        .withKind("ImageStreamTag")
                        .withName(openshiftName(name) + ":0")
                    .endFrom()
                .endImageChangeParams()
                .withType("ImageChange")
            .endTrigger()
            .addNewTrigger()
                .withType("ConfigChange")
            .endTrigger()
        .endSpec();
}
 
Example #16
Source File: MetadataVisitor.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ObjectMeta getOrCreateMetadata(DeploymentConfigBuilder item) {
    return addEmptyLabelsAndAnnotations(item::hasMetadata, item::withNewMetadata, item::editMetadata, item::buildMetadata)
            .endMetadata().buildMetadata();
}
 
Example #17
Source File: KafkaConnectS2ICluster.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
/**
 * Generate new DeploymentConfig
 *
 * @param annotations The annotations.
 * @param isOpenShift Whether we're on OpenShift.
 * @param imagePullPolicy The image pull policy.
 * @param imagePullSecrets The image pull secrets.
 * @return Source ImageStream resource definition
 */
public DeploymentConfig generateDeploymentConfig(Map<String, String> annotations, boolean isOpenShift, ImagePullPolicy imagePullPolicy,
                                                 List<LocalObjectReference> imagePullSecrets) {
    Container container = new ContainerBuilder()
            .withName(name)
            .withImage(image)
            .withEnv(getEnvVars())
            .withCommand("/opt/kafka/s2i/run")
            .withPorts(getContainerPortList())
            .withLivenessProbe(createHttpProbe(livenessPath, REST_API_PORT_NAME, livenessProbeOptions))
            .withReadinessProbe(createHttpProbe(readinessPath, REST_API_PORT_NAME, readinessProbeOptions))
            .withVolumeMounts(getVolumeMounts())
            .withResources(getResources())
            .withImagePullPolicy(determineImagePullPolicy(imagePullPolicy, image))
            .withSecurityContext(templateContainerSecurityContext)
            .build();

    DeploymentTriggerPolicy configChangeTrigger = new DeploymentTriggerPolicyBuilder()
            .withType("ConfigChange")
            .build();

    DeploymentTriggerPolicy imageChangeTrigger = new DeploymentTriggerPolicyBuilder()
            .withType("ImageChange")
            .withNewImageChangeParams()
                .withAutomatic(true)
                .withContainerNames(name)
                .withNewFrom()
                    .withKind("ImageStreamTag")
                    .withName(image)
                .endFrom()
            .endImageChangeParams()
            .build();

    DeploymentStrategy updateStrategy = new DeploymentStrategyBuilder()
            .withType("Rolling")
            .withNewRollingParams()
                .withMaxSurge(new IntOrString(1))
                .withMaxUnavailable(new IntOrString(0))
            .endRollingParams()
            .build();

    DeploymentConfig dc = new DeploymentConfigBuilder()
            .withNewMetadata()
                .withName(name)
                .withLabels(getLabelsWithStrimziName(name, templateDeploymentLabels).toMap())
                .withAnnotations(mergeLabelsOrAnnotations(null, templateDeploymentAnnotations))
                .withNamespace(namespace)
                .withOwnerReferences(createOwnerReference())
            .endMetadata()
            .withNewSpec()
                .withReplicas(replicas)
                .withSelector(getSelectorLabels().toMap())
                .withNewTemplate()
                    .withNewMetadata()
                        .withAnnotations(mergeLabelsOrAnnotations(annotations, templatePodAnnotations))
                        .withLabels(getLabelsWithStrimziName(name, templatePodLabels).toMap())
                    .endMetadata()
                    .withNewSpec()
                        .withContainers(container)
                        .withVolumes(getVolumes(isOpenShift))
                        .withTolerations(getTolerations())
                        .withAffinity(getMergedAffinity())
                        .withTerminationGracePeriodSeconds(Long.valueOf(templateTerminationGracePeriodSeconds))
                        .withImagePullSecrets(templateImagePullSecrets != null ? templateImagePullSecrets : imagePullSecrets)
                        .withSecurityContext(templateSecurityContext)
                        .withPriorityClassName(templatePodPriorityClassName)
                        .withSchedulerName(templatePodSchedulerName)
                    .endSpec()
                .endTemplate()
                .withTriggers(configChangeTrigger, imageChangeTrigger)
            .withStrategy(updateStrategy)
            .endSpec()
            .build();
    return dc;
}
 
Example #18
Source File: MavenProjectEnricherTest.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
private KubernetesListBuilder createListWithDeploymentConfig() {
    return new KubernetesListBuilder().addToItems(new DeploymentConfigBuilder()
        .withNewMetadata().endMetadata()
        .withNewSpec().endSpec()
        .build());
}
 
Example #19
Source File: DeploymentConfigCrudTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testCrud() {
  OpenShiftClient client = server.getOpenshiftClient();

  DeploymentConfig deploymentConfig1 = new DeploymentConfigBuilder().withNewMetadata()
    .withName("deploymentConfig1")
    .withNamespace("ns1")
    .addToLabels("testKey", "testValue")
    .endMetadata()
    .build();

  DeploymentConfig deploymentConfig2 = new DeploymentConfigBuilder().withNewMetadata()
    .withName("deploymentConfig2")
    .withNamespace("ns1")
    .addToLabels("testKey", "testValue")
    .endMetadata()
    .build();

  DeploymentConfig deploymentConfig3 = new DeploymentConfigBuilder().withNewMetadata()
    .withName("deploymentConfig3")
    .addToLabels("testKey", "testValue")
    .withNamespace("ns2")
    .endMetadata()
    .build();

  client.deploymentConfigs().inNamespace("ns1").create(deploymentConfig1);
  client.deploymentConfigs().inNamespace("ns1").create(deploymentConfig2);
  client.deploymentConfigs().inNamespace("ns2").create(deploymentConfig3);

  DeploymentConfigList aDeploymentConfigList = client.deploymentConfigs().list();
  assertNotNull(aDeploymentConfigList);
  assertEquals(0, aDeploymentConfigList.getItems().size());

  aDeploymentConfigList = client.deploymentConfigs().inAnyNamespace().list();
  assertNotNull(aDeploymentConfigList);
  assertEquals(3, aDeploymentConfigList.getItems().size());

  aDeploymentConfigList = client.deploymentConfigs().inNamespace("ns1").list();
  assertNotNull(aDeploymentConfigList);
  assertEquals(2, aDeploymentConfigList.getItems().size());

  aDeploymentConfigList = client.deploymentConfigs().inNamespace("ns1")
    .withLabels(Collections.singletonMap("testKey", "testValue")).list();
  assertNotNull(aDeploymentConfigList);
  assertEquals(2, aDeploymentConfigList.getItems().size());

  deploymentConfig3 = client.deploymentConfigs().inNamespace("ns2").withName("deploymentConfig3").edit()
    .editMetadata().addToLabels("testkey1","testvalue2").endMetadata()
    .done();
  assertNotNull(deploymentConfig3);
  assertEquals(2, deploymentConfig3.getMetadata().getLabels().size());

  // ! Doesn't work
  // boolean bDeleted = client.deploymentConfigs().inNamespace("ns1").withName("deploymentConfig2").delete();
  // assertTrue(bDeleted);
}
 
Example #20
Source File: RevisionHistoryEnricher.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void visit(DeploymentConfigBuilder item) {
    item.editOrNewSpec()
            .withRevisionHistoryLimit(maxRevisionHistories)
            .endSpec();
}
 
Example #21
Source File: DeploymentConfigTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testDelete() throws InterruptedException {
  DeploymentConfig dc1 = new DeploymentConfigBuilder()
    .withNewMetadata()
      .withName("dc1")
    .endMetadata()
    .withNewSpec()
      .withReplicas(1)
      .addToSelector("name", "dc1")
      .withNewTemplate()
        .withNewSpec()
          .addNewContainer()
            .withName("container")
            .withImage("image")
          .endContainer()
        .endSpec()
      .endTemplate()
    .endSpec()
    .build();

  DeploymentConfig dc2 = new DeploymentConfigBuilder()
    .withNewMetadata()
      .withName("dc2")
    .endMetadata()
    .withNewSpec()
      .withReplicas(1)
      .addToSelector("name", "dc1")
      .withNewTemplate()
        .withNewSpec()
          .addNewContainer()
            .withName("container")
            .withImage("image")
          .endContainer()
        .endSpec()
      .endTemplate()
    .endSpec()
    .withNewStatus()
      .withObservedGeneration(1L)
    .endStatus()
    .build();

 server.expect().withPath("/apis/apps.openshift.io/v1/namespaces/test/deploymentconfigs/dc1").andReturn(200, dc1).times(2);
 server.expect().withPath("/apis/apps.openshift.io/v1/namespaces/ns1/deploymentconfigs/dc2").andReturn( 200, dc2).times(5);

  OpenShiftClient client = server.getOpenshiftClient();

  Boolean deleted = client.deploymentConfigs().withName("dc1").delete();
  assertNotNull(deleted);
  deleted = client.deploymentConfigs().withName("dc2").delete();
  assertFalse(deleted);

  deleted = client.deploymentConfigs().inNamespace("ns1").withName("dc2").delete();
  assertTrue(deleted);
  RecordedRequest recordedRequest = server.getLastRequest();
  assertEquals("{\"apiVersion\":\"v1\",\"kind\":\"DeleteOptions\",\"propagationPolicy\":\"Background\"}", recordedRequest.getBody().readUtf8());
}
 
Example #22
Source File: DeploymentConfigTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeploymentConfigVisitor() {
 AtomicBoolean visitedContainer = new AtomicBoolean();

 DeploymentConfig dc1 = new DeploymentConfigBuilder()
    .withNewMetadata()
      .withName("dc1")
    .endMetadata()
    .withNewSpec()
      .withReplicas(1)
      .addToSelector("name", "dc1")
      .addNewTrigger()
      .withType("ImageChange")
      .withNewImageChangeParams()
      .withAutomatic(true)
      .withContainerNames("container")
      .withNewFrom()
      .withKind("ImageStreamTag")
      .withName("image:1.0")
      .endFrom()
      .endImageChangeParams()
      .endTrigger()
      .withNewTemplate()
        .withNewSpec()
          .addNewContainer()
            .withName("container")
            .withImage("image")
          .endContainer()
        .endSpec()
      .endTemplate()
    .endSpec()
    .build();

 DeploymentConfig dc2 = new DeploymentConfigBuilder(dc1)
   .accept(new TypedVisitor<DeploymentConfigSpecFluent<?>>() {
     @Override
     public void visit(DeploymentConfigSpecFluent<?> spec) {
       spec.editMatchingTrigger(b -> b.buildImageChangeParams().getContainerNames().contains("container"))
         .withType("ImageChange")
         .endTrigger();
     }
   })
   .accept(new TypedVisitor<ContainerFluent<?>>() {
     @Override
     public void visit(ContainerFluent<?> container) {
       container.addNewEnv().withName("FOO").withValue("BAR").endEnv();
       visitedContainer.set(true);

     }
   }).build();
 assertTrue(visitedContainer.get());
}