Skip to content

Commit 19ecd8e

Browse files
shenshuoyanshenshuoyan
shenshuoyan
authored and
shenshuoyan
committed
adaptive terway for lingjun
1 parent 4e8df45 commit 19ecd8e

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

daemon/daemon.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ func newNetworkService(ctx context.Context, configFilePath, daemonMode string) (
860860
_ = netSrv.k8s.SetCustomStatefulWorkloadKinds(config.CustomStatefulWorkloadKinds)
861861
netSrv.ipamType = config.IPAMType
862862

863-
if os.Getenv("TERWAY_DEPLOY_ENV") == envEFLO {
863+
if lingjunNodeType := types.LingjunNodeTypeFromLables(netSrv.k8s.GetNodeLabels()); lingjunNodeType {
864864
instance.SetPopulateFunc(instance.EfloPopulate)
865865
client.SetGetLimit(client.EfloGetLimit)
866866
}
@@ -892,7 +892,7 @@ func newNetworkService(ctx context.Context, configFilePath, daemonMode string) (
892892
}
893893

894894
instanceType := meta.InstanceType
895-
if os.Getenv("TERWAY_DEPLOY_ENV") == envEFLO {
895+
if lingjunNodeType := types.LingjunNodeTypeFromLables(netSrv.k8s.GetNodeLabels()); lingjunNodeType {
896896
instanceType = meta.InstanceID
897897
}
898898
limit, err := client.GetLimit(aliyunClient, instanceType)
@@ -938,7 +938,7 @@ func newNetworkService(ctx context.Context, configFilePath, daemonMode string) (
938938
}
939939

940940
var factory factory.Factory
941-
if os.Getenv("TERWAY_DEPLOY_ENV") == envEFLO {
941+
if lingjunNodeType := types.LingjunNodeTypeFromLables(netSrv.k8s.GetNodeLabels()); lingjunNodeType {
942942
factory = aliyun.NewEflo(ctx, aliyunClient, vswPool, eniConfig)
943943
} else {
944944
factory = aliyun.NewAliyun(ctx, aliyunClient, eni2.NewENIMetadata(enableIPv4, enableIPv6), vswPool, eniConfig)

pkg/eni/manager_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ func (f *FakeK8s) GetNodeDynamicConfigLabel() string {
166166
panic("implement me")
167167
}
168168

169+
func (f *FakeK8s) GetNodeLabels() map[string]string {
170+
//TODO implement me
171+
panic("implement me")
172+
}
173+
169174
func (f *FakeK8s) GetDynamicConfigWithName(ctx context.Context, name string) (string, error) {
170175
//TODO implement me
171176
panic("implement me")

pkg/k8s/k8s.go

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type Kubernetes interface {
8888

8989
GetServiceCIDR() *types.IPNetSet
9090
GetNodeCidr() *types.IPNetSet
91+
GetNodeLabels() map[string]string
9192
SetNodeAllocatablePod(count int) error
9293

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

521+
func (k *k8s) GetNodeLabels() map[string]string {
522+
if k.node.Labels == nil {
523+
return map[string]string{}
524+
}
525+
return k.node.Labels
526+
}
527+
520528
// GetNodeDynamicConfigLabel returns value with label config
521529
func (k *k8s) GetNodeDynamicConfigLabel() string {
522530
// use node cached in newK8s()

pkg/k8s/mocks/Kubernetes.go

+21-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/lingjun.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package types
2+
3+
const (
4+
NodeTypeLabel = "alibabacloud.com/lingjun-worker"
5+
)
6+
7+
func LingjunNodeTypeFromLables(labels map[string]string) bool {
8+
nodeType, ok := labels[NodeTypeLabel]
9+
if ok && nodeType == "true" {
10+
return true
11+
}
12+
return false
13+
}

0 commit comments

Comments
 (0)