-
Notifications
You must be signed in to change notification settings - Fork 8
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 a command-line option to edit status of resource with specified yaml file #3
base: master
Are you sure you want to change the base?
Conversation
Hi @ulucinar, If you are interested in this feature, the PR can be tested with the following steps:
|
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.
Hi @sergenyalcin,
Thank you very much for the PR!
Let's define what we expect in the yaml file passed with the new -i
option. In my opinion, it should be possible just to specify a partial status
section in input file. What do you think?
My suggestion would be as follows:
- If
-i
option is specified, branch out and call the newEditStatusOptions.writeResourceStatusFromInputFile
instead ofEditStatusOptions.editResource
. However, execution had better continue from rest ofEditStatusOptions.Run
in order to prevent code duplication. Although at the moment we just callEditStatusOptions.writeResourceStatus
, we may do some other post-processing later. - Then in
EditStatusOptions.writeResourceStatusFromInputFile
, we could just read and replace thestatus
JSON object into the temp file and the rest stays the same. So instead of opening an interactive editor for the user to edit thestatus
section, we would be replacing it from the specified file with the-i
option.
What do you think? And again, thank you very much for your contribution. It's very much appreciated.
Also could you please sign your commit with -S
option of git commit
? We can setup a call if you need help in doing so.
if err = o.writeResourceStatusFromInputFile(); err != nil { | ||
return | ||
} | ||
|
||
return nil |
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.
if err = o.writeResourceStatusFromInputFile(); err != nil { | |
return | |
} | |
return nil | |
return o.writeResourceStatusFromInputFile() |
|
||
defer func() { | ||
if errClose := f.Close(); err != nil { | ||
err = errClose |
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 will not be returning the IO error from File.Close
from writeResourceStatusFromInputFile
. In order for this to work, you should be assigning the error in the deferred call to a named return value. For an example, please see the deferred call in EditStatusOptions.Run
.
if err = o.writeResourceStatus(f); err != nil { | ||
return err | ||
} | ||
|
||
return nil |
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.
if err = o.writeResourceStatus(f); err != nil { | |
return err | |
} | |
return nil | |
return o.writeResourceStatus(f) |
Usage: kubectl edit-status <resource> <resource-name> --namespace <namespace> --in <filepath>