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

fix (kubernetes-client) : edit(), patch() and other mutating operations shouldn't be allowed in NonNamespaceOperation (#3772) #3798

Merged
merged 1 commit into from
Feb 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Bugs
* Fix #3776: VerticalPodAutoscaler cannot load yaml with "controlledResources"
* Fix #3772: `edit()` should not be allowed as a NonNamespaceOperation

#### Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
public interface NonNamespaceOperation<T, L, R> extends
Nameable<R>,
FilterWatchListMultiDeletable<T, L>,
WritableOperation<T>,
Createable<T>,
CreateOrReplaceable<T>,
DryRunable<WritableOperation<T>>,
Loadable<R> {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface Resource<T> extends CreateOrReplaceable<T>,
CreateFromServerGettable<T>,
CascadingEditReplacePatchDeletable<T>,
VersionWatchAndWaitable<T>,
WritableOperation<T>,
DryRunable<WritableOperation<T>>,
Requirable<T>, Readiable, Informable<T>,
CreateOrDeleteable<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void testFullObjectPatch() {
// When
ConfigMap configMapFromServer = client.configMaps().inNamespace(currentNamespace).withName(name).get();
configMapFromServer.setData(Collections.singletonMap("foo", "bar"));
ConfigMap patchedConfigMap = client.configMaps().patch(configMapFromServer);
ConfigMap patchedConfigMap = client.configMaps().inNamespace(currentNamespace).withName(name).patch(configMapFromServer);

// Then
assertThat(patchedConfigMap).isNotNull();
Expand All @@ -148,7 +148,7 @@ public void testFullObjectPatchWithConcurrentChange() {
// concurrent change to empty
ConfigMap baseCopy = new ConfigMapBuilder(base).build();
baseCopy.setData(Collections.emptyMap());
client.configMaps().patch(baseCopy);
client.configMaps().inNamespace(currentNamespace).withName(name).patch(baseCopy);

// concurrent change to empty
ConfigMap baseCopy2 = new ConfigMapBuilder(base).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void replaceStatusSubresource() {
// use the original pet, no need to pick up the resourceVersion
pet.getSpec().setType("shouldn't change");
pet.setStatus(petStatusToUpdate);
Pet updatedPet = petClient.inNamespace(currentNamespace).replaceStatus(pet);
Pet updatedPet = petClient.inNamespace(currentNamespace).withName(pet.getMetadata().getName()).replaceStatus(pet);

// Then
assertPet(updatedPet, "pet-replacestatus", "Pigeon", "Sleeping");
Expand All @@ -234,7 +234,7 @@ public void patchStatusSubresource() {
// use the original pet, no need to pick up the resourceVersion
pet.getSpec().setType("shouldn't change");
pet.setStatus(petStatusToUpdate);
Pet updatedPet = petClient.inNamespace(currentNamespace).patchStatus(pet);
Pet updatedPet = petClient.inNamespace(currentNamespace).withName(pet.getMetadata().getName()).patchStatus(pet);

// Then
assertPet(updatedPet, "pet-applystatus", "Pigeon", "Sleeping");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void testStatusSubresourceHandling() {

cronTab.getMetadata().setLabels(labels);

result = cronTabClient.replace(cronTab);
result = cronTabClient.withName(cronTab.getMetadata().getName()).replace(cronTab);

String originalUid = result.getMetadata().getUid();

Expand All @@ -187,13 +187,13 @@ void testStatusSubresourceHandling() {
labels.put("other", "label");
cronTab.setStatus(null);

result = cronTabClient.replace(cronTab);
result = cronTabClient.withName(cronTab.getMetadata().getName()).replace(cronTab);

// should retain the existing
assertNotNull(result.getStatus());

labels.put("another", "label");
result = cronTabClient.patch(cronTab);
result = cronTabClient.withName(cronTab.getMetadata().getName()).patch(cronTab);

// should retain the existing
assertNotNull(result.getStatus());
Expand All @@ -220,7 +220,7 @@ void testStatusPatch() {

result.setStatus(status);

result = cronTabClient.patchStatus(result);
result = cronTabClient.withName(cronTab.getMetadata().getName()).patchStatus(result);
assertNotNull(result.getStatus());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void testStatusReplace() throws InterruptedException {
server.expect().put().withPath("/apis/example.crd.com/v1alpha1/stars/sun/status").andReturn(200, "{\"apiVersion\":\"example.crd.com/v1alpha1\",\"kind\":\"Star\",\"metadata\":{\"name\":\"sun\",\"resourceVersion\":\"2\"},\"spec\":{\"type\":\"G\",\"location\":\"Galaxy\"},\"status\":{\"location\":\"M\"}}").once();
starClient = client.customResources(Star.class);

Star replaced = starClient.inNamespace("test").replaceStatus(updatedStar);
Star replaced = starClient.inNamespace("test").withName(updatedStar.getMetadata().getName()).replaceStatus(updatedStar);
assertEquals("2", replaced.getMetadata().getResourceVersion());
RecordedRequest recordedRequest = server.getLastRequest();
// get of the latest version, put of status
Expand Down