io.fabric8.kubernetes.api.model.apps.DeploymentBuilder Java Examples

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

  KubernetesClient client = server.getClient();

  Deployment deployment = client.apps().deployments().withName("deployment1").get();
  assertNotNull(deployment);

  deployment = client.apps().deployments().withName("deployment2").get();
  assertNull(deployment);

  deployment = client.apps().deployments().inNamespace("ns1").withName("deployment2").get();
  assertNotNull(deployment);
}
 
Example #2
Source File: KubernetesInternalRuntimeTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
private static Deployment mockDeployment(List<Container> containers) {
  final Deployment deployment =
      new DeploymentBuilder()
          .withNewMetadata()
          .withName(WORKSPACE_POD_NAME)
          .withLabels(
              ImmutableMap.of(
                  POD_SELECTOR, WORKSPACE_POD_NAME, CHE_ORIGINAL_NAME_LABEL, WORKSPACE_POD_NAME))
          .endMetadata()
          .withNewSpec()
          .withNewTemplate()
          .withNewSpec()
          .withContainers(containers)
          .endSpec()
          .withNewMetadata()
          .withName(WORKSPACE_POD_NAME)
          .withLabels(
              ImmutableMap.of(
                  POD_SELECTOR, WORKSPACE_POD_NAME, CHE_ORIGINAL_NAME_LABEL, WORKSPACE_POD_NAME))
          .endMetadata()
          .endTemplate()
          .endSpec()
          .build();
  return deployment;
}
 
Example #3
Source File: ServiceCatalogExampleTest.java    From dekorate with Apache License 2.0 6 votes vote down vote up
@Test
 public void shouldContainServiceInstanceAndBinding() {
  KubernetesList list = Serialization.unmarshalAsList(ServiceCatalogExampleTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
  assertNotNull(list);
  assertTrue(findFirst(list, ServiceInstance.class).isPresent());
  assertTrue(findFirst(list, ServiceBinding.class).isPresent());
  Optional<Deployment> deployment = findFirst(list, Deployment.class);
  assertTrue(deployment.isPresent());

  AtomicBoolean hasBindingEnv = new AtomicBoolean(false);
  new DeploymentBuilder(deployment.get()).accept(new TypedVisitor<EnvFromSourceFluent>() {
    @Override
    public void visit(EnvFromSourceFluent env) {
      if (env.hasSecretRef()) {
        hasBindingEnv.set(true);
      }
    }
  });
  assertTrue(hasBindingEnv.get());
}
 
Example #4
Source File: KubernetesEnvironmentFactoryTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldUseDeploymentNameAsPodTemplateNameIfItIsMissing() throws Exception {
  // given
  PodTemplateSpec podTemplate = new PodTemplateSpecBuilder().withNewSpec().endSpec().build();
  Deployment deployment =
      new DeploymentBuilder()
          .withNewMetadata()
          .withName("deployment-test")
          .endMetadata()
          .withNewSpec()
          .withTemplate(podTemplate)
          .endSpec()
          .build();
  when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(deployment));

  // when
  final KubernetesEnvironment k8sEnv =
      k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());

  // then
  Deployment deploymentTest = k8sEnv.getDeploymentsCopy().get("deployment-test");
  assertNotNull(deploymentTest);
  PodTemplateSpec resultPodTemplate = deploymentTest.getSpec().getTemplate();
  assertEquals(resultPodTemplate.getMetadata().getName(), "deployment-test");
}
 
Example #5
Source File: OpenShiftEnvironmentFactoryTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldUseDeploymentNameAsPodTemplateNameIfItIsMissing() throws Exception {
  // given
  PodTemplateSpec podTemplate = new PodTemplateSpecBuilder().withNewSpec().endSpec().build();
  Deployment deployment =
      new DeploymentBuilder()
          .withNewMetadata()
          .withName("deployment-test")
          .endMetadata()
          .withNewSpec()
          .withTemplate(podTemplate)
          .endSpec()
          .build();
  when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(asList(deployment));

  // when
  final KubernetesEnvironment k8sEnv =
      osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());

  // then
  Deployment deploymentTest = k8sEnv.getDeploymentsCopy().get("deployment-test");
  assertNotNull(deploymentTest);
  PodTemplateSpec resultPodTemplate = deploymentTest.getSpec().getTemplate();
  assertEquals(resultPodTemplate.getMetadata().getName(), "deployment-test");
}
 
