Skip to content

Commit 5b056ec

Browse files
author
runzexia
committed
serverside apply constan & example
Signed-off-by: runzexia <[email protected]>
1 parent a03550d commit 5b056ec

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class PatchExample {
4747
"{\"metadata\":{\"$deleteFromPrimitiveList/finalizers\":[\"example.com/test\"]}}";
4848
static String jsonDeploymentStr =
4949
"{\"kind\":\"Deployment\",\"apiVersion\":\"extensions/v1beta1\",\"metadata\":{\"name\":\"hello-node\",\"finalizers\":[\"example.com/test\"],\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-node\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"terminationGracePeriodSeconds\":30,\"containers\":[{\"name\":\"hello-node\",\"image\":\"hello-node:v1\",\"ports\":[{\"containerPort\":8080}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}";
50+
static String applyYamlStr =
51+
"{\"kind\":\"Deployment\",\"apiVersion\":\"extensions/v1beta1\",\"metadata\":{\"name\":\"hello-node\",\"finalizers\":[\"example.com/test\"],\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-node\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"terminationGracePeriodSeconds\":30,\"containers\":[{\"name\":\"hello-node\",\"image\":\"hello-node:v2\",\"ports\":[{\"containerPort\":8080}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}";
5052

5153
public static void main(String[] args) throws IOException {
5254
try {
@@ -88,6 +90,16 @@ public static void main(String[] args) throws IOException {
8890
null);
8991
System.out.println("strategic-merge-patched deployment" + deploy3);
9092

93+
// apply-yaml a deployment
94+
ApiClient applyYamlClient =
95+
ClientBuilder.standard().setOverridePatchFormat(V1Patch.PATCH_FORMAT_APPLY_YAML).build();
96+
applyYamlClient.setDebugging(true);
97+
ExtensionsV1beta1Deployment deploy4 =
98+
new ExtensionsV1beta1Api(applyYamlClient)
99+
.patchNamespacedDeployment(
100+
"hello-node", "default", new V1Patch(applyYamlStr), null, null, null, null);
101+
System.out.println("application/apply-patch+yaml deployment" + deploy4);
102+
91103
} catch (ApiException e) {
92104
System.out.println(e.getResponseBody());
93105
e.printStackTrace();

kubernetes/src/main/java/io/kubernetes/client/custom/V1Patch.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class V1Patch {
1515
public static final String PATCH_FORMAT_JSON_PATCH = "application/json-patch+json";
1616
public static final String PATCH_FORMAT_JSON_MERGE_PATCH = "application/merge-patch+json";
1717
public static final String PATCH_FORMAT_STRATEGIC_MERGE_PATCH = "application/strategic-merge-patch+json";
18+
public static final String PATCH_FORMAT_APPLY_YAML = "application/apply-patch+yaml";
1819

1920
public V1Patch(final String value) {
2021
this.value = value;

0 commit comments

Comments
 (0)