@@ -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 ();
0 commit comments