Skip to content

Commit f4ec11b

Browse files
authored
Merge pull request #618 from runzexia/serverside-apply
serverside apply & example
2 parents f0e846f + 6d10daa commit f4ec11b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

Lines changed: 14 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,18 @@ 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, server side apply is alpha in kubernetes v1.14,
94+
// You need to actively enable the Server Side Apply alpha feature
95+
// 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+
ExtensionsV1beta1Deployment deploy4 =
100+
new ExtensionsV1beta1Api(applyYamlClient)
101+
.patchNamespacedDeployment(
102+
"hello-node", "default", new V1Patch(applyYamlStr), null, null, null, null);
103+
System.out.println("application/apply-patch+yaml deployment" + deploy4);
104+
91105
} catch (ApiException e) {
92106
System.out.println(e.getResponseBody());
93107
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)