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 git ops options #1122

Merged
merged 15 commits into from
Jan 14, 2021
Merged

add git ops options #1122

merged 15 commits into from
Jan 14, 2021

Conversation

itsmurugappan
Copy link
Contributor

@itsmurugappan itsmurugappan commented Nov 17, 2020

Description

Adds Gitops mode where in the changes are made in a local directory instead of a remote cluster

Changes

  • This PR only enables the option for kn service create/delete/update/list/describe
  • Gitops client implementing the knservingclient interface
  • Client injection is based on the command
    * Tests pending
  • e2e pending

Need reveiwers input on the below

  • When '--in-dir' flag is provided this mode is enabled
  • Named the new client gitops client

Reference

Partially fixes #30

/hold

cc @rhuss @navidshaikh @dsimansk @maximilien

@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 Nov 17, 2020
@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Nov 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: 4 warnings.

In response to this:

Description

Adds Gitops mode where in the changes are made in a local directory instead of a remote cluster

Changes

  • This PR only enables the option for kn service create/delete/update/list/describe
  • Gitops client implementing the knservingclient interface
  • Client injection is based on the command
  • Tests pending

Need reveiwers input on the below

  • When '--in-dir' flag is provided this mode is enabled
  • Named the new client gitops client

Reference

Partially fixes #30

/hold

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/human_readable_flags.go Show resolved Hide resolved
pkg/serving/v1/gitops.go Outdated Show resolved Hide resolved
pkg/serving/v1/gitops.go Show resolved Hide resolved
pkg/serving/v1/gitops.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 17, 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.

Good start. Important feature. Thanks for starting 💯