Example #6
Source File: PropagationPolicyTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("Should delete a Deployment with PropagationPolicy=Background")
void testDeleteDeployment() throws InterruptedException {
  // Given
  server.expect().delete().withPath("/apis/apps/v1/namespaces/ns1/deployments/mydeployment")
    .andReturn(HttpURLConnection.HTTP_OK, new DeploymentBuilder().build())
    .once();
  KubernetesClient client = server.getClient();

  // When
  Boolean isDeleted = client.apps().deployments().inNamespace("ns1").withName("mydeployment").delete();

  // Then
  assertTrue(isDeleted);
  assertDeleteOptionsInLastRecordedRequest(DeletionPropagation.BACKGROUND.toString(), server.getLastRequest());
}
 
Example #7
Source File: PropagationPolicyTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("Should delete a Deployment with explicitly set PropagationPolicy")
void testDeleteDeploymentWithExplicitPropagationPolicy() throws InterruptedException {
  // Given
  server.expect().delete().withPath("/apis/apps/v1/namespaces/ns1/deployments/mydeployment")
    .andReturn(HttpURLConnection.HTTP_OK, new DeploymentBuilder().build())
    .once();
  KubernetesClient client = server.getClient();

  // When
  Boolean isDeleted = client.apps().deployments().inNamespace("ns1").withName("mydeployment").withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();

  // Then
  assertTrue(isDeleted);
  assertDeleteOptionsInLastRecordedRequest(DeletionPropagation.FOREGROUND.toString(), server.getLastRequest());
}
 
Example #8
Source File: MavenProjectEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testGeneratedResources() {
    ProjectLabelEnricher projectEnricher = new ProjectLabelEnricher(context);

    KubernetesListBuilder builder = createListWithDeploymentConfig();
    projectEnricher.enrich(PlatformMode.kubernetes, builder);
    KubernetesList list = builder.build();

    Map<String, String> labels = list.getItems().get(0).getMetadata().getLabels();

    assertNotNull(labels);
    assertEquals("groupId", labels.get("group"));
    assertEquals("artifactId", labels.get("app"));
    assertEquals("version", labels.get("version"));
    assertNull(labels.get("project"));

    builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().build());
    projectEnricher.create(PlatformMode.kubernetes, builder);

    Deployment deployment = (Deployment)builder.buildFirstItem();
    Map<String, String> selectors = deployment.getSpec().getSelector().getMatchLabels();
    assertEquals("groupId", selectors.get("group"));
    assertEquals("artifactId", selectors.get("app"));
    assertNull(selectors.get("version"));
    assertNull(selectors.get("project"));
}
 
Example #9
Source File: ControllerViaPluginConfigurationEnricher.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Override
    public void visit(DeploymentBuilder deploymentBuilder) {
        deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
        mergeDeploymentSpec(deploymentBuilder, spec);
    }
});

if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
    final PodSpec podSpec = spec.getTemplate().getSpec();
    builder.accept(new TypedVisitor<PodSpecBuilder>() {
        @Override
        public void visit(PodSpecBuilder builder) {
            String defaultApplicationContainerName = KubernetesResourceUtil.mergePodSpec(builder, podSpec, name, getValueFromConfig(SIDECAR, false));
            if(defaultApplicationContainerName != null) {
                setProcessingInstruction(NEED_IMAGECHANGE_TRIGGERS, Collections.singletonList(defaultApplicationContainerName));
            }
        }
    });
}
 
Example #10
Source File: KafkaClientsResource.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
public static DoneableDeployment deployKafkaClients(boolean tlsListener, String kafkaClientsName, boolean hostnameVerification, KafkaUser... kafkaUsers) {
    Map<String, String> label = Collections.singletonMap(Constants.KAFKA_CLIENTS_LABEL_KEY, Constants.KAFKA_CLIENTS_LABEL_VALUE);
    Deployment kafkaClient = new DeploymentBuilder()
        .withNewMetadata()
            .withName(kafkaClientsName)
            .withLabels(label)
        .endMetadata()
        .withNewSpec()
            .withNewSelector()
                .addToMatchLabels("app", kafkaClientsName)
                .addToMatchLabels(label)
            .endSelector()
            .withReplicas(1)
            .withNewTemplate()
                .withNewMetadata()
                    .addToLabels("app", kafkaClientsName)
                    .addToLabels(label)
                .endMetadata()
                .withSpec(createClientSpec(tlsListener, kafkaClientsName, hostnameVerification, kafkaUsers))
            .endTemplate()
        .endSpec()
        .build();

    return KubernetesResource.deployNewDeployment(kafkaClient);
}
 
