Skip to content

Commit

Permalink
Merge pull request #2365 from matthyx/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
fusesource-ci committed Jul 27, 2020
2 parents f1d695d + ea1c048 commit a0a4516
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public Map<String, Object> edit(String name, String objectAsString) throws IOExc
* @throws IOException in case of network/serialization failures or failures from Kubernetes API
*/
public Map<String, Object> edit(String namespace, String name, Map<String, Object> object) throws IOException {
object = appendResourceVersionInObject(namespace, name, object);
return validateAndSubmitRequest(namespace, name, objectMapper.writeValueAsString(object), HttpCallMethod.PUT);
}

Expand Down Expand Up @@ -853,13 +854,18 @@ private Request getRequest(String url, String body, HttpCallMethod httpCallMetho
}

private String appendResourceVersionInObject(String namespace, String customResourceName, String customResourceAsJsonString) throws IOException {
Map<String, Object> newObject = convertJsonOrYamlStringToMap(customResourceAsJsonString);

return objectMapper.writeValueAsString(appendResourceVersionInObject(namespace, customResourceName, newObject));
}

private Map<String, Object> appendResourceVersionInObject(String namespace, String customResourceName, Map<String, Object> customResource) throws IOException {
Map<String, Object> oldObject = get(namespace, customResourceName);
String resourceVersion = ((Map<String, Object>)oldObject.get(METADATA)).get(RESOURCE_VERSION).toString();

Map<String, Object> newObject = convertJsonOrYamlStringToMap(customResourceAsJsonString);
((Map<String, Object>)newObject.get(METADATA)).put(RESOURCE_VERSION, resourceVersion);
((Map<String, Object>)customResource.get(METADATA)).put(RESOURCE_VERSION, resourceVersion);

return objectMapper.writeValueAsString(newObject);
return customResource;
}

private DeleteOptions fetchDeleteOptions(boolean cascading, String propagationPolicy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void testCreateOrReplace() throws IOException {
server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_CREATED, jsonObject).once();
server.expect().post().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos").andReturn(HttpURLConnection.HTTP_CONFLICT, jsonObject).once();
server.expect().put().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos/example-hello").andReturn(HttpURLConnection.HTTP_OK, jsonObject).once();
server.expect().get().withPath("/apis/test.fabric8.io/v1alpha1/namespaces/ns1/hellos/example-hello").andReturn(HttpURLConnection.HTTP_OK, jsonObject).once();
KubernetesClient client = server.getClient();

KubernetesClientException exception = Assertions.assertThrows(KubernetesClientException.class,
Expand Down

0 comments on commit a0a4516

Please sign in to comment.