From 2436284d75c2beb0873dc3e80c823f68017dd32d Mon Sep 17 00:00:00 2001 From: calvinyv Date: Fri, 19 Jan 2018 15:47:11 +0800 Subject: [PATCH] Always retry to delete lb even if it is not existed (#20) * modify glide with k8s 1.8 dependence * adjust code for k8s 1.8 dependence * adjust code for k8s 1.8 dependence * always retry to del lb even if it is not existed * always retry to del lb even if it is not existed * always retry to del lb even if it is not existed * always retry to del lb even if it is not existed --- main.go | 8 ++++++-- qingcloud/doc.go | 4 ++++ qingcloud/qingcloud.go | 4 ++++ qingcloud/qingcloud_instances.go | 4 ++++ qingcloud/qingcloud_loadbalancer.go | 24 +++++++++++++++--------- qingcloud/qingcloud_test.go | 4 ++++ qingcloud/qingcloud_util.go | 4 ++++ qingcloud/version.go | 4 ++++ 8 files changed, 45 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 8acdf3cca..9d9d4dfee 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,7 @@ +// Copyright 2017 Yunify Inc. All rights reserved. +// Use of this source code is governed by a Apache license +// that can be found in the LICENSE file. + package main import ( @@ -17,8 +21,8 @@ import ( _ "github.com/yunify/qingcloud-cloud-controller-manager/qingcloud" - "github.com/spf13/pflag" goflag "flag" + "github.com/spf13/pflag" ) func init() { @@ -37,7 +41,7 @@ func main() { defer logs.FlushLogs() verflag.PrintAndExitIfRequested() - fmt.Fprintf(os.Stderr,"final flag: %+v\n", s) + fmt.Fprintf(os.Stderr, "final flag: %+v\n", s) cloud, err := cloudprovider.InitCloudProvider("qingcloud", s.CloudConfigFile) if err != nil { fmt.Fprintf(os.Stderr, "Cloud provider could not be initialized: %v", err) diff --git a/qingcloud/doc.go b/qingcloud/doc.go index 4aad8b386..382c98ad6 100644 --- a/qingcloud/doc.go +++ b/qingcloud/doc.go @@ -1,3 +1,7 @@ +// Copyright 2017 Yunify Inc. All rights reserved. +// Use of this source code is governed by a Apache license +// that can be found in the LICENSE file. + // Package qingcloud is an implementation of Interface, LoadBalancer // and Instances for QingCloud. package qingcloud diff --git a/qingcloud/qingcloud.go b/qingcloud/qingcloud.go index 94e8f345c..8330890a7 100644 --- a/qingcloud/qingcloud.go +++ b/qingcloud/qingcloud.go @@ -1,3 +1,7 @@ +// Copyright 2017 Yunify Inc. All rights reserved. +// Use of this source code is governed by a Apache license +// that can be found in the LICENSE file. + package qingcloud // Please see qingcloud document: https://docs.qingcloud.com/index.html diff --git a/qingcloud/qingcloud_instances.go b/qingcloud/qingcloud_instances.go index e52c8ef0c..c976d8613 100644 --- a/qingcloud/qingcloud_instances.go +++ b/qingcloud/qingcloud_instances.go @@ -1,3 +1,7 @@ +// Copyright 2017 Yunify Inc. All rights reserved. +// Use of this source code is governed by a Apache license +// that can be found in the LICENSE file. + package qingcloud // See https://docs.qingcloud.com/api/instance/index.html diff --git a/qingcloud/qingcloud_loadbalancer.go b/qingcloud/qingcloud_loadbalancer.go index f2fbf3e03..c259dcbe8 100644 --- a/qingcloud/qingcloud_loadbalancer.go +++ b/qingcloud/qingcloud_loadbalancer.go @@ -1,3 +1,7 @@ +// Copyright 2017 Yunify Inc. All rights reserved. +// Use of this source code is governed by a Apache license +// that can be found in the LICENSE file. + package qingcloud // See https://docs.qingcloud.com/api/lb/index.html @@ -153,7 +157,7 @@ func (qc *QingCloud) EnsureLoadBalancer(clusterName string, service *v1.Service, return nil, fmt.Errorf("Error checking if qingcloud load balancer already exists: %v", err) } - if loadBalancer != nil && *loadBalancer.Status != qcclient.LoadBalancerStatusCeased { + if loadBalancer != nil { glog.V(1).Infof("LB '%s' is existed in this k8s cluster, will compare LB settng with related attributes in service spec, if anything is changed, , will update this LB ", *loadBalancer.LoadBalancerID) qyEips, qyPrivateIps, qyEipIDs := qc.getLoadBalancerNetConfig(loadBalancer) // check lisener: balance mode and port, add/update/delete listener @@ -413,14 +417,16 @@ func (qc *QingCloud) EnsureLoadBalancerDeleted(clusterName string, service *v1.S if loadBalancer == nil { return nil } - - err = qc.deleteLoadBalancer(*loadBalancer.LoadBalancerID) - if err != nil { - return err + glog.Infof("Try to delete loadBalancer by its id '%s'", *loadBalancer.LoadBalancerID) + errDelLoadbalancer := qc.deleteLoadBalancer(*loadBalancer.LoadBalancerID) + glog.Infof("Try to delete security group by its id '%s'", *loadBalancer.SecurityGroupID) + errDelSecurityGrp := qc.DeleteSecurityGroup(loadBalancer.SecurityGroupID) + if errDelLoadbalancer != nil { + glog.Errorf("Delete loadBalancer '%s' err '%s' ", *loadBalancer.LoadBalancerID, errDelLoadbalancer) + return errDelLoadbalancer } - err = qc.DeleteSecurityGroup(loadBalancer.SecurityGroupID) - if err != nil { - glog.Errorf("Delete SecurityGroup '%s' err '%s' ", *loadBalancer.SecurityGroupID, err) + if errDelSecurityGrp != nil { + glog.Errorf("Delete SecurityGroup '%s' err '%s' ", *loadBalancer.SecurityGroupID, errDelSecurityGrp) } glog.Infof("Delete loadBalancer '%s' in zone '%s'", loadBalancerName, qc.zone) @@ -515,7 +521,7 @@ func (qc *QingCloud) addLoadBalancerListener(loadBalancerID string, listenerPort } func (qc *QingCloud) getLoadBalancerByName(name string) (*qcservice.LoadBalancer, error) { - status := []*string{qcservice.String("pending"), qcservice.String("active"), qcservice.String("stopped"), qcservice.String("ceased")} + status := []*string{qcservice.String("pending"), qcservice.String("active"), qcservice.String("stopped")} output, err := qc.lbService.DescribeLoadBalancers(&qcservice.DescribeLoadBalancersInput{ Status: status, SearchWord: &name, diff --git a/qingcloud/qingcloud_test.go b/qingcloud/qingcloud_test.go index 0d499461f..2f5a69345 100644 --- a/qingcloud/qingcloud_test.go +++ b/qingcloud/qingcloud_test.go @@ -1,3 +1,7 @@ +// Copyright 2017 Yunify Inc. All rights reserved. +// Use of this source code is governed by a Apache license +// that can be found in the LICENSE file. + package qingcloud import ( diff --git a/qingcloud/qingcloud_util.go b/qingcloud/qingcloud_util.go index 3ab52acb2..8224ab690 100644 --- a/qingcloud/qingcloud_util.go +++ b/qingcloud/qingcloud_util.go @@ -1,3 +1,7 @@ +// Copyright 2017 Yunify Inc. All rights reserved. +// Use of this source code is governed by a Apache license +// that can be found in the LICENSE file. + package qingcloud import ( diff --git a/qingcloud/version.go b/qingcloud/version.go index feec9b744..73269a228 100644 --- a/qingcloud/version.go +++ b/qingcloud/version.go @@ -1,3 +1,7 @@ +// Copyright 2017 Yunify Inc. All rights reserved. +// Use of this source code is governed by a Apache license +// that can be found in the LICENSE file. + package qingcloud var (