Example #11
Source File: DeploymentTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreate() {
  Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("deployment1").withNamespace("test").endMetadata()
    .withNewSpec()
    .withReplicas(1)
    .endSpec()
    .build();

  server.expect().post().withPath("/apis/apps/v1/namespaces/test/deployments")
    .andReturn(200, deployment1)
    .once();

  KubernetesClient client = server.getClient();
  Deployment result = client.apps().deployments().inNamespace("test").create(deployment1);
  assertNotNull(result);
  assertEquals("deployment1", result.getMetadata().getName());
}
 
Example #12
Source File: DeploymentTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateMulti() {
  IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
    Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("deployment1").withNamespace("test").endMetadata()
      .withNewSpec()
      .withReplicas(1)
      .endSpec()
      .build();
    Deployment deployment2 = new DeploymentBuilder().withNewMetadata().withName("deployment1").withNamespace("test").endMetadata()
      .withNewSpec()
      .withReplicas(1)
      .endSpec()
      .build();

    server.expect().post().withPath("/apis/apps/v1/namespaces/test/deployments")
      .andReturn(200, deployment1)
      .once();

    KubernetesClient client = server.getClient();
    // Will throw exception
    client.apps().deployments().inNamespace("test").create(deployment1, deployment2);
  });

  assertEquals("Too many items to create.", exception.getMessage());
}
 
Example #13
Source File: DeploymentTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
private DeploymentBuilder getDeploymentBuilder() {
  return new DeploymentBuilder()
    .withNewMetadata()
    .withName("deploy1")
    .addToLabels("app", "nginx")
    .addToAnnotations("app", "nginx")
    .endMetadata()
    .withNewSpec()
    .withReplicas(1)
    .withNewSelector()
    .addToMatchLabels("app", "nginx")
    .endSelector()
    .withNewTemplate()
    .withNewMetadata().addToLabels("app", "nginx").endMetadata()
    .withNewSpec()
    .addNewContainer()
    .withName("nginx")
    .withImage("nginx:1.7.9")
    .addNewPort().withContainerPort(80).endPort()
    .endContainer()
    .endSpec()
    .endTemplate()
    .endSpec();
}
 
Example #14
Source File: DockerHealthCheckEnricherTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private KubernetesListBuilder addDeployment(KubernetesListBuilder list, String name) {
    return list.addToItems(new DeploymentBuilder()
        .withNewMetadata()
        .withName(name)
        .endMetadata()
        .withNewSpec()
        .withNewTemplate()
        .withNewSpec()
        .addNewContainer()
        .withName(name)
        .endContainer()
        .endSpec()
        .endTemplate()
        .endSpec()
        .build());
}
 
