Browse code

add kubectl patch

deads2k authored on 2015/07/08 21:54:25
Showing 6 changed files
... ...
@@ -494,6 +494,19 @@ Request a new project
494 494
 ====
495 495
 
496 496
 
497
+== oc patch
498
+Update field(s) of a resource by stdin.
499
+
500
+====
501
+
502
+[options="nowrap"]
503
+----
504
+  // Partially update a node using strategic merge patch
505
+  $ openshift cli patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'
506
+----
507
+====
508
+
509
+
497 510
 == oc port-forward
498 511
 Forward one or more local ports to a pod.
499 512
 
... ...
@@ -581,11 +594,14 @@ Replace a resource by filename or stdin.
581 581
 
582 582
 [options="nowrap"]
583 583
 ----
584
-  // Update a pod using the data in pod.json.
585
-  $ openshift cli update -f pod.json
584
+  // Replace a pod using the data in pod.json.
585
+  $ openshift cli replace -f pod.json
586
+
587
+  // Replace a pod based on the JSON passed into stdin.
588
+  $ cat pod.json | openshift cli replace -f -
586 589
 
587
-  // Update a pod based on the JSON passed into stdin.
588
-  $ cat pod.json | openshift cli update -f -
590
+  // Force replace, delete and then re-create the resource
591
+  $ openshift cli replace --force -f pod.json
589 592
 ----
590 593
 ====
591 594
 
... ...
@@ -318,6 +318,8 @@ echo "templates: ok"
318 318
 [ "$(openshift help start master 2>&1 | grep 'Start an OpenShift master')" ]
319 319
 [ "$(openshift help start node 2>&1 | grep 'Start an OpenShift node')" ]
320 320
 [ "$(openshift cli help update 2>&1 | grep 'openshift')" ]
321
+[ "$(openshift cli help replace 2>&1 | grep 'openshift')" ]
322
+[ "$(openshift cli help patch 2>&1 | grep 'openshift')" ]
321 323
 
322 324
 # runnable commands with required flags must error consistently
323 325
 [ "$(oc get 2>&1 | grep 'Required resource not specified')" ]
