mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 15:05:20 +00:00
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:
@@ -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{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user