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

CNI: add fallback logic if no ip address references sandboxed interface #9895

Merged
merged 4 commits into from
Apr 9, 2021
Merged
Changes from 3 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
22 changes: 22 additions & 0 deletions client/allocrunner/networking_cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package allocrunner

import (
"context"
"encoding/json"
"fmt"
"math/rand"
"os"
Expand Down Expand Up @@ -111,6 +112,11 @@ func (c *cniNetworkConfigurator) Setup(ctx context.Context, alloc *structs.Alloc
break
}

if c.logger.IsDebug() {
resultJSON, _ := json.Marshal(res)
c.logger.Debug("received result from CNI", "result", string(resultJSON))
}

netStatus := new(structs.AllocNetworkStatus)

if len(res.Interfaces) > 0 {
Expand All @@ -134,6 +140,22 @@ func (c *cniNetworkConfigurator) Setup(ctx context.Context, alloc *structs.Alloc
netStatus.Address = iface.IPConfigs[0].IP.String()
}
}

if netStatus.Address == "" {
c.logger.Debug("no address found for sandboxed interface from CNI result, using first available")
var found bool
for _, iface := range res.Interfaces {
if len(iface.IPConfigs) > 0 {
schmichael marked this conversation as resolved.
Show resolved Hide resolved
netStatus.Address = iface.IPConfigs[0].IP.String()
schmichael marked this conversation as resolved.
Show resolved Hide resolved
found = true
break
}
}
if !found {
c.logger.Warn("no address could be found from CNI result", "allocID", alloc.ID)
}
}

if len(res.DNS) > 0 {
netStatus.DNS = &structs.DNSConfig{
Servers: res.DNS[0].Nameservers,
Expand Down