Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubectl namespace support #1941

Merged
merged 1 commit into from
Oct 30, 2014
Merged

Conversation

derekwaynecarr
Copy link
Member

Added support for setting a namespace for kubectl requests.

FYI @ghodss

@smarterclayton
Copy link
Contributor

Tests?

@derekwaynecarr
Copy link
Member Author

Added test for getting namespace information from disk.

@ghodss
Copy link
Contributor

ghodss commented Oct 22, 2014

Instead of a separate subcommand and file on disk for this info, I think this shows we are overdue for a kubectl config command. See #1755 (comment) for more info and imagine using kubectl config namespace myns to change the current namespace.

@smarterclayton
Copy link
Contributor

I don't know that I consider 'git config' to be the right experience here. If you're switching contexts, that's not just a single config flag, it's a whole stack of behaviors. Swapping between those is a contextual action - how does config make it better?

----- Original Message -----

Instead of a separate subcommand and file on disk for this info, I think this
shows we are overdue for a kubectl config command. See
#1755 (comment)
for more info and imagine using kubectl config namespace myns to change
the current namespace.


Reply to this email directly or view it on GitHub:
#1941 (comment)

@ghodss
Copy link
Contributor

ghodss commented Oct 22, 2014

Maybe we need a kubectl namespace command, but I still think the storage of the information should ultimately not be on its own and instead should be bundled and managed with the rest of any kubectl config.

If we implement #1755, then when I'm using kubectl, I've likely done some command like kubectl use timsgce (instead of setting the env var like we do today). At this point the kubectl namespace <ns> command would change the param in the timsgce config I have on disk. If I run kubectl namespace <ns> when I am not in a cluster context, I would expect it to do something like set my global default namespace to <ns>.

This all needs to be designed and implemented, so this PR is probably good for now, but I would just expect the internal behavior (and possibly some of the external behavior) to change when we sort out all the config stuff.

Using namespace default

