Skip to content

Commit 9f5f063

Browse files
feat: rename templating variables (#1693)
when templating the output of the namespace connectivity check we were referring to the 'fromCIDR' as 'fromNamespace'. it makes way more sense to refer to it as 'fromCIDR' as this is how it is provided in the input for the collector. as this is a brand new feature it is very unlikely that anyone is using this feature (except for the embedded cluster that still needs to be patched accodringly). this is how the analyser were defined before: ```yaml apiVersion: troubleshoot.sh/v1beta2 kind: HostPreflight metadata: name: ec-cluster-preflight spec: analyzers: - networkNamespaceConnectivity: collectorName: check-network-connectivity outcomes: - pass: message: "Communication between {{ .FromNamespace }} and {{ .ToNamespace }} is working" - fail: message: "{{ .ErrorMessage }}" ``` and this is how it is now: ```yaml apiVersion: troubleshoot.sh/v1beta2 kind: HostPreflight metadata: name: ec-cluster-preflight spec: analyzers: - networkNamespaceConnectivity: collectorName: check-network-connectivity outcomes: - pass: message: "Communication between {{ .FromCIDR }} and {{ .ToCIDR }} is working" - fail: message: "{{ .ErrorMessage }}" ```
1 parent 6167fd8 commit 9f5f063

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

pkg/collect/host_network_namespace_connectivity.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import (
1818
// have the logs, the information from the source and destination namespaces,
1919
// errors and a success flag.
2020
type NetworkNamespaceConnectivityInfo struct {
21-
FromNamespace string `json:"from_namespace"`
22-
ToNamespace string `json:"to_namespace"`
23-
Errors NetworkNamespaceConnectivityErrors `json:"errors"`
24-
Output NetworkNamespaceConnectivityOutput `json:"output"`
25-
Success bool `json:"success"`
21+
FromCIDR string `json:"from_cidr"`
22+
ToCIDR string `json:"to_cidr"`
23+
Errors NetworkNamespaceConnectivityErrors `json:"errors"`
24+
Output NetworkNamespaceConnectivityOutput `json:"output"`
25+
Success bool `json:"success"`
2626
}
2727

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

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

53-
if e.ToNamespaceCreation != "" {
53+
if e.ToCIDRCreation != "" {
5454
sb.WriteString("Failed to create 'to' namespace: ")
55-
sb.WriteString(e.ToNamespaceCreation + "\n")
55+
sb.WriteString(e.ToCIDRCreation + "\n")
5656
}
5757

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

167167
result := &NetworkNamespaceConnectivityInfo{
168-
FromNamespace: c.hostCollector.FromCIDR,
169-
ToNamespace: c.hostCollector.ToCIDR,
168+
FromCIDR: c.hostCollector.FromCIDR,
169+
ToCIDR: c.hostCollector.ToCIDR,
170170
}
171171

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

189189
fromNS, err := namespaces.NewNamespacePinger("from", c.hostCollector.FromCIDR, opts...)
190190
if err != nil {
191-
result.Errors.ToNamespaceCreation = err.Error()
191+
result.Errors.ToCIDRCreation = err.Error()
192192
return c.marshal(result)
193193
}
194194
defer fromNS.Close()
195195

196196
toNS, err := namespaces.NewNamespacePinger("to", c.hostCollector.ToCIDR, opts...)
197197
if err != nil {
198-
result.Errors.FromNamespaceCreation = err.Error()
198+
result.Errors.FromCIDRCreation = err.Error()
199199
return c.marshal(result)
200200
}
201201
defer toNS.Close()

0 commit comments

Comments
 (0)