Skip to content

Commit

Permalink
add info message just when needed (#297)
Browse files Browse the repository at this point in the history
add the info message "\nconnections are stateful unless marked with *\n" just when at least one vpc have stateless conns
  • Loading branch information
olasaadi99 authored Jan 14, 2024
1 parent c77e888 commit ff6e34c
Show file tree
Hide file tree
Showing 28 changed files with 62 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@
| sub2-2-ky | sub2-1-ky | All Connections |
| sub3-1-ky | sub1-1-ky | protocol: ICMP icmp-type: 0 icmp-code: 0 |
| sub3-1-ky | sub2-1-ky | protocol: ICMP icmp-type: 0 icmp-code: 0; protocol: TCP dst-ports: 443 |

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ sub2-1-ky => sub3-1-ky : protocol: ICMP icmp-type: 0 icmp-code: 0; protocol: TCP
sub2-2-ky => sub2-1-ky : All Connections
sub3-1-ky => sub1-1-ky : protocol: ICMP icmp-type: 0 icmp-code: 0
sub3-1-ky => sub2-1-ky : protocol: ICMP icmp-type: 0 icmp-code: 0; protocol: TCP dst-ports: 443

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@
| sub2-1-ky | Public Internet 8.8.8.8/32 | protocol: UDP dst-ports: 53 |
| sub2-1-ky | sub2-2-ky | All Connections |
| sub2-2-ky | sub2-1-ky | All Connections |

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ sub1-3-ky => sub1-2-ky : protocol: TCP
sub2-1-ky => Public Internet 8.8.8.8/32 : protocol: UDP dst-ports: 53
sub2-1-ky => sub2-2-ky : All Connections
sub2-2-ky => sub2-1-ky : All Connections

connections are stateful unless marked with *
2 changes: 0 additions & 2 deletions pkg/ibmvpc/examples/demo_with_instances_all_vpcs_.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,3 @@
| transit-2-instance-ky[192.168.24.4] | private-2-instance-ky[192.168.8.4] | protocol: TCP src-ports: 443 |
| transit-2-instance-ky[192.168.24.4] | transit-0-instance-ky[192.168.16.4] | All Connections |
| transit-2-instance-ky[192.168.24.4] | transit-1-instance-ky[192.168.20.4] | All Connections |

connections are stateful unless marked with *
2 changes: 0 additions & 2 deletions pkg/ibmvpc/examples/demo_with_instances_all_vpcs_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,3 @@ transit-2-instance-ky[192.168.24.4] => private-1-instance-ky[192.168.4.4] : prot
transit-2-instance-ky[192.168.24.4] => private-2-instance-ky[192.168.8.4] : protocol: TCP src-ports: 443
transit-2-instance-ky[192.168.24.4] => transit-0-instance-ky[192.168.16.4] : All Connections
transit-2-instance-ky[192.168.24.4] => transit-1-instance-ky[192.168.20.4] : All Connections

connections are stateful unless marked with *
2 changes: 0 additions & 2 deletions pkg/ibmvpc/examples/demo_with_instances_all_vpcs__debug.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6032,5 +6032,3 @@ transit-2-instance-ky[192.168.24.4] => private-1-instance-ky[192.168.4.4] : prot
transit-2-instance-ky[192.168.24.4] => private-2-instance-ky[192.168.8.4] : protocol: TCP src-ports: 443
transit-2-instance-ky[192.168.24.4] => transit-0-instance-ky[192.168.16.4] : All Connections
transit-2-instance-ky[192.168.24.4] => transit-1-instance-ky[192.168.20.4] : All Connections

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,3 @@ transit-2-instance-ky[192.168.24.4] => private-1-instance-ky[192.168.4.4] : prot
transit-2-instance-ky[192.168.24.4] => private-2-instance-ky[192.168.8.4] : protocol: TCP src-ports: 443
transit-2-instance-ky[192.168.24.4] => transit-0-instance-ky[192.168.16.4] : All Connections
transit-2-instance-ky[192.168.24.4] => transit-1-instance-ky[192.168.20.4] : All Connections

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,3 @@ ky-testenv-transit-subnet-3 => ky-testenv-private-subnet-2 : protocol: TCP src-p
ky-testenv-transit-subnet-3 => ky-testenv-private-subnet-3 : protocol: TCP src-ports: 443
ky-testenv-transit-subnet-3 => ky-testenv-transit-subnet-1 : All Connections
ky-testenv-transit-subnet-3 => ky-testenv-transit-subnet-2 : All Connections

connections are stateful unless marked with *
2 changes: 0 additions & 2 deletions pkg/ibmvpc/examples/demo_with_instances_vpes_all_vpcs_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,3 @@ transit-2-instance-ky[192.168.24.4] => private-1-instance-ky[192.168.4.4] : prot
transit-2-instance-ky[192.168.24.4] => private-2-instance-ky[192.168.8.4] : protocol: TCP src-ports: 443
transit-2-instance-ky[192.168.24.4] => transit-0-instance-ky[192.168.16.4] : All Connections
transit-2-instance-ky[192.168.24.4] => transit-1-instance-ky[192.168.20.4] : All Connections

connections are stateful unless marked with *
2 changes: 0 additions & 2 deletions pkg/ibmvpc/examples/experiments_env_all_vpcs_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ vsi2-ky[10.240.2.4] => vsi1-ky[10.240.1.4] : All Connections
Connectivity for VPC test-vpc2-ky
vsi20-ky[10.240.128.4] => vsi21-ky[10.240.128.5] : All Connections
vsi21-ky[10.240.128.5] => vsi20-ky[10.240.128.4] : All Connections

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,3 @@ iks-node[192.168.8.4] => iks-node[192.168.32.4] : All Connections
iks-node[192.168.8.4] => iks-node[192.168.36.4] : All Connections
iks-node[192.168.8.4] => iks-node[192.168.4.4] : All Connections
iks-node[192.168.8.4] => iks-node[192.168.40.4] : All Connections

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,3 @@ sub2-1-ky => sub3-1-ky : protocol: ICMP icmp-type: 0 icmp-code: 0; protocol: TCP
sub2-2-ky => sub2-1-ky : All Connections
sub3-1-ky => sub1-1-ky : protocol: ICMP icmp-type: 0 icmp-code: 0
sub3-1-ky => sub2-1-ky : protocol: ICMP icmp-type: 0 icmp-code: 0; protocol: TCP dst-ports: 443

connections are stateful unless marked with *
2 changes: 0 additions & 2 deletions pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@
| vsi3b-ky[10.240.30.4] | vsi1-ky[10.240.10.4] | All Connections |
| vsi3b-ky[10.240.30.4] | vsi2-ky[10.240.20.4] | protocol: TCP |
| vsi3b-ky[10.240.30.4] | vsi3a-ky[10.240.30.5] | All Connections |

connections are stateful unless marked with *
2 changes: 0 additions & 2 deletions pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ vsi3b-ky[10.240.30.4] => db-endpoint-gateway-ky[10.240.30.6] : All Connections
vsi3b-ky[10.240.30.4] => vsi1-ky[10.240.10.4] : All Connections
vsi3b-ky[10.240.30.4] => vsi2-ky[10.240.20.4] : protocol: TCP
vsi3b-ky[10.240.30.4] => vsi3a-ky[10.240.30.5] : All Connections

connections are stateful unless marked with *
2 changes: 0 additions & 2 deletions pkg/ibmvpc/examples/sg_testing1_new_all_vpcs__debug.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3292,5 +3292,3 @@ vsi3b-ky[10.240.30.4] => db-endpoint-gateway-ky[10.240.30.6] : All Connections
vsi3b-ky[10.240.30.4] => vsi1-ky[10.240.10.4] : All Connections
vsi3b-ky[10.240.30.4] => vsi2-ky[10.240.20.4] : protocol: TCP
vsi3b-ky[10.240.30.4] => vsi3a-ky[10.240.30.5] : All Connections

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ vsi2-ky[10.240.20.4] => Public Internet 142.0.0.0/8 : protocol: ICMP
vsi2-ky[10.240.20.4] => vsi1-ky[10.240.10.4] : All Connections
vsi2-ky[10.240.20.4] => vsi3b-ky[10.240.30.4] : protocol: TCP
vsi3b-ky[10.240.30.4] => vsi2-ky[10.240.20.4] : protocol: TCP

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ diff-type: removed, source: vsi1-ky[10.240.10.4], destination: Public Internet 1
diff-type: removed, source: vsi3a-ky[10.240.30.5], destination: db-endpoint-gateway-ky[10.240.30.6], config1: All Connections, config2: No Connections, vsis-diff-info: vsi3a-ky[10.240.30.5] removed
diff-type: removed, source: vsi3a-ky[10.240.30.5], destination: vsi1-ky[10.240.10.4], config1: All Connections, config2: No Connections, vsis-diff-info: vsi3a-ky[10.240.30.5] removed
diff-type: removed, source: vsi3b-ky[10.240.30.4], destination: vsi3a-ky[10.240.30.5], config1: All Connections, config2: No Connections, vsis-diff-info: vsi3a-ky[10.240.30.5] removed

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ subnet2-ky => subnet1-ky : All Connections
subnet2-ky => subnet3-ky : All Connections
subnet3-ky => subnet1-ky : All Connections
subnet3-ky => subnet2-ky : All Connections

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ Connectivity for VPC test-vpc1-ky
combined connections between subnets:
subnet1-ky => Public Internet (all ranges) : All Connections
subnet1-ky,subnet2-ky,subnet3-ky => subnet1-ky,subnet2-ky,subnet3-ky : All Connections

connections are stateful unless marked with *
2 changes: 0 additions & 2 deletions pkg/ibmvpc/examples/tgw_basic_example_all_vpcs_.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ ky-vpc1-vsi[10.240.0.5] => Public Internet (all ranges) : All Connections

Connectivity for VPC ky-vpc2


connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ combined connections between subnets:
Connectivity for VPC ky-vpc2
combined connections between subnets:


connections are stateful unless marked with *
4 changes: 3 additions & 1 deletion pkg/vpcmodel/debugOutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func (t *DebugOutputFormatter) WriteOutput(c1, c2 *VPCConfig,
grouping bool,
uc OutputUseCase) (*SingleAnalysisOutput, error) {
out, err := headerOfAnalyzedVPC(uc, c1.VPC.Name(), "", c1)
hasStatelessConns := false
if err != nil {
return nil, err
}
Expand All @@ -20,10 +21,11 @@ func (t *DebugOutputFormatter) WriteOutput(c1, c2 *VPCConfig,
// TODO: add a flag of whether to include grouped output or not
// TODO: add another 'debug' format that includes all detailed output
out = conn.DetailedString()
hasStatelessConns = conn.GroupedConnectivity.hasStatelessConns()
case AllSubnets:
case SingleSubnet:
case SubnetsDiff, EndpointsDiff:
}
_, err = WriteToFile(out, outFile)
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: "", format: Debug}, err
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: "", format: Debug, hasStatelessConn: hasStatelessConns}, err
}
12 changes: 12 additions & 0 deletions pkg/vpcmodel/grouping.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,18 @@ func (g *GroupConnLines) String() string {
return strings.Join(linesStr, "\n") + "\n"
}

