Skip to content

Commit

Permalink
Fix #2717: Remove edit() methods from RawCustomResourceOperationsImpl…
Browse files Browse the repository at this point in the history
… taking InputStream arguments

As discussed in #2717, it's not a good idea to take InputStream for
edit() methods which simply does a PATCH to Kubernetes APIServer.
  • Loading branch information
rohanKanojia authored and manusa committed Feb 2, 2021
1 parent aabc17e commit e5e48ca
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Fix #2748: Pass custom headers in kubernetes-client to watch api by modify WatchConnectionManager

#### Improvements
* Fix #2717: Remove edit() methods from RawCustomResourceOperationsImpl taking InputStream arguments

#### Dependency Upgrade
* update Tekton Triggers model to v0.11.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,31 +286,6 @@ public Map<String, Object> edit(String namespace, String name, String objectAsSt
return validateAndSubmitRequest(namespace, name, objectAsString, HttpCallMethod.PUT);
}

/**
* Edit a custom resource object which is a non-namespaced object.
*
* @param name name of the custom resource
* @param objectAsStream new object as a file input stream
* @return Object as HashMap
* @throws IOException in case of network/serialization failures or failures from Kubernetes API
*/
public Map<String, Object> edit(String name, InputStream objectAsStream) throws IOException {
return validateAndSubmitRequest(null, name, IOHelpers.readFully(objectAsStream), HttpCallMethod.PUT);
}

/**
* Edit a custom resource object which is a namespaced object.
*
* @param namespace desired namespace
* @param name name of the custom resource
* @param objectAsStream new object as a file input stream
* @return Object as HashMap
* @throws IOException in case of network/serialization failures or failures from Kubernetes API
*/
public Map<String, Object> edit(String namespace, String name, InputStream objectAsStream) throws IOException {
return validateAndSubmitRequest(namespace, name, IOHelpers.readFully(objectAsStream), HttpCallMethod.PUT);
}

/**
* Update status related to a CustomResource, this method does a PUT request on /status endpoint related
* to the CustomResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testCrudUsingMap() throws IOException {
}

@Test
public void testCrudUsingInputStream() throws IOException {
public void testCreateReadDeleteUsingInputStream() throws IOException {
// Create
String name = "hippo";
InputStream hippoInputStream = getClass().getResourceAsStream("/rawcustomresourceit-crud-inputstream.yml");
Expand All @@ -162,13 +162,6 @@ public void testCrudUsingInputStream() throws IOException {
hippoCr = client.customResource(customResourceDefinitionContext).get(currentNamespace, name);
assertAnimal(hippoCr, name, "Hippopotamidae");

// Update
((Map<String, Object>)hippoCr.get("spec")).put("image", "river-hippo");
File updatedHippoManifest = Files.createTempFile("hippo", "yml").toFile();
FileUtils.writeStringToFile(updatedHippoManifest, Serialization.jsonMapper().writeValueAsString(hippoCr));
hippoCr = client.customResource(customResourceDefinitionContext).edit(currentNamespace, name, new FileInputStream(updatedHippoManifest));
assertAnimal(hippoCr, name, "river-hippo");

// Delete
Map<String, Object> deletionStatusMap = client.customResource(customResourceDefinitionContext).delete(currentNamespace, name);
assertDeletionStatus(deletionStatusMap, "Success");
Expand Down

0 comments on commit e5e48ca

Please sign in to comment.