-
Notifications
You must be signed in to change notification settings - Fork 261
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
Added changes to support container port information while creating/updating service #191
Conversation
Hi @savitaashture. 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. |
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 ! Beside some minor nit-picks, I would verify and assert that there is only one port and one container in the template's PodSpec (see comments).
@@ -33,6 +33,9 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command { | |||
# Updates a service 'mysvc' with new environment variables | |||
kn service update mysvc --env KEY1=VALUE1 --env KEY2=VALUE2 | |||
|
|||
# Update a service with given port |
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.
# Update service "mysvc" to expose port 80
Be more specific, it's an example.
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.
Modified with proper comments
@@ -46,6 +46,10 @@ func NewServiceCreateCommand(p *commands.KnParams) *cobra.Command { | |||
# Create or replace environment variables of service 's1' using --force flag | |||
kn service create --force s1 --env KEY1=NEW_VALUE1 --env NEW_KEY2=NEW_VALUE2 --image dev.local/ns/image:v1 | |||
|
|||
# Create a service with given port | |||
# If port is not specified it will take 8080 as a default port |
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.
# Create service 'mysvc' with port 80
# If no --port is given the default port 8080 is used
I would be more specific and more concise in the documentation.
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.
Modified with proper comments
hack/generate-docs.go
Outdated
@@ -29,9 +29,9 @@ func main() { | |||
if len(os.Args) > 1 { | |||
dir = os.Args[1] | |||
} | |||
err := doc.GenMarkdownTree(rootCmd, dir + "/docs/cmd/") | |||
err := doc.GenMarkdownTree(rootCmd, dir+"/docs/cmd/") |
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.
would revert that as it's not related to this 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.
When i ran go fmt for complete client code its modified i have reverted back now.
pkg/serving/config_changes.go
Outdated
}} | ||
|
||
} else { | ||
for i, _ := range container.Ports { |
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.
There should be only one. Please either assert that there is only one port (that is what Knative serving allows) and return an error or truncate to take only the first.
Tbh, I would just overwrite unconditionally any existing port.
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.
Overwritten the existing port
pkg/serving/config_changes_test.go
Outdated
t.Fatal(err) | ||
} | ||
// Verify update is successful or not | ||
for p, _ := range template.Spec.Containers { |
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.
assert that there are only 1 container and 1 port. Then just assert on template.Spec.Containers[0].Ports[0]
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.
Modified in all the places
pkg/serving/config_changes_test.go
Outdated
@@ -139,6 +139,43 @@ func testUpdateEnvVarsModify(t *testing.T, revision *servingv1alpha1.RevisionTem | |||
} | |||
} | |||
|
|||
func TestUpdateContainerPort(t *testing.T) { | |||
template, _ := getV1alpha1Config() | |||
err := UpdateContainerPort(template, 8080) |
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.
Why do you use the default port for the update ? I think for clarities sake its better to use something different.
pkg/serving/config_changes_test.go
Outdated
// update template with container port info | ||
for i, _ := range template.Spec.Containers { | ||
for j, _ := range template.Spec.Containers[i].Ports { | ||
template.Spec.Containers[i].Ports[j].ContainerPort = 9090 |
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.
there is only 1 container and 1 port. If there are more, than that's an error.
pkg/serving/config_changes_test.go
Outdated
} | ||
|
||
// Verify that given port overrides the existing container port | ||
for p, _ := range template.Spec.Containers { |
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.
assert again, that there is only 1 container and 1 port after the update (you could put that into an extrac func as its needed twice)
/ok-to-test |
a97594e
to
1bf28e6
Compare
pkg/serving/config_changes.go
Outdated
return err | ||
} | ||
|
||
if len(container.Ports) == 0 { |
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.
@savitaashture : I think @rhuss mentioned to worry about the len of container ports, just replace it with container.Ports[0].ContainerPort = port
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 this condition i have added because while executing
kn service create --image imagename --port 80
during that time contanier.Ports is nil so iam adding that condition to check and initialize the container.Ports.
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 would just then unconditionally set
container.Ports = []corev1.ContainerPort{{
ContainerPort: port,
}}
in any case. This makes the code simple to read, and we are sure that only 1 port is set (although as mentioned the slice should have only one entry)
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.
Updated
@@ -102,6 +105,11 @@ func (p *ConfigurationEditFlags) Apply(service *servingv1alpha1.Service, cmd *co | |||
return err | |||
} | |||
|
|||
err = servinglib.UpdateContainerPort(template, p.Port) |
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.
Say I have configured my service to run on port 9090, now I want to update my service with an environment variable, this Apply
gets called, irrespective of user intent to update the port, this will update the container port to default one (8080).
invoke this operation by flag check
if cmd.Flag().Changed('port')
(as done for image
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.
Updated
@@ -54,12 +55,14 @@ func (p *ConfigurationEditFlags) AddUpdateFlags(command *cobra.Command) { | |||
command.Flags().IntVar(&p.MaxScale, "max-scale", 0, "Maximal number of replicas.") | |||
command.Flags().IntVar(&p.ConcurrencyTarget, "concurrency-target", 0, "Recommendation for when to scale up based on the concurrent number of incoming request. Defaults to --concurrency-limit when given.") | |||
command.Flags().IntVar(&p.ConcurrencyLimit, "concurrency-limit", 0, "Hard Limit of concurrent requests to be processed by a single replica.") | |||
command.Flags().Int32VarP(&p.Port, "port", "p", 8080, "The port that the application should run.") |
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.
*The port where application listens on.
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.
modified
a359585
to
911d1ca
Compare
} | ||
|
||
func (p *ConfigurationEditFlags) AddCreateFlags(command *cobra.Command) { | ||
p.AddUpdateFlags(command) | ||
command.Flags().BoolVar(&p.ForceCreate, "force", false, "Create service forcefully, replaces existing service if any.") | ||
command.MarkFlagRequired("image") | ||
|
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.
why this extra line?
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.
Added by mistake :) removed now.
Thanku
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.
Nice job overall. Needed and welcome addition to kn
.
Did you consider also adding to the e2e test suite? Would be easy to change one of the created services update its port. Thanks.
@maximilien Thank you |
Build error is the same as in #192 (comment) so let's wait until this if fixed and retest here again. |
93617ae
to
3512d0c
Compare
@@ -102,6 +104,13 @@ func (p *ConfigurationEditFlags) Apply(service *servingv1alpha1.Service, cmd *co | |||
return err | |||
} | |||
|
|||
if cmd.Flags().Changed("port") { |
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 it's a bit weird for us to not set container port if we are going to specify it as a default in the above flag definition.
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.
Right! Apply
gets called for create
as well update
both.
@savitaashture: We'll probably need to identify the command in Apply
definition.
cmd.Name()
returns the command name, we can update this check to not set the port when cmd.Name() == "update" && !cmd.Flags().Changed("port")
and set for all other cases.
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.
i think it's a bit weird for us to not set container port if we are going to specify it as a default in the above flag definition.
Do you mean, we should update the port value to default one for service update
, even if user doesnt specify -p
port for service update
command ?
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.
@savitaashture : or we just remove the default value of port and the mentioned conditional should suffice.
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 we can just remove default port value 8080 from the flag and if cmd.Flags().Changed("port") {
condition will work for all the scenario.
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 it's best to rely on the server default and not specify default in the cli (shows up in -h). if user does specify the port configuration then it should be applied.
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 i have removed saying default value from (shows up in -h) and if user specify it will be applied.
Glad to see that this is being added. I just hit this problem where the container I want to use doesn't listen on port 8080 |
e3d3cfd
to
1134b3e
Compare
/test pull-knative-client-integration-tests |
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.
Except for some minor feature request the PR lgtm.
The following is the coverage report on pkg/.
|
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.
👍
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rhuss, savitaashture 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 |
@savitaashture Thanks a lot, looks good to me. I'm on the integration-test issue, and if this is resolved (it unrelated to this PR), lets merge it. |
@rhuss Thank you :) |
/retest pull-knative-client-integration-tests |
/retest |
/lgtm |
* [release-v1.9] Add kn-plugin-source-kafka v1.9.1 * Update vendor dir
Issue: #142
Description:
When someone writes application which listens on port other than 8080(default port in knative-serving) then deploy using cli(kn) then there is no way to specify the port.
Current:
Supported flags are
Expected:
Along with current flags it should support port flag so that user can specify port at which application is running.
ex: something like below
Usage: