io.fabric8.kubernetes.api.model.Container Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.Container.
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: K8sContainerResolver.java From che with Eclipse Public License 2.0 | 6 votes |
private void provisionCpuLimit(Container container, CheContainer cheContainer) throws InfrastructureException { String cpuLimit = cheContainer.getCpuLimit(); if (isNullOrEmpty(cpuLimit)) { return; } try { KubernetesSize.toCores(cpuLimit); } catch (IllegalArgumentException e) { throw new InfrastructureException( format( "Sidecar CPU limit field contains illegal value '%s'. Error: '%s'", cpuLimit, e.getMessage())); } Containers.addCpuLimit(container, cpuLimit); }
Example #2
Source File: DefaultContainerFactoryTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testProbeHeadersWithoutAuth() throws Exception { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource()); ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest) .withExternalPort(8080); ContainerFactory containerFactory = new DefaultContainerFactory(new KubernetesDeployerProperties()); Container container = containerFactory.create(containerConfiguration); assertTrue("Liveness probe should not contain any HTTP headers", container.getLivenessProbe().getHttpGet().getHttpHeaders().isEmpty()); assertTrue("Readiness probe should not contain any HTTP headers", container.getReadinessProbe().getHttpGet().getHttpHeaders().isEmpty()); }
Example #3
Source File: DefaultContainerFactoryTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void create() { KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties(); DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory( kubernetesDeployerProperties); AppDefinition definition = new AppDefinition("app-test", null); Resource resource = getResource(); Map<String, String> props = new HashMap<>(); props.put("spring.cloud.deployer.kubernetes.limits.memory", "128Mi"); props.put("spring.cloud.deployer.kubernetes.environment-variables", "JAVA_OPTIONS=-Xmx64m,KUBERNETES_NAMESPACE=test-space"); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, resource, props); ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest); Container container = defaultContainerFactory.create(containerConfiguration); assertNotNull(container); assertEquals(3, container.getEnv().size()); EnvVar envVar1 = container.getEnv().get(0); EnvVar envVar2 = container.getEnv().get(1); assertEquals("JAVA_OPTIONS", envVar1.getName()); assertEquals("-Xmx64m", envVar1.getValue()); assertEquals("KUBERNETES_NAMESPACE", envVar2.getName()); assertEquals("test-space", envVar2.getValue()); }
Example #4
Source File: GoCDContainerDetails.java From kubernetes-elastic-agents with Apache License 2.0 | 6 votes |
public static GoCDContainerDetails fromContainer(Container container, ContainerStatus containerStatus) { GoCDContainerDetails containerDetails = new GoCDContainerDetails(); containerDetails.name = container.getName(); containerDetails.image = container.getImage(); containerDetails.imagePullPolicy = container.getImagePullPolicy(); containerDetails.command = container.getCommand(); containerDetails.env = new ArrayList<>(); for (EnvVar var : container.getEnv()) { containerDetails.env.add(new EnvironmentVariable(var.getName(), var.getValue())); } if (containerStatus != null) { containerDetails.ready = containerStatus.getReady(); containerDetails.restartCount = containerStatus.getRestartCount(); } else { containerDetails.ready = false; containerDetails.restartCount = 0; } return containerDetails; }
Example #5
Source File: KafkaMirrorMakerClusterTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Test public void testGenerateDeploymentWithProducerOAuthWithAccessToken() { KafkaMirrorMaker resource = new KafkaMirrorMakerBuilder(this.resource) .editSpec() .editProducer() .withAuthentication( new KafkaClientAuthenticationOAuthBuilder() .withNewAccessToken() .withSecretName("my-token-secret") .withKey("my-token-key") .endAccessToken() .build()) .endProducer() .endSpec() .build(); KafkaMirrorMakerCluster kc = KafkaMirrorMakerCluster.fromCrd(resource, VERSIONS); Deployment dep = kc.generateDeployment(emptyMap(), true, null, null); Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0); assertThat(cont.getEnv().stream().filter(var -> KafkaMirrorMakerCluster.ENV_VAR_KAFKA_MIRRORMAKER_SASL_MECHANISM_PRODUCER.equals(var.getName())).findFirst().orElse(null).getValue(), is("oauth")); assertThat(cont.getEnv().stream().filter(var -> KafkaMirrorMakerCluster.ENV_VAR_KAFKA_MIRRORMAKER_OAUTH_ACCESS_TOKEN_PRODUCER.equals(var.getName())).findFirst().orElse(null).getValueFrom().getSecretKeyRef().getName(), is("my-token-secret")); assertThat(cont.getEnv().stream().filter(var -> KafkaMirrorMakerCluster.ENV_VAR_KAFKA_MIRRORMAKER_OAUTH_ACCESS_TOKEN_PRODUCER.equals(var.getName())).findFirst().orElse(null).getValueFrom().getSecretKeyRef().getKey(), is("my-token-key")); assertThat(cont.getEnv().stream().filter(var -> KafkaMirrorMakerCluster.ENV_VAR_KAFKA_MIRRORMAKER_OAUTH_CONFIG_PRODUCER.equals(var.getName())).findFirst().orElse(null).getValue().isEmpty(), is(true)); }
Example #6
Source File: Sample12Test.java From module-ballerina-kubernetes with Apache License 2.0 | 6 votes |
@Test public void validateDeployment() { Assert.assertNotNull(deployment); Assert.assertEquals(deployment.getMetadata().getName(), "hello-world-copy-file-deployment"); Assert.assertEquals(deployment.getSpec().getReplicas().intValue(), 1); Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getVolumes().size(), 1); Assert.assertEquals(deployment.getMetadata().getLabels().get(KubernetesConstants .KUBERNETES_SELECTOR_KEY), "hello_world_copy_file"); Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().size(), 1); // Assert Containers Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0); Assert.assertEquals(container.getVolumeMounts().size(), 1); Assert.assertEquals(container.getImage(), DOCKER_IMAGE); Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name()); Assert.assertEquals(container.getPorts().size(), 1); }
Example #7
Source File: KafkaConnectClusterTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Test public void testJvmOptions() { Map<String, String> xx = new HashMap<>(2); xx.put("UseG1GC", "true"); xx.put("MaxGCPauseMillis", "20"); KafkaConnect resource = new KafkaConnectBuilder(this.resource) .editSpec() .withNewJvmOptions() .withNewXms("512m") .withNewXmx("1024m") .withNewServer(true) .withXx(xx) .endJvmOptions() .endSpec() .build(); KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(resource, VERSIONS); Deployment dep = kc.generateDeployment(Collections.EMPTY_MAP, true, null, null); Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0); assertThat(cont.getEnv().stream().filter(env -> "KAFKA_JVM_PERFORMANCE_OPTS".equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").contains("-server"), is(true)); assertThat(cont.getEnv().stream().filter(env -> "KAFKA_JVM_PERFORMANCE_OPTS".equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").contains("-XX:+UseG1GC"), is(true)); assertThat(cont.getEnv().stream().filter(env -> "KAFKA_JVM_PERFORMANCE_OPTS".equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").contains("-XX:MaxGCPauseMillis=20"), is(true)); assertThat(cont.getEnv().stream().filter(env -> "KAFKA_HEAP_OPTS".equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").contains("-Xmx1024m"), is(true)); assertThat(cont.getEnv().stream().filter(env -> "KAFKA_HEAP_OPTS".equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").contains("-Xms512m"), is(true)); }
Example #8
Source File: BrokerEnvironmentFactoryTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldNameContainersAfterArtifactsPluginBrokerImage() throws Exception { // given Collection<PluginFQN> pluginFQNs = singletonList(new PluginFQN(null, "id")); ArgumentCaptor<BrokersConfigs> captor = ArgumentCaptor.forClass(BrokersConfigs.class); // when factory.createForArtifactsBroker(pluginFQNs, runtimeId); // then verify(factory).doCreate(captor.capture()); BrokersConfigs brokersConfigs = captor.getValue(); PodSpec brokerPodSpec = brokersConfigs.pods.values().iterator().next().getSpec(); List<Container> containers = brokerPodSpec.getContainers(); assertEquals(containers.size(), 1); assertEquals(containers.get(0).getName(), "artifacts-image"); }
Example #9
Source File: MultiHostExternalServiceExposureStrategyTest.java From che with Eclipse Public License 2.0 | 6 votes |
@BeforeMethod public void setUp() throws Exception { Container container = new ContainerBuilder().withName("main").build(); Pod pod = new PodBuilder() .withNewMetadata() .withName("pod") .endMetadata() .withNewSpec() .withContainers(container) .endSpec() .build(); kubernetesEnvironment = KubernetesEnvironment.builder().setPods(ImmutableMap.of("pod", pod)).build(); externalServerExposer = new ExternalServerExposer<>( new MultiHostExternalServiceExposureStrategy(DOMAIN, MULTI_HOST_STRATEGY), emptyMap(), "%s"); }
Example #10
Source File: InitContainerHandler.java From jkube with Eclipse Public License 2.0 | 6 votes |
public void appendInitContainer(PodTemplateSpecBuilder builder, Container initContainer) { String name = initContainer.getName(); Container existing = getInitContainer(builder, name); if (existing != null) { if (existing.equals(initContainer)) { log.warn("Trying to add init-container %s a second time. Ignoring ....", name); return; } else { throw new IllegalArgumentException( String.format("PodSpec %s already contains a different init container with name %s but can not add a second one with the same name. " + "Please choose a different name for the init container", builder.build().getMetadata().getName(), name)); } } ensureSpec(builder); builder.editSpec().addToInitContainers(initContainer).endSpec(); }
Example #11
Source File: BrokerEnvironmentFactoryTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldNameContainersAfterMetadataPluginBrokerImage() throws Exception { // given Collection<PluginFQN> pluginFQNs = singletonList(new PluginFQN(null, "id")); ArgumentCaptor<BrokersConfigs> captor = ArgumentCaptor.forClass(BrokersConfigs.class); // when factory.createForMetadataBroker(pluginFQNs, runtimeId); // then verify(factory).doCreate(captor.capture()); BrokersConfigs brokersConfigs = captor.getValue(); PodSpec brokerPodSpec = brokersConfigs.pods.values().iterator().next().getSpec(); List<Container> containers = brokerPodSpec.getContainers(); assertEquals(containers.size(), 1); assertEquals(containers.get(0).getName(), "metadata-image"); }
Example #12
Source File: FlinkConfMountDecorator.java From flink with Apache License 2.0 | 6 votes |
@Override public FlinkPod decorateFlinkPod(FlinkPod flinkPod) { final Pod mountedPod = decoratePod(flinkPod.getPod()); final Container mountedMainContainer = new ContainerBuilder(flinkPod.getMainContainer()) .addNewVolumeMount() .withName(FLINK_CONF_VOLUME) .withMountPath(kubernetesComponentConf.getFlinkConfDirInPod()) .endVolumeMount() .build(); return new FlinkPod.Builder(flinkPod) .withPod(mountedPod) .withMainContainer(mountedMainContainer) .build(); }
Example #13
Source File: Sample10Test.java From module-ballerina-kubernetes with Apache License 2.0 | 6 votes |
@Test public void validatePizzaDeployment() { Assert.assertNotNull(pizzaDeployment); Assert.assertEquals(pizzaDeployment.getMetadata().getName(), "foodstore"); Assert.assertEquals(pizzaDeployment.getSpec().getReplicas().intValue(), 3); Assert.assertEquals(pizzaDeployment.getSpec().getTemplate().getSpec().getVolumes().size(), 0); Assert.assertEquals(pizzaDeployment.getMetadata().getLabels().get(KubernetesConstants .KUBERNETES_SELECTOR_KEY), PIZZA_SELECTOR); Assert.assertEquals(pizzaDeployment.getSpec().getTemplate().getSpec().getContainers().size(), 1); // Assert Containers Container container = pizzaDeployment.getSpec().getTemplate().getSpec().getContainers().get(0); Assert.assertEquals(container.getVolumeMounts().size(), 0); Assert.assertEquals(container.getImage(), PIZZA_DOCKER_IMAGE); Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name()); Assert.assertEquals(container.getPorts().size(), 1); Assert.assertEquals(container.getEnv().size(), 2); }
Example #14
Source File: KubernetesResourceUtil.java From jkube with Eclipse Public License 2.0 | 6 votes |
private static void ensureHasEnv(Container container, EnvVar envVar) { List<EnvVar> envVars = container.getEnv(); if (envVars == null) { envVars = new ArrayList<>(); container.setEnv(envVars); } for (EnvVar var : envVars) { if (Objects.equals(var.getName(), envVar.getName())) { // lets replace the object so that we can update the value or valueFrom envVars.remove(var); envVars.add(envVar); return; } } envVars.add(envVar); }
Example #15
Source File: KubernetesResourceUtil.java From jkube with Eclipse Public License 2.0 | 6 votes |
public static boolean podHasContainerImage(Pod pod, String imageName) { if (pod != null) { PodSpec spec = pod.getSpec(); if (spec != null) { List<Container> containers = spec.getContainers(); if (containers != null) { for (Container container : containers) { if (Objects.equals(imageName, container.getImage())) { return true; } } } } } return false; }
Example #16
Source File: ContainerResourceProvisionerTest.java From che with Eclipse Public License 2.0 | 6 votes |
@BeforeMethod public void setup() { resourceProvisioner = new ContainerResourceProvisioner(1024, 512, "500m", "100m"); container = new Container(); container.setName(CONTAINER_NAME); when(k8sEnv.getMachines()).thenReturn(of(MACHINE_NAME, internalMachineConfig)); when(internalMachineConfig.getAttributes()) .thenReturn( of( MEMORY_LIMIT_ATTRIBUTE, RAM_LIMIT_VALUE, MEMORY_REQUEST_ATTRIBUTE, RAM_REQUEST_VALUE, CPU_LIMIT_ATTRIBUTE, CPU_LIMIT_VALUE, CPU_REQUEST_ATTRIBUTE, CPU_REQUEST_VALUE)); final ObjectMeta podMetadata = mock(ObjectMeta.class); when(podMetadata.getName()).thenReturn(POD_NAME); final PodSpec podSpec = mock(PodSpec.class); when(podSpec.getContainers()).thenReturn(Collections.singletonList(container)); when(k8sEnv.getPodsData()).thenReturn(of(POD_NAME, new PodData(podSpec, podMetadata))); }
Example #17
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testImagePullPolicyDefault() { KubernetesSchedulerProperties kubernetesSchedulerProperties = new KubernetesSchedulerProperties(); if (kubernetesSchedulerProperties.getNamespace() == null) { kubernetesSchedulerProperties.setNamespace("default"); } KubernetesClient kubernetesClient = new DefaultKubernetesClient() .inNamespace(kubernetesSchedulerProperties.getNamespace()); KubernetesScheduler kubernetesScheduler = new KubernetesScheduler(kubernetesClient, kubernetesSchedulerProperties); AppDefinition appDefinition = new AppDefinition(randomName(), getAppProperties()); ScheduleRequest scheduleRequest = new ScheduleRequest(appDefinition, getSchedulerProperties(), getDeploymentProperties(), getCommandLineArgs(), randomName(), testApplication()); CronJob cronJob = kubernetesScheduler.createCronJob(scheduleRequest); CronJobSpec cronJobSpec = cronJob.getSpec(); Container container = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec().getContainers().get(0); assertEquals("Unexpected default image pull policy", ImagePullPolicy.IfNotPresent, ImagePullPolicy.relaxedValueOf(container.getImagePullPolicy())); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }
Example #18
Source File: KubernetesDockerRunnerPodResourceTest.java From styx with Apache License 2.0 | 6 votes |
@Test public void shouldNotHaveSecretsMountIfNoSecret() { Pod pod = createPod( WORKFLOW_INSTANCE, DockerRunner.RunSpec.simple("eid", "busybox"), EMPTY_SECRET_SPEC); List<Volume> volumes = pod.getSpec().getVolumes(); List<Container> containers = pod.getSpec().getContainers(); assertThat(volumes.size(), is(0)); assertThat(containers.size(), is(2)); assertThat(containers.get(0).getName(), is(MAIN_CONTAINER_NAME)); Container container = containers.get(0); List<VolumeMount> volumeMounts = container.getVolumeMounts(); assertThat(volumeMounts.size(), is(0)); }
Example #19
Source File: KafkaConnectS2IClusterTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Test public void testGenerateDeploymentConfigWithTls() { KafkaConnectS2I resource = new KafkaConnectS2IBuilder(this.resource) .editSpec() .editOrNewTls() .addToTrustedCertificates(new CertSecretSourceBuilder().withSecretName("my-secret").withCertificate("cert.crt").build()) .addToTrustedCertificates(new CertSecretSourceBuilder().withSecretName("my-secret").withCertificate("new-cert.crt").build()) .addToTrustedCertificates(new CertSecretSourceBuilder().withSecretName("my-another-secret").withCertificate("another-cert.crt").build()) .endTls() .endSpec() .build(); KafkaConnectS2ICluster kc = KafkaConnectS2ICluster.fromCrd(resource, VERSIONS); DeploymentConfig dep = kc.generateDeploymentConfig(Collections.EMPTY_MAP, true, null, null); assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().get(1).getName(), is("my-secret")); assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().get(2).getName(), is("my-another-secret")); List<Container> containers = dep.getSpec().getTemplate().getSpec().getContainers(); assertThat(containers.get(0).getVolumeMounts().get(1).getMountPath(), is(KafkaConnectCluster.TLS_CERTS_BASE_VOLUME_MOUNT + "my-secret")); assertThat(containers.get(0).getVolumeMounts().get(2).getMountPath(), is(KafkaConnectCluster.TLS_CERTS_BASE_VOLUME_MOUNT + "my-another-secret")); assertThat(AbstractModel.containerEnvVars(containers.get(0)).get(KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_TRUSTED_CERTS), is("my-secret/cert.crt;my-secret/new-cert.crt;my-another-secret/another-cert.crt")); assertThat(AbstractModel.containerEnvVars(containers.get(0)).get(KafkaConnectCluster.ENV_VAR_KAFKA_CONNECT_TLS), is("true")); }
Example #20
Source File: K8sContainerResolver.java From che with Eclipse Public License 2.0 | 6 votes |
private void provisionMemoryRequest(Container container, CheContainer cheContainer) throws InfrastructureException { String memoryRequest = cheContainer.getMemoryRequest(); if (isNullOrEmpty(memoryRequest)) { return; } try { KubernetesSize.toBytes(memoryRequest); } catch (IllegalArgumentException e) { throw new InfrastructureException( format( "Sidecar memory request field contains illegal value '%s'. Error: '%s'", memoryRequest, e.getMessage())); } Containers.addRamRequest(container, memoryRequest); }
Example #21
Source File: SubPathPrefixesTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldPrefixVolumeMountsSubpathsAndUsePvcNameAsVolumeName() { // when subpathPrefixes.prefixVolumeMountsSubpaths(k8sEnv, WORKSPACE_ID); // then PodSpec podSpec = k8sEnv.getPodsData().get(POD_1_NAME).getSpec(); io.fabric8.kubernetes.api.model.Volume userPodVolume = podSpec.getVolumes().get(0); assertEquals(userPodVolume.getPersistentVolumeClaim().getClaimName(), USER_DATA_PVC_NAME); assertEquals( podSpec.getVolumes().get(0).getPersistentVolumeClaim().getClaimName(), USER_DATA_PVC_NAME); Container initContainer = podSpec.getInitContainers().get(0); VolumeMount initVolumeMount = initContainer.getVolumeMounts().get(0); assertEquals( initVolumeMount.getSubPath(), WORKSPACE_ID + "/" + USER_DATA_PVC_NAME + "/tmp/init/userData"); assertEquals(initVolumeMount.getName(), userPodVolume.getName()); Container container = podSpec.getContainers().get(0); VolumeMount volumeMount = container.getVolumeMounts().get(0); assertEquals( volumeMount.getSubPath(), WORKSPACE_ID + "/" + USER_DATA_PVC_NAME + "/home/user/data"); assertEquals(volumeMount.getName(), userPodVolume.getName()); }
Example #22
Source File: ContainerSearchTest.java From che with Eclipse Public License 2.0 | 6 votes |
@Test public void shouldFindAllContainersIfNotRestricted() { ContainerSearch search = new ContainerSearch(null, null, null); List<Container> results = search.search(testList); Assert.assertEquals(results.size(), 12); assertContainsContainer(results, "container1"); assertContainsContainer(results, "container2"); assertContainsContainer(results, "container3"); assertContainsContainer(results, "container4"); assertContainsContainer(results, "container5"); assertContainsContainer(results, "container6"); assertContainsContainer(results, "container7"); assertContainsContainer(results, "container8"); assertContainsContainer(results, "container9"); assertContainsContainer(results, "container10"); assertContainsContainer(results, "container11"); assertContainsContainer(results, "container12"); }
Example #23
Source File: KubernetesPluginsToolingApplierTest.java From che with Eclipse Public License 2.0 | 5 votes |
private void verifyPortsExposed(Container container, int... ports) { List<ContainerPort> actualPorts = container.getPorts(); List<ContainerPort> expectedPorts = new ArrayList<>(); for (int port : ports) { expectedPorts.add( new ContainerPortBuilder().withContainerPort(port).withProtocol("TCP").build()); } assertEquals(actualPorts, expectedPorts); }
Example #24
Source File: OpenShiftInternalRuntimeTest.java From che with Eclipse Public License 2.0 | 5 votes |
private static Pod mockPod(List<Container> containers) { final Pod pod = mock(Pod.class); final PodSpec spec = mock(PodSpec.class); mockName(POD_NAME, pod); when(spec.getContainers()).thenReturn(containers); when(pod.getSpec()).thenReturn(spec); when(pod.getMetadata().getLabels()) .thenReturn(ImmutableMap.of(POD_SELECTOR, POD_NAME, CHE_ORIGINAL_NAME_LABEL, POD_NAME)); return pod; }
Example #25
Source File: JavaCmdJobManagerDecoratorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testStartCommandWithLogback() throws IOException { KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, "logback.xml"); final Container resultMainContainer = javaCmdJobManagerDecorator.decorateFlinkPod(baseFlinkPod).getMainContainer(); assertEquals(Collections.singletonList(KUBERNETES_ENTRY_PATH), resultMainContainer.getCommand()); final String expectedCommand = getJobManagerExpectedCommand("", logback); final List<String> expectedArgs = Arrays.asList("/bin/bash", "-c", expectedCommand); assertEquals(expectedArgs, resultMainContainer.getArgs()); }
Example #26
Source File: CruiseControlTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Test public void testResources() { Map<String, Quantity> requests = new HashMap<>(2); requests.put("cpu", new Quantity("250m")); requests.put("memory", new Quantity("512Mi")); Map<String, Quantity> limits = new HashMap<>(2); limits.put("cpu", new Quantity("500m")); limits.put("memory", new Quantity("1024Mi")); CruiseControlSpec cruiseControlSpec = new CruiseControlSpecBuilder() .withImage(ccImage) .withResources(new ResourceRequirementsBuilder().withLimits(limits).withRequests(requests).build()) .build(); Kafka resource = new KafkaBuilder(ResourceUtils.createKafkaCluster(namespace, cluster, replicas, image, healthDelay, healthTimeout)) .editSpec() .editKafka() .withVersion(version) .endKafka() .withCruiseControl(cruiseControlSpec) .endSpec() .build(); CruiseControl cc = CruiseControl.fromCrd(resource, VERSIONS); Deployment dep = cc.generateDeployment(true, null, null, null); List<Container> containers = dep.getSpec().getTemplate().getSpec().getContainers(); Container ccContainer = containers.stream().filter(container -> ccImage.equals(container.getImage())).findFirst().get(); assertThat(ccContainer.getResources().getLimits(), is(limits)); assertThat(ccContainer.getResources().getRequests(), is(requests)); }
Example #27
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testEntryPointStyleOverride() throws Exception { KubernetesSchedulerProperties kubernetesSchedulerProperties = new KubernetesSchedulerProperties(); if (kubernetesSchedulerProperties.getNamespace() == null) { kubernetesSchedulerProperties.setNamespace("default"); } KubernetesClient kubernetesClient = new DefaultKubernetesClient() .inNamespace(kubernetesSchedulerProperties.getNamespace()); KubernetesScheduler kubernetesScheduler = new KubernetesScheduler(kubernetesClient, kubernetesSchedulerProperties); String prefix = KubernetesSchedulerProperties.KUBERNETES_SCHEDULER_PROPERTIES_PREFIX; Map<String, String> schedulerProperties = new HashMap<>(getSchedulerProperties()); schedulerProperties.put(prefix + ".entryPointStyle", "boot"); AppDefinition appDefinition = new AppDefinition(randomName(), getAppProperties()); ScheduleRequest scheduleRequest = new ScheduleRequest(appDefinition, schedulerProperties, null, getCommandLineArgs(), randomName(), testApplication()); CronJob cronJob = kubernetesScheduler.createCronJob(scheduleRequest); CronJobSpec cronJobSpec = cronJob.getSpec(); Container container = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec().getContainers().get(0); assertTrue("Environment variables should not be empty", !container.getEnv().isEmpty()); assertTrue("Invalid number of environment variables", container.getEnv().size() > 1); String springApplicationJson = container.getEnv().get(0).getValue(); Map<String, String> springApplicationJsonValues = new ObjectMapper().readValue(springApplicationJson, new TypeReference<HashMap<String, String>>() { }); assertNotNull("SPRING_APPLICATION_JSON should not be null", springApplicationJsonValues); assertEquals("Invalid number of SPRING_APPLICATION_JSON entries", 2, springApplicationJsonValues.size()); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }
Example #28
Source File: DefaultContainerFactoryTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void createCustomReadinessPortFromAppRequest() { int defaultPort = 8080; int readinessPort = 8090; KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties(); DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory( kubernetesDeployerProperties); AppDefinition definition = new AppDefinition("app-test", null); Resource resource = getResource(); Map<String, String> props = new HashMap<>(); props.put("spring.cloud.deployer.kubernetes.readinessProbePort", Integer.toString(readinessPort)); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, resource, props); ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest) .withHostNetwork(true) .withExternalPort(defaultPort); Container container = defaultContainerFactory.create(containerConfiguration); assertNotNull(container); List<ContainerPort> containerPorts = container.getPorts(); assertNotNull(containerPorts); assertTrue("Only two container ports should be set", containerPorts.size() == 2); assertTrue(8080 == containerPorts.get(0).getContainerPort()); assertTrue(8080 == containerPorts.get(0).getHostPort()); assertTrue(8090 == containerPorts.get(1).getContainerPort()); assertTrue(8090 == containerPorts.get(1).getHostPort()); assertTrue(8090 == container.getReadinessProbe().getHttpGet().getPort().getIntVal()); }
Example #29
Source File: DockerimageComponentToWorkspaceApplierTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldProvisionContainerWithMemoryLimitSpecified() throws Exception { // given ComponentImpl dockerimageComponent = new ComponentImpl(); dockerimageComponent.setAlias("jdk"); dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE); dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest"); dockerimageComponent.setMemoryLimit("1G"); // when dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null); // then verify(k8sEnvProvisioner) .provision( eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture()); List<HasMetadata> objects = objectsCaptor.getValue(); assertEquals(objects.size(), 1); assertTrue(objects.get(0) instanceof Deployment); Deployment deployment = (Deployment) objects.get(0); PodTemplateSpec podTemplate = deployment.getSpec().getTemplate(); assertEquals(podTemplate.getSpec().getContainers().size(), 1); Container container = podTemplate.getSpec().getContainers().get(0); Quantity memoryLimit = container.getResources().getLimits().get("memory"); assertEquals(memoryLimit.getAmount(), "1"); assertEquals(memoryLimit.getFormat(), "G"); }
Example #30
Source File: KubernetesServerExposer.java From che with Eclipse Public License 2.0 | 5 votes |
public KubernetesServerExposer( ExternalServerExposer<T> externalServerExposer, SecureServerExposer<T> secureServerExposer, String machineName, PodData pod, Container container, T k8sEnv) { this.externalServerExposer = externalServerExposer; this.secureServerExposer = secureServerExposer; this.machineName = machineName; this.pod = pod; this.container = container; this.k8sEnv = k8sEnv; }