Skip to content

Commit

Permalink
Merge pull request #547 from l1b0k/fix/size
Browse files Browse the repository at this point in the history
pool: fix min size cal
  • Loading branch information
BSWANG authored Dec 21, 2023
2 parents 6aeadef + cf70d74 commit 24cdbaa
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func getPoolConfig(cfg *daemon.Config, daemonMode string, limit *aliyun.Limits)
poolConfig.MaxPoolSize = cfg.MaxPoolSize
}

poolConfig.MinPoolSize = cfg.MinPoolSize

if cfg.MinENI > 0 {
poolConfig.MinPoolSize = cfg.MinENI
}
Expand Down Expand Up @@ -92,6 +94,8 @@ func getPoolConfig(cfg *daemon.Config, daemonMode string, limit *aliyun.Limits)
poolConfig.MaxPoolSize = cfg.MaxPoolSize
}

poolConfig.MinPoolSize = cfg.MinPoolSize

if cfg.MinENI > 0 {
poolConfig.MinPoolSize = cfg.MinENI * ipPerENI
}
Expand Down
67 changes: 67 additions & 0 deletions daemon/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package daemon

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/AliyunContainerService/terway/pkg/aliyun"
"github.com/AliyunContainerService/terway/types/daemon"
)

func init() {
aliyun.Test = true
}

func TestGetPoolConfigWithVPCMode(t *testing.T) {
cfg := &daemon.Config{
MaxPoolSize: 5,
MinPoolSize: 1,
EniCapRatio: 1,
RegionID: "foo",
}
limit := &aliyun.Limits{
Adapters: 10,
MemberAdapterLimit: 5,
}
poolConfig, err := getPoolConfig(cfg, "VPC", limit)
assert.NoError(t, err)
assert.Equal(t, 5, poolConfig.MaxPoolSize)
assert.Equal(t, 1, poolConfig.MinPoolSize)
}

func TestGetPoolConfigWithENIOnlyMode(t *testing.T) {
cfg := &daemon.Config{
MaxPoolSize: 5,
MinPoolSize: 1,
EniCapRatio: 1,
RegionID: "foo",
}
limit := &aliyun.Limits{
Adapters: 10,
MemberAdapterLimit: 5,
}
poolConfig, err := getPoolConfig(cfg, "ENIOnly", limit)
assert.NoError(t, err)
assert.Equal(t, 5, poolConfig.MaxPoolSize)
assert.Equal(t, 1, poolConfig.MinPoolSize)
}

func TestGetPoolConfigWithENIMultiIPMode(t *testing.T) {
cfg := &daemon.Config{
MaxPoolSize: 5,
MinPoolSize: 1,
EniCapRatio: 1,
RegionID: "foo",
}
limit := &aliyun.Limits{
Adapters: 10,
IPv4PerAdapter: 5,
MemberAdapterLimit: 5,
}
poolConfig, err := getPoolConfig(cfg, "ENIMultiIP", limit)
assert.NoError(t, err)
assert.Equal(t, 5, poolConfig.MaxPoolSize)
assert.Equal(t, 1, poolConfig.MinPoolSize)
assert.Equal(t, 5, poolConfig.MaxIPPerENI)
}
4 changes: 4 additions & 0 deletions pkg/aliyun/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
var defaultIns *Instance
var once sync.Once
var logIns = logger.DefaultLogger
var Test = false

type Instance struct {
RegionID string
Expand All @@ -27,6 +28,9 @@ type Instance struct {
}

func GetInstanceMeta() *Instance {
if Test {
return &Instance{}
}
once.Do(func() {
regionID, err := metadata.GetLocalRegion()
if err != nil || regionID == "" {
Expand Down

0 comments on commit 24cdbaa

Please sign in to comment.