Skip to content

Commit f4d6d20

Browse files
author
Ravi Sankar Penta
committed
Network diags: Determine runtime based on local node object
Follow up of openshift#20647 We could have some nodes running crio and others with docker runtime. Starter clusters are doing this but this could change with 4.0+ release. Fetch the runtime info from the local node object so that it works on all cases.
1 parent 80abd58 commit f4d6d20

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/collect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ func (d CollectNetworkInfo) CanRun() (bool, error) {
4747
func (d CollectNetworkInfo) Check() types.DiagnosticResult {
4848
r := types.NewDiagnosticResult(CollectNetworkInfoName)
4949

50-
nodeName, _, err := util.GetLocalNode(d.KubeClient)
50+
node, _, err := util.GetLocalNode(d.KubeClient)
5151
if err != nil {
5252
r.Error("DColNet1001", err, fmt.Sprintf("Fetching local node info failed: %s", err))
5353
return r
5454
}
5555

5656
l := util.LogInterface{
5757
Result: r,
58-
Logdir: filepath.Join(util.NetworkDiagDefaultLogDir, util.NetworkDiagNodeLogDirPrefix, nodeName),
58+
Logdir: filepath.Join(util.NetworkDiagDefaultLogDir, util.NetworkDiagNodeLogDirPrefix, node.Name),
5959
}
6060
l.LogNode(d.KubeClient, d.Runtime)
6161
return r

pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/util/runtime.go

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,31 +114,26 @@ func (r *Runtime) GetRuntimeVersion() (string, error) {
114114
}
115115

116116
func getRuntimeEndpoint(kubeClient kclientset.Interface) (string, string, string, error) {
117-
nodes, err := GetNodes(kubeClient)
117+
node, _, err := GetLocalNode(kubeClient)
118118
if err != nil {
119119
return "", "", "", err
120120
}
121-
if len(nodes) == 0 {
122-
return "", "", "", fmt.Errorf("no nodes found to detect the runtime")
123-
}
124121

125-
for _, node := range nodes {
126-
if len(node.Status.NodeInfo.ContainerRuntimeVersion) > 0 {
127-
runtimeTokens := strings.Split(node.Status.NodeInfo.ContainerRuntimeVersion, "://")
128-
switch runtimeTokens[0] {
129-
case crioRuntimeType:
130-
if err := filePathExists(defaultCRIOShimSocket); err != nil {
131-
return "", "", "", fmt.Errorf("detected crio runtime but validation of socket file %q failed: %v", defaultCRIOShimSocket, err)
132-
}
133-
return crioRuntimeName, crioRuntimeType, defaultCRIOShimSocket, nil
134-
case dockerRuntimeType:
135-
if err := filePathExists(defaultDockerShimSocket); err != nil {
136-
return "", "", "", fmt.Errorf("detected docker runtime but validation of socket file %q failed: %v", defaultDockerShimSocket, err)
137-
}
138-
return dockerRuntimeName, dockerRuntimeType, defaultDockerShimSocket, nil
139-
default:
140-
return "", "", "", fmt.Errorf("runtime %q is not supported", runtimeTokens[0])
122+
if len(node.Status.NodeInfo.ContainerRuntimeVersion) > 0 {
123+
runtimeTokens := strings.Split(node.Status.NodeInfo.ContainerRuntimeVersion, "://")
124+
switch runtimeTokens[0] {
125+
case crioRuntimeType:
126+
if err := filePathExists(defaultCRIOShimSocket); err != nil {
127+
return "", "", "", fmt.Errorf("detected crio runtime but validation of socket file %q failed: %v", defaultCRIOShimSocket, err)
128+
}
129+
return crioRuntimeName, crioRuntimeType, defaultCRIOShimSocket, nil
130+
case dockerRuntimeType:
131+
if err := filePathExists(defaultDockerShimSocket); err != nil {
132+
return "", "", "", fmt.Errorf("detected docker runtime but validation of socket file %q failed: %v", defaultDockerShimSocket, err)
141133
}
134+
return dockerRuntimeName, dockerRuntimeType, defaultDockerShimSocket, nil
135+
default:
136+
return "", "", "", fmt.Errorf("runtime %q is not supported", runtimeTokens[0])
142137
}
143138
}
144139

pkg/oc/cli/admin/diagnostics/diagnostics/cluster/network/in_pod/util/util.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ func GetSchedulableNodes(kubeClient kclientset.Interface) ([]kapi.Node, error) {
107107
return filteredNodes, nil
108108
}
109109

110-
func GetLocalNode(kubeClient kclientset.Interface) (string, string, error) {
110+
func GetLocalNode(kubeClient kclientset.Interface) (*kapi.Node, string, error) {
111111
nodeList, err := kubeClient.Core().Nodes().List(metav1.ListOptions{})
112112
if err != nil {
113-
return "", "", err
113+
return nil, "", err
114114
}
115115

116116
_, hostIPs, err := netutils.GetHostIPNetworks(nil)
117117
if err != nil {
118-
return "", "", err
118+
return nil, "", err
119119
}
120120
for _, node := range nodeList.Items {
121121
if len(node.Status.Addresses) == 0 {
@@ -124,12 +124,12 @@ func GetLocalNode(kubeClient kclientset.Interface) (string, string, error) {
124124
for _, ip := range hostIPs {
125125
for _, addr := range node.Status.Addresses {
126126
if addr.Type == kapi.NodeInternalIP && ip.String() == addr.Address {
127-
return node.Name, addr.Address, nil
127+
return &node, addr.Address, nil
128128
}
129129
}
130130
}
131131
}
132-
return "", "", fmt.Errorf("unable to find local node IP")
132+
return nil, "", fmt.Errorf("unable to find local node IP")
133133
}
134134

135135
// Get local/non-local pods in network diagnostic namespaces

0 commit comments

Comments
 (0)