diff --git a/spring-cloud-deployer-kubernetes/pom.xml b/spring-cloud-deployer-kubernetes/pom.xml index dc69c908..e0d467ef 100644 --- a/spring-cloud-deployer-kubernetes/pom.xml +++ b/spring-cloud-deployer-kubernetes/pom.xml @@ -21,7 +21,7 @@ 3.8.0 2.0.2 3.14.9 - 5.12.2 + 5.12.4 @@ -161,6 +161,24 @@ org.apache.maven.plugins maven-checkstyle-plugin + + org.apache.maven.plugins + maven-failsafe-plugin + 3.0.0 + + + **/*IT.* + + + + + + verify + integration-test + + + + diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java index 2c6b3df5..a948510f 100755 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesAppDeployer.java @@ -39,6 +39,7 @@ import io.fabric8.kubernetes.api.model.ServiceList; import io.fabric8.kubernetes.api.model.ServicePort; import io.fabric8.kubernetes.api.model.ServiceSpecBuilder; +import io.fabric8.kubernetes.api.model.StatusDetails; import io.fabric8.kubernetes.api.model.VolumeBuilder; import io.fabric8.kubernetes.api.model.VolumeMountBuilder; import io.fabric8.kubernetes.api.model.apps.Deployment; @@ -51,7 +52,11 @@ import io.fabric8.kubernetes.api.model.apps.StatefulSetSpecBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; +import io.fabric8.kubernetes.client.dsl.PodResource; +import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.RollableScalableResource; import io.fabric8.kubernetes.client.dsl.ScalableResource; +import io.fabric8.kubernetes.client.dsl.ServiceResource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesScheduler.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesScheduler.java index 6b927563..9194493b 100644 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesScheduler.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesScheduler.java @@ -26,9 +26,10 @@ import io.fabric8.kubernetes.api.model.LocalObjectReference; import io.fabric8.kubernetes.api.model.PodSpec; import io.fabric8.kubernetes.api.model.StatusCause; -import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob; -import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJobBuilder; -import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJobList; +import io.fabric8.kubernetes.api.model.StatusDetails; +import io.fabric8.kubernetes.api.model.batch.v1.CronJob; +import io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder; +import io.fabric8.kubernetes.api.model.batch.v1.CronJobList; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientException; @@ -156,7 +157,7 @@ public void validateScheduleName(ScheduleRequest request) { @Override public void unschedule(String scheduleName) { - boolean unscheduled = this.client.batch().cronjobs().withName(scheduleName).delete(); + boolean unscheduled = this.client.batch().v1().cronjobs().withName(scheduleName).delete(); if (!unscheduled) { throw new SchedulerException("Failed to unschedule schedule " + scheduleName + " does not exist."); @@ -173,7 +174,7 @@ public List list(String taskDefinitionName) { @Override public List list() { - CronJobList cronJobList = this.client.batch().cronjobs().list(); + CronJobList cronJobList = this.client.batch().v1().cronjobs().list(); List cronJobs = cronJobList.getItems(); List scheduleInfos = new ArrayList<>(); @@ -244,7 +245,7 @@ protected CronJob createCronJob(ScheduleRequest scheduleRequest) { setImagePullSecret(scheduleRequest, cronJob); - return this.client.batch().cronjobs().create(cronJob); + return this.client.batch().v1().cronjobs().create(cronJob); } protected String getExceptionMessageForField(KubernetesClientException clientException, diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesTaskLauncher.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesTaskLauncher.java index 7f92b756..9d6bc920 100755 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesTaskLauncher.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesTaskLauncher.java @@ -35,6 +35,7 @@ import io.fabric8.kubernetes.api.model.PodSpec; import io.fabric8.kubernetes.api.model.PodStatus; import io.fabric8.kubernetes.api.model.PodTemplateSpec; +import io.fabric8.kubernetes.api.model.StatusDetails; import io.fabric8.kubernetes.api.model.batch.v1.Job; import io.fabric8.kubernetes.api.model.batch.v1.JobBuilder; import io.fabric8.kubernetes.api.model.batch.v1.JobList; @@ -45,6 +46,7 @@ import io.fabric8.kubernetes.client.KubernetesClientException; import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; import io.fabric8.kubernetes.client.dsl.PodResource; +import io.fabric8.kubernetes.client.dsl.ScalableResource; import org.hashids.Hashids; import org.springframework.beans.factory.annotation.Autowired; @@ -393,11 +395,11 @@ private void deleteJob(String id) { if (jobsToDelete == null || ObjectUtils.isEmpty(jobsToDelete.list().getItems())) { logger.warn(String.format("Cannot delete job for task \"%s\" (reason: job does not exist)", id)); + } else { + logger.debug(String.format("Deleting job for task: %s", id)); + boolean deleted = jobsToDelete.delete(); + logger.debug(String.format("Job was%s deleted for task: %s", id, (deleted ? "" : " not"))); } - - logger.debug(String.format("Deleting job for task: %s", id)); - boolean deleted = jobsToDelete.delete(); - logger.debug(String.format("Job was%s deleted for task: %s", id, (deleted ? "" : " not"))); } private void deletePod(String id) { diff --git a/spring-cloud-deployer-kubernetes/src/test/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesSchedulerIT.java b/spring-cloud-deployer-kubernetes/src/test/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesSchedulerIT.java index 2af702c7..73e7f97d 100644 --- a/spring-cloud-deployer-kubernetes/src/test/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesSchedulerIT.java +++ b/spring-cloud-deployer-kubernetes/src/test/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesSchedulerIT.java @@ -37,10 +37,10 @@ import io.fabric8.kubernetes.api.model.StatusCause; import io.fabric8.kubernetes.api.model.StatusDetails; import io.fabric8.kubernetes.api.model.batch.v1.JobSpec; -import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob; -import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJobList; -import io.fabric8.kubernetes.api.model.batch.v1beta1.CronJobSpec; -import io.fabric8.kubernetes.api.model.batch.v1beta1.JobTemplateSpec; +import io.fabric8.kubernetes.api.model.batch.v1.CronJob; +import io.fabric8.kubernetes.api.model.batch.v1.CronJobList; +import io.fabric8.kubernetes.api.model.batch.v1.CronJobSpec; +import io.fabric8.kubernetes.api.model.batch.v1.JobTemplateSpec; import io.fabric8.kubernetes.client.DefaultKubernetesClient; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientException; @@ -241,9 +241,9 @@ public void listScheduleWithExternalCronJobs() { cronJob3.setSpec(cronJobSpec); cronJob3.setMetadata(objectMeta3); cronJobList.setItems(Arrays.asList(cronJob1, cronJob2, cronJob3)); - this.kubernetesClient.batch().cronjobs().create(cronJob1); - this.kubernetesClient.batch().cronjobs().create(cronJob2); - this.kubernetesClient.batch().cronjobs().create(cronJob3); + this.kubernetesClient.batch().v1().cronjobs().create(cronJob1); + this.kubernetesClient.batch().v1().cronjobs().create(cronJob2); + this.kubernetesClient.batch().v1().cronjobs().create(cronJob3); List scheduleInfos = this.scheduler.list(); assertThat(scheduleInfos.size() == 1); assertThat(scheduleInfos.get(0).getScheduleName().equals("job1"));