Skip to content

Commit

Permalink
Network diags: Determine runtime based on local node object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ravi Sankar Penta committed Aug 15, 2018
1 parent 80abd58 commit f4d6d20
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ 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
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit f4d6d20

Please sign in to comment.