Skip to content

Commit 4c5cfe4

Browse files
committed
convert vpcconfig methods to functions
1 parent 22fd40b commit 4c5cfe4

22 files changed

+121
-128
lines changed

pkg/commonvpc/vpc.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (ni *NetworkInterface) VsiName() string {
9191
}
9292

9393
func (ni *NetworkInterface) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
94-
return MultipleVPCsConfigPrefix(c, &ni.VPCResource) + nameWithBracketsInfo(ni.Vsi, ni.Address())
94+
return vpcmodel.MultipleVPCsConfigPrefix(c, &ni.VPCResource) + nameWithBracketsInfo(ni.Vsi, ni.Address())
9595
}
9696

9797
func nameWithBracketsInfo(name, inBrackets string) string {
@@ -733,11 +733,3 @@ func getTableConnEffect(connQuery, conn *connection.Set) (*connection.Set, vpcmo
733733
return conn.Intersect(connQuery), vpcmodel.PartlyAllow
734734
}
735735
}
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/egress_routing_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (test *testRTAnalyzer) run(t *testing.T) {
149149
// build config and routing tables from test
150150
config1, egressRT1 := newBasicConfig(test.rps)
151151
for _, rt := range egressRT1 {
152-
config1.AddRoutingTable(rt)
152+
vpcmodel.AddRoutingTable(config1, rt)
153153
}
154154

155155
rtAnalyzer1 := newRTAnalyzer(config1)

pkg/ibmvpc/implicit_routing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type systemRTConfig struct {
6363
}
6464

6565
func (rt *systemImplicitRT) destAsPath(dest *ipblock.IPBlock) vpcmodel.Path {
66-
internalNodes := rt.vpcConfig.GetNodesWithinInternalAddress(dest)
66+
internalNodes := vpcmodel.GetNodesWithinInternalAddress(rt.vpcConfig, dest)
6767
if len(internalNodes) != 1 {
6868
// TODO: add error handling here?
6969
return nil

pkg/ibmvpc/ingress_routing_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func newHubSpokeBase2Config() (*vpcmodel.MultipleVPCConfigs, *GlobalRTAnalyzer)
158158
ingressRT := newIngressRoutingTableFromRoutes([]*route{r1, r2}, transitConfig, &vpcmodel.VPCResource{})
159159

160160
// add ingressRT to transit vpc config
161-
transitConfig.AddRoutingTable(ingressRT)
161+
vpcmodel.AddRoutingTable(transitConfig, ingressRT)
162162

163163
analyzer := NewGlobalRTAnalyzer(globalConfig)
164164
return globalConfig, analyzer
@@ -185,7 +185,7 @@ func newHubSpokeBase3Config() (*vpcmodel.MultipleVPCConfigs, *GlobalRTAnalyzer)
185185
ingressRT := newIngressRoutingTableFromRoutes([]*route{r1, r2, r3}, transitConfig, &vpcmodel.VPCResource{})
186186

187187
// add ingressRT to transit vpc config
188-
transitConfig.AddRoutingTable(ingressRT)
188+
vpcmodel.AddRoutingTable(transitConfig, ingressRT)
189189
analyzer := NewGlobalRTAnalyzer(globalConfig)
190190
return globalConfig, analyzer
191191
}
@@ -224,16 +224,16 @@ func newHubSpokeBase4Config() (*vpcmodel.MultipleVPCConfigs, *GlobalRTAnalyzer)
224224
// define routes of the ingress routing table for transit vpc
225225
ingressRT := newIngressRoutingTableFromRoutes([]*route{r1, r2}, transitConfig, &vpcmodel.VPCResource{})
226226
// add ingressRT to transit vpc config
227-
transitConfig.AddRoutingTable(ingressRT)
227+
vpcmodel.AddRoutingTable(transitConfig, ingressRT)
228228

229229
transitEgressRT := newEgressRoutingTableFromRoutes([]*route{r4, r5, r6},
230230
getSubnetsByUIDs(transitConfig, []string{"workerSubnetTransit"}), transitConfig, &vpcmodel.VPCResource{})
231-
transitConfig.AddRoutingTable(transitEgressRT)
231+
vpcmodel.AddRoutingTable(transitConfig, transitEgressRT)
232232

233233
spokeConfig := globalConfig.Config("spoke")
234234
spokeEgressRT := newEgressRoutingTableFromRoutes([]*route{r4, r5, r7},
235235
getSubnetsByUIDs(spokeConfig, []string{"workerSubnetSpoke"}), spokeConfig, &vpcmodel.VPCResource{})
236-
spokeConfig.AddRoutingTable(spokeEgressRT)
236+
vpcmodel.AddRoutingTable(spokeConfig, spokeEgressRT)
237237
// define routes of the egress routing table for transit vpc
238238

239239
analyzer := NewGlobalRTAnalyzer(globalConfig)

pkg/ibmvpc/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (rc *IBMresourcesContainer) getRoutingTables(
251251
}
252252
logging.Debugf("add rt %s for vpc %s\n", rtObj.Name(), vpcUID)
253253

254-
vpcConfig.AddRoutingTable(rtObj)
254+
vpcmodel.AddRoutingTable(vpcConfig, rtObj)
255255
res.SetConfig(vpcUID, vpcConfig)
256256
}
257257
return nil
@@ -1135,7 +1135,7 @@ func (rc *IBMresourcesContainer) getVPEconfig(
11351135

11361136
func getSubnetByCidr(res *vpcmodel.MultipleVPCConfigs, cidr string) (*commonvpc.Subnet, error) {
11371137
for _, config := range res.Configs() {
1138-
if subnet, err := config.SubnetCidrToSubnetElem(cidr); err == nil {
1138+
if subnet, err := vpcmodel.SubnetCidrToSubnetElem(config, cidr); err == nil {
11391139
return subnet.(*commonvpc.Subnet), nil
11401140
}
11411141
}

pkg/ibmvpc/vpc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type ReservedIP struct {
3838
}
3939

4040
func (r *ReservedIP) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
41-
return commonvpc.MultipleVPCsConfigPrefix(c, &r.VPCResource) + nameWithBracketsInfo(r.vpe, r.Address())
41+
return vpcmodel.MultipleVPCsConfigPrefix(c, &r.VPCResource) + nameWithBracketsInfo(r.vpe, r.Address())
4242
}
4343

4444
// used for synthesis output
@@ -71,7 +71,7 @@ func (pip *PrivateIP) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
7171
address = strings.Join(pip.block.ListToPrint(), ",")
7272
}
7373
name := nameWithBracketsInfo(pip.loadBalancer.Name(), kind)
74-
return commonvpc.MultipleVPCsConfigPrefix(c, &pip.VPCResource) + nameWithBracketsInfo(name, address)
74+
return vpcmodel.MultipleVPCsConfigPrefix(c, &pip.VPCResource) + nameWithBracketsInfo(name, address)
7575
}
7676

7777
// AbstractedToNodeSet returns the pip load balancer if it was abstracted
@@ -96,7 +96,7 @@ func (n *IKSNode) VsiName() string {
9696
}
9797

9898
func (n *IKSNode) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
99-
return commonvpc.MultipleVPCsConfigPrefix(c, &n.VPCResource) + nameWithBracketsInfo(n.Name(), n.Address())
99+
return vpcmodel.MultipleVPCsConfigPrefix(c, &n.VPCResource) + nameWithBracketsInfo(n.Name(), n.Address())
100100
}
101101

102102
// vpe can be in multiple zones - depending on the zones of its network interfaces..
@@ -150,7 +150,7 @@ func (lb *LoadBalancer) nameWithKind() string {
150150
return nameWithBracketsInfo(lb.ResourceName, lb.Kind())
151151
}
152152
func (lb *LoadBalancer) NameForAnalyzerOut(c *vpcmodel.VPCConfig) string {
153-
return commonvpc.MultipleVPCsConfigPrefix(c, &lb.VPCResource) + lb.nameWithKind()
153+
return vpcmodel.MultipleVPCsConfigPrefix(c, &lb.VPCResource) + lb.nameWithKind()
154154
}
155155

156156
func (lb *LoadBalancer) Nodes() []vpcmodel.Node {

pkg/linter/lintRuleCIDROutOfRange.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func findRuleNonRelevantCIDR(configs map[string]*vpcmodel.VPCConfig, filterLayer
5959
continue // no use in executing lint on dummy vpcs
6060
}
6161
vpcAddressRange := config.VPC.AddressRange()
62-
filterLayer := config.GetFilterTrafficResourceOfKind(filterLayerName)
62+
filterLayer := vpcmodel.GetFilterTrafficResourceOfKind(config, filterLayerName)
6363
rules, err := filterLayer.GetRules()
6464
if err != nil {
6565
return nil, err

pkg/linter/lintRuleShadowedOrImplied.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func getAtomicBlocks(atomicBlocks []*ipblock.IPBlock, srcOrdst *ipblock.IPBlock)
158158
// 2. To slice of the atomic blocks of the table
159159
func getTablesRulesAndAtomicBlocks(config *vpcmodel.VPCConfig, filterLayerName string) (tableToRules map[int][]*vpcmodel.RuleOfFilter,
160160
tableToAtomicBlocks map[int][]*ipblock.IPBlock, err error) {
161-
filterLayer := config.GetFilterTrafficResourceOfKind(filterLayerName)
161+
filterLayer := vpcmodel.GetFilterTrafficResourceOfKind(config, filterLayerName)
162162
rules, err := filterLayer.GetRules()
163163
if err != nil {
164164
return nil, nil, err

pkg/linter/lintRuleSplitSubnet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func findSplitRulesSubnet(configs map[string]*vpcmodel.VPCConfig, filterLayerNam
5757
if config.IsMultipleVPCsConfig {
5858
continue // no use in executing lint on dummy vpcs
5959
}
60-
filterLayer := config.GetFilterTrafficResourceOfKind(filterLayerName)
60+
filterLayer := vpcmodel.GetFilterTrafficResourceOfKind(config, filterLayerName)
6161
rules, err := filterLayer.GetRules()
6262
if err != nil {
6363
return nil, err

pkg/linter/lintUnattached.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func findUnattachedTables(configs map[string]*vpcmodel.VPCConfig, filterLayerNam
5555
if config.IsMultipleVPCsConfig {
5656
continue // no use in executing this lint on dummy vpcs
5757
}
58-
filterLayer := config.GetFilterTrafficResourceOfKind(filterLayerName)
58+
filterLayer := vpcmodel.GetFilterTrafficResourceOfKind(config, filterLayerName)
5959
layerName := vpcmodel.FilterKindName(filterLayerName)
6060
filtersAttachedResources := filterLayer.GetFiltersAttachedResources()
6161
for table, attached := range filtersAttachedResources {

0 commit comments

Comments
 (0)