From df0ca8b7d5e57b96fcd5a4984068f40842049d6f Mon Sep 17 00:00:00 2001 From: James Strachan Date: Thu, 27 Jul 2017 10:40:59 +0100 Subject: [PATCH] improve support for generating jobs --- .gitignore | 1 + .../core/util/KubernetesResourceUtil.java | 7 +++++- .../maven/core/util/ResourceVersioning.java | 22 +++++++++++++++++-- .../core/util/KubernetesResourceUtilTest.java | 9 ++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index b4e98692..37c51d93 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ notes.md .project .classpath .settings +.vscode velocity.log diff --git a/core/src/main/java/io/fabric8/maven/core/util/KubernetesResourceUtil.java b/core/src/main/java/io/fabric8/maven/core/util/KubernetesResourceUtil.java index d4b94d52..84b2dab0 100644 --- a/core/src/main/java/io/fabric8/maven/core/util/KubernetesResourceUtil.java +++ b/core/src/main/java/io/fabric8/maven/core/util/KubernetesResourceUtil.java @@ -117,10 +117,12 @@ public class KubernetesResourceUtil { public static final String API_VERSION = "v1"; public static final String API_EXTENSIONS_VERSION = "extensions/v1beta1"; public static final String API_APPS_VERSION = "apps/v1beta1"; + public static final String JOB_VERSION = "batch/v1"; public static final ResourceVersioning DEFAULT_RESOURCE_VERSIONING = new ResourceVersioning() .withCoreVersion(API_VERSION) .withExtensionsVersion(API_EXTENSIONS_VERSION) - .withAppsVersion(API_APPS_VERSION); + .withAppsVersion(API_APPS_VERSION) + .withJobVersion(JOB_VERSION); public static final HashSet> SIMPLE_FIELD_TYPES = new HashSet<>(); @@ -235,6 +237,7 @@ public class KubernetesResourceUtil { "deployment", "Deployment", "is", "ImageStream", "istag", "ImageStreamTag", + "job", "Job", "lr", "LimitRange", "limitrange", "LimitRange", "ns", "Namespace", @@ -314,6 +317,8 @@ public class KubernetesResourceUtil { apiVersion = apiVersions.getExtensionsVersion(); } else if (Objects.equals(kind, "StatefulSet")) { apiVersion = apiVersions.getAppsVersion(); + } else if (Objects.equals(kind, "Job")) { + apiVersion = apiVersions.getJobVersion(); } addIfNotExistent(fragment, "apiVersion", apiVersion); diff --git a/core/src/main/java/io/fabric8/maven/core/util/ResourceVersioning.java b/core/src/main/java/io/fabric8/maven/core/util/ResourceVersioning.java index c0d00ba9..ef66d0fc 100644 --- a/core/src/main/java/io/fabric8/maven/core/util/ResourceVersioning.java +++ b/core/src/main/java/io/fabric8/maven/core/util/ResourceVersioning.java @@ -27,13 +27,16 @@ public class ResourceVersioning { private String appsVersion; + private String jobVersion; + public ResourceVersioning() { } - public ResourceVersioning(String coreVersion, String extensionsVersion, String appsVersion) { + public ResourceVersioning(String coreVersion, String extensionsVersion, String appsVersion, String jobVersion) { this.coreVersion = coreVersion; this.extensionsVersion = extensionsVersion; this.appsVersion = appsVersion; + this.jobVersion = jobVersion; } public String getCoreVersion() { @@ -60,6 +63,14 @@ public class ResourceVersioning { this.appsVersion = appsVersion; } + public String getJobVersion() { + return jobVersion; + } + + public void setJobVersion(String jobVersion) { + this.jobVersion = jobVersion; + } + public ResourceVersioning withCoreVersion(String coreVersion) { ResourceVersioning c = copy(); c.setCoreVersion(coreVersion); @@ -78,17 +89,24 @@ public class ResourceVersioning { return c; } + public ResourceVersioning withJobVersion(String jobVersion) { + ResourceVersioning c = copy(); + c.setJobVersion(jobVersion); + return c; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder("ResourceVersioning{"); sb.append("coreVersion='").append(coreVersion).append('\''); sb.append(", extensionsVersion='").append(extensionsVersion).append('\''); sb.append(", appsVersion='").append(appsVersion).append('\''); + sb.append(", jobVersion='").append(jobVersion).append('\''); sb.append('}'); return sb.toString(); } protected ResourceVersioning copy() { - return new ResourceVersioning(coreVersion, extensionsVersion, appsVersion); + return new ResourceVersioning(coreVersion, extensionsVersion, appsVersion, jobVersion); } } diff --git a/core/src/test/java/io/fabric8/maven/core/util/KubernetesResourceUtilTest.java b/core/src/test/java/io/fabric8/maven/core/util/KubernetesResourceUtilTest.java index 4368c011..79f83094 100644 --- a/core/src/test/java/io/fabric8/maven/core/util/KubernetesResourceUtilTest.java +++ b/core/src/test/java/io/fabric8/maven/core/util/KubernetesResourceUtilTest.java @@ -31,6 +31,7 @@ import org.junit.Test; import static io.fabric8.maven.core.util.KubernetesResourceUtil.API_VERSION; import static io.fabric8.maven.core.util.KubernetesResourceUtil.DEFAULT_RESOURCE_VERSIONING; +import static io.fabric8.maven.core.util.KubernetesResourceUtil.JOB_VERSION; import static io.fabric8.maven.core.util.KubernetesResourceUtil.getResource; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -86,6 +87,14 @@ public class KubernetesResourceUtilTest { assertEquals("ReplicationController", ret.getKind()); } + + @Test + public void job() throws Exception { + HasMetadata ret = getResource(DEFAULT_RESOURCE_VERSIONING, new File(fabric8Dir, "job.yml"), "app"); + assertEquals("Job", ret.getKind()); + assertEquals(JOB_VERSION, ret.getApiVersion()); + } + @Test public void containsNoKindAndNoTypeInFilename() throws Exception { try {