-
Notifications
You must be signed in to change notification settings - Fork 72
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
WIP: refactor: place utility methods in pkg/cmd #1371
WIP: refactor: place utility methods in pkg/cmd #1371
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.
Calling all of these packages a generic sdk
makes things less readable.
pkg/cmd/cluster/bind/bind.go
Outdated
"github.com/redhat-developer/app-services-cli/pkg/cmd/cluster/sdk" | ||
"github.com/redhat-developer/app-services-cli/pkg/cmd/cluster/sdk/kubeclient" | ||
"github.com/redhat-developer/app-services-cli/pkg/cmd/cluster/sdk/services/resources" | ||
"github.com/redhat-developer/app-services-cli/pkg/cmd/cluster/sdk/v1alpha" |
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 not class the cluster packages as utils - isn't the purpose of this PR to only move utils?
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 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.
Yeah I agree. sdk and util is the same thing to me, different names.. cluster
should be the package name here.
pkg/cmd/cluster/sdk/bind.go
Outdated
@@ -1,12 +1,12 @@ | |||
package cluster | |||
package sdk |
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.
This package name is too generic IMO. You will have multiple packages called sdk.
pkg/cmd/kafka/acl/admin/admin.go
Outdated
@@ -83,7 +83,7 @@ func NewAdminACLCommand(f *factory.Factory) *cobra.Command { | |||
} | |||
|
|||
// user and service account should not allow wildcard | |||
if userID == aclutil.Wildcard || serviceAccount == aclutil.Wildcard || userID == aclutil.AllAlias || serviceAccount == aclutil.AllAlias { | |||
if userID == sdk.Wildcard || serviceAccount == sdk.Wildcard || userID == sdk.AllAlias || serviceAccount == sdk.AllAlias { |
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.
If you look at this line, it is very difficult to understand what sdk
relates to. aclutil
is much more self descriptive.
<thing>util
is a common pattern in Go: https://pkg.go.dev/io/ioutil
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 have followed <thing>util
for utility methods at top level, i.e pkg/kafkautil
, pkg/serviceregistryutil
. I was hoping to follow a different naming convention for utils specific to commands, maybe aclcmdutil
, topiccmdutil
could be better alternative? 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 is all about import path.
if util/sdk/common has subpackages then we have nice pattern - single name used across all cli packages with specific sub packages.
It might be overkill so them we sacrifice pattern of using single name towards more packages in root - which is ok
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.
Quick look at other projects confirms what enda said. Havents seen packages with common subpackages being used in go
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.
Although our case is different as people might want import sdk etc. so it is self documenting change. etc
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.
Yeah, the import path does not matter a bit, what is important is the name of the package which will be used in the code.
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 have followed
<thing>util
for utility methods at top level, i.epkg/kafkautil
,pkg/serviceregistryutil
. I was hoping to follow a different naming convention for utils specific to commands, maybeaclcmdutil
,topiccmdutil
could be better alternative? Wdyt?
Yes I like that!.
Reviewed it later than Enda. Fully agree with the naming scheme that Enda proposed. |
I will agree, reverting the commit. |
21e5ced
to
379ce33
Compare
Amazing work! We can do that after PR is merged |
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.
LGTM!
@@ -162,7 +162,7 @@ func runDelete(instanceID string, opts *aclutil.CrudOptions) error { | |||
defer httpRes.Body.Close() | |||
} | |||
|
|||
err = aclutil.ValidateAPIError(httpRes, opts.Localizer, err, "delete", kafkaInstance.GetName()) | |||
err = aclcmdutil.ValidateAPIError(httpRes, opts.Localizer, err, "delete", kafkaInstance.GetName()) |
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 that ValidateAPIError
belongs more in an SDK instead of a cmd util, but we can revisit that when the error handling refactor happens.
activeMembersCount := consumergrouputil.GetActiveConsumersCount(consumers) | ||
partitionsWithLagCount := consumergrouputil.GetPartitionsWithLag(consumers) | ||
unassignedPartitions := consumergrouputil.GetUnassignedPartitions(consumers) | ||
activeMembersCount := groupcmdutil.GetActiveConsumersCount(consumers) |
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 and concise now :)
@@ -203,7 +202,7 @@ func runCmd(opts *options) error { | |||
} | |||
|
|||
func runInteractivePrompt(opts *options) (err error) { | |||
validator := topicutil.Validator{ | |||
validator := topiccmdutil.Validator{ |
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'd say eventually, validators wont be in the util package as they are not util methods, again that can happen during the SDK creation.
@@ -1,4 +1,4 @@ | |||
package topicutil | |||
package topiccmdutil |
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.
We should probably start to document all pakcage names and their meaning too, this should happen at the top of the package topiccmdutil
declaration, but to prevent duplication can be added in a doc.go file: https://go.dev/blog/godoc
We could document packages using the available Go tooling. You can define it all in a |
@craicoverflow @rkpattnaik780 Since we talking - what is your preference: A) Package based docs like: https://github.com/redhat-developer/app-services-cli/blob/main/pkg/cluster/cluster.go or B) Markdown format: |
Actually realized that syntax for the ones we have is wrong: https://pkg.go.dev/github.com/redhat-developer/[email protected]/pkg/cluster and as enda mentioned we should probably use docs.go instead. |
Moved utility methods to respective commands.
The sub-directories of
kafkautil
could be moved to the respective command specific directory.Certain methods of
kafkautil
,serviceregistryutil
andserviceaccountutil
had few methods used by core, specific methods have been moved to respective directory.Directory Structure
Type of change
Checklist