diff --git a/CHANGELOG.md b/CHANGELOG.md index 1372ee2009f..d4916549a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ * Fix #5022: adding additional buffering to ExecWatchInputStream * Fix #5052: add Quantity.fromNumericalAmount, the inverse of getNumericalAmount * Fix #5080: minimizing debug logs related to the backoff interval +* Fix #5073: `NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl` extends `ServerSideApplicable` #### Dependency Upgrade * Fix #5006: Bump BouncyCastle to 1.72 diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/ListVisitFromServerWritable.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/ListVisitFromServerWritable.java index bd882445d03..6c2428cccaa 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/ListVisitFromServerWritable.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/ListVisitFromServerWritable.java @@ -17,7 +17,10 @@ import java.util.List; -public interface ListVisitFromServerWritable extends - DeletableWithOptions, CreateOrReplaceable>, FieldValidateable>> { +public interface ListVisitFromServerWritable + extends DeletableWithOptions, + CreateOrReplaceable>, + ServerSideApplicable>, + FieldValidateable>> { } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java index 6388c25ba68..2fb40cdb5e5 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java @@ -332,4 +332,18 @@ public List update() { return performOperation(Resource::update); } + @Override + public List serverSideApply() { + return performOperation(Resource::serverSideApply); + } + + @Override + public ListVisitFromServerGetDeleteRecreateWaitApplicable fieldManager(String manager) { + return newInstance(context.withFieldManager(manager)); + } + + @Override + public ListVisitFromServerGetDeleteRecreateWaitApplicable forceConflicts() { + return newInstance(context.withForceConflicts()); + } } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/OperationContext.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/OperationContext.java index 0c9b55ce9a6..3a91bc9d233 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/OperationContext.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/OperationContext.java @@ -508,7 +508,11 @@ public C clientInWriteContext(Class clazz) { // operationcontext OperationContext newContext = HasMetadataOperationsImpl.defaultContext(client).withDryRun(getDryRun()) .withGracePeriodSeconds(getGracePeriodSeconds()).withPropagationPolicy(getPropagationPolicy()) - .withFieldValidation(this.fieldValidation); + .withFieldValidation(this.fieldValidation).withFieldManager(this.fieldManager); + + if (Boolean.TRUE.equals(this.forceConflicts)) { + newContext = newContext.withForceConflicts(); + } // check before setting to prevent flipping the default flag if (!Objects.equals(getNamespace(), newContext.getNamespace()) diff --git a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/impl/PatchTest.java b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/impl/PatchTest.java index a74440a0cfb..3e069fcbe4c 100644 --- a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/impl/PatchTest.java +++ b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/impl/PatchTest.java @@ -15,7 +15,10 @@ */ package io.fabric8.kubernetes.client.impl; +import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.PodBuilder; +import io.fabric8.kubernetes.api.model.Service; +import io.fabric8.kubernetes.api.model.ServiceBuilder; import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.KubernetesClient; @@ -29,6 +32,7 @@ import io.fabric8.kubernetes.client.http.HttpRequest.Builder; import io.fabric8.kubernetes.client.http.StandardHttpRequest; import io.fabric8.kubernetes.client.http.TestHttpResponse; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -72,6 +76,12 @@ public void setUp() throws IOException { }); } + @AfterEach + public void tearDown() { + kubernetesClient.close(); + kubernetesClient = null; + } + @Test void testJsonPatch() { // Given @@ -184,6 +194,23 @@ void testServerSideApplyWithPatchOptions() { PatchType.SERVER_SIDE_APPLY.getContentType()); } + @Test + void testResourceListServerSideApply() { + // Given + Pod pod = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("default").endMetadata().build(); + Service svc = new ServiceBuilder().withNewMetadata().withName("svc1").endMetadata().build(); + // When + kubernetesClient.resourceList(pod, svc).inNamespace("ns1").fieldManager("x") + .forceConflicts().serverSideApply(); + + // Then + verify(mockClient, times(2)).sendAsync(any(), any()); + assertRequest(0, "PATCH", "/api/v1/namespaces/ns1/pods/pod1", "fieldManager=x&force=true", + PatchType.SERVER_SIDE_APPLY.getContentType()); + assertRequest(1, "PATCH", "/api/v1/namespaces/ns1/services/svc1", "fieldManager=x&force=true", + PatchType.SERVER_SIDE_APPLY.getContentType()); + } + private void assertRequest(String method, String url, String queryParam) { assertRequest(0, method, url, queryParam, null); }