Skip to content

Commit

Permalink
adaptive terway for lingjun
Browse files Browse the repository at this point in the history
  • Loading branch information
shenshuoyan authored and shenshuoyan committed May 11, 2024
1 parent 4e8df45 commit 19ecd8e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
6 changes: 3 additions & 3 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ func newNetworkService(ctx context.Context, configFilePath, daemonMode string) (
_ = 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 863 in daemon/daemon.go

View check run for this annotation

Codecov / codecov/patch

daemon/daemon.go#L863

Added line #L863 was not covered by tests
instance.SetPopulateFunc(instance.EfloPopulate)
client.SetGetLimit(client.EfloGetLimit)
}
Expand Down Expand Up @@ -892,7 +892,7 @@ func newNetworkService(ctx context.Context, configFilePath, daemonMode string) (
}

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

Check warning on line 895 in daemon/daemon.go

View check run for this annotation

Codecov / codecov/patch

daemon/daemon.go#L895

Added line #L895 was not covered by tests
instanceType = meta.InstanceID
}
limit, err := client.GetLimit(aliyunClient, instanceType)
Expand Down Expand Up @@ -938,7 +938,7 @@ func newNetworkService(ctx context.Context, configFilePath, daemonMode string) (
}

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

Check warning on line 941 in daemon/daemon.go

View check run for this annotation

Codecov / codecov/patch

daemon/daemon.go#L941

Added line #L941 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
}

0 comments on commit 19ecd8e

Please sign in to comment.