Skip to content

Commit

Permalink
loadbalance: set nodecount to 2 when create lb (#103)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
duanjiong authored Jul 21, 2020
1 parent fbe9805 commit 7278181
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pkg/loadbalance/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type LoadBalancerSpec struct {
Nodes []*corev1.Node
Name string
clusterName string
NodeCount int
AnnotaionConfig
}

Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions pkg/qingcloud/loadbalancer_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/qingcloud/patch.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7278181

Please sign in to comment.