Browse code

Fixes oc set env --overwrite=false with multiple resources

Fabiano Franz authored on 2016/06/25 02:32:35
Showing 1 changed files
... ...
@@ -177,7 +177,7 @@ func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Comman
177 177
 	}
178 178
 
179 179
 	skipped := 0
180
-	errored := 0
180
+	errored := []*resource.Info{}
181 181
 	for _, info := range infos {
182 182
 		ok, err := f.UpdatePodSpecForObject(info.Object, func(spec *kapi.PodSpec) error {
183 183
 			containers, _ := selectContainers(spec.Containers, containerMatch)
... ...
@@ -188,7 +188,7 @@ func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Comman
188 188
 			for _, c := range containers {
189 189
 				if !overwrite {
190 190
 					if err := validateNoOverwrites(c.Env, env); err != nil {
191
-						errored++
191
+						errored = append(errored, info)
192 192
 						return err
193 193
 					}
194 194
 				}
... ...
@@ -217,7 +217,7 @@ func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Comman
217 217
 				}
218 218
 				if !overwrite {
219 219
 					if err := validateNoOverwrites(*vars, env); err != nil {
220
-						errored++
220
+						errored = append(errored, info)
221 221
 						return err
222 222
 					}
223 223
 				}
... ...
@@ -243,8 +243,8 @@ func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Comman
243 243
 	if one && skipped == len(infos) {
244 244
 		return fmt.Errorf("%s/%s is not a pod or does not have a pod template", infos[0].Mapping.Resource, infos[0].Name)
245 245
 	}
246
-	if errored == len(infos) {
247
-		return fmt.Errorf("no environment variable has been set")
246
+	if len(errored) == len(infos) {
247
+		return cmdutil.ErrExit
248 248
 	}
249 249
 
250 250
 	if list {
... ...
@@ -284,7 +284,13 @@ func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Comman
284 284
 	}
285 285
 
286 286
 	failed := false
287
+updates:
287 288
 	for i, info := range infos {
289
+		for _, erroredInfo := range errored {
290
+			if info == erroredInfo {
291
+				continue updates
292
+			}
293
+		}
288 294
 		newData, err := json.Marshal(objects[i])
289 295
 		if err != nil {
290 296
 			return err