Skip to content

Commit 7497375

Browse files
authored
refactor Name() and ExtendedName(c) methods (#865)
* refactor Name() and ExtendedName(c) methods * remove extendedPrefix method * remove ExtendedName() method * fix * pass config param where possible
1 parent 1fd0169 commit 7497375

30 files changed

+222
-212
lines changed

pkg/awsvpc/parser.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,15 @@ func printConfig(c *vpcmodel.VPCConfig) {
446446
if n.IsExternal() {
447447
continue
448448
}
449-
logging.Debug(strings.Join([]string{n.Kind(), n.CidrOrAddress(), n.Name(), n.UID()}, separator))
449+
logging.Debug(strings.Join([]string{n.Kind(), n.CidrOrAddress(), n.NameForAnalyzerOut(c), n.UID()}, separator))
450450
}
451451
logging.Debug("Subnets:")
452452
for _, n := range c.Subnets {
453-
logging.Debug(strings.Join([]string{n.Kind(), n.CIDR(), n.Name(), n.UID()}, separator))
453+
logging.Debug(strings.Join([]string{n.Kind(), n.CIDR(), n.NameForAnalyzerOut(c), n.UID()}, separator))
454454
}
455455
logging.Debug("NodeSets:")
456456
for _, n := range c.NodeSets {
457-
logging.Debug(strings.Join([]string{n.Kind(), n.AddressRange().ToIPRanges(), n.Name(), n.UID()}, separator))
457+
logging.Debug(strings.Join([]string{n.Kind(), n.AddressRange().ToIPRanges(), n.NameForAnalyzerOut(c), n.UID()}, separator))
458458
}
459459
logging.Debug("FilterResources:")
460460
for _, f := range c.FilterResources {

pkg/commonvpc/vpc.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,8 @@ func (ni *NetworkInterface) VsiName() string {
9090
return ni.Vsi
9191
}
9292

93-
func (ni *NetworkInterface) Name() string {
94-
return nameWithBracketsInfo(ni.Vsi, ni.Address())
95-
}
96-
97-
func (ni *NetworkInterface) ExtendedName(c *vpcmodel.VPCConfig) string {
98-
return ni.ExtendedPrefix(c) + ni.Name()
93+
func (ni *NetworkInterface) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
94+
return MultipleVPCsConfigPrefix(c, &ni.VPCResource) + nameWithBracketsInfo(ni.Vsi, ni.Address())
9995
}
10096

10197
func nameWithBracketsInfo(name, inBrackets string) string {
@@ -737,3 +733,11 @@ func getTableConnEffect(connQuery, conn *connection.Set) (*connection.Set, vpcmo
737733
return conn.Intersect(connQuery), vpcmodel.PartlyAllow
738734
}
739735
}
736+
737+
// MultipleVPCsConfigPrefix returns the vpcName of the passed resource when config is multi-vpc
738+
func MultipleVPCsConfigPrefix(c *vpcmodel.VPCConfig, resource *vpcmodel.VPCResource) string {
739+
if c != nil && resource.VPC() != nil {
740+
return c.MultipleVPCsConfigPrefix(resource.VPC().Name())
741+
}
742+
return ""
743+
}

pkg/ibmvpc/examples/out/synthesis_out/acl_testing3_all_vpcs_.json

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@
44
"external-1": "161.26.0.0/16"
55
},
66
"required-connections": [
7+
{
8+
"allowed-protocols": [
9+
{
10+
"protocol": "ANY"
11+
}
12+
],
13+
"dst": {
14+
"name": "test-vpc1-ky/vsi1-ky",
15+
"type": "instance"
16+
},
17+
"src": {
18+
"name": "test-vpc1-ky/vsi2-ky",
19+
"type": "instance"
20+
}
21+
},
22+
{
23+
"allowed-protocols": [
24+
{
25+
"protocol": "ICMP"
26+
}
27+
],
28+
"dst": {
29+
"name": "external-0",
30+
"type": "external"
31+
},
32+
"src": {
33+
"name": "test-vpc1-ky/vsi2-ky",
34+
"type": "instance"
35+
}
36+
},
737
{
838
"allowed-protocols": [
939
{
@@ -16,8 +46,8 @@
1646
"type": "instance"
1747
},
1848
"src": {
19-
"name": "test-vpc1-ky/vsi3c-ky",
20-
"type": "instance"
49+
"name": "test-vpc1-ky/db-endpoint-gateway-ky",
50+
"type": "vpe"
2151
}
2252
},
2353
{
@@ -32,8 +62,8 @@
3262
"type": "instance"
3363
},
3464
"src": {
35-
"name": "test-vpc1-ky/vsi3c-ky",
36-
"type": "instance"
65+
"name": "test-vpc1-ky/db-endpoint-gateway-ky",
66+
"type": "vpe"
3767
}
3868
},
3969
{
@@ -47,8 +77,8 @@
4777
"type": "instance"
4878
},
4979
"src": {
50-
"name": "test-vpc1-ky/vsi3c-ky",
51-
"type": "instance"
80+
"name": "test-vpc1-ky/db-endpoint-gateway-ky",
81+
"type": "vpe"
5282
}
5383
},
5484
{
@@ -65,8 +95,8 @@
6595
"type": "instance"
6696
},
6797
"src": {
68-
"name": "test-vpc1-ky/vsi3c-ky",
69-
"type": "instance"
98+
"name": "test-vpc1-ky/db-endpoint-gateway-ky",
99+
"type": "vpe"
70100
}
71101
},
72102
{
@@ -77,12 +107,12 @@
77107
],
78108
"bidirectional": true,
79109
"dst": {
80-
"name": "test-vpc1-ky/db-endpoint-gateway-ky",
81-
"type": "vpe"
82-
},
83-
"src": {
84110
"name": "test-vpc1-ky/vsi3c-ky",
85111
"type": "instance"
112+
},
113+
"src": {
114+
"name": "test-vpc1-ky/db-endpoint-gateway-ky",
115+
"type": "vpe"
86116
}
87117
},
88118
{
@@ -142,8 +172,8 @@
142172
],
143173
"bidirectional": true,
144174
"dst": {
145-
"name": "test-vpc1-ky/db-endpoint-gateway-ky",
146-
"type": "vpe"
175+
"name": "test-vpc1-ky/vsi3c-ky",
176+
"type": "instance"
147177
},
148178
"src": {
149179
"name": "test-vpc1-ky/vsi3b-ky",
@@ -191,41 +221,11 @@
191221
],
192222
"bidirectional": true,
193223
"dst": {
194-
"name": "test-vpc1-ky/db-endpoint-gateway-ky",
195-
"type": "vpe"
196-
},
197-
"src": {
198-
"name": "test-vpc1-ky/vsi3a-ky",
199-
"type": "instance"
200-
}
201-
},
202-
{
203-
"allowed-protocols": [
204-
{
205-
"protocol": "ANY"
206-
}
207-
],
208-
"dst": {
209-
"name": "test-vpc1-ky/vsi1-ky",
210-
"type": "instance"
211-
},
212-
"src": {
213-
"name": "test-vpc1-ky/vsi2-ky",
224+
"name": "test-vpc1-ky/vsi3c-ky",
214225
"type": "instance"
215-
}
216-
},
217-
{
218-
"allowed-protocols": [
219-
{
220-
"protocol": "ICMP"
221-
}
222-
],
223-
"dst": {
224-
"name": "external-0",
225-
"type": "external"
226226
},
227227
"src": {
228-
"name": "test-vpc1-ky/vsi2-ky",
228+
"name": "test-vpc1-ky/vsi3a-ky",
229229
"type": "instance"
230230
}
231231
},
@@ -273,8 +273,8 @@
273273
"type": "instance"
274274
},
275275
"src": {
276-
"name": "test-vpc1-ky/db-endpoint-gateway-ky",
277-
"type": "vpe"
276+
"name": "test-vpc1-ky/vsi3c-ky",
277+
"type": "instance"
278278
}
279279
},
280280
{
@@ -291,8 +291,8 @@
291291
"type": "instance"
292292
},
293293
"src": {
294-
"name": "test-vpc1-ky/db-endpoint-gateway-ky",
295-
"type": "vpe"
294+
"name": "test-vpc1-ky/vsi3c-ky",
295+
"type": "instance"
296296
}
297297
}
298298
]

