Browse code

Fixes bug 1345773 - https://bugzilla.redhat.com/show_bug.cgi?id=1345773

Adds --local flag to allow for modifcations without communicating with the server api

Allows for overriding of deployment config options in file (using -f) by including the options on the command line

Fixes miscellaneous test errors in test/cmd/deployments.sh cause by missing oc create and oc delete commands

Updates oc and openshift command line completion files and doc/manpages with new --local option

Corey Daley authored on 2016/10/18 00:32:17
Showing 9 changed files
... ...
@@ -12914,6 +12914,8 @@ _oc_set_deployment-hook()
12914 12914
     flags_with_completion+=("-f")
12915 12915
     flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
12916 12916
     local_nonpersistent_flags+=("--filename=")
12917
+    flags+=("--local")
12918
+    local_nonpersistent_flags+=("--local")
12917 12919
     flags+=("--mid")
12918 12920
     local_nonpersistent_flags+=("--mid")
12919 12921
     flags+=("--no-headers")
... ...
@@ -17498,6 +17498,8 @@ _openshift_cli_set_deployment-hook()
17498 17498
     flags_with_completion+=("-f")
17499 17499
     flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
17500 17500
     local_nonpersistent_flags+=("--filename=")
17501
+    flags+=("--local")
17502
+    local_nonpersistent_flags+=("--local")
17501 17503
     flags+=("--mid")
17502 17504
     local_nonpersistent_flags+=("--mid")
17503 17505
     flags+=("--no-headers")
... ...
@@ -13075,6 +13075,8 @@ _oc_set_deployment-hook()
13075 13075
     flags_with_completion+=("-f")
13076 13076
     flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
13077 13077
     local_nonpersistent_flags+=("--filename=")
13078
+    flags+=("--local")
13079
+    local_nonpersistent_flags+=("--local")
13078 13080
     flags+=("--mid")
13079 13081
     local_nonpersistent_flags+=("--mid")
13080 13082
     flags+=("--no-headers")
... ...
@@ -17659,6 +17659,8 @@ _openshift_cli_set_deployment-hook()
17659 17659
     flags_with_completion+=("-f")
17660 17660
     flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
17661 17661
     local_nonpersistent_flags+=("--filename=")
17662
+    flags+=("--local")
17663
+    local_nonpersistent_flags+=("--local")
17662 17664
     flags+=("--mid")
17663 17665
     local_nonpersistent_flags+=("--mid")
17664 17666
     flags+=("--no-headers")
... ...
@@ -63,6 +63,10 @@ the abort policy, because at that point the deployment has already happened.
63 63
     Filename, directory, or URL to file to use to edit the resource.
64 64
 
65 65
 .PP
66
+\fB\-\-local\fP=false
67
+    If true, set deployment hook will NOT contact api\-server but run locally.
68
+
69
+.PP
66 70
 \fB\-\-mid\fP=false
67 71
     Set or remove a mid deployment hook
68 72
 
... ...
@@ -63,6 +63,10 @@ the abort policy, because at that point the deployment has already happened.
63 63
     Filename, directory, or URL to file to use to edit the resource.
64 64
 
65 65
 .PP
66
+\fB\-\-local\fP=false
67
+    If true, set deployment hook will NOT contact api\-server but run locally.
68
+
69
+.PP
66 70
 \fB\-\-mid\fP=false
67 71
     Set or remove a mid deployment hook
68 72
 
