From 727818170164a1ec27470b75ce4171bd69e2efb1 Mon Sep 17 00:00:00 2001 From: Duan Jiong Date: Tue, 21 Jul 2020 18:18:49 +0800 Subject: [PATCH] loadbalance: set nodecount to 2 when create lb (#103) Notice: We don't change the number of nodes of an existing load balancer, you can change it in the interface if you want. and fixed some formatting issues Signed-off-by: Duan Jiong --- pkg/loadbalance/loadbalancer.go | 4 ++++ pkg/qingcloud/loadbalancer_impl.go | 6 ++++++ pkg/qingcloud/patch.go | 11 ++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pkg/loadbalance/loadbalancer.go b/pkg/loadbalance/loadbalancer.go index 2fa14fefa..a44f83b91 100644 --- a/pkg/loadbalance/loadbalancer.go +++ b/pkg/loadbalance/loadbalancer.go @@ -35,6 +35,7 @@ type LoadBalancerSpec struct { Nodes []*corev1.Node Name string clusterName string + NodeCount int AnnotaionConfig } @@ -56,6 +57,7 @@ type NewLoadBalancerOption struct { ClusterName string SkipCheck bool DefaultVxnet string + NodeCount int } // NewLoadBalancer create loadbalancer in memory, not in cloud, call 'CreateQingCloudLB' to create a real loadbalancer in qingcloud @@ -73,6 +75,7 @@ func NewLoadBalancer(opt *NewLoadBalancerOption) (*LoadBalancer, error) { result.service = opt.K8sService result.Nodes = opt.K8sNodes result.clusterName = opt.ClusterName + result.NodeCount = opt.NodeCount config, err := ParseAnnotation(opt.K8sService.GetAnnotations(), false) if err != nil { @@ -245,6 +248,7 @@ func (l *LoadBalancer) CreateQingCloudLB() error { LoadBalancerType: &l.ScaleType, LoadBalancerName: &l.Name, SecurityGroup: l.Status.QcSecurityGroup.SecurityGroupID, + NodeCount: &l.NodeCount, } if l.NetworkType == NetworkModePublic { diff --git a/pkg/qingcloud/loadbalancer_impl.go b/pkg/qingcloud/loadbalancer_impl.go index 209426557..3c583f96d 100644 --- a/pkg/qingcloud/loadbalancer_impl.go +++ b/pkg/qingcloud/loadbalancer_impl.go @@ -13,6 +13,11 @@ import ( "k8s.io/klog" ) +const ( + //The default node should be at least two, allowing for a minimum level of high availability. + defaultNodeCount = 2 +) + var _ cloudprovider.LoadBalancer = &QingCloud{} func (qc *QingCloud) newLoadBalance(ctx context.Context, service *v1.Service, nodes []*v1.Node, skipCheck bool) (*loadbalance.LoadBalancer, error) { @@ -38,6 +43,7 @@ func (qc *QingCloud) newLoadBalance(ctx context.Context, service *v1.Service, no ClusterName: qc.clusterID, SkipCheck: skipCheck, DefaultVxnet: qc.defaultVxNetForLB, + NodeCount: defaultNodeCount, } return loadbalance.NewLoadBalancer(opt) } diff --git a/pkg/qingcloud/patch.go b/pkg/qingcloud/patch.go index fc879b132..372626af9 100644 --- a/pkg/qingcloud/patch.go +++ b/pkg/qingcloud/patch.go @@ -1,14 +1,15 @@ package qingcloud import ( + "encoding/json" "fmt" + + "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/strategicpatch" + corev1 "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/klog" ) -import corev1 "k8s.io/client-go/kubernetes/typed/core/v1" -import "k8s.io/api/core/v1" -import "k8s.io/apimachinery/pkg/types" -import "encoding/json" -import "k8s.io/apimachinery/pkg/util/strategicpatch" type servicePatcher struct { kclient corev1.CoreV1Interface