Example #15
Source File: DeploymentRollingUpdater.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
protected Deployment createClone(Deployment obj, String newName, String newDeploymentHash) {
  return new DeploymentBuilder(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 #16
Source File: KubernetesEnvironmentProvisionerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldUpgradeKubernetesEnvironmentToOpenShiftTypeOnOpenShiftComponentProvisioning()
    throws Exception {
  // given
  workspaceConfig.setDefaultEnv("default");
  RecipeImpl existingRecipe =
      new RecipeImpl(KubernetesEnvironment.TYPE, "yaml", "existing-content", null);
  workspaceConfig
      .getEnvironments()
      .put("default", new EnvironmentImpl(existingRecipe, emptyMap()));

  List<HasMetadata> componentsObject = new ArrayList<>();
  Deployment componentDeployment =
      new DeploymentBuilder()
          .withNewMetadata()
          .withName("web-app")
          .endMetadata()
          .withNewSpec()
          .endSpec()
          .build();
  componentsObject.add(new DeploymentBuilder(componentDeployment).build());
  doReturn(new ArrayList<>()).when(k8sRecipeParser).parse(anyString());

  // when
  k8sEnvProvisioner.provision(workspaceConfig, "openshift", componentsObject, emptyMap());

  // then
  EnvironmentImpl resultEnv =
      workspaceConfig.getEnvironments().get(workspaceConfig.getDefaultEnv());
  RecipeImpl resultRecipe = resultEnv.getRecipe();
  assertEquals(resultRecipe.getType(), "openshift");
}
 
Example #17
Source File: DeploymentTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateWithNameMismatch() {
  assertThrows(KubernetesClientException.class, () -> {
    Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("deployment1").withNamespace("test").and().build();
    KubernetesClient client = server.getClient();

    client.apps().deployments().inNamespace("test1").withName("mydeployment1").create(deployment1);
  });
}
 
Example #18
Source File: DeploymentIT.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {

  currentNamespace = session.getNamespace();

  client.apps().deployments().inNamespace(currentNamespace).delete();
  client.pods().inNamespace(currentNamespace).delete();

  deployment1 = new DeploymentBuilder()
    .withNewMetadata()
      .withName("deployment1")
      .addToLabels("test", "deployment")
    .endMetadata()
    .withNewSpec()
      .withReplicas(1)
      .withNewTemplate()
        .withNewMetadata()
        .addToLabels("app", "httpd")
        .endMetadata()
        .withNewSpec()
          .addNewContainer()
            .withName("busybox")
            .withImage("busybox")
            .withCommand("sleep","36000")
          .endContainer()
        .endSpec()
      .endTemplate()
      .withNewSelector()
        .addToMatchLabels("app","httpd")
      .endSelector()
    .endSpec()
    .build();

  client.apps().deployments().inNamespace(currentNamespace).create(deployment1);
}
 
Example #19
Source File: KubernetesEnvironmentFactoryTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void addDeploymentsWhenRecipeContainsThem() throws Exception {
  // given
  PodTemplateSpec podTemplate =
      new PodTemplateSpecBuilder()
          .withNewMetadata()
          .withName("deployment-pod")
          .endMetadata()
          .withNewSpec()
          .endSpec()
          .build();
  Deployment deployment =
      new DeploymentBuilder()
          .withNewMetadata()
          .withName("deployment-test")
          .endMetadata()
          .withNewSpec()
          .withTemplate(podTemplate)
          .endSpec()
          .build();

  when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(deployment));

  // when
  final KubernetesEnvironment k8sEnv =
      k8sEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());

  // then
  assertEquals(k8sEnv.getDeploymentsCopy().size(), 1);
  assertEquals(k8sEnv.getDeploymentsCopy().get("deployment-test"), deployment);

  assertEquals(k8sEnv.getPodsData().size(), 1);
  assertEquals(
      k8sEnv.getPodsData().get("deployment-test").getMetadata(), podTemplate.getMetadata());
  assertEquals(k8sEnv.getPodsData().get("deployment-test").getSpec(), podTemplate.getSpec());
}
 
Example #20
Source File: KubernetesJobManagerFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Deployment createJobManagerDeployment(
		FlinkPod flinkPod,
		KubernetesJobManagerParameters kubernetesJobManagerParameters) {
	final Container resolvedMainContainer = flinkPod.getMainContainer();

	final Pod resolvedPod = new PodBuilder(flinkPod.getPod())
		.editOrNewSpec()
			.addToContainers(resolvedMainContainer)
			.endSpec()
		.build();

	final Map<String, String> labels = resolvedPod.getMetadata().getLabels();

	return new DeploymentBuilder()
		.withApiVersion(Constants.APPS_API_VERSION)
		.editOrNewMetadata()
			.withName(KubernetesUtils.getDeploymentName(kubernetesJobManagerParameters.getClusterId()))
			.withLabels(kubernetesJobManagerParameters.getLabels())
			.endMetadata()
		.editOrNewSpec()
			.withReplicas(1)
			.editOrNewTemplate()
				.withMetadata(resolvedPod.getMetadata())
				.withSpec(resolvedPod.getSpec())
				.endTemplate()
			.editOrNewSelector()
				.addToMatchLabels(labels)
				.endSelector()
			.endSpec()
		.build();
}
 
Example #21
Source File: KubernetesResourceManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void onSetup() throws Exception {
	super.onSetup();

	final Deployment mockDeployment = new DeploymentBuilder()
		.editOrNewMetadata()
			.withName(KubernetesUtils.getDeploymentName(CLUSTER_ID))
			.endMetadata()
		.build();
	kubeClient.apps().deployments().inNamespace(NAMESPACE).create(mockDeployment);
}
 
