kubectl should error when namespace doesn't match file for update

A user who runs `kubectl update -f foo.json` where foo.json is a
resource in a namespace that does not match $(kubectl namespace)
may not intend to update the resource in that other namespace.

For now, return an error when the user does not explicitly set
the namespace via the CLI:

    # foo.json in 'one', current is 'two'
    $ kubectl update -f foo.json # FAILS

    $ kubectl update --namespace=one -f foo.json # SUCCEEDS
This commit is contained in:
Clayton Coleman
2014-11-01 12:40:59 -04:00
parent 09cfa364c5
commit e46adc4cd0
3 changed files with 26 additions and 0 deletions

View File

@@ -196,6 +196,18 @@ func getKubeNamespace(cmd *cobra.Command) string {
return result
}
// getExplicitKubeNamespace returns the value of the namespace a
// user explicitly provided on the command line, or false if no
// such namespace was specified.
func getExplicitKubeNamespace(cmd *cobra.Command) (string, bool) {
if ns := getFlagString(cmd, "namespace"); len(ns) > 0 {
return ns, true
}
// TODO: determine when --ns-path is set but equal to the default
// value and return its value and true.
return "", false
}
func getKubeConfig(cmd *cobra.Command) *client.Config {
config := &client.Config{}