Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network diags: Determine runtime based on local node object #20658

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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