[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
This commit is contained in:
shidao-ytt
2018-11-27 03:08:37 +08:00
committed by Robbie Zhang
parent f07daf494b
commit 688c10fa8b
4 changed files with 25 additions and 6 deletions

View File

@@ -53,5 +53,5 @@ spec:
Alibaba Cloud serverless kubernetes allows you to quickly create kubernetes container applications without 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. 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)

View File

@@ -15,6 +15,7 @@ type providerConfig struct {
Pods string Pods string
VSwitch string VSwitch string
SecureGroup string SecureGroup string
ClusterName string
} }
func (p *ECIProvider) loadConfig(r io.Reader) error { func (p *ECIProvider) loadConfig(r io.Reader) error {
@@ -47,5 +48,9 @@ func (p *ECIProvider) loadConfig(r io.Reader) error {
if p.operatingSystem == "" { if p.operatingSystem == "" {
p.operatingSystem = providers.OperatingSystemLinux p.operatingSystem = providers.OperatingSystemLinux
} }
p.clusterName = config.ClusterName
if p.clusterName == "" {
p.clusterName = "default"
}
return nil return nil
} }

View File

@@ -42,6 +42,7 @@ type ECIProvider struct {
region string region string
nodeName string nodeName string
operatingSystem string operatingSystem string
clusterName string
cpu string cpu string
memory string memory string
pods string pods string
@@ -101,7 +102,12 @@ func NewECIProvider(config string, rm *manager.ResourceManager, nodeName, operat
return nil, err 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 != "" { if r := os.Getenv("ECI_REGION"); r != "" {
p.region = r p.region = r
} }
@@ -204,10 +210,10 @@ func (p *ECIProvider) CreatePod(ctx context.Context, pod *v1.Pod) error {
request.ImageRegistryCredentials = creds request.ImageRegistryCredentials = creds
CreationTimestamp := pod.CreationTimestamp.UTC().Format(podTagTimeFormat) CreationTimestamp := pod.CreationTimestamp.UTC().Format(podTagTimeFormat)
tags := []eci.Tag{ tags := []eci.Tag{
eci.Tag{Key: "PodName", Value: pod.Name}, eci.Tag{Key: "ClusterName", Value: p.clusterName},
eci.Tag{Key: "ClusterName", Value: pod.ClusterName}, eci.Tag{Key: "NodeName", Value: p.nodeName},
eci.Tag{Key: "NodeName", Value: pod.Spec.NodeName},
eci.Tag{Key: "NameSpace", Value: pod.Namespace}, 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: "UID", Value: string(pod.UID)},
eci.Tag{Key: "CreationTimestamp", Value: CreationTimestamp}, eci.Tag{Key: "CreationTimestamp", Value: CreationTimestamp},
} }
@@ -347,6 +353,13 @@ func (p *ECIProvider) GetCgs() []eci.ContainerGroup {
if getECITagValue(&cg, "NodeName") != p.nodeName { if getECITagValue(&cg, "NodeName") != p.nodeName {
continue continue
} }
cn := getECITagValue(&cg, "ClusterName")
if cn == "" {
cn = "default"
}
if cn != p.clusterName {
continue
}
cgs = append(cgs, cg) cgs = append(cgs, cg)
} }
if request.NextToken == "" { if request.NextToken == "" {
@@ -771,7 +784,7 @@ func containerGroupToPod(cg *eci.ContainerGroup) (*v1.Pod, error) {
Message: "", Message: "",
Reason: "", Reason: "",
HostIP: "", HostIP: "",
PodIP: cg.InternetIp, PodIP: cg.IntranetIp,
StartTime: &containerStartTime, StartTime: &containerStartTime,
ContainerStatuses: containerStatuses, ContainerStatuses: containerStatuses,
}, },

View File

@@ -3,3 +3,4 @@ OperatingSystem = "Linux"
CPU = "20" CPU = "20"
Memory = "100Gi" Memory = "100Gi"
Pods = "20" Pods = "20"
ClusterName = "default"