-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
Conversation
@adohe is this no longer WIP? |
Also, are the test failures legit? |
bf0faa5
to
fb38b1a
Compare
@fabianofranz @pwittrock ready for review, ptal. |
@k8s-bot verify test this |
@k8s-bot verify test this |
pkg/kubectl/cmd/util/helpers.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
fb38b1a
to
8b4233f
Compare
@@ -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 { |
There was a problem hiding this comment.
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 ?
Rebased and test cases fixed. @pwittrock @fabianofranz please take a look, I would like to get this merged asap. |
/assign @pwittrock |
"k8s.io/kubernetes/pkg/printers" | ||
"k8s.io/kubernetes/pkg/util/crlf" | ||
|
||
"github.com/evanphx/json-patch" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lowercase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/kubectl/cmd/util/editor/editoptions.go, line 349 at r4 (raw file):
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 |
just have a quick look, generally lgtm, thanks for this work, I will add a third mode |
pkg/kubectl/cmd/edit.go
Outdated
"k8s.io/kubernetes/pkg/util/i18n" | ||
|
||
jsonpatch "github.com/evanphx/json-patch" | ||
"github.com/golang/glog" | ||
"github.com/spf13/cobra" |
There was a problem hiding this comment.
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)
@adohe is there any progress on this ? if you really busy, I would like to pick up the rest of work |
rebased and comments addressed, ptal. |
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):
Flag help text inconsistent. pkg/kubectl/cmd/util/editor/editoptions.go, line 349 at r4 (raw file): Previously, shiywang (Shiyang Wang) wrote…
This is not identical to before. Before is Comments from Reviewable |
sgtm |
/lgtm |
[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 |
Automatic merge from submit-queue |
Created #44905 to make sure the comments left will be addressed. |
FYI. Added
EditOptions
to decouple edit implementation from cobra command, thus make edit reusable. Once this get merged, we can refactorcreate
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.