Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#152: add k8s.aliyun.com/eip-charge-type annotation #157

Merged
merged 1 commit into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion daemon/eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (e *eipResourceManager) Allocate(context *networkContext, prefer string) (t
return nil, fmt.Errorf("pod network mode not support EIP associate")
}

eipInfo, err := e.ecs.AllocateEipAddress(context.pod.EipInfo.PodEipBandWidth, context.pod.EipInfo.PodEipID, eniID, eniIP, e.allowEipRob)
eipInfo, err := e.ecs.AllocateEipAddress(context.pod.EipInfo.PodEipBandWidth, context.pod.EipInfo.PodEipChargeType, context.pod.EipInfo.PodEipID, eniID, eniIP, e.allowEipRob)
if err != nil {
return nil, errors.Errorf("error allocate eip info: %v", err)
}
Expand Down
17 changes: 13 additions & 4 deletions daemon/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/AliyunContainerService/terway/deviceplugin"
"github.com/AliyunContainerService/terway/pkg/storage"
"github.com/denverdino/aliyungo/common"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -50,10 +51,11 @@ const (
)

type podEipInfo struct {
PodEip bool
PodEipID string
PodEipIP string
PodEipBandWidth int
PodEip bool
PodEipID string
PodEipIP string
PodEipBandWidth int
PodEipChargeType common.InternetChargeType
}

type podInfo struct {
Expand Down Expand Up @@ -312,6 +314,7 @@ const podEgressBandwidth = "k8s.aliyun.com/egress-bandwidth"
const podWithEip = "k8s.aliyun.com/pod-with-eip"
const eciWithEip = "k8s.aliyun.com/eci-with-eip" // to adopt ask annotation
const podEipBandwidth = "k8s.aliyun.com/eip-bandwidth"
const podEipChargeType = "k8s.aliyun.com/eip-charge-type"
const podEciEipInstanceID = "k8s.aliyun.com/eci-eip-instanceid" // to adopt ask annotation
const podPodEipInstanceID = "k8s.aliyun.com/pod-eip-instanceid"
const podEipAddress = "k8s.aliyun.com/allocated-eipAddress"
Expand Down Expand Up @@ -384,10 +387,12 @@ func convertPod(daemonMode string, pod *corev1.Pod) *podInfo {
if eipAnnotation, ok := podAnnotation[podWithEip]; ok && eipAnnotation == conditionTrue {
pi.EipInfo.PodEip = true
pi.EipInfo.PodEipBandWidth = 5
pi.EipInfo.PodEipChargeType = common.PayByTraffic
}
if eipAnnotation, ok := podAnnotation[eciWithEip]; ok && eipAnnotation == conditionTrue {
pi.EipInfo.PodEip = true
pi.EipInfo.PodEipBandWidth = 5
pi.EipInfo.PodEipChargeType = common.PayByTraffic
}

if eipAnnotation, ok := podAnnotation[podEipBandwidth]; ok {
Expand All @@ -399,6 +404,10 @@ func convertPod(daemonMode string, pod *corev1.Pod) *podInfo {
}
}

if eipAnnotation, ok := podAnnotation[podEipChargeType]; ok {
pi.EipInfo.PodEipChargeType = common.InternetChargeType(eipAnnotation)
}

if eipAnnotation, ok := podAnnotation[podEciEipInstanceID]; ok && eipAnnotation != "" {
pi.EipInfo.PodEip = true
pi.EipInfo.PodEipID = eipAnnotation
Expand Down
2 changes: 1 addition & 1 deletion pkg/aliyun/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type ECS interface {
GetAttachedSecurityGroup(instanceID string) (string, error)
DescribeVSwitch(vSwitch string) (availIPCount int, err error)
// EIP
AllocateEipAddress(bandwidth int, eipID, eniID string, eniIP net.IP, allowRob bool) (*types.EIP, error)
AllocateEipAddress(bandwidth int, chargeType common.InternetChargeType, eipID, eniID string, eniIP net.IP, allowRob bool) (*types.EIP, error)
UnassociateEipAddress(eipID, eniID, eniIP string) error
ReleaseEipAddress(eipID, eniID string, eniIP net.IP) error
QueryEniIDByIP(address net.IP) (string, error)
Expand Down
5 changes: 3 additions & 2 deletions pkg/aliyun/eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (

"github.com/AliyunContainerService/terway/pkg/metric"
"github.com/AliyunContainerService/terway/types"
"github.com/denverdino/aliyungo/common"
"github.com/denverdino/aliyungo/ecs"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/wait"
)

func (e *ecsImpl) AllocateEipAddress(bandwidth int, eipID, eniID string, eniIP net.IP, allowRob bool) (*types.EIP, error) {
func (e *ecsImpl) AllocateEipAddress(bandwidth int, chargeType common.InternetChargeType, eipID, eniID string, eniIP net.IP, allowRob bool) (*types.EIP, error) {
var (
eipInfo *types.EIP
err error
Expand All @@ -23,7 +24,7 @@ func (e *ecsImpl) AllocateEipAddress(bandwidth int, eipID, eniID string, eniIP n
start := time.Now()
var eipAddressStr, allocationID string
eipAddressStr, allocationID, err = e.clientSet.Vpc().AllocateEipAddress(
&ecs.AllocateEipAddressArgs{RegionId: e.region, Bandwidth: bandwidth},
&ecs.AllocateEipAddressArgs{RegionId: e.region, Bandwidth: bandwidth, InternetChargeType: chargeType},
)
metric.OpenAPILatency.WithLabelValues("AllocateEipAddress", fmt.Sprint(err != nil)).Observe(metric.MsSince(start))
logrus.Debugf("AllocateEipAddress: %v, %v, %v", eipAddressStr, allocationID, err)
Expand Down