Skip to content

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

Merged
merged 18 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pkg/commonvpc/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ func (ni *NetworkInterface) VsiName() string {
}

func (ni *NetworkInterface) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
prefix := ""
if c != nil {
prefix = c.MultipleVPCsConfigPrefix(ni.VPC().Name())
}
return prefix + nameWithBracketsInfo(ni.Vsi, ni.Address())
return MultipleVPCsConfigPrefix(c, ni.VPC().Name()) + nameWithBracketsInfo(ni.Vsi, ni.Address())
}

func nameWithBracketsInfo(name, inBrackets string) string {
Expand Down Expand Up @@ -737,3 +733,11 @@ func getTableConnEffect(connQuery, conn *connection.Set) (*connection.Set, vpcmo
return conn.Intersect(connQuery), vpcmodel.PartlyAllow
}
}

// MultipleVPCsConfigPrefix returns the passed vpcName when config is multi-vpc
func MultipleVPCsConfigPrefix(c *vpcmodel.VPCConfig, vpcName string) string {
if c != nil && c.IsMultipleVPCsConfig {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if c != nil && c.IsMultipleVPCsConfig {
if c != nil {

return c.MultipleVPCsConfigPrefix(vpcName)
}
return ""
}
25 changes: 4 additions & 21 deletions pkg/ibmvpc/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ type ReservedIP struct {
}

func (r *ReservedIP) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
prefix := ""
if c != nil {
prefix = c.MultipleVPCsConfigPrefix(r.VPC().Name())
}
return prefix + nameWithBracketsInfo(r.vpe, r.Address())
return commonvpc.MultipleVPCsConfigPrefix(c, r.VPC().Name()) + nameWithBracketsInfo(r.vpe, r.Address())
}

// used for synthesis output
Expand All @@ -67,11 +63,6 @@ type PrivateIP struct {
}

func (pip *PrivateIP) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
prefix := ""
if c != nil {
prefix = c.MultipleVPCsConfigPrefix(pip.VPC().Name())
}

kind := "LB private IP"
address := pip.Address()
if !pip.original {
Expand All @@ -80,7 +71,7 @@ func (pip *PrivateIP) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
address = strings.Join(pip.block.ListToPrint(), ",")
}
name := nameWithBracketsInfo(pip.loadBalancer.Name(), kind)
return prefix + nameWithBracketsInfo(name, address)
return commonvpc.MultipleVPCsConfigPrefix(c, pip.VPC().Name()) + nameWithBracketsInfo(name, address)
}

// AbstractedToNodeSet returns the pip load balancer if it was abstracted
Expand All @@ -105,11 +96,7 @@ func (n *IKSNode) VsiName() string {
}

func (n *IKSNode) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
prefix := ""
if c != nil {
prefix = c.MultipleVPCsConfigPrefix(n.VPC().Name())
}
return prefix + nameWithBracketsInfo(n.Name(), n.Address())
return commonvpc.MultipleVPCsConfigPrefix(c, n.VPC().Name()) + nameWithBracketsInfo(n.Name(), n.Address())
}

// vpe can be in multiple zones - depending on the zones of its network interfaces..
Expand Down Expand Up @@ -163,11 +150,7 @@ func (lb *LoadBalancer) nameWithKind() string {
return nameWithBracketsInfo(lb.ResourceName, lb.Kind())
}
func (lb *LoadBalancer) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
prefix := ""
if c != nil {
prefix = c.MultipleVPCsConfigPrefix(lb.VPC().Name())
}
return prefix + lb.nameWithKind()
return commonvpc.MultipleVPCsConfigPrefix(c, lb.VPC().Name()) + lb.nameWithKind()
}

func (lb *LoadBalancer) Nodes() []vpcmodel.Node {
Expand Down
6 changes: 3 additions & 3 deletions pkg/vpcmodel/vpcConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ type VPCConfig struct {
IsMultipleVPCsConfig bool
}

// MultipleVPCsConfigPrefix returns the passed prefix when config is multi-vpc
func (c *VPCConfig) MultipleVPCsConfigPrefix(prefix string) string {
// MultipleVPCsConfigPrefix returns the passed vpcName when config is multi-vpc
func (c *VPCConfig) MultipleVPCsConfigPrefix(vpcName string) string {
if c.IsMultipleVPCsConfig {
return prefix + Deliminator
return vpcName + Deliminator
}
return ""
}
Expand Down
Loading