Skip to content

Commit

Permalink
Merge pull request #663 from l1b0k/release-1.8
Browse files Browse the repository at this point in the history
fix: some compare logic
  • Loading branch information
BSWANG authored Aug 12, 2024
2 parents e51e879 + e1cae0f commit 6de5139
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/crds/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func CreateOrUpdateCRD(ctx context.Context, c client.Client, name string) error
}

result := semver.Compare(exist.Annotations[crdVersionKey], expect.Annotations[crdVersionKey])
if result <= 0 {
if result >= 0 {
return nil
}
log.Info("update crd", "exist", exist.Annotations[crdVersionKey], "expect", expect.Annotations[crdVersionKey])
Expand Down
2 changes: 1 addition & 1 deletion pkg/eni/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (l *Local) Allocate(ctx context.Context, cni *daemon.CNI, request ResourceR
}
}

if expectV4 > 0 && expectV6 > 0 && l.ipAllocInhibitExpireAt.After(time.Now()) {
if (expectV4 > 0 || expectV6 > 0) && l.ipAllocInhibitExpireAt.After(time.Now()) {
log.Info("eni alloc inhibit", "expire", l.ipAllocInhibitExpireAt.String())
return nil, []Trace{{Condition: InsufficientVSwitchIP, Reason: fmt.Sprintf("alloc inhibit, expire at %s", l.ipAllocInhibitExpireAt.String())}}
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/eni/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/netip"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
"golang.org/x/time/rate"
Expand Down Expand Up @@ -265,6 +266,19 @@ func TestLocal_Allocate_ERDMA(t *testing.T) {
assert.Equal(t, ResourceTypeMismatch, resp[0].Condition)
}

func TestLocal_Allocate_Inhibit(t *testing.T) {
local := NewLocalTest(&daemon.ENI{ID: "eni-1"}, nil, &types.PoolConfig{MaxIPPerENI: 2, EnableIPv4: true}, "")

request := &LocalIPRequest{}
cni := &daemon.CNI{PodID: "pod-1"}

local.ipAllocInhibitExpireAt = time.Now().Add(time.Minute)

allocResp, resp := local.Allocate(context.Background(), cni, request)
assert.Nil(t, allocResp)
assert.Equal(t, 1, len(resp))
}

func Test_parseResourceID(t *testing.T) {
type args struct {
id string
Expand Down

0 comments on commit 6de5139

Please sign in to comment.