@@ -68,7 +68,7 @@ func executeRevisionCommand(client clientservingv1.KnServingClient, args ...stri

output := new(bytes.Buffer)
knParams.Output = output
knParams.NewServingClient = func(namespace string) (clientservingv1.KnServingClient, error) {
knParams.NewServingClient = func(namespace string, cmd *cobra.Command) (clientservingv1.KnServingClient, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about typing this CreateClient(...) function type?

pkg/kn/commands/types.go Outdated Show resolved Hide resolved
pkg/serving/v1/gitops.go Outdated Show resolved Hide resolved
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: itsmurugappan, maximilien

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

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

rhuss commented Dec 1, 2020

@itsmurugappan sorry that I couldn't review it yet. This week is still crazy busy for me, but let me give it a quick review at least about the UX tomorrow.

@knative-prow-robot knative-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 6, 2020
@itsmurugappan
Copy link
Contributor Author

tests are passing and unit tests are added

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 and sorry for the late reply.

I like the simplicity of the implementation but have some stylistic comment though.
There are probably some edge case, and we should "cleanup" the service from the empty / default value before writing it out (same as we do the for kn service apply command)

Not sure about the name of the option though, and maybe we should allow also to operate on a single file (eg. with an option that points to a file instead of a directory).

The directory option is nice because it will allow to add other objects (e.g. from eventing) into the mix.

Let's discuss tomorrow the naming a bit, I need to sleep over it ;-)

pkg/serving/v1/gitops.go Outdated Show resolved Hide resolved
pkg/kn/commands/types.go Outdated Show resolved Hide resolved
pkg/serving/v1/gitops.go Outdated Show resolved Hide resolved
pkg/serving/v1/gitops.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 7, 2020
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.

Except for the tmpdir calculation, looks good to me ! We still need to think about a proper option name, as I think that in-dir is not descriptive enough.

What's about:

  • --offline-dir (emphasizing that we are 'offline')
  • --local-dir (emphasizing that no cluster is used, but lacks an indication that its for the output)
  • --target-dir (emphasizing that it is generating something in the directory)

Or we could also have something like --offline / --local together with the --target-dir to make it even clearer that we:

  • Don't connect to a cluster
  • Create something in a target-dir. We could default to "." for the target dir if not given.
  • Allows also to add later an --target-file which then would point to a single file to update.

Instead of target we could also use output (e.g. (--output-dir, --output (for a file) or --output-file. However, --output (or -o) is already kind of occupied by the output format for the read-only commands, so I probably wouldn't reuse it in this context. (but --target, --target-dir would be also possible)

Finally we might think if the extra namespace directory level is needed. E.g do we expect to create many services across namespaces or is the major use case to create a single service or multiple services in the same namespace. Because if the latter is the case, we might first implement a single file argument --target mysvcl.yml and later maybe add options for bulk operations.

wdyt ?

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.

Also, while trying it out, I think we need to tune the output message as this still is focussed on cluster-side creation. E.g. we see an empty URL (which is natural), and we might need to adapt / check certain output methods that they can work with an empty status: field.

@itsmurugappan
Copy link
Contributor Author

Finally we might think if the extra namespace directory level is needed. E.g do we expect to create many services across namespaces or is the major use case to create a single service or multiple services in the same namespace. Because if the latter is the case, we might first implement a single file argument --target mysvcl.yml and later maybe add options for bulk operations.

IMO having namespaces will have the following benefits

  • Organized
  • Scenario where this command is used to generate files and checkin to GitHub , followed by ci process creating the services, namespaces might be handy
  • Supports listing
  • from kn argument perspective we still have the one argument

@itsmurugappan
Copy link
Contributor Author

Except for the tmpdir calculation, looks good to me ! We still need to think about a proper option name, as I think that in-dir is not descriptive enough.

What's about:

  • --offline-dir (emphasizing that we are 'offline')
  • --local-dir (emphasizing that no cluster is used, but lacks an indication that its for the output)
  • --target-dir (emphasizing that it is generating something in the directory)

I like offline-dir

@dsimansk
Copy link
Contributor

dsimansk commented Dec 9, 2020

My preferential list would be:

  1. --offline-dir
  2. --target-dir
  3. --local-dir

However, I wonder if we need to have *-dir suffix at all. E.g. to have a bit shorter flag name without dash, just --offline flag.
With the following resolution:

  • default: ./ - write to current dir
  • path/to/dir - write everything to the directory
  • path/to/file.yaml - write to single file

@rhuss
Copy link
Contributor

rhuss commented Dec 9, 2020

Yeah, I discussed this with @itsmurugappan on slack and my current preference would be --target (as "offline" sounds so negative ;-P

And also I think we can use a single option for both modes that we might want to support:

I think we should not create the top-level dir automatically and when we use --target something then, if something points to a directory we do it like implemented, but if not, and something ends with .yaml , .yml, or .json we create the appropriate file (even if it does not exist).

So for the directory mode, we would require an existing directory (the structure within the directory can then be built up by us)

For the file mode, we require a proper extension and create the file if needed.

@dsimansk
Copy link
Contributor

dsimansk commented Dec 9, 2020

Yeah, I discussed this with @itsmurugappan on slack and my current preference would be --target (as "offline" sounds so negative ;-P

@rhuss @itsmurugappan +1 sounds well thought through.

@knative-prow-robot knative-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 10, 2020
@lgtm-com
Copy link

lgtm-com bot commented Dec 11, 2020

This pull request introduces 1 alert when merging 3fd6e3b into bfd1834 - view on LGTM.com

new alerts:

  • 1 for Missing error check

@itsmurugappan
Copy link
Contributor Author

@rhuss @dsimansk all comments have been addressed, please take a look.

@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/create.go 84.7% 85.0% 0.3
pkg/kn/commands/service/delete.go 87.2% 87.5% 0.3
pkg/kn/commands/service/describe.go 83.8% 83.9% 0.1
pkg/kn/commands/service/list.go 93.8% 93.9% 0.2
pkg/kn/commands/service/service.go 91.7% 88.9% -2.8
pkg/kn/commands/service/update.go 92.5% 92.7% 0.3
pkg/kn/commands/types.go 55.9% 51.6% -4.4
pkg/serving/v1/gitops.go Do not exist 83.3%


// AddGitOpsFlags adds flags to enable gitops mode
func AddGitOpsFlags(flags *pflag.FlagSet) {
flags.String("target", "", "work on local directory instead of a remote cluster")
Copy link
Contributor

Choose a reason for hiding this comment

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

A little formatting nit to align with the rest.

Suggested change
flags.String("target", "", "work on local directory instead of a remote cluster")
flags.String("target", "", "Work on local directory instead of a remote cluster.")

Copy link
Contributor

@dsimansk dsimansk Dec 15, 2020

Choose a reason for hiding this comment

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

On a second thought I wonder if the message shouldn't be more descriptive/verbose. The following is just an example feel free to change or ignore it. :)

Create Knative resources in local directory or file instead of a remote cluster. Default mode is current directory, in addition path to custom directory or file extensions .yaml, .yml, .json are accepted. 

@rhuss I recall you've mentioned the feature is experimental. Therefore we should add (experimental) suffix at the end of description, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we should mark it as experimental and we should definitely include it for 0.20

Copy link
Contributor

Choose a reason for hiding this comment

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

To not lose to much time, lets merge this and create a followup PR to add the indication that this feature is experimental in a followup PR.

@rhuss
Copy link
Contributor

rhuss commented Dec 15, 2020

@itsmurugappan thanks a ton ! hope to jump on a next round of review tomorrow or the day after. End of the year is always crazy busy, but I will be there next week, too, when things are slowing down. So confident to get this landed within this year still !

@rhuss
Copy link
Contributor

rhuss commented Jan 14, 2021

/lgtm

let's merge it now to get it into 0.20 and address the remaining minor issues (marking as "experimental" in the description in a new PR (which we should also merge right before 0.20)

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 14, 2021
@rhuss
Copy link
Contributor

rhuss commented Jan 14, 2021

/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 Jan 14, 2021
@knative-prow-robot knative-prow-robot merged commit f5ac441 into knative:master Jan 14, 2021
@itsmurugappan itsmurugappan deleted the gitops branch October 11, 2021 01:55
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. 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.

Gitops mode
6 participants