From 2b34132b693e4d35b5d529ee5eaa2b4cf6c027cf Mon Sep 17 00:00:00 2001 From: Steve Hawkins Date: Thu, 6 Oct 2022 09:51:18 -0400 Subject: [PATCH] fix #4478: status handling was inserting an explicit missing node --- CHANGELOG.md | 11 +++++---- .../client/server/mock/crud/PatchHandler.java | 2 +- .../client/server/mock/crud/PutHandler.java | 4 ++-- .../client/mock/CustomResourceCrudTest.java | 24 +++++++++++++++++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 935c47ce644..c1488ee2edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,17 +3,18 @@ ### 6.2-SNAPSHOT #### Bugs +* Fix #3733: The authentication command from the .kube/config won't be discarded if no arguments are specified * Fix #4312: fix timestamp can't be deserialized for IstioCondition * Fix #4369: Informers will retry with a backoff on list/watch failure as they did in 5.12 and prior. -* Fix #4350: SchemaSwap annotation is now repeatable and is applied multiple times if classes are used more than once in the class hierarchy. -* Fix #3733: The authentication command from the .kube/config won't be discarded if no arguments are specified -* Fix #4460: removing split packages. Converting Default clients into adapters rather than real instances. +* Fix #4426: [java-generator] Encode an `AnyType` instead of an Object if `x-kubernetes-preserve-unknown-fields` is present and the type is null. * Fix #4441: corrected patch base handling for the patch methods available from a Resource - resource(item).patch() will be evaluated as resource(latest).patch(item). Also undeprecated patch(item), which is consistent with leaving patch(context, item) undeprecated as well. For consistency with the other operations (such as edit), patch(item) will use the context item as the base when available, or the server side item when not. This means that patch(item) is only the same as resource(item).patch() when the patch(item) is called when the context item is missing or is the same as the latest. * Fix #4442: TokenRefreshInterceptor doesn't overwrite existing OAuth token with empty string +* Fix #4350: SchemaSwap annotation is now repeatable and is applied multiple times if classes are used more than once in the class hierarchy. * Fix #4459: Fixed OSGi startup exceptions while using KubernetesClient/OpenShiftClient -* Fix #4482: Fixing blocking behavior of okhttp log watch +* Fix #4460: removing split packages. Converting Default clients into adapters rather than real instances. * Fix #4473: Fix regression in backoff interval introduced in #4365 -* Fix #4426: [java-generator] Encode an `AnyType` instead of an Object if `x-kubernetes-preserve-unknown-fields` is present and the type is null. +* Fix #4478: Removing the resourceVersion bump with null status +* Fix #4482: Fixing blocking behavior of okhttp log watch #### Improvements * Fix #4471: Adding KubernetesClientBuilder.withHttpClientBuilderConsumer to further customize the HttpClient for any implementation. diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PatchHandler.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PatchHandler.java index a3bba34b44f..544d808ca64 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PatchHandler.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PatchHandler.java @@ -67,7 +67,7 @@ public MockResponse handle(String path, String contentType, String requestBody) final JsonNode updatedResource; if (isStatusPath(path)) { updatedResource = currentResource.deepCopy(); - setStatus(updatedResource, fullPatch.path(STATUS)); + setStatus(updatedResource, fullPatch.get(STATUS)); } else { updatedResource = fullPatch; // preserve original status (PATCH requests to the custom resource ignore changes to the status stanza) diff --git a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PutHandler.java b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PutHandler.java index 774cbe92162..47d456938d7 100644 --- a/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PutHandler.java +++ b/junit/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/crud/PutHandler.java @@ -48,12 +48,12 @@ public MockResponse handle(String path, String contentType, String requestBody) final JsonNode updatedResource; if (isStatusPath(path)) { updatedResource = currentResource.deepCopy(); - setStatus(updatedResource, persistence.asNode(requestBody).path(STATUS)); + setStatus(updatedResource, persistence.asNode(requestBody).get(STATUS)); } else { updatedResource = persistence.asNode(requestBody); // preserve original status (PUT requests to the custom resource ignore changes to the status stanza) if (persistence.isStatusSubresourceEnabledForResource(path)) { - setStatus(updatedResource, currentResource.path(STATUS)); + setStatus(updatedResource, currentResource.get(STATUS)); } } validatePath(attributes, updatedResource); diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceCrudTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceCrudTest.java index 8f75d6bbed7..ee0c0b4cc14 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceCrudTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceCrudTest.java @@ -195,6 +195,30 @@ void testStatusPatch() { assertNotNull(result.getStatus()); } + @Test + void testNullStatus() { + CronTab cronTab = createCronTab("my-new-cron-object", "* * * * */5", 3, "my-awesome-cron-image"); + + NonNamespaceOperation, Resource> cronTabClient = client + .resources(CronTab.class).inNamespace("test-ns"); + + CronTab result = cronTabClient.resource(cronTab).create(); + + // should be null after create + assertNull(result.getStatus()); + String resourceVersion = result.getMetadata().getResourceVersion(); + + // should be a no-op + result = cronTabClient.resource(result).patchStatus(); + assertNull(result.getStatus()); + assertEquals(resourceVersion, result.getMetadata().getResourceVersion()); + + // should be a no-op + result = cronTabClient.resource(result).replace(); + assertNull(result.getStatus()); + assertEquals(resourceVersion, result.getMetadata().getResourceVersion()); + } + void assertCronTab(CronTab cronTab, String name, String cronTabSpec, int replicas, String image) { assertEquals(name, cronTab.getMetadata().getName()); assertEquals(cronTabSpec, cronTab.getSpec().getCronSpec());