1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,57 @@ |
0 |
+package network |
|
1 |
+ |
|
2 |
+import ( |
|
3 |
+ "errors" |
|
4 |
+ "fmt" |
|
5 |
+ "path/filepath" |
|
6 |
+ |
|
7 |
+ kclient "k8s.io/kubernetes/pkg/client/unversioned" |
|
8 |
+ |
|
9 |
+ "github.com/openshift/origin/pkg/diagnostics/networkpod/util" |
|
10 |
+ "github.com/openshift/origin/pkg/diagnostics/types" |
|
11 |
+) |
|
12 |
+ |
|
13 |
+const ( |
|
14 |
+ CollectNetworkInfoName = "CollectNetworkInfo" |
|
15 |
+) |
|
16 |
+ |
|
17 |
+// CollectNetworkInfo is a Diagnostic to collect network information in the cluster. |
|
18 |
+type CollectNetworkInfo struct { |
|
19 |
+ KubeClient *kclient.Client |
|
20 |
+} |
|
21 |
+ |
|
22 |
+// Name is part of the Diagnostic interface and just returns name. |
|
23 |
+func (d CollectNetworkInfo) Name() string { |
|
24 |
+ return CollectNetworkInfoName |
|
25 |
+} |
|
26 |
+ |
|
27 |
+// Description is part of the Diagnostic interface and just returns the diagnostic description. |
|
28 |
+func (d CollectNetworkInfo) Description() string { |
|
29 |
+ return "Collect network information in the cluster." |
|
30 |
+} |
|
31 |
+ |
|
32 |
+// CanRun is part of the Diagnostic interface; it determines if the conditions are right to run this diagnostic. |
|
33 |
+func (d CollectNetworkInfo) CanRun() (bool, error) { |
|
34 |
+ if d.KubeClient == nil { |
|
35 |
+ return false, errors.New("must have kube client") |
|
36 |
+ } |
|
37 |
+ return true, nil |
|
38 |
+} |
|
39 |
+ |
|
40 |
+// Check is part of the Diagnostic interface; it runs the actual diagnostic logic |
|
41 |
+func (d CollectNetworkInfo) Check() types.DiagnosticResult { |
|
42 |
+ r := types.NewDiagnosticResult(CollectNetworkInfoName) |
|
43 |
+ |
|
44 |
+ nodeName, _, err := util.GetLocalNode(d.KubeClient) |
|
45 |
+ if err != nil { |
|
46 |
+ r.Error("DColNet1001", err, fmt.Sprintf("Fetching local node info failed: %s", err)) |
|
47 |
+ return r |
|
48 |
+ } |
|
49 |
+ |
|
50 |
+ l := util.LogInterface{ |
|
51 |
+ Result: r, |
|
52 |
+ Logdir: filepath.Join(util.NetworkDiagDefaultLogDir, util.NetworkDiagNodeLogDirPrefix, nodeName), |
|
53 |
+ } |
|
54 |
+ l.LogNode(d.KubeClient) |
|
55 |
+ return r |
|
56 |
+} |