Skip to content

Commit f981157

Browse files
authored
Merge pull request kubernetes-client#830 from yue9944882/example/patch-util
Update patch example to reflect usage of PatchUtil
2 parents 744825e + a22d43c commit f981157

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

examples/src/main/java/io/kubernetes/client/examples/PatchExample.java

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
package io.kubernetes.client.examples;
1414

1515
import io.kubernetes.client.custom.V1Patch;
16-
import io.kubernetes.client.openapi.ApiClient;
1716
import io.kubernetes.client.openapi.ApiException;
1817
import io.kubernetes.client.openapi.Configuration;
1918
import io.kubernetes.client.openapi.apis.ExtensionsV1beta1Api;
2019
import io.kubernetes.client.openapi.models.ExtensionsV1beta1Deployment;
2120
import io.kubernetes.client.util.ClientBuilder;
21+
import io.kubernetes.client.util.PatchUtils;
2222
import java.io.IOException;
2323

2424
/**
@@ -64,42 +64,59 @@ public static void main(String[] args) throws IOException {
6464
System.out.println("original deployment" + deploy1);
6565

6666
// json-patch a deployment
67-
ApiClient jsonPatchClient =
68-
ClientBuilder.standard().setOverridePatchFormat(V1Patch.PATCH_FORMAT_JSON_PATCH).build();
6967
ExtensionsV1beta1Deployment deploy2 =
70-
new ExtensionsV1beta1Api(jsonPatchClient)
71-
.patchNamespacedDeployment(
72-
"hello-node", "default", new V1Patch(jsonPatchStr), null, null, null, null);
68+
PatchUtils.patch(
69+
ExtensionsV1beta1Deployment.class,
70+
() ->
71+
api.patchNamespacedDeploymentCall(
72+
"hello-node",
73+
"default",
74+
new V1Patch(jsonPatchStr),
75+
null,
76+
null,
77+
null,
78+
null,
79+
null),
80+
V1Patch.PATCH_FORMAT_JSON_PATCH,
81+
api.getApiClient());
7382
System.out.println("json-patched deployment" + deploy2);
7483

7584
// strategic-merge-patch a deployment
76-
ApiClient strategicMergePatchClient =
77-
ClientBuilder.standard()
78-
.setOverridePatchFormat(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH)
79-
.build();
80-
strategicMergePatchClient.setDebugging(true);
8185
ExtensionsV1beta1Deployment deploy3 =
82-
new ExtensionsV1beta1Api(strategicMergePatchClient)
83-
.patchNamespacedDeployment(
84-
"hello-node",
85-
"default",
86-
new V1Patch(strategicMergePatchStr),
87-
null,
88-
null,
89-
null,
90-
null);
86+
PatchUtils.patch(
87+
ExtensionsV1beta1Deployment.class,
88+
() ->
89+
api.patchNamespacedDeploymentCall(
90+
"hello-node",
91+
"default",
92+
new V1Patch(strategicMergePatchStr),
93+
null,
94+
null,
95+
null,
96+
null,
97+
null),
98+
V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH,
99+
api.getApiClient());
91100
System.out.println("strategic-merge-patched deployment" + deploy3);
92101

93102
// apply-yaml a deployment, server side apply is alpha in kubernetes v1.14,
94103
// You need to actively enable the Server Side Apply alpha feature
95104
// https://kubernetes.io/docs/reference/using-api/api-concepts/#server-side-apply
96-
ApiClient applyYamlClient =
97-
ClientBuilder.standard().setOverridePatchFormat(V1Patch.PATCH_FORMAT_APPLY_YAML).build();
98-
applyYamlClient.setDebugging(true);
99105
ExtensionsV1beta1Deployment deploy4 =
100-
new ExtensionsV1beta1Api(applyYamlClient)
101-
.patchNamespacedDeployment(
102-
"hello-node", "default", new V1Patch(applyYamlStr), null, null, null, null);
106+
PatchUtils.patch(
107+
ExtensionsV1beta1Deployment.class,
108+
() ->
109+
api.patchNamespacedDeploymentCall(
110+
"hello-node",
111+
"default",
112+
new V1Patch(applyYamlStr),
113+
null,
114+
null,
115+
null,
116+
null,
117+
null),
118+
V1Patch.PATCH_FORMAT_APPLY_YAML,
119+
api.getApiClient());
103120
System.out.println("application/apply-patch+yaml deployment" + deploy4);
104121

105122
} catch (ApiException e) {

0 commit comments

Comments
 (0)