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 all 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 @@ -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
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 @@ -72,6 +76,12 @@ public void setUp() throws IOException {
});
}

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

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