✨ feat(eci): 添加EIP注解支持并优化配置逻辑
All checks were successful
Virtual Kubelet Docker Build and Deploy / build-and-deploy (push) Successful in 4m40s
All checks were successful
Virtual Kubelet Docker Build and Deploy / build-and-deploy (push) Successful in 4m40s
- 新增EIP相关注解支持:k8s.aliyun.com/eci-with-eip和k8s.aliyun.com/eci-eip-instanceid - 添加EipInstanceId字段到CreateContainerGroupRequest结构体 - 优化EIP配置逻辑:当未配置EIP注解时默认启用自动创建EIP - 移除硬编码的AutoCreateEip设置,改为基于注解的灵活配置
This commit is contained in:
17
eci.go
17
eci.go
@@ -190,12 +190,27 @@ func (p *ECIProvider) CreatePod(ctx context.Context, pod *v1.Pod) error {
|
|||||||
if specs, exists := pod.Annotations["k8s.aliyun.com/eci-use-specs"]; exists {
|
if specs, exists := pod.Annotations["k8s.aliyun.com/eci-use-specs"]; exists {
|
||||||
request.InstanceType = specs
|
request.InstanceType = specs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 解析EIP注解
|
||||||
|
if withEip, exists := pod.Annotations["k8s.aliyun.com/eci-with-eip"]; exists {
|
||||||
|
if autoCreate, err := strconv.ParseBool(withEip); err == nil {
|
||||||
|
request.AutoCreateEip = requests.Boolean(strconv.FormatBool(autoCreate))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if eipInstanceId, exists := pod.Annotations["k8s.aliyun.com/eci-eip-instanceid"]; exists {
|
||||||
|
request.EipInstanceId = eipInstanceId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有配置EIP注解,默认启用自动创建EIP
|
||||||
|
if request.AutoCreateEip == "" && request.EipInstanceId == "" {
|
||||||
|
request.AutoCreateEip = requests.Boolean(strconv.FormatBool(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加抢占式实例策略配置
|
// 添加抢占式实例策略配置
|
||||||
request.SpotStrategy = "SpotAsPriceGo" // 设置抢占式实例策略为按价格竞价
|
request.SpotStrategy = "SpotAsPriceGo" // 设置抢占式实例策略为按价格竞价
|
||||||
//request.SpotDuration = 0 // 设置抢占式实例持续时间为0(非定时抢占)
|
//request.SpotDuration = 0 // 设置抢占式实例持续时间为0(非定时抢占)
|
||||||
request.AutoCreateEip = requests.Boolean(strconv.FormatBool(true)) //
|
|
||||||
|
|
||||||
// get containers
|
// get containers
|
||||||
containers, err := p.getContainers(pod, false)
|
containers, err := p.getContainers(pod, false)
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ type CreateContainerGroupRequest struct {
|
|||||||
Volumes []Volume `position:"Query" name:"Volume" type:"Repeated"`
|
Volumes []Volume `position:"Query" name:"Volume" type:"Repeated"`
|
||||||
ContainerGroupName string `position:"Query" name:"ContainerGroupName"`
|
ContainerGroupName string `position:"Query" name:"ContainerGroupName"`
|
||||||
AutoCreateEip requests.Boolean `position:"Query" name:"AutoCreateEip"`
|
AutoCreateEip requests.Boolean `position:"Query" name:"AutoCreateEip"`
|
||||||
|
EipInstanceId string `position:"Query" name:"EipInstanceId"`
|
||||||
ZoneId string `position:"Query" name:"ZoneId"`
|
ZoneId string `position:"Query" name:"ZoneId"`
|
||||||
SpotStrategy string `position:"Query" name:"SpotStrategy"`
|
SpotStrategy string `position:"Query" name:"SpotStrategy"`
|
||||||
InstanceType string `position:"Query" name:"InstanceType"`
|
InstanceType string `position:"Query" name:"InstanceType"`
|
||||||
|
|||||||
Reference in New Issue
Block a user