diff --git a/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/collect.go b/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/collect.go index 5c033737b405..4529b863dc9f 100644 --- a/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/collect.go +++ b/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/collect.go @@ -47,7 +47,7 @@ func (d CollectNetworkInfo) CanRun() (bool, error) { func (d CollectNetworkInfo) Check() types.DiagnosticResult { r := types.NewDiagnosticResult(CollectNetworkInfoName) - nodeName, _, err := util.GetLocalNode(d.KubeClient) + node, _, err := util.GetLocalNode(d.KubeClient) if err != nil { r.Error("DColNet1001", err, fmt.Sprintf("Fetching local node info failed: %s", err)) return r @@ -55,7 +55,7 @@ func (d CollectNetworkInfo) Check() types.DiagnosticResult { l := util.LogInterface{ Result: r, - Logdir: filepath.Join(util.NetworkDiagDefaultLogDir, util.NetworkDiagNodeLogDirPrefix, nodeName), + Logdir: filepath.Join(util.NetworkDiagDefaultLogDir, util.NetworkDiagNodeLogDirPrefix, node.Name), } l.LogNode(d.KubeClient, d.Runtime) return r diff --git a/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/util/runtime.go b/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/util/runtime.go index 31866a9fae9a..c1f47c5b3ead 100644 --- a/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/util/runtime.go +++ b/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/util/runtime.go @@ -114,31 +114,26 @@ func (r *Runtime) GetRuntimeVersion() (string, error) { } func getRuntimeEndpoint(kubeClient kclientset.Interface) (string, string, string, error) { - nodes, err := GetNodes(kubeClient) + node, _, err := GetLocalNode(kubeClient) if err != nil { return "", "", "", err } - if len(nodes) == 0 { - return "", "", "", fmt.Errorf("no nodes found to detect the runtime") - } - for _, node := range nodes { - if len(node.Status.NodeInfo.ContainerRuntimeVersion) > 0 { - runtimeTokens := strings.Split(node.Status.NodeInfo.ContainerRuntimeVersion, "://") - switch runtimeTokens[0] { - case crioRuntimeType: - if err := filePathExists(defaultCRIOShimSocket); err != nil { - return "", "", "", fmt.Errorf("detected crio runtime but validation of socket file %q failed: %v", defaultCRIOShimSocket, err) - } - return crioRuntimeName, crioRuntimeType, defaultCRIOShimSocket, nil - case dockerRuntimeType: - if err := filePathExists(defaultDockerShimSocket); err != nil { - return "", "", "", fmt.Errorf("detected docker runtime but validation of socket file %q failed: %v", defaultDockerShimSocket, err) - } - return dockerRuntimeName, dockerRuntimeType, defaultDockerShimSocket, nil - default: - return "", "", "", fmt.Errorf("runtime %q is not supported", runtimeTokens[0]) + if len(node.Status.NodeInfo.ContainerRuntimeVersion) > 0 { + runtimeTokens := strings.Split(node.Status.NodeInfo.ContainerRuntimeVersion, "://") + switch runtimeTokens[0] { + case crioRuntimeType: + if err := filePathExists(defaultCRIOShimSocket); err != nil { + return "", "", "", fmt.Errorf("detected crio runtime but validation of socket file %q failed: %v", defaultCRIOShimSocket, err) + } + return crioRuntimeName, crioRuntimeType, defaultCRIOShimSocket, nil + case dockerRuntimeType: + if err := filePathExists(defaultDockerShimSocket); err != nil { + return "", "", "", fmt.Errorf("detected docker runtime but validation of socket file %q failed: %v", defaultDockerShimSocket, err) } + return dockerRuntimeName, dockerRuntimeType, defaultDockerShimSocket, nil + default: + return "", "", "", fmt.Errorf("runtime %q is not supported", runtimeTokens[0]) } } diff --git a/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/util/util.go b/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/util/util.go index 653e7d12d42c..66e3629e601d 100644 --- a/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/util/util.go +++ b/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/util/util.go @@ -107,15 +107,15 @@ func GetSchedulableNodes(kubeClient kclientset.Interface) ([]kapi.Node, error) { return filteredNodes, nil } -func GetLocalNode(kubeClient kclientset.Interface) (string, string, error) { +func GetLocalNode(kubeClient kclientset.Interface) (*kapi.Node, string, error) { nodeList, err := kubeClient.Core().Nodes().List(metav1.ListOptions{}) if err != nil { - return "", "", err + return nil, "", err } _, hostIPs, err := netutils.GetHostIPNetworks(nil) if err != nil { - return "", "", err + return nil, "", err } for _, node := range nodeList.Items { if len(node.Status.Addresses) == 0 { @@ -124,12 +124,12 @@ func GetLocalNode(kubeClient kclientset.Interface) (string, string, error) { for _, ip := range hostIPs { for _, addr := range node.Status.Addresses { if addr.Type == kapi.NodeInternalIP && ip.String() == addr.Address { - return node.Name, addr.Address, nil + return &node, addr.Address, nil } } } } - return "", "", fmt.Errorf("unable to find local node IP") + return nil, "", fmt.Errorf("unable to find local node IP") } // Get local/non-local pods in network diagnostic namespaces