From 477be5dadc86f566704753e2debd2b46bc4492dc Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Mon, 6 Aug 2018 16:06:09 +0530 Subject: [PATCH] Fix #1172 : Use v1beta1 for CronJob --- CHANGELOG.md | 2 ++ .../dsl/internal/CronJobOperationsImpl.java | 2 +- .../kubernetes/examples/CronJobExample.java | 1 + .../java/io/fabric8/kubernetes/CronJobIT.java | 4 +-- .../kubernetes/client/mock/CronJobTest.java | 26 +++++++++---------- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29ff4056370..0d0df49b27a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ * Fix #1165 : Null parameter values when processing a template are now handled properly + * Fix #1172 : Use v1beta1 for CronJob + Improvements * Added Kubernetes/Openshift examples for client.getVersion() diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CronJobOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CronJobOperationsImpl.java index 2ec63445fe5..66f364c2db5 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CronJobOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/CronJobOperationsImpl.java @@ -31,7 +31,7 @@ public class CronJobOperationsImpl extends HasMetadataOperation> { public CronJobOperationsImpl(OkHttpClient client, Config config, String namespace) { - this(client, config, "v2alpha1", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); + this(client, config, "v1beta1", namespace, null, true, null, null, false, -1, new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap(), new TreeMap()); } public CronJobOperationsImpl(OkHttpClient client, Config config, String apiVersion, String namespace, String name, Boolean cascading, CronJob item, String resourceVersion, Boolean reloadingFromServer, long gracePeriodSeconds, Map labels, Map labelsNot, Map labelsIn, Map labelsNotIn, Map fields) { diff --git a/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CronJobExample.java b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CronJobExample.java index 6e181d2e336..a30be95bc35 100644 --- a/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CronJobExample.java +++ b/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/CronJobExample.java @@ -45,6 +45,7 @@ public static void main(String args[]) throws InterruptedException { final String namespace = client.getNamespace(); CronJob cronJob1 = new CronJobBuilder() + .withApiVersion("batch/v1beta1") .withNewMetadata() .withName("hello") .withLabels(Collections.singletonMap("foo", "bar")) diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CronJobIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CronJobIT.java index b46065d2a4e..32c04c8fb7b 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CronJobIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/CronJobIT.java @@ -53,7 +53,7 @@ public class CronJobIT { @Before public void init() { currentNamespace = session.getNamespace(); - cronJob1 = new CronJobBuilder().withNewMetadata() + cronJob1 = new CronJobBuilder().withApiVersion("batch/v1beta1").withNewMetadata() .withName("cronjob1") .endMetadata() .withNewSpec() @@ -74,7 +74,7 @@ public void init() { .endJobTemplate() .endSpec() .build(); - cronJob2 = new CronJobBuilder().withNewMetadata() + cronJob2 = new CronJobBuilder().withApiVersion("batch/v1beta1").withNewMetadata() .withName("cronjob2") .endMetadata() .withNewSpec() diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CronJobTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CronJobTest.java index d598971f19c..666efdfa827 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CronJobTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CronJobTest.java @@ -32,12 +32,12 @@ public class CronJobTest { @Test public void testList() { - server.expect().withPath("/apis/batch/v2alpha1/namespaces/test/cronjobs").andReturn(200, new CronJobListBuilder().build()).once(); - server.expect().withPath("/apis/batch/v2alpha1/namespaces/ns1/cronjobs").andReturn(200, new CronJobListBuilder() + server.expect().withPath("/apis/batch/v1beta1/namespaces/test/cronjobs").andReturn(200, new CronJobListBuilder().build()).once(); + server.expect().withPath("/apis/batch/v1beta1/namespaces/ns1/cronjobs").andReturn(200, new CronJobListBuilder() .addNewItem().and() .addNewItem().and().build()).once(); - server.expect().withPath("/apis/batch/v2alpha1/cronjobs").andReturn(200, new CronJobListBuilder() + server.expect().withPath("/apis/batch/v1beta1/cronjobs").andReturn(200, new CronJobListBuilder() .addNewItem().and() .addNewItem().and() .addNewItem() @@ -59,8 +59,8 @@ public void testList() { @Test public void testListWithLables() { - server.expect().withPath("/apis/batch/v2alpha1/namespaces/test/cronjobs?labelSelector=" + toUrlEncoded("key1=value1,key2=value2,key3=value3")).andReturn(200, new CronJobListBuilder().build()).always(); - server.expect().withPath("/apis/batch/v2alpha1/namespaces/test/cronjobs?labelSelector=" + toUrlEncoded("key1=value1,key2=value2")).andReturn(200, new CronJobListBuilder() + server.expect().withPath("/apis/batch/v1beta1/namespaces/test/cronjobs?labelSelector=" + toUrlEncoded("key1=value1,key2=value2,key3=value3")).andReturn(200, new CronJobListBuilder().build()).always(); + server.expect().withPath("/apis/batch/v1beta1/namespaces/test/cronjobs?labelSelector=" + toUrlEncoded("key1=value1,key2=value2")).andReturn(200, new CronJobListBuilder() .addNewItem().and() .addNewItem().and() .addNewItem().and() @@ -87,8 +87,8 @@ public void testListWithLables() { } @Test public void testGet() { - server.expect().withPath("/apis/batch/v2alpha1/namespaces/test/cronjobs/cronjob1").andReturn(200, new CronJobBuilder().build()).once(); - server.expect().withPath("/apis/batch/v2alpha1/namespaces/ns1/cronjobs/cronjob2").andReturn(200, new CronJobBuilder().build()).once(); + server.expect().withPath("/apis/batch/v1beta1/namespaces/test/cronjobs/cronjob1").andReturn(200, new CronJobBuilder().build()).once(); + server.expect().withPath("/apis/batch/v1beta1/namespaces/ns1/cronjobs/cronjob2").andReturn(200, new CronJobBuilder().build()).once(); KubernetesClient client = server.getClient(); @@ -104,7 +104,7 @@ public void testGet() { @Test public void testDelete() { - server.expect().withPath("/apis/batch/v2alpha1/namespaces/test/cronjobs/cronJob1").andReturn(200, new CronJobBuilder().withNewMetadata() + server.expect().withPath("/apis/batch/v1beta1/namespaces/test/cronjobs/cronJob1").andReturn(200, new CronJobBuilder().withNewMetadata() .withName("cronJob1") .withResourceVersion("1") .endMetadata() @@ -137,7 +137,7 @@ public void testDelete() { .endSpec() .build()).once(); - server.expect().withPath("/apis/batch/v2alpha1/namespaces/test/cronjobs/cronJob2").andReturn(200, new CronJobBuilder().withNewMetadata() + server.expect().withPath("/apis/batch/v1beta1/namespaces/test/cronjobs/cronJob2").andReturn(200, new CronJobBuilder().withNewMetadata() .withName("cronJob2") .withResourceVersion("1") .endMetadata() @@ -201,11 +201,11 @@ public void testDeleteMulti() { .build(); CronJob cronjob3 = new CronJobBuilder().withNewMetadata().withName("cronjob3").withNamespace("any").and().build(); - server.expect().withPath("/apis/batch/v2alpha1/namespaces/test/cronjobs/cronjob1").andReturn(200, cronjob1).once(); - server.expect().withPath("/apis/batch/v2alpha1/namespaces/test/cronjobs/cronjob1").andReturn(200, new CronJobBuilder(cronjob1) + server.expect().withPath("/apis/batch/v1beta1/namespaces/test/cronjobs/cronjob1").andReturn(200, cronjob1).once(); + server.expect().withPath("/apis/batch/v1beta1/namespaces/test/cronjobs/cronjob1").andReturn(200, new CronJobBuilder(cronjob1) .editStatus().endStatus().build()).times(5); - server.expect().withPath("/apis/batch/v2alpha1/namespaces/ns1/cronjobs/cronjob2").andReturn(200, cronjob2).once(); - server.expect().withPath("/apis/batch/v2alpha1/namespaces/ns1/cronjobs/cronjob2").andReturn(200, new CronJobBuilder(cronjob2) + server.expect().withPath("/apis/batch/v1beta1/namespaces/ns1/cronjobs/cronjob2").andReturn(200, cronjob2).once(); + server.expect().withPath("/apis/batch/v1beta1/namespaces/ns1/cronjobs/cronjob2").andReturn(200, new CronJobBuilder(cronjob2) .editStatus().endStatus().build()).times(5); KubernetesClient client = server.getClient();