// get indication if the connections contain a stateless connection
func (g *GroupConnLines) hasStatelessConns() bool {
hasStatelessConns := false
for _, line := range g.GroupedLines {
if line.commonProperties.conn.IsStateful == common.StatefulFalse {
hasStatelessConns = true
break
}
}
return hasStatelessConns
}

func listEndpointElemStr(eps []EndpointElem, fn func(ep EndpointElem) string) string {
endpointsStrings := make([]string, len(eps))
for i, ep := range eps {
Expand Down
6 changes: 5 additions & 1 deletion pkg/vpcmodel/mdOutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ func (m *MDoutputFormatter) WriteOutput(c1, c2 *VPCConfig,
out = "# " + out
var lines []string
var connLines []string
hasStatelessConns := false
switch uc {
case AllEndpoints:
lines = []string{mdDefaultTitle, mdDefaultHeader}
connLines = m.getGroupedOutput(conn.GroupedConnectivity)
hasStatelessConns = conn.GroupedConnectivity.hasStatelessConns()
case AllSubnets:
lines = []string{mdSubnetsTitle, mdDefaultHeader}
connLines = m.getGroupedOutput(subnetsConn.GroupedConnectivity)
hasStatelessConns = subnetsConn.GroupedConnectivity.hasStatelessConns()
case SubnetsDiff, EndpointsDiff:
var mdTitle, mdHeader string
if uc == EndpointsDiff {
Expand All @@ -59,13 +62,14 @@ func (m *MDoutputFormatter) WriteOutput(c1, c2 *VPCConfig,
}
lines = []string{mdTitle, mdHeader}
connLines = m.getGroupedDiffOutput(cfgsDiff)
hasStatelessConns = cfgsDiff.hasStatelessConns()
case SingleSubnet:
return nil, errors.New("DebugSubnet use case not supported for md format currently ")
}
out += linesToOutput(connLines, lines)

_, err = WriteToFile(out, outFile)
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: v2Name, format: MD}, err
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: v2Name, format: MD, hasStatelessConn: hasStatelessConns}, err
}

func linesToOutput(connLines, lines []string) string {
Expand Down
27 changes: 20 additions & 7 deletions pkg/vpcmodel/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ type SingleAnalysisOutput struct {
Output string
jsonStruct interface{}
format OutFormat
// hasStatelessConn indicates if the connectivity results contain a stateless conn
hasStatelessConn bool
}

// Generate returns a string representing the analysis output for all input VPCs
Expand Down Expand Up @@ -188,7 +190,7 @@ func (of *serialOutputFormatter) WriteOutput(c1, c2 map[string]*VPCConfig, conns
if err2 != nil {
return "", err2
}
return of.WriteDiffOutput(vpcAnalysisOutput, outFile)
return of.WriteDiffOutput(vpcAnalysisOutput, uc, outFile)
}

func WriteToFile(content, fileName string) (string, error) {
Expand All @@ -199,6 +201,15 @@ func WriteToFile(content, fileName string) (string, error) {
return content, nil
}

// getAsteriskDetails returns the info message about how non stateful conns are marked in the output, when relevant
func getAsteriskDetails(uc OutputUseCase, hasStatelessConn bool, outFormat OutFormat) string {
if uc != SingleSubnet && (outFormat == Text || outFormat == MD || outFormat == Debug) && hasStatelessConn {
return asteriskDetails
}

return ""
}

// AggregateVPCsOutput returns the output string for a list of SingleAnalysisOutput objects
// and writes the output to outFile
func (of *serialOutputFormatter) AggregateVPCsOutput(outputList []*SingleAnalysisOutput, uc OutputUseCase, outFile string) (string, error) {
Expand All @@ -213,14 +224,15 @@ func (of *serialOutputFormatter) AggregateVPCsOutput(outputList []*SingleAnalysi
case Text, MD, Debug:
// plain concatenation
vpcsOut := make([]string, len(outputList))
hasStatelessConn := false
for i, o := range outputList {
vpcsOut[i] = o.Output
if o.hasStatelessConn {
hasStatelessConn = true
}
}
infoMessage := asteriskDetails
sort.Strings(vpcsOut)
if uc == SingleSubnet {
infoMessage = ""
}
infoMessage := getAsteriskDetails(uc, hasStatelessConn, of.outFormat)
res, err = WriteToFile(strings.Join(vpcsOut, "\n")+infoMessage, outFile)

case JSON:
Expand All @@ -234,12 +246,13 @@ func (of *serialOutputFormatter) AggregateVPCsOutput(outputList []*SingleAnalysi
}

// WriteDiffOutput actual writing the output into file, with required format adjustments
func (of *serialOutputFormatter) WriteDiffOutput(output *SingleAnalysisOutput, outFile string) (string, error) {
func (of *serialOutputFormatter) WriteDiffOutput(output *SingleAnalysisOutput, uc OutputUseCase, outFile string) (string, error) {
var res string
var err error
switch of.outFormat {
case Text, MD, Debug: // currently, return out as is
res, err = WriteToFile(output.Output+asteriskDetails, outFile)
infoMessage := getAsteriskDetails(uc, output.hasStatelessConn, of.outFormat)
res, err = WriteToFile(output.Output+infoMessage, outFile)
case JSON:
all := map[string]interface{}{}
head := fmt.Sprintf("diff-%s-%s", output.VPC1Name, output.VPC2Name)
Expand Down
15 changes: 15 additions & 0 deletions pkg/vpcmodel/semanticDiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ func (diffCfgs *diffBetweenCfgs) String() string {
return strings.Join(strList, "")
}

// get the grouped diff connectivity stateLessness
func (diffCfgs *diffBetweenCfgs) hasStatelessConns() bool {
hasStatelessConns := false
for _, grouped := range diffCfgs.groupedLines {
if (grouped.commonProperties.connDiff.conn1 != nil &&
grouped.commonProperties.connDiff.conn1.IsStateful == common.StatefulFalse) ||
(grouped.commonProperties.connDiff.conn2 != nil &&
grouped.commonProperties.connDiff.conn2.IsStateful == common.StatefulFalse) {
hasStatelessConns = true
break
}
}
return hasStatelessConns
}

// prints connection for the above string(..) where the connection could be empty
func connStr(conn *common.ConnectionSet) string {
if conn == nil {
Expand Down
8 changes: 7 additions & 1 deletion pkg/vpcmodel/textOutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,24 @@ func (t *TextOutputFormatter) WriteOutput(c1, c2 *VPCConfig,
if err != nil {
return nil, err
}
hasStatelessConns := false

// get output by analysis type
switch uc {
case AllEndpoints:
out += conn.GroupedConnectivity.String()
hasStatelessConns = conn.GroupedConnectivity.hasStatelessConns()
case AllSubnets:
out += subnetsConn.String()
hasStatelessConns = subnetsConn.GroupedConnectivity.hasStatelessConns()
case SingleSubnet:
out += c1.GetConnectivityOutputPerEachSubnetSeparately()
case SubnetsDiff, EndpointsDiff:
out += cfgsDiff.String()
hasStatelessConns = cfgsDiff.hasStatelessConns()
}
// write output to file and return the output string
_, err = WriteToFile(out, outFile)
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: vpc2Name, format: Text}, err
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(),
VPC2Name: vpc2Name, format: Text, hasStatelessConn: hasStatelessConns}, err
}

0 comments on commit ff6e34c

Please sign in to comment.