Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl extends ServerSideApplicable #5073

Merged
merged 4 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* fix #5036: Better websocket error handling for protocol / client enforced errors, also update frame/message limits
* Fix #5044: disable Vert.x instance file caching
* Fix #5059: Vert.x InputStreamReader uses an empty Buffer sentinel to avoid NPE
* Fix #5073: `NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl` extends `ServerSideApplicable`

#### Improvements
* Fix #4434: Update CronJobIT to use `batch/v1` CronJob instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

import java.util.List;

public interface ListVisitFromServerWritable<T> extends
DeletableWithOptions, CreateOrReplaceable<List<T>>, FieldValidateable<CreateOrReplaceable<List<T>>> {
public interface ListVisitFromServerWritable<T>
extends DeletableWithOptions,
CreateOrReplaceable<List<T>>,
ServerSideApplicable<List<T>>,
FieldValidateable<CreateOrReplaceable<List<T>>> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,18 @@ public List<HasMetadata> update() {
return performOperation(Resource::update);
}

@Override
public List<HasMetadata> serverSideApply() {
return performOperation(Resource::serverSideApply);
}

@Override
public ListVisitFromServerGetDeleteRecreateWaitApplicable<HasMetadata> fieldManager(String manager) {
return newInstance(context.withFieldManager(manager));
}

@Override
public ListVisitFromServerGetDeleteRecreateWaitApplicable<HasMetadata> forceConflicts() {
return newInstance(context.withForceConflicts());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,11 @@ public <C extends Client> C clientInWriteContext(Class<C> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -71,6 +75,12 @@ public void setUp() throws IOException {
});
}

@AfterEach
public void tearDown() {
kubernetesClient.close();
kubernetesClient = null;
}

@Test
void testJsonPatch() {
// Given
Expand Down Expand Up @@ -183,6 +193,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);
}
Expand Down