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

pool: fix min size cal #547

Merged
merged 1 commit into from
Dec 21, 2023
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
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
Loading