org.springframework.cloud.deployer.spi.core.AppDefinition Java Examples
The following examples show how to use
org.springframework.cloud.deployer.spi.core.AppDefinition.
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: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testTaskServiceAccountNameDefault() { 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(); String serviceAccountName = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec() .getServiceAccountName(); assertEquals("Unexpected service account name", KubernetesSchedulerProperties.DEFAULT_TASK_SERVICE_ACCOUNT_NAME, serviceAccountName); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }
Example #2
Source File: JavaExecutionCommandBuilderTests.java From spring-cloud-deployer-local with Apache License 2.0 | 6 votes |
@Test public void testCommandBuilderSpringApplicationJson() { LocalDeployerProperties properties = new LocalDeployerProperties(); LocalAppDeployer deployer = new LocalAppDeployer(properties); AppDefinition definition = new AppDefinition("foo", Collections.singletonMap("foo","bar")); deploymentProperties.put(LocalDeployerProperties.DEBUG_PORT, "9999"); deploymentProperties.put(LocalDeployerProperties.DEBUG_SUSPEND, "y"); deploymentProperties.put(LocalDeployerProperties.INHERIT_LOGGING, "true"); AppDeploymentRequest request = new AppDeploymentRequest(definition, testResource(), deploymentProperties); ProcessBuilder builder = deployer.buildProcessBuilder(request, definition.getProperties(), Optional.of(1), "foo" ); assertThat(builder.environment().keySet(), hasItem(AbstractLocalDeployerSupport.SPRING_APPLICATION_JSON)); assertThat(builder.environment().get(AbstractLocalDeployerSupport.SPRING_APPLICATION_JSON), is("{\"foo\":\"bar\"}")); }
Example #3
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void deployWithEnvironmentWithMultipleCommaDelimitedValue() throws Exception { AppDefinition definition = new AppDefinition("app-test", null); Map<String, String> props = new HashMap<>(); props.put("spring.cloud.deployer.kubernetes.environmentVariables", "JAVA_TOOL_OPTIONS='thing1,thing2',OPTS='thing3, thing4'"); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props); deployer = new KubernetesAppDeployer(bindDeployerProperties(), null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); assertThat(podSpec.getContainers().get(0).getEnv()) .contains( new EnvVar("JAVA_TOOL_OPTIONS", "thing1,thing2", null), new EnvVar("OPTS", "thing3, thing4", null)); }
Example #4
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testPodSecurityContextGlobalProperty() { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null); KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties(); KubernetesDeployerProperties.PodSecurityContext securityContext = new KubernetesDeployerProperties.PodSecurityContext(); securityContext.setFsGroup(65534L); securityContext.setRunAsUser(65534L); kubernetesDeployerProperties.setPodSecurityContext(securityContext); deployer = new KubernetesAppDeployer(kubernetesDeployerProperties, null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); PodSecurityContext podSecurityContext = podSpec.getSecurityContext(); assertNotNull("Pod security context should not be null", podSecurityContext); assertEquals("Unexpected run as user", Long.valueOf("65534"), podSecurityContext.getRunAsUser()); assertEquals("Unexpected fs group", Long.valueOf("65534"), podSecurityContext.getFsGroup()); }
Example #5
Source File: LocalAppDeployerIntegrationTests.java From spring-cloud-deployer-local with Apache License 2.0 | 6 votes |
@Test public void testFailureToCallShutdownOnUndeploy() { Map<String, String> properties = new HashMap<>(); // disable shutdown endpoint properties.put("endpoints.shutdown.enabled", "false"); AppDefinition definition = new AppDefinition(randomName(), properties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); log.info("Deploying {}...", request.getDefinition().getName()); String deploymentId = appDeployer().deploy(request); Timeout timeout = deploymentTimeout(); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<AppStatus>hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause)); log.info("Undeploying {}...", deploymentId); timeout = undeploymentTimeout(); appDeployer().undeploy(deploymentId); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<AppStatus>hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause)); }
Example #6
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testImagePullSecretDefault() { 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(); List<LocalObjectReference> secrets = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec() .getImagePullSecrets(); assertTrue("There should be no secrets", secrets.isEmpty()); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }
Example #7
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testSchedulerPropertiesMerge() { final String baseScheduleName = "test-schedule1"; Map<String, String> schedulerProperties = new HashMap<>(); schedulerProperties.put(CRON_EXPRESSION, "0/10 * * * *"); schedulerProperties.put(KubernetesSchedulerProperties.KUBERNETES_SCHEDULER_PROPERTIES_PREFIX + ".imagePullPolicy", "Never"); Map<String, String> deploymentProperties = new HashMap<>(); deploymentProperties.put(KubernetesDeployerProperties.KUBERNETES_DEPLOYER_PROPERTIES_PREFIX + ".environmentVariables", "MYVAR1=MYVAL1,MYVAR2=MYVAL2"); deploymentProperties.put(KubernetesDeployerProperties.KUBERNETES_DEPLOYER_PROPERTIES_PREFIX + ".imagePullPolicy", "Always"); AppDefinition appDefinition = new AppDefinition(randomName(), null); ScheduleRequest scheduleRequest = new ScheduleRequest(appDefinition, schedulerProperties, deploymentProperties, null, baseScheduleName, testApplication()); Map<String, String> mergedProperties = KubernetesScheduler.mergeSchedulerProperties(scheduleRequest); assertTrue("Expected value from Scheduler properties, but found in Deployer properties", mergedProperties.get(KubernetesSchedulerProperties.KUBERNETES_SCHEDULER_PROPERTIES_PREFIX + ".imagePullPolicy").equals("Never")); assertTrue("Deployer property is expected to be merged as scheduler property", mergedProperties.get(KubernetesSchedulerProperties.KUBERNETES_SCHEDULER_PROPERTIES_PREFIX + ".environmentVariables").equals("MYVAR1=MYVAL1,MYVAR2=MYVAL2")); }
Example #8
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testPodSecurityContextPropertyOverrideGlobal() { Map<String, String> props = new HashMap<>(); props.put("spring.cloud.deployer.kubernetes.podSecurityContext", "{runAsUser: 65534, fsGroup: 65534}"); AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props); KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties(); KubernetesDeployerProperties.PodSecurityContext securityContext = new KubernetesDeployerProperties.PodSecurityContext(); securityContext.setFsGroup(1000L); securityContext.setRunAsUser(1000L); kubernetesDeployerProperties.setPodSecurityContext(securityContext); deployer = new KubernetesAppDeployer(kubernetesDeployerProperties, null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); PodSecurityContext podSecurityContext = podSpec.getSecurityContext(); assertNotNull("Pod security context should not be null", podSecurityContext); assertEquals("Unexpected run as user", Long.valueOf("65534"), podSecurityContext.getRunAsUser()); assertEquals("Unexpected fs group", Long.valueOf("65534"), podSecurityContext.getFsGroup()); }
Example #9
Source File: AbstractTaskLauncherIntegrationTests.java From spring-cloud-deployer with Apache License 2.0 | 6 votes |
@Test public void testSimpleLaunch() throws InterruptedException { Map<String, String> appProperties = new HashMap<>(); appProperties.put("killDelay", "0"); appProperties.put("exitCode", "0"); AppDefinition definition = new AppDefinition(randomName(), appProperties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); log.info("Launching {}...", request.getDefinition().getName()); String launchId = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(launchId, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.complete))), timeout.maxAttempts, timeout.pause)); taskLauncher().destroy(definition.getName()); }
Example #10
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testSecretKeyRefGlobalFromYaml() throws Exception { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null); deployer = new KubernetesAppDeployer(bindDeployerProperties(), null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); List<EnvVar> envVars = podSpec.getContainers().get(0).getEnv(); assertEquals("Invalid number of env vars", 3, envVars.size()); EnvVar secretKeyRefEnvVar = envVars.get(0); assertEquals("Unexpected env var name", "SECRET_PASSWORD", secretKeyRefEnvVar.getName()); SecretKeySelector secretKeySelector = secretKeyRefEnvVar.getValueFrom().getSecretKeyRef(); assertEquals("Unexpected secret name", "mySecret", secretKeySelector.getName()); assertEquals("Unexpected secret data key", "myPassword", secretKeySelector.getKey()); }
Example #11
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testPodSecurityContextUIDOnly() { Map<String, String> props = new HashMap<>(); props.put("spring.cloud.deployer.kubernetes.podSecurityContext", "{runAsUser: 65534}"); AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props); deployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(), null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); PodSecurityContext podSecurityContext = podSpec.getSecurityContext(); assertNotNull("Pod security context should not be null", podSecurityContext); assertEquals("Unexpected run as user", Long.valueOf("65534"), podSecurityContext.getRunAsUser()); assertNull("Unexpected fs group", podSecurityContext.getFsGroup()); }
Example #12
Source File: AbstractAppDeployerIntegrationTests.java From spring-cloud-deployer with Apache License 2.0 | 6 votes |
/** * Tests that an app which takes a long time to deploy is correctly reported as deploying. * Test that such an app can be undeployed. */ @Test public void testDeployingStateCalculationAndCancel() { Map<String, String> properties = new HashMap<>(); properties.put("initDelay", "" + 1000 * 60 * 60); // 1hr AppDefinition definition = new AppDefinition(randomName(), properties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, properties); log.info("Deploying {}...", request.getDefinition().getName()); String deploymentId = appDeployer().deploy(request); Timeout timeout = deploymentTimeout(); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<AppStatus>hasProperty("state", is(deploying))), timeout.maxAttempts, timeout.pause)); log.info("Undeploying {}...", deploymentId); timeout = undeploymentTimeout(); appDeployer().undeploy(deploymentId); assertThat(deploymentId, eventually(hasStatusThat( Matchers.<AppStatus>hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause)); }
Example #13
Source File: LocalTaskLauncherIntegrationTests.java From spring-cloud-deployer-local with Apache License 2.0 | 6 votes |
@Test public void testAppLogRetrieval() { Map<String, String> appProperties = new HashMap<>(); appProperties.put("killDelay", "0"); appProperties.put("exitCode", "0"); AppDefinition definition = new AppDefinition(randomName(), appProperties); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); String launchId1 = taskLauncher().launch(request); Timeout timeout = deploymentTimeout(); assertThat(launchId1, eventually(hasStatusThat( Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.complete))), timeout.maxAttempts, timeout.pause)); String logContent = taskLauncher().getLog(launchId1); assertThat(logContent, containsString("Starting DeployerIntegrationTestApplication")); }
Example #14
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testConfigMapKeyRef() { Map<String, String> props = new HashMap<>(); props.put("spring.cloud.deployer.kubernetes.configMapKeyRefs", "[{envVarName: 'MY_ENV', configMapName: 'myConfigMap', dataKey: 'envName'}]"); AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props); deployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(), null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); List<EnvVar> envVars = podSpec.getContainers().get(0).getEnv(); assertEquals("Invalid number of env vars", 2, envVars.size()); EnvVar configMapKeyRefEnvVar = envVars.get(0); assertEquals("Unexpected env var name", "MY_ENV", configMapKeyRefEnvVar.getName()); ConfigMapKeySelector configMapKeySelector = configMapKeyRefEnvVar.getValueFrom().getConfigMapKeyRef(); assertEquals("Unexpected config map name", "myConfigMap", configMapKeySelector.getName()); assertEquals("Unexpected config map data key", "envName", configMapKeySelector.getKey()); }
Example #15
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testPodAffinityGlobalProperty() { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null); KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties(); LabelSelector labelSelector = new LabelSelector(); labelSelector.setMatchExpressions(Arrays.asList(new LabelSelectorRequirementBuilder() .withKey("security") .withOperator("In") .withValues("S1") .build())); PodAffinityTerm podAffinityTerm = new PodAffinityTerm(labelSelector, null, "failure-domain.beta.kubernetes.io/zone"); LabelSelector labelSelector2 = new LabelSelector(); labelSelector2.setMatchExpressions(Arrays.asList(new LabelSelectorRequirementBuilder() .withKey("security") .withOperator("In") .withValues("s2") .build())); PodAffinityTerm podAffinityTerm2 = new PodAffinityTerm(labelSelector2, null, "failure-domain.beta.kubernetes.io/zone"); WeightedPodAffinityTerm weightedPodAffinityTerm = new WeightedPodAffinityTerm(podAffinityTerm2, 100); PodAffinity podAffinity = new AffinityBuilder() .withNewPodAffinity() .withRequiredDuringSchedulingIgnoredDuringExecution(podAffinityTerm) .withPreferredDuringSchedulingIgnoredDuringExecution(weightedPodAffinityTerm) .endPodAffinity() .buildPodAffinity(); kubernetesDeployerProperties.setPodAffinity(podAffinity); deployer = new KubernetesAppDeployer(kubernetesDeployerProperties, null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); PodAffinity podAffinityTest = podSpec.getAffinity().getPodAffinity(); assertNotNull("Pod affinity should not be null", podAffinityTest); assertNotNull("RequiredDuringSchedulingIgnoredDuringExecution should not be null", podAffinityTest.getRequiredDuringSchedulingIgnoredDuringExecution()); assertEquals("PreferredDuringSchedulingIgnoredDuringExecution should have one element", 1, podAffinityTest.getPreferredDuringSchedulingIgnoredDuringExecution().size()); }
Example #16
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testNodeAffinityFromYaml() throws Exception { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null); deployer = new KubernetesAppDeployer(bindDeployerProperties(), null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); NodeAffinity nodeAffinity = podSpec.getAffinity().getNodeAffinity(); assertNotNull("Node affinity should not be null", nodeAffinity); assertNotNull("RequiredDuringSchedulingIgnoredDuringExecution should not be null", nodeAffinity.getRequiredDuringSchedulingIgnoredDuringExecution()); assertEquals("PreferredDuringSchedulingIgnoredDuringExecution should have one element", 1, nodeAffinity.getPreferredDuringSchedulingIgnoredDuringExecution().size()); }
Example #17
Source File: KubernetesAppDeployerIntegrationTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testScaleDeployment() { log.info("Testing {}...", "ScaleDeployment"); KubernetesDeployerProperties deployProperties = new KubernetesDeployerProperties(); ContainerFactory containerFactory = new DefaultContainerFactory(deployProperties); KubernetesAppDeployer appDeployer = new KubernetesAppDeployer(deployProperties, kubernetesClient, containerFactory); AppDefinition definition = new AppDefinition(randomName(), null); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, Collections.emptyMap()); log.info("Deploying {}...", request.getDefinition().getName()); Timeout timeout = deploymentTimeout(); String deploymentId = appDeployer.deploy(request); assertThat(deploymentId, eventually(hasStatusThat( Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause)); assertThat(deploymentId, eventually(appInstanceCount(is(1)))); log.info("Scale Up {}...", request.getDefinition().getName()); appDeployer.scale(new AppScaleRequest(deploymentId, 3)); assertThat(deploymentId, eventually(appInstanceCount(is(3)), timeout.maxAttempts, timeout.pause)); log.info("Scale Down {}...", request.getDefinition().getName()); appDeployer.scale(new AppScaleRequest(deploymentId, 1)); assertThat(deploymentId, eventually(appInstanceCount(is(1)), timeout.maxAttempts, timeout.pause)); appDeployer.undeploy(deploymentId); }
Example #18
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testPodAffinityFromYaml() throws Exception { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null); deployer = new KubernetesAppDeployer(bindDeployerProperties(), null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); PodAffinity podAffinity = podSpec.getAffinity().getPodAffinity(); assertNotNull("Pod affinity should not be null", podAffinity); assertNotNull("RequiredDuringSchedulingIgnoredDuringExecution should not be null", podAffinity.getRequiredDuringSchedulingIgnoredDuringExecution()); assertEquals("PreferredDuringSchedulingIgnoredDuringExecution should have one element", 1, podAffinity.getPreferredDuringSchedulingIgnoredDuringExecution().size()); }
Example #19
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testPodAffinityProperty() { Map<String, String> props = new HashMap<>(); props.put("spring.cloud.deployer.kubernetes.affinity.podAffinity", "{ requiredDuringSchedulingIgnoredDuringExecution:" + " { labelSelector:" + " [ { matchExpressions:" + " [ { key: 'app', " + " operator: 'In'," + " values:" + " [ 'store']}]}], " + " topologyKey: 'kubernetes.io/hostname'}, " + " preferredDuringSchedulingIgnoredDuringExecution:" + " [ { weight: 1," + " podAffinityTerm:" + " { labelSelector:" + " { matchExpressions:" + " [ { key: 'security'," + " operator: 'In'," + " values:" + " [ 'S2' ]}]}, " + " topologyKey: 'failure-domain.beta.kubernetes.io/zone'}}]}"); AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props); deployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(), null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); PodAffinity podAffinity = podSpec.getAffinity().getPodAffinity(); assertNotNull("Pod affinity should not be null", podAffinity); assertNotNull("RequiredDuringSchedulingIgnoredDuringExecution should not be null", podAffinity.getRequiredDuringSchedulingIgnoredDuringExecution()); assertEquals("PreferredDuringSchedulingIgnoredDuringExecution should have one element", 1, podAffinity.getPreferredDuringSchedulingIgnoredDuringExecution().size()); }
Example #20
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testConfigMapKeyRefMultiple() { Map<String, String> props = new HashMap<>(); props.put("spring.cloud.deployer.kubernetes.configMapKeyRefs", "[{envVarName: 'MY_ENV', configMapName: 'myConfigMap', dataKey: 'envName'}," + "{envVarName: 'ENV_VALUES', configMapName: 'myOtherConfigMap', dataKey: 'diskType'}]"); AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props); deployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(), null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); List<EnvVar> envVars = podSpec.getContainers().get(0).getEnv(); assertEquals("Invalid number of env vars", 3, envVars.size()); EnvVar configMapKeyRefEnvVar = envVars.get(0); assertEquals("Unexpected env var name", "MY_ENV", configMapKeyRefEnvVar.getName()); ConfigMapKeySelector configMapKeySelector = configMapKeyRefEnvVar.getValueFrom().getConfigMapKeyRef(); assertEquals("Unexpected config map name", "myConfigMap", configMapKeySelector.getName()); assertEquals("Unexpected config map data key", "envName", configMapKeySelector.getKey()); configMapKeyRefEnvVar = envVars.get(1); assertEquals("Unexpected env var name", "ENV_VALUES", configMapKeyRefEnvVar.getName()); configMapKeySelector = configMapKeyRefEnvVar.getValueFrom().getConfigMapKeyRef(); assertEquals("Unexpected config map name", "myOtherConfigMap", configMapKeySelector.getName()); assertEquals("Unexpected config map data key", "diskType", configMapKeySelector.getKey()); }
Example #21
Source File: KubernetesAppDeployerIntegrationTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testDefaultServicePortOverride() { log.info("Testing {}...", "DefaultServicePortOverride"); KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(), kubernetesClient); AppDefinition definition = new AppDefinition(randomName(), Collections.singletonMap("server.port", "9090")); Resource resource = testApplication(); AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); log.info("Deploying {}...", request.getDefinition().getName()); String deploymentId = kubernetesAppDeployer.deploy(request); Timeout timeout = deploymentTimeout(); assertThat(deploymentId, eventually(hasStatusThat( Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause)); List<ServicePort> servicePorts = kubernetesClient.services().withName(request.getDefinition().getName()).get() .getSpec().getPorts(); assertThat(servicePorts, is(notNullValue())); assertThat(servicePorts.size(), is(1)); assertTrue(servicePorts.stream().anyMatch(o -> o.getPort().equals(9090))); assertTrue(servicePorts.stream().anyMatch(o -> o.getName().equals("port-9090"))); log.info("Undeploying {}...", deploymentId); timeout = undeploymentTimeout(); kubernetesAppDeployer.undeploy(deploymentId); assertThat(deploymentId, eventually(hasStatusThat( Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause)); }
Example #22
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void deployWithTolerations() throws Exception { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), new HashMap<>()); deployer = new KubernetesAppDeployer(bindDeployerProperties(), null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); assertThat(podSpec.getTolerations()).isNotEmpty(); }
Example #23
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testPodSecurityContextFromYaml() throws Exception { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null); deployer = new KubernetesAppDeployer(bindDeployerProperties(), null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); PodSecurityContext podSecurityContext = podSpec.getSecurityContext(); assertNotNull("Pod security context should not be null", podSecurityContext); assertEquals("Unexpected run as user", Long.valueOf("65534"), podSecurityContext.getRunAsUser()); assertEquals("Unexpected fs group", Long.valueOf("65534"), podSecurityContext.getFsGroup()); }
Example #24
Source File: CloudFoundryAppDeployerTests.java From spring-cloud-deployer-cloudfoundry with Apache License 2.0 | 5 votes |
@Test public void automaticallyConfigureForCfEnv() throws JsonProcessingException { Resource resource = new FileSystemResource("src/test/resources/log-sink-rabbit-3.0.0.BUILD-SNAPSHOT.jar"); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(new AppDefinition("test-application", Collections.EMPTY_MAP), resource, Collections.EMPTY_MAP); Map<String, String> env = deployer.getEnvironmentVariables("test-application-id", appDeploymentRequest); assertThat(env, hasEntry(CfEnvConfigurer.JBP_CONFIG_SPRING_AUTO_RECONFIGURATION, CfEnvConfigurer.ENABLED_FALSE)); assertThat(env, hasKey(equalTo("SPRING_APPLICATION_JSON"))); ObjectMapper objectMapper = new ObjectMapper(); Map<String, String> saj = objectMapper.readValue(env.get("SPRING_APPLICATION_JSON"),HashMap.class); assertThat(saj, hasEntry(CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN, CfEnvConfigurer.CLOUD_PROFILE_NAME)); }
Example #25
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testInvalidMultipleDeploymentLabelDelimiter() { Map<String, String> props = Collections.singletonMap("spring.cloud.deployer.kubernetes.deploymentLabels", "label1:value1 label2:value2"); AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props); this.deploymentPropertiesResolver.getDeploymentLabels(appDeploymentRequest.getDeploymentProperties()); }
Example #26
Source File: DefaultContainerFactoryTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void createProbesWithOverrides() { KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties(); DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory( kubernetesDeployerProperties); Map<String,String> appProperties = new HashMap<>(); appProperties.put("spring.cloud.deployer.kubernetes.livenessProbePath", "/liveness"); appProperties.put("spring.cloud.deployer.kubernetes.readinessProbePath", "/readiness"); AppDefinition definition = new AppDefinition("app-test", appProperties); Resource resource = getResource(); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, resource, appProperties); ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest) .withHostNetwork(true) .withExternalPort(8080); Container container = defaultContainerFactory.create(containerConfiguration); assertNotNull(container); assertNotNull(container.getReadinessProbe().getHttpGet().getPath()); assertEquals("/readiness", container.getReadinessProbe().getHttpGet().getPath()); assertNotNull(container.getLivenessProbe().getHttpGet().getPath()); assertEquals("/liveness", container.getLivenessProbe().getHttpGet().getPath()); }
Example #27
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void deployWithDuplicateGlobalToleration() { AppDefinition definition = new AppDefinition("app-test", null); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null); KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties(); KubernetesDeployerProperties.Toleration toleration1 = new KubernetesDeployerProperties.Toleration(); toleration1.setEffect("NoSchedule"); toleration1.setKey("test"); toleration1.setOperator("Equal"); toleration1.setTolerationSeconds(5L); toleration1.setValue("false"); kubernetesDeployerProperties.getTolerations().add(toleration1); KubernetesDeployerProperties.Toleration toleration2 = new KubernetesDeployerProperties.Toleration(); toleration2.setEffect("NoSchedule"); toleration2.setKey("test"); toleration2.setOperator("Equal"); toleration2.setTolerationSeconds(5L); toleration2.setValue("true"); kubernetesDeployerProperties.getTolerations().add(toleration2); deployer = new KubernetesAppDeployer(kubernetesDeployerProperties, null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); assertNotNull(podSpec.getTolerations()); assertThat(podSpec.getTolerations().size() == 1); assertThat(podSpec.getTolerations().contains(new Toleration("NoSchedule", "test2", "Equal", 5L, "true"))); }
Example #28
Source File: KubernetesAppDeployerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void deployWithTolerationPropertyOverride() { AppDefinition definition = new AppDefinition("app-test", null); Map<String, String> props = new HashMap<>(); props.put("spring.cloud.deployer.kubernetes.tolerations", "[{key: 'test', value: 'true', operator: 'Equal', effect: 'NoSchedule', tolerationSeconds: 5}, " + "{key: 'test2', value: 'false', operator: 'Equal', effect: 'NoSchedule', tolerationSeconds: 5}]"); AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props); KubernetesDeployerProperties.Toleration toleration = new KubernetesDeployerProperties.Toleration(); toleration.setEffect("NoSchedule"); toleration.setKey("test"); toleration.setOperator("Equal"); toleration.setTolerationSeconds(5L); toleration.setValue("false"); KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties(); kubernetesDeployerProperties.getTolerations().add(toleration); deployer = new KubernetesAppDeployer(kubernetesDeployerProperties, null); PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest); assertNotNull(podSpec.getTolerations()); assertThat(podSpec.getTolerations().size() == 2); assertThat(podSpec.getTolerations().contains(new Toleration("NoSchedule", "test", "Equal", 5L, "true"))); assertThat(podSpec.getTolerations().contains(new Toleration("NoSchedule", "test2", "Equal", 5L, "false"))); }
Example #29
Source File: AbstractSchedulerIntegrationTests.java From spring-cloud-deployer with Apache License 2.0 | 5 votes |
@Test public void testInvalidCronExpression() { final String INVALID_EXPRESSION = "BAD"; String definitionName = randomName(); String scheduleName = scheduleName() + definitionName; Map<String, String> properties = new HashMap<>(getSchedulerProperties()); properties.put(SchedulerPropertyKeys.CRON_EXPRESSION, INVALID_EXPRESSION); AppDefinition definition = new AppDefinition(definitionName, properties); ScheduleRequest request = new ScheduleRequest(definition, properties, getDeploymentProperties(), getCommandLineArgs(), scheduleName, testApplication()); this.expectedException.expect(CreateScheduleException.class); taskScheduler().schedule(request); }
Example #30
Source File: AppDeploymentRequestFactory.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
/** * Creates an {@link AppDeploymentRequest}. * * @param applicationSpec the Spring Cloud Deployer application spec * @param releaseName the release name * @param version the release version * @return a created AppDeploymentRequest */ public AppDeploymentRequest createAppDeploymentRequest(SpringCloudDeployerApplicationManifest applicationSpec, String releaseName, String version) { SpringCloudDeployerApplicationSpec spec = applicationSpec.getSpec(); Map<String, String> applicationProperties = new TreeMap<>(); if (spec.getApplicationProperties() != null) { applicationProperties.putAll(spec.getApplicationProperties()); } // we need to keep group name same for consumer groups not getting broken, but // app name needs to differentiate as otherwise it may result same deployment id and // failure on a deployer. AppDefinition appDefinition = new AppDefinition(applicationSpec.getApplicationName() + "-v" + version, applicationProperties); Resource resource; try { resource = delegatingResourceLoader.getResource(getResourceLocation(spec.getResource(), spec.getVersion())); } catch (Exception e) { throw new SkipperException( "Could not load Resource " + spec.getResource() + ". Message = " + e.getMessage(), e); } Map<String, String> deploymentProperties = new TreeMap<>(); if (spec.getDeploymentProperties() != null) { deploymentProperties.putAll(spec.getDeploymentProperties()); } if (!deploymentProperties.containsKey(AppDeployer.GROUP_PROPERTY_KEY)) { logger.debug("Defaulting spring.cloud.deployer.group=" + releaseName); deploymentProperties.put(AppDeployer.GROUP_PROPERTY_KEY, releaseName); } AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(appDefinition, resource, deploymentProperties); return appDeploymentRequest; }