Example #22
Source File: SystemtestsKubernetesApps.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private static Deployment getMessagingAppDeploymentResource() {
    return new DeploymentBuilder()
            .withNewMetadata()
            .withName(MESSAGING_CLIENTS)
            .endMetadata()
            .withNewSpec()
            .withNewSelector()
            .addToMatchLabels("app", MESSAGING_CLIENTS)
            .endSelector()
            .withReplicas(1)
            .withNewTemplate()
            .withNewMetadata()
            .addToLabels("app", MESSAGING_CLIENTS)
            .endMetadata()
            .withNewSpec()
            .addNewContainer()
            .withName(MESSAGING_CLIENTS)
            .withImage("quay.io/enmasse/systemtests-clients:latest")
            .withImagePullPolicy(env.getImagePullPolicy())
            .withCommand("sleep")
            .withArgs("infinity")
            .withEnv(new EnvVarBuilder().withName("PN_TRACE_FRM").withValue("true").build())
            .endContainer()
            .endSpec()
            .endTemplate()
            .endSpec()
            .build();
}
 
Example #23
Source File: DeploymentTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteWithNamespaceMismatch() {
  assertThrows(KubernetesClientException.class, () -> {
    Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("deployment1").withNamespace("test").endMetadata()
      .withNewSpec()
      .withReplicas(1)
      .endSpec()
      .build();
    KubernetesClient client = server.getClient();

    Boolean deleted = client.apps().deployments().inNamespace("test1").delete(deployment1);
    assertFalse(deleted);
  });
}
 
Example #24
Source File: KubernetesDeployments.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Starts the specified Pod via a Deployment.
 *
 * @param pod pod to deploy
 * @return created pod
 * @throws InfrastructureException when any exception occurs
 */
public Pod deploy(Pod pod) throws InfrastructureException {
  putLabel(pod, CHE_WORKSPACE_ID_LABEL, workspaceId);
  // Since we use the pod's metadata as the deployment's metadata
  // This is used to identify the pod in CreateWatcher.
  String originalName = pod.getMetadata().getName();
  putLabel(pod, CHE_DEPLOYMENT_NAME_LABEL, originalName);

  ObjectMeta metadata = pod.getMetadata();
  PodSpec podSpec = pod.getSpec();
  podSpec.setRestartPolicy("Always"); // Only allowable value

  Deployment deployment =
      new DeploymentBuilder()
          .withMetadata(metadata)
          .withNewSpec()
          .withNewSelector()
          .withMatchLabels(metadata.getLabels())
          .endSelector()
          .withReplicas(1)
          .withNewTemplate()
          .withMetadata(metadata)
          .withSpec(podSpec)
          .endTemplate()
          .endSpec()
          .build();
  return createDeployment(deployment, workspaceId);
}
 
Example #25
Source File: PodMerger.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private Deployment createEmptyDeployment(String name) {
  return new DeploymentBuilder()
      .withMetadata(new ObjectMetaBuilder().withName(name).build())
      .withNewSpec()
      .withNewSelector()
      .endSelector()
      .withReplicas(1)
      .withNewTemplate()
      .withNewMetadata()
      .endMetadata()
      .withSpec(new PodSpec())
      .endTemplate()
      .endSpec()
      .build();
}
 
Example #26
Source File: OpenShiftEnvironmentFactoryTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private Deployment createEmptyDeployment(String name) {
  return new DeploymentBuilder()
      .withNewMetadata()
      .withName(name)
      .endMetadata()
      .withNewSpec()
      .withNewTemplate()
      .withNewMetadata()
      .endMetadata()
      .withNewSpec()
      .endSpec()
      .endTemplate()
      .endSpec()
      .build();
}
 
