-
Notifications
You must be signed in to change notification settings - Fork 264
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
Adds --force flag to service create command (service replace) #79
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. Instructions 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
pkg/kn/commands/service_create.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the service does not exist ? In this case, no delete should be attempted.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 --force
to create a fresh service without history by deleting any old service of this name. No error if the service already exists.kn service create --replace
for 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
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.
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.
Getting close.
pkg/kn/commands/service_create.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -29,6 +29,7 @@ type ConfigurationEditFlags struct { | |||
Image string | |||
Env []string | |||
RequestsFlags, LimitsFlags ResourceFlags | |||
ForceCreate 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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@navidshaikh up to you on the timeline. i think current implementation is fine.
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.
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
Needs 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
--force
flag