@@ -47,6 +47,8 @@ public class PatchExample {
47
47
"{\" metadata\" :{\" $deleteFromPrimitiveList/finalizers\" :[\" example.com/test\" ]}}" ;
48
48
static String jsonDeploymentStr =
49
49
"{\" 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\" :{}}" ;
50
52
51
53
public static void main (String [] args ) throws IOException {
52
54
try {
@@ -88,6 +90,18 @@ public static void main(String[] args) throws IOException {
88
90
null );
89
91
System .out .println ("strategic-merge-patched deployment" + deploy3 );
90
92
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
+
91
105
} catch (ApiException e ) {
92
106
System .out .println (e .getResponseBody ());
93
107
e .printStackTrace ();
0 commit comments