Example #27
Source File: OpenShiftEnvironmentFactoryTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void addDeploymentsWhenRecipeContainsThem() throws Exception {
  // given
  PodTemplateSpec podTemplate =
      new PodTemplateSpecBuilder()
          .withNewMetadata()
          .withName("deployment-pod")
          .endMetadata()
          .withNewSpec()
          .endSpec()
          .build();
  Deployment deployment =
      new DeploymentBuilder()
          .withNewMetadata()
          .withName("deployment-test")
          .endMetadata()
          .withNewSpec()
          .withTemplate(podTemplate)
          .endSpec()
          .build();

  when(k8sRecipeParser.parse(any(InternalRecipe.class))).thenReturn(singletonList(deployment));

  // when
  final KubernetesEnvironment osEnv =
      osEnvFactory.doCreate(internalRecipe, emptyMap(), emptyList());

  // then
  assertEquals(osEnv.getDeploymentsCopy().size(), 1);
  assertEquals(osEnv.getDeploymentsCopy().get("deployment-test"), deployment);

  assertEquals(osEnv.getPodsData().size(), 1);
  assertEquals(
      osEnv.getPodsData().get("deployment-test").getMetadata(), podTemplate.getMetadata());
  assertEquals(osEnv.getPodsData().get("deployment-test").getSpec(), podTemplate.getSpec());
}
 
Example #28
Source File: SystemtestsKubernetesApps.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private static Deployment getProxyApiAppDeploymentResource() {
    return new DeploymentBuilder()
            .withNewMetadata()
            .withName(API_PROXY)
            .addToLabels("app", API_PROXY)
            .endMetadata()
            .withNewSpec()
            .withNewSelector()
            .addToMatchLabels("app", API_PROXY)
            .endSelector()
            .withReplicas(1)
            .withNewTemplate()
            .withNewMetadata()
            .addToLabels("app", API_PROXY)
            .endMetadata()
            .withNewSpec()
            .addNewContainer()
            .withName(API_PROXY)
            .withImage("quay.io/enmasse/api-proxy:latest")
            .withPorts(new ContainerPortBuilder().withContainerPort(8443).withName("https").withProtocol("TCP").build())
            .withVolumeMounts(new VolumeMountBuilder().withMountPath("/etc/tls/private").withName("api-proxy-tls").withReadOnly(true).build())
            .endContainer()
            .withVolumes(Collections.singletonList(new VolumeBuilder().withName("api-proxy-tls").withSecret(new SecretVolumeSourceBuilder().withDefaultMode(420).withSecretName("api-proxy-cert").build()).build()))
            .endSpec()
            .endTemplate()
            .endSpec()
            .build();
}
 
Example #29
Source File: SystemtestsKubernetesApps.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private static Deployment getMessagingAppDeploymentResource(String namespace) {
    return new DeploymentBuilder(getMessagingAppDeploymentResource())
            .editMetadata()
            .withName(namespace)
            .endMetadata()
            .editSpec()
            .withNewSelector()
            .addToMatchLabels("app", namespace)
            .endSelector()
            .editTemplate()
            .withNewMetadata()
            .addToLabels("app", namespace)
            .endMetadata()
            .endTemplate()
            .endSpec()
            .build();

    /*
     * return new DoneableDeployment(getMessagingAppDeploymentResource())
     * .editMetadata()
     * .withName(namespace)
     * .endMetadata()
     * .editSpec()
     * .withNewSelector()
     * .addToMatchLabels("app", namespace)
     * .endSelector()
     * .editTemplate()
     * .withNewMetadata()
     * .addToLabels("app", namespace)
     * .endMetadata()
     * .endTemplate()
     * .endSpec()
     * .done();
     */
}
 
Example #30
Source File: SystemtestsKubernetesApps.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private static Deployment getOpenshiftCertValidatorDeploymentResource() {
    return new DeploymentBuilder()
            .withNewMetadata()
            .withName(OPENSHIFT_CERT_VALIDATOR)
            .endMetadata()
            .withNewSpec()
            .withNewSelector()
            .addToMatchLabels("app", OPENSHIFT_CERT_VALIDATOR)
            .endSelector()
            .withReplicas(1)
            .withNewTemplate()
            .withNewMetadata()
            .addToLabels("app", OPENSHIFT_CERT_VALIDATOR)
            .endMetadata()
            .withNewSpec()
            .addNewContainer()
            .withName(OPENSHIFT_CERT_VALIDATOR)
            .withImage("quay.io/enmasse/systemtests-cert-validator:1.0")
            .addNewPort()
            .withContainerPort(8080)
            .endPort()
            .withNewLivenessProbe()
            .withNewTcpSocket()
            .withNewPort(8080)
            .endTcpSocket()
            .withInitialDelaySeconds(10)
            .withPeriodSeconds(5)
            .endLivenessProbe()
            .endContainer()
            .endSpec()
            .endTemplate()
            .endSpec()
            .build();
}