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

expose eni create log #322

Merged
merged 1 commit into from
Feb 17, 2022
Merged
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
48 changes: 42 additions & 6 deletions daemon/eni-multi-ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ import (
corev1 "k8s.io/api/core/v1"
)

type AllocCtx struct {
Trace []Trace
}

func (a *AllocCtx) String() string {
var s []string
for _, t := range a.Trace {
s = append(s, t.Msg)
}
return strings.Join(s, "\n")
}

type Trace struct {
Msg string
}

var eniIPLog = logger.DefaultLogger

const (
Expand Down Expand Up @@ -138,7 +154,7 @@ func (e *ENI) allocateWorker(resultChan chan<- *ENIIP) {
}
}

func (f *eniIPFactory) getEnis() ([]*ENI, error) {
func (f *eniIPFactory) getEnis(ctx *AllocCtx) ([]*ENI, error) {
var (
enis []*ENI
pendingEnis []*ENI
Expand All @@ -156,7 +172,16 @@ func (f *eniIPFactory) getEnis() ([]*ENI, error) {
// If VSwitchSelectionPolicy is ordered, then call f.eniFactory.GetVSwitches() API to get a switch slice
// in descending order per each switch's available IP count.
vSwitches, err := f.eniFactory.GetVSwitches()
eniIPLog.Infof("adjusted vswitch slice: %+v, original eni slice: %+v", vSwitches, f.enis)
eniIPLog.Infof("adjusted vswitch slice: %+v, original eni slice: %s", vSwitches, func(enis []*ENI) string {
var vsw []string
for i := 0; i < len(enis); i++ {
if enis[i] == nil {
continue
}
vsw = append(vsw, enis[i].VSwitchID)
}
return strings.Join(vsw, ",")
}(f.enis))
if err != nil {
eniIPLog.Errorf("error to get vswitch slice: %v, instead use original eni slice in eniIPFactory: %v", err, f.enis)
return f.enis, err
Expand All @@ -173,15 +198,21 @@ func (f *eniIPFactory) getEnis() ([]*ENI, error) {
}
}
enis = append(enis, pendingEnis...)
if len(enis) == 0 && len(f.enis) != 0 {
ctx.Trace = append(ctx.Trace, Trace{
Msg: "current eni have vSwitch not as expected, please check eni-config",
})
}

return enis, nil

}

func (f *eniIPFactory) submit() error {
func (f *eniIPFactory) submit(ctx *AllocCtx) error {
f.Lock()
defer f.Unlock()
var enis []*ENI
enis, _ = f.getEnis()
enis, _ = f.getEnis(ctx)
for _, eni := range enis {
eniIPLog.Infof("check existing eni: %+v", eni)
eni.lock.Lock()
Expand All @@ -193,6 +224,10 @@ func (f *eniIPFactory) submit() error {
// if the current eni has been inhibited for Pod IP allocation, then skip current eni.
if now.Before(eni.ipAllocInhibitExpireAt) && eni.ENI != nil {
eni.lock.Unlock()

// vsw have insufficient ip
ctx.Trace = append(ctx.Trace, Trace{Msg: fmt.Sprintf("eni %s vSwitch %s have insufficient IP, next check %s", eni.ID, eni.VSwitchID, eni.ipAllocInhibitExpireAt)})

eniIPLog.Debugf("skip IP allocation: eni = %+v, vsw = %s", eni, eni.VSwitchID)
continue
}
Expand Down Expand Up @@ -260,6 +295,7 @@ func (f *eniIPFactory) popResult() (ip *types.ENIIP, err error) {
}

func (f *eniIPFactory) Create(count int) ([]types.NetworkResource, error) {
ctx := &AllocCtx{}
var (
ipResult []types.NetworkResource
err error
Expand All @@ -277,7 +313,7 @@ func (f *eniIPFactory) Create(count int) ([]types.NetworkResource, error) {

// find for available ENIs and submit for ip allocation
for ; waiting < count; waiting++ {
err = f.submit()
err = f.submit(ctx)
if err != nil {
break
}
Expand All @@ -304,7 +340,7 @@ func (f *eniIPFactory) Create(count int) ([]types.NetworkResource, error) {

// no ip has been created
if waiting == 0 {
return ipResult, errors.Errorf("error submit ip create request: %v", err)
return ipResult, errors.Errorf("error submit ip create request: %v,%s", err, ctx.String())
}

var ip *types.ENIIP
Expand Down