|
13 | 13 | package io.kubernetes.client.examples; |
14 | 14 |
|
15 | 15 | import io.kubernetes.client.custom.V1Patch; |
16 | | -import io.kubernetes.client.openapi.ApiClient; |
17 | 16 | import io.kubernetes.client.openapi.ApiException; |
18 | 17 | import io.kubernetes.client.openapi.Configuration; |
19 | 18 | import io.kubernetes.client.openapi.apis.ExtensionsV1beta1Api; |
20 | 19 | import io.kubernetes.client.openapi.models.ExtensionsV1beta1Deployment; |
21 | 20 | import io.kubernetes.client.util.ClientBuilder; |
| 21 | +import io.kubernetes.client.util.PatchUtils; |
22 | 22 | import java.io.IOException; |
23 | 23 |
|
24 | 24 | /** |
@@ -64,42 +64,59 @@ public static void main(String[] args) throws IOException { |
64 | 64 | System.out.println("original deployment" + deploy1); |
65 | 65 |
|
66 | 66 | // json-patch a deployment |
67 | | - ApiClient jsonPatchClient = |
68 | | - ClientBuilder.standard().setOverridePatchFormat(V1Patch.PATCH_FORMAT_JSON_PATCH).build(); |
69 | 67 | 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()); |
73 | 82 | System.out.println("json-patched deployment" + deploy2); |
74 | 83 |
|
75 | 84 | // 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); |
81 | 85 | 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()); |
91 | 100 | System.out.println("strategic-merge-patched deployment" + deploy3); |
92 | 101 |
|
93 | 102 | // apply-yaml a deployment, server side apply is alpha in kubernetes v1.14, |
94 | 103 | // You need to actively enable the Server Side Apply alpha feature |
95 | 104 | // 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); |
99 | 105 | 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()); |
103 | 120 | System.out.println("application/apply-patch+yaml deployment" + deploy4); |
104 | 121 |
|
105 | 122 | } catch (ApiException e) { |
|
0 commit comments