... ...
@@ -70,6 +70,7 @@ type DeploymentHookOptions struct {
70 70
 	All       bool
71 71
 
72 72
 	ShortOutput bool
73
+	Local       bool
73 74
 	Mapper      meta.RESTMapper
74 75
 
75 76
 	PrintObject func(runtime.Object) error
... ...
@@ -126,6 +127,8 @@ func NewCmdDeploymentHook(fullName string, f *clientcmd.Factory, out, errOut io.
126 126
 
127 127
 	cmd.Flags().String("failure-policy", "ignore", "The failure policy for the deployment hook. Valid values are: abort,retry,ignore")
128 128
 
129
+	cmd.Flags().BoolVar(&options.Local, "local", false, "If true, set deployment hook will NOT contact api-server but run locally.")
130
+
129 131
 	cmd.MarkFlagFilename("filename", "yaml", "yml", "json")
130 132
 
131 133
 	return cmd
... ...
@@ -159,16 +162,20 @@ func (o *DeploymentHookOptions) Complete(f *clientcmd.Factory, cmd *cobra.Comman
159 159
 		ContinueOnError().
160 160
 		NamespaceParam(cmdNamespace).DefaultNamespace().
161 161
 		FilenameParam(explicit, false, o.Filenames...).
162
-		SelectorParam(o.Selector).
163
-		ResourceNames("deploymentconfigs", resources...).
164 162
 		Flatten()
163
+	if !o.Local {
164
+		o.Builder = o.Builder.
165
+			ResourceNames("deploymentconfigs", resources...).
166
+			SelectorParam(o.Selector).
167
+			Latest()
168
+		if o.All {
169
+			o.Builder.ResourceTypes("deploymentconfigs").SelectAllParam(o.All)
170
+		}
165 171
 
166
-	if o.All {
167
-		o.Builder.ResourceTypes("deploymentconfigs").SelectAllParam(o.All)
168 172
 	}
169 173
 
170 174
 	output := kcmdutil.GetFlagString(cmd, "output")
171
-	if len(output) != 0 {
175
+	if len(output) != 0 || o.Local {
172 176
 		o.PrintObject = func(obj runtime.Object) error { return f.PrintObject(cmd, mapper, obj, o.Out) }
173 177
 	}
174 178
 
... ...
@@ -15,7 +15,6 @@ import (
15 15
 // FIXME: Remove commands from this list as the --local flag is implemented
16 16
 var localFlagExceptions = sets.NewString(
17 17
 	"build-hook",
18
-	"deployment-hook",
19 18
 	"env",
20 19
 	"probe",
21 20
 	"route-backends",
... ...
@@ -145,6 +145,10 @@ os::test::junit::declare_suite_start "cmd/deployments/setdeploymenthook"
145 145
 arg="-f test/integration/testdata/test-deployment-config.yaml"
146 146
 os::cmd::expect_failure_and_text "oc set deployment-hook" "error: one or more deployment configs"
147 147
 os::cmd::expect_failure_and_text "oc set deployment-hook ${arg}" "error: you must specify one of --pre, --mid, or --post"
148
+os::cmd::expect_failure_and_text "oc set deployment-hook ${arg} -o yaml --pre -- mycmd" 'Error from server: deploymentconfigs'
149
+os::cmd::expect_success_and_text "oc set deployment-hook ${arg} --local -o yaml --post -- mycmd" 'mycmd'
150
+os::cmd::expect_success_and_not_text "oc set deployment-hook ${arg} --local -o yaml --post -- mycmd | oc set deployment-hook -f - --local -o yaml --post --remove" 'mycmd'
151
+os::cmd::expect_success "oc create ${arg}"
148 152
 os::cmd::expect_success_and_text "oc set deployment-hook ${arg} --pre  -o yaml -- echo 'hello world'" 'pre:'
149 153
 os::cmd::expect_success_and_text "oc set deployment-hook ${arg} --pre  -o yaml -- echo 'hello world'" 'execNewPod:'
150 154
 os::cmd::expect_success_and_text "oc set deployment-hook ${arg} --pre  -o yaml -- echo 'hello world'" '\- echo'
... ...
@@ -164,6 +168,7 @@ os::cmd::expect_success_and_text "oc set deployment-hook ${arg} --pre --containe
164 164
 # Existing volume
165 165
 os::cmd::expect_success_and_not_text "oc set deployment-hook ${arg} --pre --volumes=vol1 -o yaml -- echo 'hello world'" 'does not have a volume named'
166 166
 os::cmd::expect_success_and_text "oc set deployment-hook ${arg} --pre --volumes=vol1 -o yaml -- echo 'hello world'" '\- vol1'
167
+os::cmd::expect_success 'oc delete dc/test-deployment-config'
167 168
 # Server object tests
168 169
 os::cmd::expect_success "oc create -f test/integration/testdata/test-deployment-config.yaml"
169 170
 os::cmd::expect_failure_and_text "oc set deployment-hook dc/test-deployment-config --pre" "you must specify a command"