Skip to content

Commit

Permalink
Update Batch and Cron version from v1beta to v1. (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
corneil authored Apr 3, 2023
1 parent 8503710 commit fef4bd2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
20 changes: 19 additions & 1 deletion spring-cloud-deployer-kubernetes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
<powermock.version>2.0.2</powermock.version>
<okhttp.version>3.14.9</okhttp.version>
<fabric8-kubernetes-client.version>5.12.2</fabric8-kubernetes-client.version>
<fabric8-kubernetes-client.version>5.12.4</fabric8-kubernetes-client.version>
</properties>


Expand Down Expand Up @@ -161,6 +161,24 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<includes>
<include>**/*IT.*</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>verify</goal>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.");
Expand All @@ -173,7 +174,7 @@ public List<ScheduleInfo> list(String taskDefinitionName) {

@Override
public List<ScheduleInfo> list() {
CronJobList cronJobList = this.client.batch().cronjobs().list();
CronJobList cronJobList = this.client.batch().v1().cronjobs().list();

List<CronJob> cronJobs = cronJobList.getItems();
List<ScheduleInfo> scheduleInfos = new ArrayList<>();
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ScheduleInfo> scheduleInfos = this.scheduler.list();
assertThat(scheduleInfos.size() == 1);
assertThat(scheduleInfos.get(0).getScheduleName().equals("job1"));
Expand Down

0 comments on commit fef4bd2

Please sign in to comment.