Skip to content
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

feat: rename templating variables #1693

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
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
38 changes: 19 additions & 19 deletions pkg/collect/host_network_namespace_connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
// have the logs, the information from the source and destination namespaces,
// errors and a success flag.
type NetworkNamespaceConnectivityInfo struct {
FromNamespace string `json:"from_namespace"`
ToNamespace string `json:"to_namespace"`
Errors NetworkNamespaceConnectivityErrors `json:"errors"`
Output NetworkNamespaceConnectivityOutput `json:"output"`
Success bool `json:"success"`
FromCIDR string `json:"from_cidr"`
ToCIDR string `json:"to_cidr"`
Errors NetworkNamespaceConnectivityErrors `json:"errors"`
Output NetworkNamespaceConnectivityOutput `json:"output"`
Success bool `json:"success"`
}

// ErrorMessage returns the error message from the errors field.
Expand All @@ -33,26 +33,26 @@ func (n *NetworkNamespaceConnectivityInfo) ErrorMessage() string {
// NetworkNamespaceConnectivityErrors is a struct that contains the errors that
// occurred during the network namespace connectivity test
type NetworkNamespaceConnectivityErrors struct {
FromNamespaceCreation string `json:"from_namespace_creation"`
ToNamespaceCreation string `json:"to_namespace_creation"`
UDPClient string `json:"udp_client"`
UDPServer string `json:"udp_server"`
TCPClient string `json:"tcp_client"`
TCPServer string `json:"tcp_server"`
FromCIDRCreation string `json:"from_cidr_creation"`
ToCIDRCreation string `json:"to_cidr_creation"`
UDPClient string `json:"udp_client"`
UDPServer string `json:"udp_server"`
TCPClient string `json:"tcp_client"`
TCPServer string `json:"tcp_server"`
}

// Errors returns a string representation of the errors found during the
// network namespace connectivity test.
func (e NetworkNamespaceConnectivityErrors) Errors() string {
var sb strings.Builder
if e.FromNamespaceCreation != "" {
if e.FromCIDRCreation != "" {
sb.WriteString("Failed to create 'from' namespace: ")
sb.WriteString(e.FromNamespaceCreation + "\n")
sb.WriteString(e.FromCIDRCreation + "\n")
}

if e.ToNamespaceCreation != "" {
if e.ToCIDRCreation != "" {
sb.WriteString("Failed to create 'to' namespace: ")
sb.WriteString(e.ToNamespaceCreation + "\n")
sb.WriteString(e.ToCIDRCreation + "\n")
}

if e.UDPClient != "" {
Expand Down Expand Up @@ -165,8 +165,8 @@ func (c *CollectHostNetworkNamespaceConnectivity) Collect(progressChan chan<- in
}

result := &NetworkNamespaceConnectivityInfo{
FromNamespace: c.hostCollector.FromCIDR,
ToNamespace: c.hostCollector.ToCIDR,
FromCIDR: c.hostCollector.FromCIDR,
ToCIDR: c.hostCollector.ToCIDR,
}

opts := []namespaces.Option{namespaces.WithLogf(result.Output.Printf)}
Expand All @@ -188,14 +188,14 @@ func (c *CollectHostNetworkNamespaceConnectivity) Collect(progressChan chan<- in

fromNS, err := namespaces.NewNamespacePinger("from", c.hostCollector.FromCIDR, opts...)
if err != nil {
result.Errors.ToNamespaceCreation = err.Error()
result.Errors.ToCIDRCreation = err.Error()
return c.marshal(result)
}
defer fromNS.Close()

toNS, err := namespaces.NewNamespacePinger("to", c.hostCollector.ToCIDR, opts...)
if err != nil {
result.Errors.FromNamespaceCreation = err.Error()
result.Errors.FromCIDRCreation = err.Error()
return c.marshal(result)
}
defer toNS.Close()
Expand Down
Loading