Merged by openshift-bot
OpenShift Bot authored on 2015/11/14 07:16:47... | ... |
@@ -279,7 +279,7 @@ func GetFlagDuration(cmd *cobra.Command, flag string) time.Duration { |
279 | 279 |
} |
280 | 280 |
|
281 | 281 |
func AddValidateFlags(cmd *cobra.Command) { |
282 |
- cmd.Flags().Bool("validate", false, "If true, use a schema to validate the input before sending it") |
|
282 |
+ cmd.Flags().Bool("validate", true, "If true, use a schema to validate the input before sending it") |
|
283 | 283 |
cmd.Flags().String("schema-cache-dir", fmt.Sprintf("~/%s/%s", clientcmd.RecommendedHomeDir, clientcmd.RecommendedSchemaName), fmt.Sprintf("If non-empty, load/store cached API schemas in this directory, default is '$HOME/%s/%s'", clientcmd.RecommendedHomeDir, clientcmd.RecommendedSchemaName)) |
284 | 284 |
} |
285 | 285 |
|
... | ... |
@@ -173,6 +173,14 @@ func changeSharedFlagDefaults(rootCmd *cobra.Command) { |
173 | 173 |
showAllFlag.Changed = false |
174 | 174 |
showAllFlag.Usage = "When printing, show all resources (false means hide terminated pods.)" |
175 | 175 |
} |
176 |
+ |
|
177 |
+ // we want to disable the --validate flag by default when we're running kube commands from oc. We want to make sure |
|
178 |
+ // that we're only getting the upstream --validate flags, so check both the flag and the usage |
|
179 |
+ if validateFlag := currCmd.Flags().Lookup("validate"); (validateFlag != nil) && (validateFlag.Usage == "If true, use a schema to validate the input before sending it") { |
|
180 |
+ validateFlag.DefValue = "false" |
|
181 |
+ validateFlag.Value.Set("false") |
|
182 |
+ validateFlag.Changed = false |
|
183 |
+ } |
|
176 | 184 |
} |
177 | 185 |
} |
178 | 186 |
|
... | ... |
@@ -53,3 +53,29 @@ kubectlLoop: |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
} |
56 |
+ |
|
57 |
+// this only checks one level deep for nested commands, but it does ensure that we've gotten several |
|
58 |
+// --validate flags. Based on that we can reasonably assume we got them in the kube commands since they |
|
59 |
+// all share the same registration. |
|
60 |
+func TestValidateDisabled(t *testing.T) { |
|
61 |
+ f := clientcmd.New(pflag.NewFlagSet("name", pflag.ContinueOnError)) |
|
62 |
+ |
|
63 |
+ oc := NewCommandCLI("oc", "oc", &bytes.Buffer{}, ioutil.Discard, ioutil.Discard) |
|
64 |
+ kubectl := kcmd.NewKubectlCommand(f.Factory, nil, ioutil.Discard, ioutil.Discard) |
|
65 |
+ |
|
66 |
+ for _, kubecmd := range kubectl.Commands() { |
|
67 |
+ for _, occmd := range oc.Commands() { |
|
68 |
+ if kubecmd.Name() == occmd.Name() { |
|
69 |
+ ocValidateFlag := occmd.Flags().Lookup("validate") |
|
70 |
+ if ocValidateFlag == nil { |
|
71 |
+ continue |
|
72 |
+ } |
|
73 |
+ |
|
74 |
+ if ocValidateFlag.Value.String() != "false" { |
|
75 |
+ t.Errorf("%s --validate is not defaulting to false", occmd.Name()) |
|
76 |
+ } |
|
77 |
+ } |
|
78 |
+ } |
|
79 |
+ } |
|
80 |
+ |
|
81 |
+} |