From 688c10fa8b25024ae093cccdbb000414878a7102 Mon Sep 17 00:00:00 2001 From: shidao-ytt <43381136+shidao-ytt@users.noreply.github.com> Date: Tue, 27 Nov 2018 03:08:37 +0800 Subject: [PATCH] [AliCloud] Add cluster name and bug fix (#412) * [AliCloud] add tag ClusterName for different k8s cluster * [AliCloud] BugFix: vk get wrong pod ip * update serverless kubernetes help doc link --- providers/alicloud/README.md | 2 +- providers/alicloud/config.go | 5 +++++ providers/alicloud/eci.go | 23 ++++++++++++++++++----- providers/alicloud/eci.toml | 1 + 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/providers/alicloud/README.md b/providers/alicloud/README.md index 68f0acba0..6d0796bc5 100644 --- a/providers/alicloud/README.md +++ b/providers/alicloud/README.md @@ -53,5 +53,5 @@ spec: Alibaba Cloud serverless kubernetes allows you to quickly create kubernetes container applications without having to manage and maintain clusters and servers. It is based on ECI and fully compatible with the Kuberentes API. -You can find more infomation via [alibaba cloud serverless kubernetes product doc](https://www.alibabacloud.com/help/doc-detail/71479.htm) +You can find more infomation via [alibaba cloud serverless kubernetes product doc](https://www.alibabacloud.com/help/doc-detail/94078.htm) diff --git a/providers/alicloud/config.go b/providers/alicloud/config.go index 5cf294b72..92c26d709 100644 --- a/providers/alicloud/config.go +++ b/providers/alicloud/config.go @@ -15,6 +15,7 @@ type providerConfig struct { Pods string VSwitch string SecureGroup string + ClusterName string } func (p *ECIProvider) loadConfig(r io.Reader) error { @@ -47,5 +48,9 @@ func (p *ECIProvider) loadConfig(r io.Reader) error { if p.operatingSystem == "" { p.operatingSystem = providers.OperatingSystemLinux } + p.clusterName = config.ClusterName + if p.clusterName == "" { + p.clusterName = "default" + } return nil } diff --git a/providers/alicloud/eci.go b/providers/alicloud/eci.go index e090f1a89..ef396171c 100644 --- a/providers/alicloud/eci.go +++ b/providers/alicloud/eci.go @@ -42,6 +42,7 @@ type ECIProvider struct { region string nodeName string operatingSystem string + clusterName string cpu string memory string pods string @@ -101,7 +102,12 @@ func NewECIProvider(config string, rm *manager.ResourceManager, nodeName, operat return nil, err } } - + if r := os.Getenv("ECI_CLUSTER_NAME"); r != "" { + p.clusterName = r + } + if p.clusterName == "" { + p.clusterName = "default" + } if r := os.Getenv("ECI_REGION"); r != "" { p.region = r } @@ -204,10 +210,10 @@ func (p *ECIProvider) CreatePod(ctx context.Context, pod *v1.Pod) error { request.ImageRegistryCredentials = creds CreationTimestamp := pod.CreationTimestamp.UTC().Format(podTagTimeFormat) tags := []eci.Tag{ - eci.Tag{Key: "PodName", Value: pod.Name}, - eci.Tag{Key: "ClusterName", Value: pod.ClusterName}, - eci.Tag{Key: "NodeName", Value: pod.Spec.NodeName}, + eci.Tag{Key: "ClusterName", Value: p.clusterName}, + eci.Tag{Key: "NodeName", Value: p.nodeName}, eci.Tag{Key: "NameSpace", Value: pod.Namespace}, + eci.Tag{Key: "PodName", Value: pod.Name}, eci.Tag{Key: "UID", Value: string(pod.UID)}, eci.Tag{Key: "CreationTimestamp", Value: CreationTimestamp}, } @@ -347,6 +353,13 @@ func (p *ECIProvider) GetCgs() []eci.ContainerGroup { if getECITagValue(&cg, "NodeName") != p.nodeName { continue } + cn := getECITagValue(&cg, "ClusterName") + if cn == "" { + cn = "default" + } + if cn != p.clusterName { + continue + } cgs = append(cgs, cg) } if request.NextToken == "" { @@ -771,7 +784,7 @@ func containerGroupToPod(cg *eci.ContainerGroup) (*v1.Pod, error) { Message: "", Reason: "", HostIP: "", - PodIP: cg.InternetIp, + PodIP: cg.IntranetIp, StartTime: &containerStartTime, ContainerStatuses: containerStatuses, }, diff --git a/providers/alicloud/eci.toml b/providers/alicloud/eci.toml index acb3090e6..f37ae378b 100644 --- a/providers/alicloud/eci.toml +++ b/providers/alicloud/eci.toml @@ -3,3 +3,4 @@ OperatingSystem = "Linux" CPU = "20" Memory = "100Gi" Pods = "20" +ClusterName = "default"