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

Remove cmd from kubectl/cmd/factory #5481

Merged
merged 1 commit into from
Mar 18, 2015
Merged

Conversation

tmrts
Copy link
Contributor

@tmrts tmrts commented Mar 14, 2015

I removed the cmd arguments from the factory methods as requested in issue #4470

@satnam6502
Copy link
Contributor

@smarterclayton

@j3ffml
Copy link
Contributor

j3ffml commented Mar 14, 2015

LGTM

@j3ffml j3ffml added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 14, 2015
@tmrts
Copy link
Contributor Author

tmrts commented Mar 15, 2015

@jlowdermilk I've finished the last part. Please take a look. I'll squash the commits afterwards

Validator: func(cmd *cobra.Command) (validation.Schema, error) {
if cmdutil.GetFlagBool(cmd, "validate") {
Validator: func() (validation.Schema, error) {
if flags.Lookup("validate").Value.String() == "true" {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is causing a nil dereference in hack/test-cmd.sh. I think the issue is that the validate flag is added to the flagset of each command but not to factory.flags. Can probably fix by adding in BindFlags.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if that will work, as that would redeclare the same set of flags twice; can't remember whether that will overwrite or panic. I would suggest moving the declaration of these flags

flags.BoolVar(&f.clients.matchVersion, FlagMatchBinaryVersion, false, "Require server version to match client version")
flags.Bool("validate", false, "If true, use a schema to validate the input before sending it")

from f.BindFlags to NewFactory. That way they are added to f.flags and any command flagsets passed to f.BindFlags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I thought at first. But, wouldn't that be a bit confusing? setting a flag earlier so it doesn't cause a bug few calls later. It's a global flag design issue though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know that every command needs to validate. Get, describe, and a few others definitely do not.

On Mar 15, 2015, at 7:09 PM, Jeff Lowdermilk notifications@github.com wrote:

In pkg/kubectl/cmd/cmd.go:

        client, err := clients.ClientForVersion(mapping.APIVersion)
        if err != nil {
            return nil, err
        }
        return kubectl.ReaperFor(mapping.Kind, client)
    },
  •   Validator: func(cmd *cobra.Command) (validation.Schema, error) {
    
  •       if cmdutil.GetFlagBool(cmd, "validate") {
    
  •   Validator: func() (validation.Schema, error) {
    
  •       if flags.Lookup("validate").Value.String() == "true" {
    
    This is causing a nil dereference in hack/test-cmd.sh. I think the issue is that the validate flag is added to the flagset of each command but not to factory.flags. Can probably fix by adding in BindFlags.


Reply to this email directly or view it on GitHub.

Copy link
Contributor

Choose a reason for hiding this comment

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

@TamerTas, it's also reasonable to keep global flag declarations in bind flags and just declare them into f.flags before they are added to the passed-in flagset.

I don't know that every command needs to validate. Get, describe, and a few others definitely do not.

I agree, but changing global flag behavior seemed out of scope for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jlowdermilk I just added a nil reference check before validation flag dereference.

@tmrts tmrts force-pushed the issue#4470 branch 2 times, most recently from 5810948 to 26eabd3 Compare March 16, 2015 00:37
if cmdutil.GetFlagBool(cmd, "validate") {
Validator: func() (validation.Schema, error) {
validationFlag := flags.Lookup("validate")
if validationFlag != nil && validationFlag.Value.String() == "true" {
Copy link
Contributor

Choose a reason for hiding this comment

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

validationFlag will always be nil, because the validate flag isn't being added to f.flags, only to the command flagset. If we aren't adding it in, we might as well remove this if block, but I don't know what ClientForVersion checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jlowdermilk Then, we either remove it or add an
if validationFlag == nil { f.flags.Bool("validate") } block to BindFlags method.
A better solution would extend the scope of this pull request. But, I think flag system needs an overhaul.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine with me if you want to extend the scope of the PR to better handle global flags. If you just want this to be cmd refactoring, we should preserve the existing behavior with respect to validate, and that pretty much requires adding it to f.flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jlowdermilk I've added the validate flag to f.flags as a temporary solution. I'm currently investigating a replacement for flags as configuration stored in etcd #5582.

@j3ffml j3ffml removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 16, 2015
@tmrts tmrts force-pushed the issue#4470 branch 4 times, most recently from e1059ad to 4883e4f Compare March 18, 2015 11:03
@j3ffml j3ffml added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 18, 2015
j3ffml added a commit that referenced this pull request Mar 18, 2015
Remove cmd from kubectl/cmd/factory
@j3ffml j3ffml merged commit e92067d into kubernetes:master Mar 18, 2015
@tmrts tmrts deleted the issue#4470 branch March 18, 2015 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants