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

add EditOptions to make edit reusable #39404

Merged
merged 1 commit into from
Apr 24, 2017

Conversation

adohe-zz
Copy link

@adohe-zz adohe-zz commented Jan 4, 2017

FYI. Added EditOptions to decouple edit implementation from cobra command, thus make edit reusable. Once this get merged, we can refactor create commands to put them in their own package. @kubernetes/sig-cli-misc please give a quick review, and I would like to get this merged asap.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 4, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note-label-needed labels Jan 4, 2017
@fabianofranz
Copy link
Contributor

@adohe is this no longer WIP?

@pwittrock
Copy link
Member

Also, are the test failures legit?

@0xmichalis 0xmichalis added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Jan 11, 2017
@0xmichalis
Copy link
Contributor

@adohe thanks for working on this! Related issue: #38761

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 11, 2017
@adohe-zz adohe-zz changed the title [WIP] add EditOptions to make edit reusable add EditOptions to make edit reusable Jan 15, 2017
@adohe-zz
Copy link
Author

@fabianofranz @pwittrock ready for review, ptal.

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 15, 2017
@fabianofranz
Copy link
Contributor

@k8s-bot verify test this

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 16, 2017
@pwittrock
Copy link
Member

@k8s-bot verify test this

@@ -408,13 +414,22 @@ func AddApplyAnnotationFlags(cmd *cobra.Command) {
cmd.Flags().Bool(ApplyAnnotationsFlag, false, "If true, the configuration of current object will be saved in its annotation. This is useful when you want to perform kubectl apply on this object in the future.")
}

func AddApplyAnnotationVarFlags(cmd *cobra.Command, applyAnnotation *bool) {
Copy link
Member

Choose a reason for hiding this comment

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

WDYT of creating "Get" versions of these flags as well so they can be used in your code above?

containsError := false
var infos []*resource.Info
for {
switch o.EditMode {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this check be moved out of the loop?

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 11, 2017
@@ -648,6 +648,16 @@ func RetrieveLazy(info *Info, err error) error {
return nil
}

// CreateAndRefresh creates an object from input info and refreshes info with that object
func CreateAndRefresh(info *Info) error {
Copy link
Contributor

@shiywang shiywang Feb 14, 2017

Choose a reason for hiding this comment

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

Is this function original move from pkg/kubectl/cmd/create.go and made it public ? if so, can we delete the previous one and only keep this one ?

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 17, 2017
@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 14, 2017
@pwittrock pwittrock removed their assignment Apr 5, 2017
@adohe-zz
Copy link
Author

adohe-zz commented Apr 9, 2017

Rebased and test cases fixed. @pwittrock @fabianofranz please take a look, I would like to get this merged asap.

@adohe-zz
Copy link
Author

adohe-zz commented Apr 9, 2017

/assign @pwittrock

"k8s.io/kubernetes/pkg/printers"
"k8s.io/kubernetes/pkg/util/crlf"

"github.com/evanphx/json-patch"
Copy link
Contributor

Choose a reason for hiding this comment

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

Move these imports in between stdlib and kubernetes imports

Copy link
Author

Choose a reason for hiding this comment

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

comment addressed.

// Complete completes all the required options
func (o *EditOptions) Complete(f cmdutil.Factory, out, errOut io.Writer, args []string) error {
if o.EditMode != NormalEditMode && o.EditMode != EditBeforeCreateMode {
return fmt.Errorf("Unsupported edit mode %q", o.EditMode)
Copy link
Contributor

Choose a reason for hiding this comment

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

errors in fmt.Errorf / errors.New should start lowercased

return err
}
b := resource.NewBuilder(mapper, f.CategoryExpander(), typer, resource.ClientMapperFunc(f.UnstructuredClientForMapping), unstructured.UnstructuredJSONScheme)
if o.EditMode == NormalEditMode {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment here why is this needed for normal edit mode?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

case EditBeforeCreateMode:
err = visitToCreate(updatedVisitor, o.Mapper, o.Out)
default:
err = fmt.Errorf("Unsupported edit mode %q", o.EditMode)
Copy link
Contributor

Choose a reason for hiding this comment

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

lowercase

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@pwittrock pwittrock assigned mengqiy and unassigned pwittrock Apr 9, 2017
@shiywang
Copy link
Contributor

pkg/kubectl/cmd/util/editor/editoptions.go, line 349 at r4 (raw file):

	default:
		// if format is not specified, use yaml as default
		return &editPrinterOptions{

I'm not sure if this is right, previously if specify a invalid ouput, it will prompt "The flag 'output' must be one of yaml|json" should we keep error output compatible ?


Comments from Reviewable

@shiywang
Copy link
Contributor

shiywang commented Apr 10, 2017

just have a quick look, generally lgtm, thanks for this work, I will add a third mode ApplyEditMode when this pr get merged : )
cc @ymqytw

"k8s.io/kubernetes/pkg/util/i18n"

jsonpatch "github.com/evanphx/json-patch"
"github.com/golang/glog"
"github.com/spf13/cobra"
Copy link
Member

Choose a reason for hiding this comment

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

We should move this up per #39404 (comment)

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 13, 2017
@shiywang
Copy link
Contributor

shiywang commented Apr 17, 2017

@adohe is there any progress on this ? if you really busy, I would like to pick up the rest of work

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 18, 2017
@adohe-zz
Copy link
Author

rebased and comments addressed, ptal.

@mengqiy
Copy link
Member

mengqiy commented Apr 19, 2017

Review status: 0 of 9 files reviewed at latest revision, 10 unresolved discussions.


pkg/kubectl/cmd/util/helpers.go, line 430 at r5 (raw file):

func AddApplyAnnotationVarFlags(cmd *cobra.Command, applyAnnotation *bool) {
	cmd.Flags().BoolVar(applyAnnotation, ApplyAnnotationsFlag, false, "If true, the configuration of current object will be saved in its annotation. This is useful when you want to perform kubectl apply on this object in the future.")

Flag help text inconsistent.


pkg/kubectl/cmd/util/editor/editoptions.go, line 349 at r4 (raw file):

Previously, shiywang (Shiyang Wang) wrote…

I'm not sure if this is right, previously if specify a invalid ouput, it will prompt "The flag 'output' must be one of yaml|json" should we keep error output compatible ?

This is not identical to before.

Before is
switch format {
case "json":
// json printer
case "yaml", "": // specify yaml or unspecified
// yaml printer
default:
// error
}


Comments from Reviewable

@mengqiy
Copy link
Member

mengqiy commented Apr 21, 2017

I'm OK to merge this as is and let @shiywang to address the comments left in a followup PR.
This PR is blocking @shiywang's PR #42256.
It seems @adohe don't have bandwidth on this.

@0xmichalis
Copy link
Contributor

sgtm

@mengqiy
Copy link
Member

mengqiy commented Apr 24, 2017

/lgtm
And @shiywang will address the rest.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 24, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adohe, mengqiy

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit ed539fb into kubernetes:master Apr 24, 2017
@mengqiy
Copy link
Member

mengqiy commented Apr 25, 2017

Created #44905 to make sure the comments left will be addressed.

@adohe-zz adohe-zz deleted the refactor_edit branch June 8, 2018 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet