From 2f14719d91c2f5f500041a6ac57d75fa4c9dd9b5 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 +- .../BackwardsCompatibilityInterceptor.java | 1 + .../kubernetes/examples/CronJobExample.java | 1 + .../java/io/fabric8/kubernetes/CronJobIT.java | 4 +-- .../kubernetes/client/mock/CronJobTest.java | 26 +++++++++---------- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4ff5a93cd1..d64cc855005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ * Fix #1173 : Send response to Callback for exec commands that have no textual feedback + * 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-client/src/main/java/io/fabric8/kubernetes/client/utils/BackwardsCompatibilityInterceptor.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/utils/BackwardsCompatibilityInterceptor.java index 8c7fdbb6e8a..279ba5ea0e9 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/utils/BackwardsCompatibilityInterceptor.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/utils/BackwardsCompatibilityInterceptor.java @@ -106,6 +106,7 @@ public int hashCode() { notFoundTransformations.put(new ResourceKey("Role", "roles", "rbac.authorization.k8s.io", "v1"), new ResourceKey("Role", "roles", "rbac.authorization.k8s.io", "v1beta1")); notFoundTransformations.put(new ResourceKey("ClusterRoleBinding", "clusterrolebindings", "rbac.authorization.k8s.io", "v1"), new ResourceKey("ClusterRoleBinding", "clusterrolebindings", "rbac.authorization.k8s.io", "v1beta1")); notFoundTransformations.put(new ResourceKey("ClusterRole", "clusterroles", "rbac.authorization.k8s.io", "v1"), new ResourceKey("ClusterRole", "clusterroles", "rbac.authorization.k8s.io", "v1beta1")); + notFoundTransformations.put(new ResourceKey("CronJob", "cronjobs", "batch", "v1beta1"), new ResourceKey("CronJob", "cronjob", "batch", "v2alpha1")); badRequestTransformations.put(new ResourceKey("Deployment", "deployments", "apps", "v1beta1"), new ResourceKey("Deployment", "deployments", "extensions", "v1beta1")); 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();