Created 2 isolated and 2 global namespaces on every node, so that pod to pod connectivity
tests can be performed among same/different namespaces, same/different nodes and global/non-global pods.
... | ... |
@@ -18,7 +18,7 @@ import ( |
18 | 18 |
) |
19 | 19 |
|
20 | 20 |
func (d *NetworkDiagnostic) CollectNetworkPodLogs() error { |
21 |
- podList, err := d.getPodList(d.nsName, util.NetworkDiagPodNamePrefix) |
|
21 |
+ podList, err := d.getPodList(d.nsName1, util.NetworkDiagPodNamePrefix) |
|
22 | 22 |
if err != nil { |
23 | 23 |
return err |
24 | 24 |
} |
... | ... |
@@ -42,7 +42,7 @@ func (d *NetworkDiagnostic) CollectNetworkInfo(diagsFailed bool) error { |
42 | 42 |
l.LogMaster() |
43 | 43 |
} |
44 | 44 |
|
45 |
- podList, err := d.getPodList(d.nsName, util.NetworkDiagPodNamePrefix) |
|
45 |
+ podList, err := d.getPodList(d.nsName1, util.NetworkDiagPodNamePrefix) |
|
46 | 46 |
if err != nil { |
47 | 47 |
return err |
48 | 48 |
} |
... | ... |
@@ -31,11 +31,13 @@ type NetworkDiagnostic struct { |
31 | 31 |
PreventModification bool |
32 | 32 |
LogDir string |
33 | 33 |
|
34 |
- pluginName string |
|
35 |
- nodes []kapi.Node |
|
36 |
- nsName string |
|
37 |
- globalnsName string |
|
38 |
- res types.DiagnosticResult |
|
34 |
+ pluginName string |
|
35 |
+ nodes []kapi.Node |
|
36 |
+ nsName1 string |
|
37 |
+ nsName2 string |
|
38 |
+ globalnsName1 string |
|
39 |
+ globalnsName2 string |
|
40 |
+ res types.DiagnosticResult |
|
39 | 41 |
} |
40 | 42 |
|
41 | 43 |
// Name is part of the Diagnostic interface and just returns name. |
... | ... |
@@ -118,7 +120,7 @@ func (d *NetworkDiagnostic) runNetworkDiagnostic() { |
118 | 118 |
return |
119 | 119 |
} |
120 | 120 |
// Wait for network diagnostic pod completion |
121 |
- if err := d.waitForNetworkPod(d.nsName, util.NetworkDiagPodNamePrefix, []kapi.PodPhase{kapi.PodSucceeded, kapi.PodFailed}); err != nil { |
|
121 |
+ if err := d.waitForNetworkPod(d.nsName1, util.NetworkDiagPodNamePrefix, []kapi.PodPhase{kapi.PodSucceeded, kapi.PodFailed}); err != nil { |
|
122 | 122 |
d.res.Error("DNet2007", err, err.Error()) |
123 | 123 |
return |
124 | 124 |
} |
... | ... |
@@ -137,7 +139,7 @@ func (d *NetworkDiagnostic) runNetworkDiagnostic() { |
137 | 137 |
} |
138 | 138 |
|
139 | 139 |
// Wait for network diagnostic pod to start |
140 |
- if err := d.waitForNetworkPod(d.nsName, util.NetworkDiagPodNamePrefix, []kapi.PodPhase{kapi.PodRunning, kapi.PodFailed, kapi.PodSucceeded}); err != nil { |
|
140 |
+ if err := d.waitForNetworkPod(d.nsName1, util.NetworkDiagPodNamePrefix, []kapi.PodPhase{kapi.PodRunning, kapi.PodFailed, kapi.PodSucceeded}); err != nil { |
|
141 | 141 |
d.res.Error("DNet2010", err, err.Error()) |
142 | 142 |
// Do not bail out here, collect what ever info is available from all valid nodes |
143 | 143 |
} |
... | ... |
@@ -157,7 +159,7 @@ func (d *NetworkDiagnostic) runNetworkPod(command []string) error { |
157 | 157 |
podName := kapi.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", util.NetworkDiagPodNamePrefix)) |
158 | 158 |
|
159 | 159 |
pod := GetNetworkDiagnosticsPod(command, podName, node.Name) |
160 |
- _, err := d.KubeClient.Pods(d.nsName).Create(pod) |
|
160 |
+ _, err := d.KubeClient.Pods(d.nsName1).Create(pod) |
|
161 | 161 |
if err != nil { |
162 | 162 |
return fmt.Errorf("Creating network diagnostic pod %q on node %q with command %q failed: %v", podName, node.Name, strings.Join(command, " "), err) |
163 | 163 |
} |
... | ... |
@@ -20,12 +20,15 @@ import ( |
20 | 20 |
) |
21 | 21 |
|
22 | 22 |
func (d *NetworkDiagnostic) TestSetup() error { |
23 |
- d.nsName = kapi.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", util.NetworkDiagNamespacePrefix)) |
|
23 |
+ d.nsName1 = kapi.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", util.NetworkDiagNamespacePrefix)) |
|
24 |
+ d.nsName2 = kapi.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", util.NetworkDiagNamespacePrefix)) |
|
24 | 25 |
|
25 |
- nsList := []string{d.nsName} |
|
26 |
+ nsList := []string{d.nsName1, d.nsName2} |
|
26 | 27 |
if sdnapi.IsOpenShiftMultitenantNetworkPlugin(d.pluginName) { |
27 |
- d.globalnsName = kapi.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", util.NetworkDiagGlobalNamespacePrefix)) |
|
28 |
- nsList = append(nsList, d.globalnsName) |
|
28 |
+ d.globalnsName1 = kapi.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", util.NetworkDiagGlobalNamespacePrefix)) |
|
29 |
+ nsList = append(nsList, d.globalnsName1) |
|
30 |
+ d.globalnsName2 = kapi.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", util.NetworkDiagGlobalNamespacePrefix)) |
|
31 |
+ nsList = append(nsList, d.globalnsName2) |
|
29 | 32 |
} |
30 | 33 |
|
31 | 34 |
for _, name := range nsList { |
... | ... |
@@ -49,7 +52,7 @@ func (d *NetworkDiagnostic) TestSetup() error { |
49 | 49 |
secret := &kapi.Secret{} |
50 | 50 |
secret.Name = util.NetworkDiagSecretName |
51 | 51 |
secret.Data = map[string][]byte{strings.ToLower(kclientcmd.RecommendedConfigPathEnvVar): kconfigData} |
52 |
- if _, err = d.KubeClient.Secrets(d.nsName).Create(secret); err != nil { |
|
52 |
+ if _, err = d.KubeClient.Secrets(d.nsName1).Create(secret); err != nil { |
|
53 | 53 |
return fmt.Errorf("Creating secret %q failed: %v", secret.Name, err) |
54 | 54 |
} |
55 | 55 |
|
... | ... |
@@ -67,8 +70,10 @@ func (d *NetworkDiagnostic) TestSetup() error { |
67 | 67 |
|
68 | 68 |
func (d *NetworkDiagnostic) Cleanup() { |
69 | 69 |
// Deleting namespaces will delete corresponding service accounts/pods in the namespace automatically. |
70 |
- d.KubeClient.Namespaces().Delete(d.nsName) |
|
71 |
- d.KubeClient.Namespaces().Delete(d.globalnsName) |
|
70 |
+ d.KubeClient.Namespaces().Delete(d.nsName1) |
|
71 |
+ d.KubeClient.Namespaces().Delete(d.nsName2) |
|
72 |
+ d.KubeClient.Namespaces().Delete(d.globalnsName1) |
|
73 |
+ d.KubeClient.Namespaces().Delete(d.globalnsName2) |
|
72 | 74 |
} |
73 | 75 |
|
74 | 76 |
func (d *NetworkDiagnostic) getPodList(nsName, prefix string) (*kapi.PodList, error) { |
... | ... |
@@ -92,31 +92,31 @@ func (d CheckPodNetwork) Check() types.DiagnosticResult { |
92 | 92 |
|
93 | 93 |
func (d CheckPodNetwork) checkDifferentNodePodToPodConnection(localGlobalPods, localNonGlobalPods, nonlocalGlobalPods, nonlocalNonGlobalPods []kapi.Pod) { |
94 | 94 |
// Applicable to flat and multitenant networks |
95 |
- d.checkConnection(localGlobalPods, nonlocalGlobalPods, fmt.Sprintf("Skipping pod connectivity test for global projects on different nodes. Reason: Couldn't find 2 global pods.")) |
|
95 |
+ d.checkConnection(localGlobalPods, nonlocalGlobalPods, fmt.Sprintf("Skipping pod connectivity test for global projects on different nodes. Reason: Couldn't find 2 global pods."), true) |
|
96 | 96 |
|
97 | 97 |
// Applicable to multitenant network |
98 | 98 |
isMultitenant := (d.vnidMap != nil) |
99 | 99 |
if isMultitenant { |
100 |
- d.checkConnection(localNonGlobalPods, nonlocalNonGlobalPods, fmt.Sprintf("Skipping pod connectivity test for non-global projects on different nodes. Reason: Couldn't find 2 non-global pods.")) |
|
100 |
+ d.checkConnection(localNonGlobalPods, nonlocalNonGlobalPods, fmt.Sprintf("Skipping pod connectivity test for non-global projects on different nodes. Reason: Couldn't find 2 non-global pods."), true) |
|
101 | 101 |
|
102 |
- d.checkConnection(localGlobalPods, nonlocalNonGlobalPods, fmt.Sprintf("Skipping pod connectivity test between global to non-global projects on different nodes. Reason: Couldn't find global and/or non-global pod.")) |
|
102 |
+ d.checkConnection(localGlobalPods, nonlocalNonGlobalPods, fmt.Sprintf("Skipping pod connectivity test between global to non-global projects on different nodes. Reason: Couldn't find global and/or non-global pod."), false) |
|
103 | 103 |
} |
104 | 104 |
} |
105 | 105 |
|
106 | 106 |
func (d CheckPodNetwork) checkSameNodePodToPodConnection(globalPods, nonGlobalPods []kapi.Pod) { |
107 | 107 |
// Applicable to both flat and multitenant networks |
108 |
- d.checkConnection(globalPods, globalPods, fmt.Sprintf("Skipping pod connectivity test for global projects on the same node. Reason: Couldn't find 2 global pods.")) |
|
108 |
+ d.checkConnection(globalPods, globalPods, fmt.Sprintf("Skipping pod connectivity test for global projects on the same node. Reason: Couldn't find 2 global pods."), true) |
|
109 | 109 |
|
110 | 110 |
// Applicable to multitenant network |
111 | 111 |
isMultitenant := (d.vnidMap != nil) |
112 | 112 |
if isMultitenant { |
113 |
- d.checkConnection(nonGlobalPods, nonGlobalPods, fmt.Sprintf("Skipping pod connectivity test for non-global projects on the same node. Reason: Couldn't find 2 non-global pods.")) |
|
113 |
+ d.checkConnection(nonGlobalPods, nonGlobalPods, fmt.Sprintf("Skipping pod connectivity test for non-global projects on the same node. Reason: Couldn't find 2 non-global pods."), true) |
|
114 | 114 |
|
115 |
- d.checkConnection(globalPods, nonGlobalPods, fmt.Sprintf("Skipping pod connectivity test between global to non-global projects on the same node. Reason: Couldn't find global and/or non-global pod.")) |
|
115 |
+ d.checkConnection(globalPods, nonGlobalPods, fmt.Sprintf("Skipping pod connectivity test between global to non-global projects on the same node. Reason: Couldn't find global and/or non-global pod."), false) |
|
116 | 116 |
} |
117 | 117 |
} |
118 | 118 |
|
119 |
-func (d CheckPodNetwork) checkConnection(pods1, pods2 []kapi.Pod, warnMsg string) { |
|
119 |
+func (d CheckPodNetwork) checkConnection(pods1, pods2 []kapi.Pod, warnMsg string, checkSameNamespace bool) { |
|
120 | 120 |
minCount := 1 |
121 | 121 |
if len(pods1) > 0 && len(pods2) > 0 && (pods1[0].UID == pods2[0].UID) { |
122 | 122 |
minCount += 1 |
... | ... |
@@ -148,6 +148,13 @@ func (d CheckPodNetwork) checkConnection(pods1, pods2 []kapi.Pod, warnMsg string |
148 | 148 |
} |
149 | 149 |
} |
150 | 150 |
} |
151 |
+ |
|
152 |
+ if checkSameNamespace && !sameNamespace { |
|
153 |
+ d.res.Warn("DPodNet1010", nil, fmt.Sprintf("Same Namespace: %s", warnMsg)) |
|
154 |
+ } |
|
155 |
+ if !diffNamespace { |
|
156 |
+ d.res.Warn("DPodNet1011", nil, fmt.Sprintf("Different namespaces: %s", warnMsg)) |
|
157 |
+ } |
|
151 | 158 |
} |
152 | 159 |
|
153 | 160 |
// checkPodToPodConnection verifies connection from fromPod to toPod. |
... | ... |
@@ -132,6 +132,13 @@ func (d CheckServiceNetwork) checkConnection(pods []kapi.Pod, services []kapi.Se |
132 | 132 |
} |
133 | 133 |
} |
134 | 134 |
} |
135 |
+ |
|
136 |
+ if !sameNamespace { |
|
137 |
+ d.res.Warn("DSvcNet1012", nil, fmt.Sprintf("Same Namespace: %s", warnMsg)) |
|
138 |
+ } |
|
139 |
+ if !diffNamespace { |
|
140 |
+ d.res.Warn("DSvcNet1013", nil, fmt.Sprintf("Different namespaces: %s", warnMsg)) |
|
141 |
+ } |
|
135 | 142 |
} |
136 | 143 |
|
137 | 144 |
func getAllServices(kubeClient *kclient.Client) ([]kapi.Service, error) { |