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

adaptive terway for lingjun #628

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 3 additions & 5 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
commandResDB = "resdb"

IfEth0 = "eth0"

envEFLO = "eflo"
)

type networkService struct {
Expand Down Expand Up @@ -860,7 +858,7 @@
_ = netSrv.k8s.SetCustomStatefulWorkloadKinds(config.CustomStatefulWorkloadKinds)
netSrv.ipamType = config.IPAMType

if os.Getenv("TERWAY_DEPLOY_ENV") == envEFLO {
if lingjunNodeType := types.LingjunNodeTypeFromLables(netSrv.k8s.GetNodeLabels()); lingjunNodeType {

Check warning on line 861 in daemon/daemon.go

View check run for this annotation

Codecov / codecov/patch

daemon/daemon.go#L861

Added line #L861 was not covered by tests
instance.SetPopulateFunc(instance.EfloPopulate)
client.SetGetLimit(client.EfloGetLimit)
}
Expand Down Expand Up @@ -892,7 +890,7 @@
}

instanceType := meta.InstanceType
if os.Getenv("TERWAY_DEPLOY_ENV") == envEFLO {
if lingjunNodeType := types.LingjunNodeTypeFromLables(netSrv.k8s.GetNodeLabels()); lingjunNodeType {

Check warning on line 893 in daemon/daemon.go

View check run for this annotation

Codecov / codecov/patch

daemon/daemon.go#L893

Added line #L893 was not covered by tests
instanceType = meta.InstanceID
}
limit, err := client.GetLimit(aliyunClient, instanceType)
Expand Down Expand Up @@ -938,7 +936,7 @@
}

var factory factory.Factory
if os.Getenv("TERWAY_DEPLOY_ENV") == envEFLO {
if lingjunNodeType := types.LingjunNodeTypeFromLables(netSrv.k8s.GetNodeLabels()); lingjunNodeType {

Check warning on line 939 in daemon/daemon.go

View check run for this annotation

Codecov / codecov/patch

daemon/daemon.go#L939

Added line #L939 was not covered by tests
factory = aliyun.NewEflo(ctx, aliyunClient, vswPool, eniConfig)
} else {
factory = aliyun.NewAliyun(ctx, aliyunClient, eni2.NewENIMetadata(enableIPv4, enableIPv6), vswPool, eniConfig)
Expand Down
5 changes: 5 additions & 0 deletions pkg/eni/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func (f *FakeK8s) GetNodeDynamicConfigLabel() string {
panic("implement me")
}

func (f *FakeK8s) GetNodeLabels() map[string]string {
//TODO implement me
panic("implement me")
}

func (f *FakeK8s) GetDynamicConfigWithName(ctx context.Context, name string) (string, error) {
//TODO implement me
panic("implement me")
Expand Down
8 changes: 8 additions & 0 deletions pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Kubernetes interface {

GetServiceCIDR() *types.IPNetSet
GetNodeCidr() *types.IPNetSet
GetNodeLabels() map[string]string
SetNodeAllocatablePod(count int) error

PatchNodeAnnotations(anno map[string]string) error
Expand Down Expand Up @@ -517,6 +518,13 @@ func (k *k8s) RecordPodEvent(podName, podNamespace, eventType, reason, message s
return nil
}

func (k *k8s) GetNodeLabels() map[string]string {
if k.node.Labels == nil {
return map[string]string{}
}
return k.node.Labels
}

// GetNodeDynamicConfigLabel returns value with label config
func (k *k8s) GetNodeDynamicConfigLabel() string {
// use node cached in newK8s()
Expand Down
22 changes: 21 additions & 1 deletion pkg/k8s/mocks/Kubernetes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions types/lingjun.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package types

const (
NodeTypeLabel = "alibabacloud.com/lingjun-worker"
)

func LingjunNodeTypeFromLables(labels map[string]string) bool {
nodeType, ok := labels[NodeTypeLabel]
if ok && nodeType == "true" {
return true

Check warning on line 10 in types/lingjun.go

View check run for this annotation

Codecov / codecov/patch

types/lingjun.go#L7-L10

Added lines #L7 - L10 were not covered by tests
}
return false

Check warning on line 12 in types/lingjun.go

View check run for this annotation

Codecov / codecov/patch

types/lingjun.go#L12

Added line #L12 was not covered by tests
}
Loading