Java Code Examples for io.fabric8.kubernetes.api.model.batch.CronJob#getSpec()
The following examples show how to use
io.fabric8.kubernetes.api.model.batch.CronJob#getSpec() .
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 testEntryPointStyleDefault() 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); 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); assertTrue("Environment variables should only have SPRING_CLOUD_APPLICATION_GUID", container.getEnv().size() == 1); assertTrue("Command line arguments should not be empty", !container.getArgs().isEmpty()); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }
Example 2
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 3
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 4
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
private void testEnvironmentVariables(KubernetesSchedulerProperties kubernetesSchedulerProperties, Map<String, String> schedulerProperties, EnvVar[] expectedVars) { 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, 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()); assertThat(container.getEnv()).contains(expectedVars); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }
Example 5
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 6
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testWithExecEntryPoint() { KubernetesSchedulerProperties kubernetesSchedulerProperties = new KubernetesSchedulerProperties(); if (kubernetesSchedulerProperties.getNamespace() == null) { kubernetesSchedulerProperties.setNamespace("default"); } kubernetesSchedulerProperties.setEntryPointStyle(EntryPointStyle.exec); 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(), null, getCommandLineArgs(), randomName(), testApplication()); CronJob cronJob = kubernetesScheduler.createCronJob(scheduleRequest); CronJobSpec cronJobSpec = cronJob.getSpec(); Container container = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec().getContainers().get(0); assertNotNull("Command line arguments should not be null", container.getArgs()); assertNotNull("Environment variables should not be null", container.getEnv()); assertTrue("Environment variables should only have SPRING_CLOUD_APPLICATION_GUID", container.getEnv().size() == 1); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }
Example 7
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testWithShellEntryPoint() { KubernetesSchedulerProperties kubernetesSchedulerProperties = new KubernetesSchedulerProperties(); if (kubernetesSchedulerProperties.getNamespace() == null) { kubernetesSchedulerProperties.setNamespace("default"); } kubernetesSchedulerProperties.setEntryPointStyle(EntryPointStyle.shell); 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(), null, getCommandLineArgs(), randomName(), testApplication()); CronJob cronJob = kubernetesScheduler.createCronJob(scheduleRequest); CronJobSpec cronJobSpec = cronJob.getSpec(); Container container = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec().getContainers().get(0); assertNotNull("Command line arguments should not be null", container.getArgs()); assertEquals("Invalid number of command line arguments", 0, container.getArgs().size()); assertNotNull("Environment variables should not be null", container.getEnv()); assertTrue("Invalid number of environment variables", container.getEnv().size() > 1); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }
Example 8
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testWithBootEntryPoint() throws IOException { KubernetesSchedulerProperties kubernetesSchedulerProperties = new KubernetesSchedulerProperties(); kubernetesSchedulerProperties.setEntryPointStyle(EntryPointStyle.boot); 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(), null, getCommandLineArgs(), randomName(), testApplication()); CronJob cronJob = kubernetesScheduler.createCronJob(scheduleRequest); CronJobSpec cronJobSpec = cronJob.getSpec(); Container container = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec().getContainers().get(0); assertNotNull("Command line arguments should not be null", container.getArgs()); assertEquals("Invalid number of command line arguments", 2, container.getArgs().size()); assertNotNull("Environment variables should not be null", container.getEnv()); 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 9
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 10
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testImagePullPolicyOverride() { 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 + ".imagePullPolicy", "Always"); 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); assertEquals("Unexpected image pull policy", "Always", container.getImagePullPolicy()); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }
Example 11
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testImagePullSecret() { 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 secretName = "mysecret"; String prefix = KubernetesSchedulerProperties.KUBERNETES_SCHEDULER_PROPERTIES_PREFIX; Map<String, String> schedulerProperties = new HashMap<>(getSchedulerProperties()); schedulerProperties.put(prefix + ".imagePullSecret", secretName); 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(); List<LocalObjectReference> secrets = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec() .getImagePullSecrets(); assertEquals("Unexpected image pull secret", secretName, secrets.get(0).getName()); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }
Example 12
Source File: KubernetesSchedulerTests.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
@Test public void testTaskServiceAccountNameOverride() { 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 taskServiceAccountName = "mysa"; String prefix = KubernetesSchedulerProperties.KUBERNETES_SCHEDULER_PROPERTIES_PREFIX; Map<String, String> schedulerProperties = new HashMap<>(getSchedulerProperties()); schedulerProperties.put(prefix + ".taskServiceAccountName", taskServiceAccountName); 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(); String serviceAccountName = cronJobSpec.getJobTemplate().getSpec().getTemplate().getSpec() .getServiceAccountName(); assertEquals("Unexpected service account name", taskServiceAccountName, serviceAccountName); kubernetesScheduler.unschedule(cronJob.getMetadata().getName()); }