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

Xw/net 6307 grpc client apply #20107

Merged
merged 9 commits into from
Jan 16, 2024
Merged

Xw/net 6307 grpc client apply #20107

merged 9 commits into from
Jan 16, 2024

Conversation

wangxinyi7
Copy link
Member

@wangxinyi7 wangxinyi7 commented Jan 5, 2024

Description

In this PR, I enabled the apply command in grpc communication. I created all of the code in separate files to avoid break changes to the current HTTP communication. We will purge all of the deprecated HTTP legacy after we completely support the grpc.

The most important changes are in these two files:

command/resource/apply-grpc/apply.go
This is the Run command which executes the apply call in CLI

command/resource/resource-grpc.go
This is abstract of the underlying APPLY call. In the future, the LIST DELETE and READ will all reside in this file.

Currently they all have -grpc in the file name to avoid duplication to the current files. As I mentioned above we will change the files names after we settle down everything.

This PR is based off this PR which adds the token field to the CLI.

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

@github-actions github-actions bot added the theme/cli Flags and documentation for the CLI interface label Jan 5, 2024
command/resource/apply-grpc/apply.go Show resolved Hide resolved
if input == "" && len(c.flags.Args()) > 0 {
input = c.flags.Arg(0)
}
if input != "" {
Copy link
Member

Choose a reason for hiding this comment

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

You could eliminate some nesting/branching by having the flow be:

if input == "" {
   // error out and return
}

// parse the input

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed

Comment on lines 58 to 60
if input == "" && len(c.flags.Args()) > 0 {
input = c.flags.Arg(0)
}
Copy link
Member

Choose a reason for hiding this comment

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

My vote would be to not use positional args here but instead support only the following:

  • consul resource apply -f <path to file> - loads content from specified path
  • consul resource apply -f - - loads content from stdin

This is how kubectl works and helps to reduce redundant ways that the input source can be specified.

In the future we could even support something like: consul resource apply -d <directory> to load all the files in the directory and apply them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the input, now the code looks much much more cleaner!!! Thank you!!!

input = c.flags.Arg(0)
}
if input != "" {
data, err := resource.ParseResourceInput(input, c.testStdin)
Copy link
Member

Choose a reason for hiding this comment

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

nit: You could do parsedResource, err = ... here and avoid the intermediate data variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed

// parse resource
input := c.filePath
if input == "" {
c.UI.Error("Incorrect argument format: Must provide exactly one positional argument to specify the resource to write")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
c.UI.Error("Incorrect argument format: Must provide exactly one positional argument to specify the resource to write")
c.UI.Error("Required '-f' flag was not provided to specify where to load the resource content from")

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the catch!

Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

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

One small suggestion but otherwise everything looks right to me.

Base automatically changed from xw/NET-7077-ACL-token to main January 16, 2024 16:25
@wangxinyi7 wangxinyi7 added pr/no-changelog PR does not need a corresponding .changelog entry pr/no-backport labels Jan 16, 2024
@wangxinyi7 wangxinyi7 merged commit 74b737d into main Jan 16, 2024
113 of 115 checks passed
@wangxinyi7 wangxinyi7 deleted the xw/NET-6307-grpc-client-apply branch January 16, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/no-backport pr/no-changelog PR does not need a corresponding .changelog entry theme/cli Flags and documentation for the CLI interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants