Skip to content

Commit 4fb5479

Browse files
committed
Merge branch 'main' into lb-expalinability-in-cli
2 parents 5b75053 + a15d5fc commit 4fb5479

File tree

1 file changed

+32
-38
lines changed

1 file changed

+32
-38
lines changed

pkg/vpcmodel/explainabilityInput.go

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ const noValidInputMsg = "is not a legal IP address, CIDR, or endpoint name"
4848

4949
const deliminator = "/"
5050

51-
// was src/dst input provided as internal address of a vsi? this is required info since
52-
// if this is the case then in the output the relevant detected VSIs' names are printed
51+
// was src/dst input provided as internal address of an endpoint? this is required info since
52+
// if this is the case then in the output the relevant detected endpoints' names are printed
5353
type srcDstInternalAddr struct {
5454
src bool
5555
dst bool
@@ -63,8 +63,8 @@ type srcAndDstNodes struct {
6363

6464
// getVPCConfigAndSrcDstNodes given src, dst in string returns the config in which the exaplainability analysis of these
6565
// should be done and the Nodes for src and dst. It also returns whether src and/or dst was given as the internal address of
66-
// a vsi - which effects the output.
67-
// src/dst when referring to a vsi *name* may be prefixed with the vpc name with the deliminator "/" to solve ambiguity
66+
// an endpoint - which effects the output.
67+
// src/dst when referring to an endpoint *name* may be prefixed with the vpc name with the deliminator "/" to solve ambiguity
6868
// If such prefix is missing then a match in any vpc is valid.
6969
// At most one config should contain both src and dst, and this is the config returned:
7070
// * If one is internal and the other is external the vpcConfig of the internal is returned
@@ -74,7 +74,7 @@ type srcAndDstNodes struct {
7474
// this is the vpcConfig that will be returned, if such tgw exists; if such a tgw does not exist the src and dst are not connected
7575
// At this stage, we do not support the following:
7676
// 1. two tgw connects src and dst;
77-
// 2. src and/or dst has VSI(s) in more than one VPC
77+
// 2. src and/or dst has endpoint(s) in more than one VPC
7878

7979
// error handling: the src and dst are being searched for within the context of each vpcConfig.
8080
// if no match found, then it is due to one of the following errors:
@@ -93,12 +93,12 @@ type srcAndDstNodes struct {
9393
//
9494
// More than one match found is also considered an error. It can be due to one of the following:
9595
// 1. src and dst are of different VPCs and are connected by more than one tgw
96-
// 2. src and dst are internal address containing VSIs in more than one VPC
97-
// 3. src (dst) is internal containing VSIs in more than one VPC and dst (src) is external
96+
// 2. src and dst are internal address containing endpoints in more than one VPC
97+
// 3. src (dst) is internal containing endpoints in more than one VPC and dst (src) is external
9898
// neither are supported in this stage
9999
// todo: note that there could be cases in which src/dst are internal address that contains EPs of more than one VPC
100-
// which will not result in an error. E.g., src is a vsi of VPC1 and dst is an internal address of VPC1 and VPC2.
101-
// in this case explainability analysis will be done for VPC1
100+
// which will not result in an error. E.g., src is a endpoint of VPC1 and dst is an internal address of VPC1
101+
// and VPC2. in this case explainability analysis will be done for VPC1
102102

103103
//nolint:gocyclo // better not split into two function
104104
func (c *MultipleVPCConfigs) getVPCConfigAndSrcDstNodes(src, dst string) (vpcConfig *VPCConfig,
@@ -216,7 +216,7 @@ func (c *MultipleVPCConfigs) listNamesCfg(configsWithSrcDstNode map[string]srcAn
216216
i := 0
217217
matchConfigs := make([]string, len(configsWithSrcDstNode))
218218
for vpcUID := range configsWithSrcDstNode {
219-
// the vsis are in more than one config; lists all the configs it is in for the error msg
219+
// the endpoints are in more than one config; lists all the configs it is in for the error msg
220220
matchConfigs[i] = c.Config(vpcUID).VPC.Name()
221221
i++
222222
}
@@ -262,8 +262,8 @@ func (e *ExplanationArgs) GetConnectionSet() *connection.Set {
262262

263263
// given src and dst input and a VPCConfigs finds the []nodes they represent in the config
264264
// src/dst may refer to:
265-
// 1. VSI by UID or name; in this case we consider the network interfaces of the VSI
266-
// 2. Internal IP address or cidr; in this case we consider the VSIs in that address range
265+
// 1. Endpoint by UID or name; in this case we consider the network interfaces of the endpoint
266+
// 2. Internal IP address or cidr; in this case we consider the endpoints in that address range
267267
// 3. external IP address or cidr
268268
func (c *VPCConfig) srcDstInputToNodes(srcName, dstName string) (srcNodes,
269269
dstNodes []Node, isSrcDstInternalIP srcDstInternalAddr, errType int, err error) {
@@ -293,7 +293,7 @@ func (c *VPCConfig) srcDstInputToNodes(srcName, dstName string) (srcNodes,
293293
return srcNodes, dstNodes, srcDstInternalAddr{isSrcInternalIP, isDstInternalIP}, noErr, nil
294294
}
295295

296-
// given a VPCConfig and a string looks for the VSI/Internal IP/External address it presents,
296+
// given a VPCConfig and a string looks for the endpoint/Internal IP/External address it presents,
297297
// as described above
298298
func (c *VPCConfig) getSrcOrDstInputNode(name, srcOrDst string) (nodes []Node,
299299
internalIP bool, errType int, err error) {
@@ -304,18 +304,18 @@ func (c *VPCConfig) getSrcOrDstInputNode(name, srcOrDst string) (nodes []Node,
304304
return outNodes, isInternalIP, noErr, nil
305305
}
306306

307-
// given a VPCConfig and a string cidrOrName representing a vsi or internal/external
307+
// given a VPCConfig and a string cidrOrName representing an endpoint or internal/external
308308
// cidr/address returns the corresponding node(s) and a bool which is true iff
309309
// cidrOrName is an internal address and the nodes are its network interfaces
310310
func (c *VPCConfig) getNodesFromInputString(cidrOrName string) (nodes []Node,
311311
internalIP bool, errType int, err error) {
312-
// 1. cidrOrName references vsi
313-
vsi, errType1, err1 := c.getNodesOfVsi(cidrOrName)
312+
// 1. cidrOrName references endpoint
313+
endpoint, errType1, err1 := c.getNodesOfEndpoint(cidrOrName)
314314
if err1 != nil {
315315
return nil, false, errType1, err1
316316
}
317-
if vsi != nil {
318-
return vsi, false, noErr, nil
317+
if endpoint != nil {
318+
return endpoint, false, noErr, nil
319319
}
320320
// cidrOrName, if legal, references an address.
321321
// 2. cidrOrName references an ip address
@@ -330,42 +330,36 @@ func (c *VPCConfig) getNodesFromInputString(cidrOrName string) (nodes []Node,
330330
return c.getNodesFromAddress(cidrOrName, ipBlock)
331331
}
332332

333-
// todo https://github.com/np-guard/vpc-network-config-analyzer/issues/673:
334-
// the name, the variables names and the documentation of the following function is wrong and misleading, because:
335-
// 1. vsi is ibm specific
336-
// 2. this functions returns not only nodes of vsis, but also nodes of vpe, and recently load balancers
337-
338-
// getNodesOfVsi gets a string name or UID of VSI, and
339-
// returns the list of all nodes within this vsi
340-
func (c *VPCConfig) getNodesOfVsi(name string) ([]Node, int, error) {
341-
var nodeSetWithVsi NodeSet
342-
// vsi name may be prefixed by vpc name
343-
var vpc, vsi string
333+
// getNodesOfEndpoint gets a string name or UID of an endpoint (e.g. VSI), and
334+
// returns the list of all nodes within this endpoint
335+
func (c *VPCConfig) getNodesOfEndpoint(name string) ([]Node, int, error) {
336+
var nodeSetOfEndpoint NodeSet
337+
// endpoint name may be prefixed by vpc name
338+
var vpc, endpoint string
344339
uid := name // uid specified - vpc prefix is not relevant and uid may contain the deliminator "/"
345340
cidrOrNameSlice := strings.Split(name, deliminator)
346341
switch len(cidrOrNameSlice) {
347342
case 1: // vpc name not specified
348-
vsi = name
343+
endpoint = name
349344
case 2: // vpc name specified
350345
vpc = cidrOrNameSlice[0]
351-
vsi = cidrOrNameSlice[1]
346+
endpoint = cidrOrNameSlice[1]
352347
}
353348
for _, nodeSet := range append(c.NodeSets, c.loadBalancersAsNodeSets()...) {
354-
// currently, assuming c.NodeSets consists of VSIs or VPE
355-
if (vpc == "" || nodeSet.VPC().Name() == vpc) && nodeSet.Name() == vsi || // if vpc of vsi specified, equality must hold
349+
if (vpc == "" || nodeSet.VPC().Name() == vpc) && nodeSet.Name() == endpoint || // if vpc of endpoint specified, equality must hold
356350
nodeSet.UID() == uid {
357-
if nodeSetWithVsi != nil {
351+
if nodeSetOfEndpoint != nil {
358352
return nil, fatalErr, fmt.Errorf("ambiguity - the configuration contains multiple resources named %s, "+
359353
"try using CRNs or the VPC name to scope resources: vpc-name/instance-name"+
360-
"\nCRNs of matching resources:\n\t%s\n\t%s", name, nodeSetWithVsi.UID(), nodeSet.UID())
354+
"\nCRNs of matching resources:\n\t%s\n\t%s", name, nodeSetOfEndpoint.UID(), nodeSet.UID())
361355
}
362-
nodeSetWithVsi = nodeSet
356+
nodeSetOfEndpoint = nodeSet
363357
}
364358
}
365-
if nodeSetWithVsi == nil {
359+
if nodeSetOfEndpoint == nil {
366360
return nil, noErr, nil
367361
}
368-
return nodeSetWithVsi.Nodes(), noErr, nil
362+
return nodeSetOfEndpoint.Nodes(), noErr, nil
369363
}
370364

371365
// getNodesFromAddress gets a string and IPBlock that represents a cidr or IP address

0 commit comments

Comments
 (0)