Skip to content
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 "kn service export" (#653) #669

Merged
merged 14 commits into from
Mar 10, 2020
Merged

Conversation

itsmurugappan
Copy link
Contributor

Fixes #653

Proposed Changes

  • Add new command kn export
  • Add unit test

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Feb 17, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itsmurugappan: 1 warning.

In response to this:

Fixes #653

Proposed Changes

  • Add new command kn export
  • Add unit test

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.

pkg/kn/commands/service/export.go Show resolved Hide resolved
@knative-prow-robot
Copy link
Contributor

Hi @itsmurugappan. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@knative-prow-robot knative-prow-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 17, 2020
@itsmurugappan
Copy link
Contributor Author

/assign @rhuss

@itsmurugappan
Copy link
Contributor Author

@rhuss I checked out in the serving slack and have made the changes accordingly. I have added 2 flows

  1. kn service export service-name -o yaml - exports latest service
  2. kn service export service-name --history -o yaml - for getting the service list with current active revisions.

Please review.

@itsmurugappan
Copy link
Contributor Author

/hold

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 17, 2020
@dsimansk
Copy link
Contributor

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 17, 2020
@itsmurugappan
Copy link
Contributor Author

/test pull-knative-client-integration-tests-latest-release

@itsmurugappan
Copy link
Contributor Author

itsmurugappan commented Feb 17, 2020

/unhold

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 17, 2020
@rhuss
Copy link
Contributor

rhuss commented Feb 17, 2020

thanks a lot ! I will give it a review tomorrow ...

@itsmurugappan
Copy link
Contributor Author

/test pull-knative-client-integration-tests

1 similar comment
@itsmurugappan
Copy link
Contributor Author

/test pull-knative-client-integration-tests

@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 26, 2020
Copy link
Contributor

@maximilien maximilien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. I like the idea and this is a cool feature to have.

See my comments. Please address changes.

Thanks.

pkg/kn/commands/service/export.go Show resolved Hide resolved
pkg/kn/commands/service/export.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/export.go Show resolved Hide resolved
pkg/kn/commands/service/export.go Show resolved Hide resolved
pkg/kn/commands/service/export_test.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/export_test.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/export_test.go Show resolved Hide resolved
@maximilien
Copy link
Contributor

maximilien commented Feb 28, 2020

Also (obviously) tests are still failing. Please address as well. Thx

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 28, 2020
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 28, 2020
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/service/export.go Do not exist 83.3%
pkg/kn/commands/service/service.go 85.7% 86.4% 0.6

@itsmurugappan
Copy link
Contributor Author

/test pull-knative-client-integration-tests-latest-release

@rhuss
Copy link
Contributor

rhuss commented Mar 3, 2020

@itsmurugappan I saved some time to work on a review this week. Please stay tuned ;-)


command := &cobra.Command{
Use: "export NAME",
Short: "export a service",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "export a service",
Short: "Export a service.",

Could you please change the short description to be consistent with the rest of commands. It's used in generated .md as a sentence.

Copy link
Contributor

@dsimansk dsimansk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good. I've added a suggestion about the short name.

I have a objections to current format of tests, the common approach for the rest of cmds is to split unit and mock tests. However, it isn't impacting functionality added and can be addressed later.

Finally, would have time to add E2E tests also? If you prefer as a follow-up issue/PR?

@itsmurugappan
Copy link
Contributor Author

I have a objections to current format of tests, the common approach for the rest of cmds is to split unit and mock tests. However, it isn't impacting functionality added and can be addressed later.

@dsimansk Thanks for reviewing. I will make the changes. Regarding unit tests , all the unit tests were supposed to move to mock based on this issue #358 .
Please let me know if my understanding is wrong.

@dsimansk
Copy link
Contributor

dsimansk commented Mar 6, 2020

@itsmurugappan sorry for the confusion. My perspective was a bit different based on parts that I worked on recently (the old way) and I didn't know about #358 the new way. So your approach is actually right. :)

Copy link
Contributor

@maximilien maximilien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending e2e test. Just to make sure that this gets executed on real services. Thx.

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 9, 2020
@itsmurugappan
Copy link
Contributor Author

LGTM pending e2e test. Just to make sure that this gets executed on real services. Thx.

will add the e2e

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution, highly appreciated ! It's very well done

Some remarks:

  • I'm not 100% sold on the name --history option (maybe we should call it something like --replay or --with-traffic-targets, to make clear that we are creating kind of a service reply list which needs to be "applied" with kubectl.
  • I think you missed the annotations, that a user can add e.g. with kn service create --annotation.
  • We should wipe out the traffic block if we only export a single service. Anything else would not be usable if there is a traffic block added.
  • Some real e2e tests would be cool. I'm going to open a new issue for this.

My suggestion to proceed is:

  • We merge the PR right away.
  • I create a smaller PR with a name suggestion for the --history option now, so that we can decide on this before we release 0.13.0
  • I create an issue for the E2E tests.

Sounds good ?

pkg/kn/commands/service/export.go Show resolved Hide resolved
}
flags := command.Flags()
commands.AddNamespaceFlags(flags, false)
flags.BoolP("history", "r", false, "Export all active revisions")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the shortcut for now. I think its better to spell out the option full each time to make it explicit. Also, the -r doesn't really play well with --history. I even probably would go for a --revisions to make the option more self-explanatory for what is exported in addition (and no shortcut option) (and we could also introduce --no-revisions for this boolean option, like we do for all boolean options).

exportedSvc := servingv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: latestSvc.ObjectMeta.Name,
Labels: latestSvc.ObjectMeta.Labels,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's with custom annotations provided by the user ? We might want to filter out automatically added annotations (which we now), but as we allow a kn service create --annotation, too, we should copy over annotations as well.

exportedSvc := servingv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: latestSvc.ObjectMeta.Name,
Labels: latestSvc.ObjectMeta.Labels,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we would need annotations, too. See below.


exportedSvc.Spec.Template = servingv1.RevisionTemplateSpec{
Spec: revision.Spec,
ObjectMeta: latestSvc.Spec.ConfigurationSpec.Template.ObjectMeta,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not from the revision ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From revision they were lot other values.

From ksvc is see only the below

    metadata:
      creationTimestamp: null
      name: hello-v3

params = append(params, clientservingv1.WithService(latestSvc.ObjectMeta.Name))

// Query for list with filters
revisionList, err := client.ListRevisions(params...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could directly use

revisionList, err := client.ListRevisions(clientservingv1.WithService(latestSvc.ObjectMeta.Name))

which is shorter and supposedly easier to read the intention.

pkg/kn/commands/service/export.go Show resolved Hide resolved
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: itsmurugappan, maximilien, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rhuss
Copy link
Contributor

rhuss commented Mar 10, 2020

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 10, 2020
@rhuss rhuss changed the title add kn export (#653) add "kn service export" (#653) Mar 10, 2020
@knative-prow-robot knative-prow-robot merged commit 5c794d3 into knative:master Mar 10, 2020
@itsmurugappan
Copy link
Contributor Author

Sounds good ?

Sure.

@itsmurugappan itsmurugappan deleted the dev01 branch May 25, 2020 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "kn service export"
7 participants