-
Notifications
You must be signed in to change notification settings - Fork 263
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
feat: Add --filename flag to service create command #913
Conversation
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.
@dsimansk: 1 warning.
In response to this:
Description
Allow users to create Services from provided YAML or JSON file.
There're couple of open questions:
- Is it necessary to keep
NAME
parameter for the create command?- Should the
NAME
parameter take priority over file provided name?- Should the multi-item (services separated by
---
) YAML be supported as well?Changes
- Add new flag
--file
toservice create
commandReference
Fixes #550
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.
Yes. I would suggest just to have it as priority. And if
Yes. If both provided use
Yes. But I can easily see an argument for supporting one service in first pass and adding this after. |
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.
Good start. Left some feedback and found some lack of test coverage. One in particular important --- need test for bad input files, which is likely to happen. You may want to also add tests for files for correct structure but inconsistent or bad input values, e.g., invalid name.
Also, some answers to your questions as a comment above.
@@ -68,6 +68,8 @@ type ConfigurationEditFlags struct { | |||
GenerateRevisionName bool | |||
ForceCreate bool | |||
|
|||
File string |
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 always debate using Filename
instead of File
since there is invariably a File
object created somewhere later. Of course, File
is shorter as a flag name so makes sense too... Argh.
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.
Following the kubectl
example we could settle on -f, --filename
as --force
is not using that shorthand.
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.
Changed the name in 9a3c1b9.
if err != nil { | ||
return nil, err | ||
} |
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.
No tests for problem generating revision as I can comment these and pass tests. This is less important coverage than the comment above.
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.
- should we consider overriding name and namespace as given on the command line?
- should we turn off the client-side revision-name generation for file-mode ?
return nil, fmt.Errorf("provided service name '%s' doesn't match name from file '%s'", name, service.Name) | ||
} | ||
// Set namespace in case it's specified as --namespace | ||
service.ObjectMeta.Namespace = namespace |
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.
should the namespace also follow check as done above for service name ?
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 think for the namespace we should just allow an override from the CLI. A typical use case is that you create your service maybe for a different environment in the file but want to apply it here in a different context (that's different from the "name" which is an identifier that does not change across environments).
service.ObjectMeta.Namespace = namespace | ||
|
||
// We need to generate revision to have --force replace working | ||
revName, err := servinglib.GenerateRevisionName(editFlags.RevisionName, &service) |
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 am thinking if the client-side revision name generation could be turned off if using files 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.
➜ client git:(create-from-file) ✗ cat /tmp/hello.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-go
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
env:
- name: TARGET
value: "Go Sample v1"
➜ client git:(create-from-file) ✗ kn service create helloworld-go -f /tmp/hello.yaml
Creating service 'helloworld-go' in namespace 'default':
0.028s The Route is still working to reflect the latest desired specification.
0.061s Configuration "helloworld-go" is waiting for a Revision to become ready.
0.106s ...
3.751s ...
3.795s Ingress has not yet been reconciled.
3.868s Waiting for load balancer to be ready
4.190s Ready to serve.
Service 'helloworld-go' created to latest revision 'helloworld-go-5j5mp' is available at URL:
http://helloworld-go.default.example.com
➜ client git:(create-from-file) ✗ kn service create helloworld-go -f /tmp/hello.yaml --force
Replacing service 'helloworld-go' in namespace 'default':
When I was testing the flag locally I've experienced the above behaviour. When trying to -recreate the service with --force
the update hangs and timeouts eventually. However it's not happening for kn service update
flow or imperative kn service create
due to the fact that we generate revision name by default. May it a serving bug?
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.
yes could be, but we should be sure what it actually happen when using --force
. Could you do a debug session and check where exactly it hangs ?
For opening an issue for serving we would need to recreate the steps via yaml files, I think.
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.
Well, the issue is limited to a corner case when the same source is used twice, in other words to replace the same already created same Service. In that case such an update op never replaces the original Service content, causing no set of event to be produced in the cluster for wait to finish without timing out.
There's only one synthetic event ADDED
received, but nothing else as the server-side doesn't update anything at all.
The same behaviour can be reproduced with kubectl replace
, meaning that original service isn't actually replaced, is still the same with original timestamp etc., but there's no wait for ready that could be blocking the execution.
That kind of issue isn't present in imperative create
flow due to the fact that generated revision name is enough of a change to trigger the update/replace mechanism, therefore desired set of events is received in wait function.
I'd suggest the following:
- Implement @rhuss's suggestion from this comment
- Mark
filename
flag withmarkFlagMakesRevision
to enforce revision generation- Adding modification from other flags would always trigger new revision name generation, therefore we'll benefit from it for
filename
as well (although it might be seen as hack as well)
- Adding modification from other flags would always trigger new revision name generation, therefore we'll benefit from it for
- => Profit.
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.
For a quick win, I would go for the second option. We then can implement that improvement to pick up other options later. 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.
OK, I'm on board with quick win. :) Anyway it'll better to have improvement PR with proper amount of tests and bake time for options combination. I'll create a new issue for it.
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.
Follow-up enhancement issue #923.
I would keep the NAME argument and make it non-mandatory when My suggestion:
|
@maximilien @rhuss Please note that I've renamed initial flag name to Now it's possible to use with extended conditions suggested by Roland.
|
@rhuss will you take a pass? I can do a final review tomorrow after you or if you don’t? I like your suggestion. |
return nil, err | ||
} | ||
service.Spec.Template.Name = revName | ||
|
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.
Where does the override from all other options from the CLI happen ? I mean when someone uses
kn service create -f mysvc.yml --service-account mysa
then mysa
should be set as service account in the generated service. For array/map like options that's a bit more tricky as we have to decided whether they override those or just work on the ones from the file like with an update (i would opt for the latter). I.e. I would think adding options in addition to the file would act like an update as if the service in the file has been already present on the cluster.
wdyt ?
As this looks a bit more involved I would be happy to add this in a second PR.
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.
Initially I've left it out, because of potential clashes. However from my limited tests so far it looks well good. E.g. env vars are merged, service account added etc. I'll add a few tests to cover those use cases and update the PR. Plus there's another benefit outlined here.
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.
I suggest to merge this PR but work on a followup PR to address the part that allows updating arbitrary fields in the service from the YAML file with options from the command line (see comment below).
The following is the coverage report on the affected files.
|
/hold @rhuss feel free to remove hold when ready |
/unhold |
/retest |
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.
thanks! looks good to me, but let's continue on this story by allowing the override from CLI options.
This will give us the value add over plain kubectl
usage.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dsimansk, rhuss 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 |
Description
Allow users to create Services from provided YAML or JSON file.
There're couple of open questions:
NAME
parameter for the create command?NAME
parameter take priority over file provided name?---
) YAML be supported as well?Changes
--filename
toservice create
commandReference
Fixes #550