pkg/ibmvpc/examples/out/synthesis_out/experiments_env_all_vpcs_.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
],
1212
"bidirectional": true,
1313
"dst": {
14-
"name": "test-vpc1-ky/vsi1-ky",
14+
"name": "test-vpc1-ky/vsi2-ky",
1515
"type": "instance"
1616
},
1717
"src": {
18-
"name": "test-vpc1-ky/vsi2-ky",
18+
"name": "test-vpc1-ky/vsi1-ky",
1919
"type": "instance"
2020
}
2121
},
@@ -31,7 +31,7 @@
3131
"type": "instance"
3232
},
3333
"src": {
34-
"name": "test-vpc1-ky/vsi2-ky",
34+
"name": "test-vpc1-ky/vsi1-ky",
3535
"type": "instance"
3636
}
3737
},
@@ -43,8 +43,8 @@
4343
],
4444
"bidirectional": true,
4545
"dst": {
46-
"name": "external-0",
47-
"type": "external"
46+
"name": "test-vpc1-ky/vsi0-ky",
47+
"type": "instance"
4848
},
4949
"src": {
5050
"name": "test-vpc1-ky/vsi2-ky",
@@ -59,11 +59,11 @@
5959
],
6060
"bidirectional": true,
6161
"dst": {
62-
"name": "test-vpc1-ky/vsi0-ky",
63-
"type": "instance"
62+
"name": "external-0",
63+
"type": "external"
6464
},
6565
"src": {
66-
"name": "test-vpc1-ky/vsi1-ky",
66+
"name": "test-vpc1-ky/vsi2-ky",
6767
"type": "instance"
6868
}
6969
},

