WIP: refactor: place utility methods in pkg/cmd#1371
WIP: refactor: place utility methods in pkg/cmd#1371wtrocki merged 3 commits intoredhat-developer:developmentfrom
Conversation
craicoverflow
left a comment
There was a problem hiding this comment.
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.
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.
There was a problem hiding this comment.
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.
This package name is too generic IMO. You will have multiple packages called sdk.
pkg/cmd/kafka/acl/admin/admin.go
Outdated
|
|
||
| // 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.
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.
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.
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.
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.
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.
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.
I have followed
<thing>utilfor 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,topiccmdutilcould 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 |
| } | ||
|
|
||
| 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.
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.
nice and concise now :)
|
|
||
| func runInteractivePrompt(opts *options) (err error) { | ||
| validator := topicutil.Validator{ | ||
| validator := topiccmdutil.Validator{ |
There was a problem hiding this comment.
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.
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
kafkautilcould be moved to the respective command specific directory.Certain methods of
kafkautil,serviceregistryutilandserviceaccountutilhad few methods used by core, specific methods have been moved to respective directory.Directory Structure
Type of change
Checklist