... ...
@@ -117,7 +117,8 @@ func NewCommandCLI(name, fullName string) *cobra.Command {
117 117
 			Message: "Advanced Commands:",
118 118
 			Commands: []*cobra.Command{
119 119
 				cmd.NewCmdCreate(fullName, f, out),
120
-				cmd.NewCmdUpdate(fullName, f, out),
120
+				cmd.NewCmdReplace(fullName, f, out),
121
+				cmd.NewCmdPatch(fullName, f, out),
121 122
 				cmd.NewCmdProcess(fullName, f, out),
122 123
 				cmd.NewCmdExport(fullName, f, os.Stdin, out),
123 124
 				policy.NewCmdPolicy(policy.PolicyRecommendedName, fullName+" "+policy.PolicyRecommendedName, f, out),
... ...
@@ -54,22 +54,42 @@ func NewCmdGet(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Comm
54 54
 }
55 55
 
56 56
 const (
57
-	updateLong = `Update a resource by filename or stdin.
57
+	replaceLong = `Replace a resource by filename or stdin.
58 58
 
59 59
 JSON and YAML formats are accepted.`
60 60
 
61
-	updateExample = `  // Update a pod using the data in pod.json.
62
-  $ %[1]s update -f pod.json
61
+	replaceExample = `  // Replace a pod using the data in pod.json.
62
+  $ %[1]s replace -f pod.json
63 63
 
64
-  // Update a pod based on the JSON passed into stdin.
65
-  $ cat pod.json | %[1]s update -f -`
64
+  // Replace a pod based on the JSON passed into stdin.
65
+  $ cat pod.json | %[1]s replace -f -
66
+
67
+  // Force replace, delete and then re-create the resource
68
+  $ %[1]s replace --force -f pod.json`
66 69
 )
67 70
 
68
-// NewCmdUpdate is a wrapper for the Kubernetes cli update command
69
-func NewCmdUpdate(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
71
+// NewCmdReplace is a wrapper for the Kubernetes cli replace command
72
+func NewCmdReplace(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
70 73
 	cmd := kcmd.NewCmdReplace(f.Factory, out)
71
-	cmd.Long = updateLong
72
-	cmd.Example = fmt.Sprintf(updateExample, fullName)
74
+	cmd.Long = replaceLong
75
+	cmd.Example = fmt.Sprintf(replaceExample, fullName)
76
+	return cmd
77
+}
78
+
79
+const (
80
+	patchLong = `Update field(s) of a resource using strategic merge patch
81
+
82
+JSON and YAML formats are accepted.`
83
+
84
+	patchExample = `  // Partially update a node using strategic merge patch
85
+  $ %[1]s patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'`
86
+)
87
+
88
+// NewCmdPatch is a wrapper for the Kubernetes cli patch command
89
+func NewCmdPatch(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
90
+	cmd := kcmd.NewCmdPatch(f.Factory, out)
91
+	cmd.Long = patchLong
92
+	cmd.Example = fmt.Sprintf(patchExample, fullName)
73 93
 	return cmd
74 94
 }
75 95
 
... ...
@@ -1061,6 +1061,27 @@ _oc_replace()
1061 1061
     must_have_one_noun=()
1062 1062
 }
1063 1063
 
1064
+_oc_patch()
1065
+{
1066
+    last_command="oc_patch"
1067
+    commands=()
1068
+
1069
+    flags=()
1070
+    two_word_flags=()
1071
+    flags_with_completion=()
1072
+    flags_completion=()
1073
+
1074
+    flags+=("--help")
1075
+    flags+=("-h")
1076
+    flags+=("--patch=")
1077
+    two_word_flags+=("-p")
1078
+
1079
+    must_have_one_flag=()
1080
+    must_have_one_flag+=("--patch=")
1081
+    must_have_one_flag+=("-p")
1082
+    must_have_one_noun=()
1083
+}
1084
+
1064 1085
 _oc_process()
1065 1086
 {
1066 1087
     last_command="oc_process"
... ...
@@ -1618,6 +1639,7 @@ _oc()
1618 1618
     commands+=("proxy")
1619 1619
     commands+=("create")
1620 1620
     commands+=("replace")
1621
+    commands+=("patch")
1621 1622
     commands+=("process")
1622 1623
     commands+=("export")
1623 1624
     commands+=("policy")
... ...
@@ -2436,6 +2436,27 @@ _openshift_cli_replace()
2436 2436
     must_have_one_noun=()
2437 2437
 }
2438 2438
 
2439
+_openshift_cli_patch()
2440
+{
2441
+    last_command="openshift_cli_patch"
2442
+    commands=()
2443
+
2444
+    flags=()
2445
+    two_word_flags=()
2446
+    flags_with_completion=()
2447
+    flags_completion=()
2448
+
2449
+    flags+=("--help")
2450
+    flags+=("-h")
2451
+    flags+=("--patch=")
2452
+    two_word_flags+=("-p")
2453
+
2454
+    must_have_one_flag=()
2455
+    must_have_one_flag+=("--patch=")
2456
+    must_have_one_flag+=("-p")
2457
+    must_have_one_noun=()
2458
+}
2459
+
2439 2460
 _openshift_cli_process()
2440 2461
 {
2441 2462
     last_command="openshift_cli_process"
... ...
@@ -2993,6 +3014,7 @@ _openshift_cli()
2993 2993
     commands+=("proxy")
2994 2994
     commands+=("create")
2995 2995
     commands+=("replace")
2996
+    commands+=("patch")
2996 2997
     commands+=("process")
2997 2998
     commands+=("export")
2998 2999
     commands+=("policy")