pkg/ibmvpc/ibmDrawioGenerator.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ func (lb *LoadBalancer) GenerateDrawioTreeNode(gen *vpcmodel.DrawioGenerator) dr
7272
}
7373
}
7474
vpcTn := gen.TreeNode(lb.VPC()).(drawio.SquareTreeNodeInterface)
75-
// here we do not call lb.Name() because lb.Name() add the kind to the name
76-
return drawio.GroupPrivateIPsWithLoadBalancer(vpcTn, lb.ResourceName, privateIPs)
75+
return drawio.GroupPrivateIPsWithLoadBalancer(vpcTn, lb.Name(), privateIPs)
7776
}
7877
func (pip *PrivateIP) GenerateDrawioTreeNode(gen *vpcmodel.DrawioGenerator) drawio.TreeNodeInterface {
7978
if gen.LBAbstraction() {

pkg/ibmvpc/implicit_routing.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ func (rt *systemImplicitRT) getIngressPath(dest *ipblock.IPBlock) (vpcmodel.Path
111111
// traffic from some source is by default simply routed to dest node
112112
path := rt.destAsPath(dest)
113113
if len(path) == 0 {
114-
return nil, fmt.Errorf("getIngressPath: failed to find path to dest resource address %s in VPC %s", dest.String(), rt.vpc.Name())
114+
return nil, fmt.Errorf("getIngressPath: failed to find path to dest resource address %s in VPC %s",
115+
dest.String(), rt.vpc.Name())
115116
}
116117
return path, nil
117118
}

pkg/ibmvpc/parser.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,19 +1517,19 @@ func printConfig(c *vpcmodel.VPCConfig) {
15171517
if n.IsExternal() {
15181518
continue
15191519
}
1520-
logging.Debug(strings.Join([]string{n.Kind(), n.CidrOrAddress(), n.Name(), n.UID()}, separator))
1520+
logging.Debug(strings.Join([]string{n.Kind(), n.CidrOrAddress(), n.NameForAnalyzerOut(c), n.UID()}, separator))
15211521
}
15221522
logging.Debug("Subnets:")
15231523
for _, n := range c.Subnets {
1524-
logging.Debug(strings.Join([]string{n.Kind(), n.CIDR(), n.Name(), n.UID()}, separator))
1524+
logging.Debug(strings.Join([]string{n.Kind(), n.CIDR(), n.NameForAnalyzerOut(c), n.UID()}, separator))
15251525
}
15261526
logging.Debug("LoadBalancers:")
15271527
for _, lb := range c.LoadBalancers {
1528-
logging.Debug(strings.Join([]string{lb.Kind(), lb.Name(), lb.AddressRange().ToIPRanges(), lb.UID()}, separator))
1528+
logging.Debug(strings.Join([]string{lb.Kind(), lb.NameForAnalyzerOut(c), lb.AddressRange().ToIPRanges(), lb.UID()}, separator))
15291529
}
15301530
logging.Debug("NodeSets:")
15311531
for _, n := range c.NodeSets {
1532-
logging.Debug(strings.Join([]string{n.Kind(), n.AddressRange().ToIPRanges(), n.Name(), n.UID()}, separator))
1532+
logging.Debug(strings.Join([]string{n.Kind(), n.AddressRange().ToIPRanges(), n.NameForAnalyzerOut(c), n.UID()}, separator))
15331533
}
15341534
logging.Debug("FilterResources:")
15351535
for _, f := range c.FilterResources {
@@ -1554,14 +1554,14 @@ func printConfig(c *vpcmodel.VPCConfig) {
15541554
}
15551555
logging.Debug("RoutingResources:")
15561556
for _, r := range c.RoutingResources {
1557-
logging.Debug(strings.Join([]string{r.Kind(), r.Name(), r.UID()}, separator))
1557+
logging.Debug(strings.Join([]string{r.Kind(), r.NameForAnalyzerOut(c), r.UID()}, separator))
15581558
if tgw, ok := r.(*TransitGateway); ok {
15591559
printTGWAvailableRoutes(tgw)
15601560
}
15611561
}
15621562
logging.Debug("RoutingTables:")
15631563
for _, r := range c.RoutingTables {
1564-
logging.Debug(strings.Join([]string{r.Kind(), r.Name(), r.UID(), "vpc:", r.VPC().UID()}, separator))
1564+
logging.Debug(strings.Join([]string{r.Kind(), r.NameForAnalyzerOut(c), r.UID(), "vpc:", r.VPC().UID()}, separator))
15651565
if rt, ok := r.(*ingressRoutingTable); ok {
15661566
logging.Debug("ingress routing table")
15671567
logging.Debug(rt.string())
@@ -1572,7 +1572,7 @@ func printConfig(c *vpcmodel.VPCConfig) {
15721572
logging.Debug("subnets:")
15731573
subnetsList := make([]string, len(rt.subnets))
15741574
for i := range rt.subnets {
1575-
subnetsList[i] = rt.subnets[i].Name()
1575+
subnetsList[i] = rt.subnets[i].NameForAnalyzerOut(c)
15761576
}
15771577
logging.Debug(strings.Join(subnetsList, ","))
15781578
}

pkg/ibmvpc/routing_tables_analysis.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,8 @@ func (irt *ingressRoutingTable) advertiseRoutes(vpcConfig *vpcmodel.VPCConfig) {
618618
var tgwAB *TransitGateway
619619
for _, tgw := range tgws {
620620
for _, vpc := range tgw.vpcs {
621-
logging.Debugf("check tgw %s with vpc %s, AP %s", tgw.Name(), vpc.Name(), vpc.AddressPrefixesIPBlock.ToCidrListString())
621+
logging.Debugf("check tgw %s with vpc %s, AP %s", tgw.Name(),
622+
vpc.Name(), vpc.AddressPrefixesIPBlock.ToCidrListString())
622623
// TODO: shouldn't be containment rather than intersection?? (works with intersection on hub-n-spoke config object)
623624
if vpc.UID() != irt.vpc.UID() && routeCidr.Overlap(vpc.AddressPrefixesIPBlock) {
624625
vpcB = vpc

0 commit comments

Comments
 (0)