improve support for generating jobs

This commit is contained in:
James Strachan 2017-07-27 10:40:59 +01:00
Родитель 2da074a817
Коммит df0ca8b7d5
4 изменённых файлов: 36 добавлений и 3 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -7,4 +7,5 @@ notes.md
.project
.classpath
.settings
.vscode
velocity.log

Просмотреть файл

@ -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<Class<?>> 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);

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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 {