-
Notifications
You must be signed in to change notification settings - Fork 0
refactor Name() and ExtendedName(c) methods #865
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
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.
added a comment with some questions.
pkg/vpcmodel/abstractVPC.go
Outdated
@@ -21,6 +21,7 @@ const ( | |||
type VPCResourceIntf interface { | |||
UID() string | |||
Name() string | |||
NameForAnalyzerOut() string |
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.
still confusing/unclear functionality for Name
/ NameForAnalyzerOut
/ ExtendedName
/ ExtendedPrefix
.
- Does the interface need to have all these methods?
- what is the use case for each method?
- which methods are overriden for certain types? is this required? (cannot be implemented explicitly instead of changing expected behavior of certain method?)
- is there a method that always returns the original resource name from the config object?
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.
- is there a method that always returns the original resource name from the config object?
Name()
consider renaming to resourceName() + doc
Does the interface need to have all these methods?
we need Name() and NameForAnalyzerOut , ExtendedName and ExtendedPrefix will check if we can merge it with NameForAnalyzerOut
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.
looks good!
few more comments
pkg/ibmvpc/vpc.go
Outdated
prefix := "" | ||
if c != nil && c.IsMultipleVPCsConfig { | ||
prefix = pip.VPC().Name() + vpcmodel.Deliminator | ||
} |
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 code seems to be duplicated across this file.. can be moved to some other internal function that gets config and VPC name as inputs?
pkg/vpcmodel/abstractVPC.go
Outdated
return n.ExtendedPrefix(c) + n.Name() | ||
func (n *VPCResource) NameForAnalyzerOut(c *VPCConfig) string { | ||
prefix := "" | ||
if c != nil && c.IsMultipleVPCsConfig { |
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.
maybe the config type should have a method that encapsulates this concept of required prefix?
one more comment: can you revisit where |
I assumed that it is not needed where we originally called the previous func without the config... and passed the config where we originaly called ExtendedName (with the config). |
makes sense, but if you can revisit as suggested above this may help to better understand these aspects, update documentation as to where this is expected to be used, etc.. (maybe also find if it makes sense to add the config in other places, to be less error-prone). when should call |
pkg/ibmvpc/vpc.go
Outdated
if c != nil { | ||
prefix = c.MultipleVPCsConfigPrefix(r.VPC().Name()) |
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.
can add another internal function that gets as input arg the config object and returns that prefix, and here always just have prefix + nameWithBracketsInfo(r.vpe, r.Address())
(to avoid this duplication across this file as well) .
pkg/vpcmodel/vpcConfig.go
Outdated
@@ -44,6 +44,14 @@ type VPCConfig struct { | |||
IsMultipleVPCsConfig bool | |||
} | |||
|
|||
// MultipleVPCsConfigPrefix returns the passed prefix when config is multi-vpc | |||
func (c *VPCConfig) MultipleVPCsConfigPrefix(prefix string) string { |
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.
change arg name to vpcName ?
pkg/commonvpc/vpc.go
Outdated
|
||
// MultipleVPCsConfigPrefix returns the passed vpcName when config is multi-vpc | ||
func MultipleVPCsConfigPrefix(c *vpcmodel.VPCConfig, vpcName string) string { | ||
if c != nil && c.IsMultipleVPCsConfig { |
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 c != nil && c.IsMultipleVPCsConfig { | |
if c != nil { |
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.
looks good.
There are more cases with NameForAnalyzerOut(nil)
is used. Do you have insights about those cases?
|
||
// MultipleVPCsConfigPrefix returns the vpcName of the passed resource when config is multi-vpc | ||
func MultipleVPCsConfigPrefix(c *vpcmodel.VPCConfig, resource *vpcmodel.VPCResource) string { | ||
if c != nil && resource.VPC() != nil { |
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.
when is resource.VPC()
expected to be nil
?
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 got some tests failed before I added this condition, it seems like there are some cases we do not init config file in tests
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.
only unit tests or end-to-end tests?
this is not about initializing config file, but having the resource a pointer to the VPC it is contained in.
in these cases the config param is not reachable, or that we need to make a lot of changes |
@ShiriMoran can you review the places where |
return n.ExtendedPrefix(c) + n.Name() | ||
func (n *VPCResource) NameForAnalyzerOut(c *VPCConfig) string { | ||
prefix := "" | ||
if c != nil && n.VPC() != nil { |
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 c != nil
, can n.VPC()
be nil?
|
Thanks @ShiriMoran , sounds good. I think so as well. |
thanks |
No description provided.