$ kubectl namespace other
Using namespace other`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if there was some slightly different language for when the namespace is set vs is just being displayed. Since "default" is the namespace used when none is provided, it's not entirely clear that kubectl namespace Using namespace default isn't actually also setting it to default/clearing the value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I will make an update.

Sent from my iPhone

On Oct 22, 2014, at 3:18 PM, Sam Ghods notifications@github.com wrote:

In pkg/kubectl/cmd/namespace.go:

+)
+
+func NewCmdNamespace(out io.Writer) *cobra.Command {

  • cmd := &cobra.Command{
  •   Use:   "namespace [<namespace>]",
    
  •   Short: "Set and view the current Kubernetes namespace",
    
  •   Long: `Set and view the current Kubernetes namespace scope for command line requests.
    
    +A Kubernetes namespace subdivides the cluster into groups of logically related pods, services, and replication controllers.
    +
    +Examples:
  • $ kubectl namespace
  • Using namespace default
  • $ kubectl namespace other
  • Using namespace other`,
    It would be nice if there was some slightly different language for when the namespace is set vs is just being displayed. Since "default" is the namespace used when none is provided, it's not entirely clear that kubectl namespace Using namespace default isn't actually also setting it to default/clearing the value.


Reply to this email directly or view it on GitHub.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this get addressed?

@derekwaynecarr
Copy link
Member Author

Completely agree on need to consolidate on disk storage when that command is available.

Sent from my iPhone

On Oct 22, 2014, at 3:16 PM, Sam Ghods notifications@github.com wrote:

Maybe we need a kubectl namespace command, but I still think the storage of the information should ultimately not be on its own and instead should be bundled and managed with the rest of any kubectl config.

If we implement #1755, then when I'm using kubectl, I've likely done some command like kubectl use timsgce (instead of setting the env var like we do today). At this point the kubectl namespace command would change the param in the timsgce config I have on disk. If I run kubectl namespace when I am not in a cluster context, I would expect it to do something like set my global default namespace to .

This all needs to be designed and implemented, so this PR is probably good for now, but I would just expect the internal behavior (and possibly some of the external behavior) to change when we sort out all the config stuff.


Reply to this email directly or view it on GitHub.

@smarterclayton
Copy link
Contributor

That I agree with - like Git, there are certain config levels that make sense (global, user, repo) but unlike Git one config repository needs to handle multiple repositories of config (namespaces).

Perhaps global config, per-server config, and per-namespace config are all relevant, with user config being less relevant.

On Oct 22, 2014, at 3:16 PM, Sam Ghods notifications@github.com wrote:

Maybe we need a kubectl namespace command, but I still think the storage of the information should ultimately not be on its own and instead should be bundled and managed with the rest of any kubectl config.

If we implement #1755, then when I'm using kubectl, I've likely done some command like kubectl use timsgce (instead of setting the env var like we do today). At this point the kubectl namespace command would change the param in the timsgce config I have on disk. If I run kubectl namespace when I am not in a cluster context, I would expect it to do something like set my global default namespace to .

This all needs to be designed and implemented, so this PR is probably good for now, but I would just expect the internal behavior (and possibly some of the external behavior) to change when we sort out all the config stuff.


Reply to this email directly or view it on GitHub.

@derekwaynecarr
Copy link
Member Author

Differentiated message on set namespace versus viewing the current.
Rebased to latest.

@@ -63,11 +63,11 @@ func Modify(w io.Writer, c *client.RESTClient, action ModifyAction, data []byte)
var id string
switch action {
case "create":
id, err = doCreate(c, resource, data)
id, err = doCreate(c, namespace, resource, data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the data already has "namespace" set? Who wins? I am not so enthused about special-casing this one field, except in cases like GET where there is no input already. Allowing people (encouraging really) to rely on the environmental definition of namespace feels sketchy to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the data already has a namespace set, and you post to a URL for an alternate namespace, the server properly rejects the request and states that the namespace in the data does not match the namespace of the request.

@thockin
Copy link
Member

thockin commented Oct 24, 2014

I very much like the idea of "kubectl config", but I agree that it needs some real design work. I'm wary of this PR, partly because we haven't done that design work.

@derekwaynecarr
Copy link
Member Author

@thockin - see my previous comment if that is related to your wariness, but this is bringing the same ability we delivered to kubecfg and had specified in the namespaces.md design document. Even in the presence of kubectl config, I think we will want this command.

@derekwaynecarr
Copy link
Member Author

Rebased

@bgrant0607
Copy link
Member

Sorry for not paying attention. What do we expect to be in NamespaceInfo soon? Right now, it's just namespace, in which case this is overkill and we should just accept namespace from environment variable and command-line flag.

@bgrant0607 bgrant0607 self-assigned this Oct 27, 2014
@smarterclayton
Copy link
Contributor

I'll make the case that namespace (and context) is as or more important to get right in client tools. The pattern we're building off of is ensuring the user makes an explicit choice to set a default context instead of requiring it on every call. It's not absolutely required to deliver this, but in practice i feel this is the bare minimum to make an acceptable user experience for end users who approach the tools day to day.

The problem with environment only is that it can lead to unexpected and ambiguous behavior - forget to set an env and you can destroy a production cluster. To me, namespace is as important as the current directory is to git in terms of clearly communicating scope. Unfortunately the shell handles that scope for Git by default (the prompt is a powerful additional tool, as evidenced by common git to shell integration, that env could also be integrated with).

Derek and I can make a more structured argument in detail for this.

On Oct 27, 2014, at 7:11 PM, bgrant0607 notifications@github.com wrote:

Sorry for not paying attention. What do we expect to be in NamespaceInfo soon? Right now, it's just namespace, in which case this is overkill and we should just accept namespace from environment variable and command-line flag.


Reply to this email directly or view it on GitHub.

@derekwaynecarr
Copy link
Member Author

I guess I thought the CLI for namespaces was the least controversial aspect of the overall proposal. I echo what Clayton said, but I will elaborate that NamespaceInfo is not expected to grow, but we anticipate it moving into a central style config file similar to git-config. @erictune any input here? I think our perspective is different in that we anticipate rarely operating in the "default" namespace, and it will be the norm for our end users to switch namespace contexts. Given this an environment variable is really annoying in the same way specifying a -b argument to every git operation would be a pain if you were not on master.

Sent from my iPhone

On Oct 27, 2014, at 7:44 PM, Clayton Coleman notifications@github.com wrote:

I'll make the case that namespace (and context) is as or more important to get right in client tools. The pattern we're building off of is ensuring the user makes an explicit choice to set a default context instead of requiring it on every call. It's not absolutely required to deliver this, but in practice i feel this is the bare minimum to make an acceptable user experience for end users who approach the tools day to day.

The problem with environment only is that it can lead to unexpected and ambiguous behavior - forget to set an env and you can destroy a production cluster. To me, namespace is as important as the current directory is to git in terms of clearly communicating scope. Unfortunately the shell handles that scope for Git by default (the prompt is a powerful additional tool, as evidenced by common git to shell integration, that env could also be integrated with).

Derek and I can make a more structured argument in detail for this.

On Oct 27, 2014, at 7:11 PM, bgrant0607 notifications@github.com wrote:

Sorry for not paying attention. What do we expect to be in NamespaceInfo soon? Right now, it's just namespace, in which case this is overkill and we should just accept namespace from environment variable and command-line flag.


Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHub.

@bgrant0607
Copy link
Member

Which is considered more important at this point, making it possible to specify the namespace or getting the CLI config mechanism in place? Would you like this PR to be reviewed for one, the other, or both of these issues?

@bgrant0607
Copy link
Member

I will comment further on config in #1755.

@derekwaynecarr
Copy link
Member Author

@bgrant0607, I would like this PR reviewed as a mechanism to specify the namespace and not the general purpose CLI config mechanism. I think the operation as specified can remain unchanged, and the general purpose CLI config mechanism can move the persistence of the information to a centralized location at the same time it moves persistence of the authentication info. We have downstream use cases where this is important to us in the near term.

@derekwaynecarr
Copy link
Member Author

Just a reminder, this is migrating a feature that is in kubecfg today, but was not completed when kubectl was initially integrated. I need to get kubectl functionally equivalent.

On Oct 28, 2014, at 12:34 AM, bgrant0607 notifications@github.com wrote:

I will comment further on config in #1755.


Reply to this email directly or view it on GitHub.

@bgrant0607
Copy link
Member

Ok, this is fine by me pending the one point about distinguishing getting vs. setting in output.

We can defer the config overhaul of all similar persistent flags to #1755.

@derekwaynecarr
Copy link
Member Author

The update to distinguish between setting and viewing current namespace has been made.

$ cluster/kubectl.sh namespace
Using namespace default
$ cluster/kubectl.sh namespace other
Set current namespace to other

Thanks all.

@bgrant0607
Copy link
Member

LGTM

@bgrant0607
Copy link
Member

Pls. squash commits

Add unit test for load namespace info
Different message on display of namespace versus setting namespace
@derekwaynecarr
Copy link
Member Author

@bgrant0607 squashed.

@bgrant0607
Copy link
Member

@derekwaynecarr Would you be willing to update namespaces.md to refer to kubectl rather than kubecfg?

@derekwaynecarr
Copy link
Member Author

Sure, no problem.

Sent from my iPhone

On Jan 22, 2015, at 2:02 PM, Brian Grant notifications@github.com wrote:

@derekwaynecarr Would you be willing to update namespaces.md to refer to kubectl rather than kubecfg?


Reply to this email directly or view it on GitHub.

@derekwaynecarr derekwaynecarr deleted the kubectl_ns branch April 17, 2015 17:56
deads2k pushed a commit to deads2k/kubernetes that referenced this pull request Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants