Adds --force flag to service create command (service replace)#79
Conversation
|
Hi @navidshaikh. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
/ok-to-test |
a041f4a to
0d3e345
Compare
| if force, err := cmd.Flags().GetBool("force"); err != nil { | ||
| return err | ||
| } else if force { | ||
| client.Services(namespace).Delete(args[0], &v1.DeleteOptions{}) |
There was a problem hiding this comment.
What happens if the service does not exist ? In this case, no delete should be attempted.
There was a problem hiding this comment.
We can check that we Get call, here I am not error checking for for Delete though, since error is not handled, it creates the service.
@rhuss : Do you have some tweak in mind for this operation ?
There was a problem hiding this comment.
Don't delete the service here at all. Instead, do a GET, if it exists copy the resourceVersion to &service, and issue an update.
Why? This preserves revision history.
There was a problem hiding this comment.
Using an update instead of a delete/create would also help with the transactional issue I mentioned (if "delete" works but not "create"), because when the "update" fails you still have the situation as before (e.g. the service running).
The only issue I then have is, that this is not really a create, as I think people would expect a clean history for a create. That would again a plus for a 'replace' command or 'update --set' or something.
For my understanding we should implement:
kn service create --forceto create a fresh service without history by deleting any old service of this name. No error if the service already exists.kn service create --replacefor replacing a service, keeping the history, but erroring if the service does not exist.
An alternative for the "replace with keeping history" would be kn service replace or kn update --set.
Sorry for fueling that discussion again, but I really think that 'create afresh by potentially overwriting an existing service' (good for development) and 'replace everything, potentially with default values, but keep the history' (good for getting back to a defined and known state) are looking similar but are subtly different.
There was a problem hiding this comment.
kn service create --replace for replacing a service, keeping the history, but erroring if the service does not exist.
@rhuss ; should it really bother for erroring out ? as in, IMO the create verb/command shouldn't block on existence of service, though we could put a proper info on stdout if it existed or not.
rhuss
left a comment
There was a problem hiding this comment.
Looks good to me, except some stylistic nit-picking.
However, one question is open wrt/ to transactional behaviour. What happens when for replace the delete worked but not the create ? Is there a way for a rollback ? Because now, you would just end up with the service deleted which is not what you want when you want even when create/replace of a service fails.
| if force, err := cmd.Flags().GetBool("force"); err != nil { | ||
| return err | ||
| } else if force { | ||
| client.Services(namespace).Delete(args[0], &v1.DeleteOptions{}) |
There was a problem hiding this comment.
Don't delete the service here at all. Instead, do a GET, if it exists copy the resourceVersion to &service, and issue an update.
Why? This preserves revision history.
| Image string | ||
| Env []string | ||
| RequestsFlags, LimitsFlags ResourceFlags | ||
| ForceCreate bool |
There was a problem hiding this comment.
i wonder if at some point it would make sense to have
type ConfigurationCreateFlags struct {
ConfigurationEditFlags
ForceCreate bool
...
}
to better separate create from update at the compile time. wdyt?
There was a problem hiding this comment.
+1
@cppforlife : Do you want me to update the same PR? or log an issue and address is post v0.1 ?
There was a problem hiding this comment.
@navidshaikh up to you on the timeline. i think current implementation is fine.
There was a problem hiding this comment.
Logged the suggestion to be addressed later #110 , thanks @cppforlife
Also rebased the PR to resolve the conflicts.
|
/approve there is potential race between other tools running create, but for now this should be fine since cli will just error. |
ec41ebb to
d676c68
Compare
|
The following is the coverage report on pkg/.
|
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cppforlife, navidshaikh The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…e#79) * Adds --force flag to service create command / service replace Fixes knative#13 * Keeps the resourceVersion of service with --force flag * Updates the tests * Removes unnecessary comments
…e#79) * Adds --force flag to service create command / service replace Fixes knative#13 * Keeps the resourceVersion of service with --force flag * Updates the tests * Removes unnecessary comments
Fixes #13
Note the
--forceflag