Skip to content

Commit

Permalink
🚑 fix bugs (#54)
Browse files Browse the repository at this point in the history
* 🚑 fix bugs

* add owner to e2e-test
  • Loading branch information
Xuetao Song authored and ks-ci-bot committed May 7, 2019
1 parent 0b94c1f commit a53eeaa
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog
## [ 1.3.3 ] - 2019-05-04
### Added
- support UDP [@magicsong](https://github.com/yunify/qingcloud-cloud-controller-manager/pull/53)
### Fixed
- fixed that `https` port becomes `http` in qingcloud console [@magicsong](https://github.com/yunify/qingcloud-cloud-controller-manager/pull/53)
- fixed securityGroup is not deleted in cloud

## [ 1.3.2 ] - 2019-05-06
### Added
Expand Down
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pipeline {
ACCESS_KEY_ID = credentials('jenkins-qc-secret-key-id')
SECRET_ACCESS_KEY = credentials('jenkins-qc-secret-access-key')
IMG = "magicsong/cloud-manager:$tag"
API_OWNER = "usr-MRiIUq7M"
}
stages {
stage('Building Manager'){
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Vars describing project
NAME= qingcloud-cloud-controller-manager
GIT_REPOSITORY= github.com/yunify/qingcloud-cloud-controller-manager
IMG?= kubespheredev/cloud-controller-manager:v1.3.2
IMG?= kubespheredev/cloud-controller-manager:v1.3.3

# Generate vars to be included from external script
# Allows using bash to generate complex vars, such as project versions
Expand Down
5 changes: 4 additions & 1 deletion deploy/kube-cloud-controller-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ spec:
- --cloud-config=/etc/kubernetes/qingcloud.conf
- --allocate-node-cidrs=true
- --cluster-cidr=10.244.0.0/16
image: kubespheredev/cloud-controller-manager:v1.3.2
image: kubespheredev/cloud-controller-manager:v1.3.3
imagePullPolicy: Always
name: qingcloud-cloud-controller-manager
resources:
requests:
cpu: 100m
memory: 50Mi
limits:
cpu: 200m
memory: 100Mi
volumeMounts:
- mountPath: /etc/kubernetes
name: k8s
Expand Down
8 changes: 8 additions & 0 deletions pkg/executor/sg_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ var DefaultLBSecurityGroupRules = []*qcservice.SecurityGroupRule{
Val2: qcservice.String("65535"),
Val3: nil,
},
{
Priority: qcservice.Int(1),
Protocol: qcservice.String("udp"),
Action: qcservice.String("accept"),
Val1: qcservice.String("1"),
Val2: qcservice.String("65535"),
Val3: nil,
},
}
var _ QingCloudSecurityGroupExecutor = &qingcloudSecurityGroupExecutor{}

Expand Down
4 changes: 2 additions & 2 deletions pkg/loadbalance/loadbalance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ var _ = Describe("Loadbalance", func() {
NodeLister: &fake.FakeNodeLister{},
})
Expect(lb).ShouldNot(BeNil())
Expect(lb.TCPPorts).To(HaveLen(2))
Expect(lb.TCPPorts).To(HaveLen(3))
Expect(lb.LoadListeners()).ShouldNot(HaveOccurred())
Expect(lb.GetListeners()[0].Protocol).To(Equal("http"))
Expect(lb.GetListeners()[1].Protocol).To(Equal("tcp"))
Expect(lb.GetListeners()[1].Protocol).To(Equal("udp"))
})
})
26 changes: 18 additions & 8 deletions pkg/loadbalance/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,16 @@ func (l *LoadBalancer) GetService() *corev1.Service {
}

func (l *LoadBalancer) deleteSecurityGroup() error {
if l.Status.QcLoadBalancer != nil {
return l.sgExec.Delete(*l.Status.QcLoadBalancer.SecurityGroupID)
}
err := l.LoadSecurityGroup()
if err != nil {
klog.Errorf("Failed to load sg of lb %s", l.Name)
return err
}
if l.Status.QcSecurityGroup == nil {
err := l.LoadSecurityGroup()
if err != nil {
return err
}
if l.Status.QcSecurityGroup == nil {
return nil
}
return ErrorSGNotFoundInCloud
}
return l.sgExec.Delete(*l.Status.QcSecurityGroup.SecurityGroupID)
}
Expand Down Expand Up @@ -438,6 +440,9 @@ func (l *LoadBalancer) DeleteQingCloudLB() error {
klog.V(1).Infof("Cannot find the lb %s in cloud, maybe is deleted", l.Name)
err = l.deleteSecurityGroup()
if err != nil {
if err == ErrorSGNotFoundInCloud {
return nil
}
klog.Errorf("Failed to delete SecurityGroup of lb %s ", l.Name)
return err
}
Expand All @@ -463,7 +468,12 @@ func (l *LoadBalancer) DeleteQingCloudLB() error {
}
err = l.deleteSecurityGroup()
if err != nil {
klog.Errorf("Failed to delete SecurityGroup of lb %s err '%s' ", l.Name, err)
if err == ErrorSGNotFoundInCloud {
klog.Warningf("Detect sg %s is deleted", l.Name)
} else {
klog.Errorf("Failed to delete SecurityGroup of lb %s err '%s' ", l.Name, err)
return err
}
}

if l.EIPAllocateSource != ManualSet && *ip.EIPName == eip.AllocateEIPName {
Expand Down
11 changes: 7 additions & 4 deletions pkg/loadbalance/loadbalancer_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/yunify/qingcloud-cloud-controller-manager/pkg/executor"
qcservice "github.com/yunify/qingcloud-sdk-go/service"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/klog"
)

Expand Down Expand Up @@ -58,12 +57,13 @@ func NewListener(lb *LoadBalancer, port int) (*Listener, error) {
result.backendExec = bakExec
}
result.Name = result.PrefixName + strconv.Itoa(int(p.Port))
if p.Protocol == corev1.ProtocolTCP && (p.Name == "http" || p.Name == "https") {
if p.Protocol == corev1.ProtocolTCP && p.Name == "http" {
result.Protocol = "http"
} else if p.Protocol == corev1.ProtocolUDP {
result.Protocol = "udp"
} else {
result.Protocol = "tcp"
}

return result, nil
}

Expand Down Expand Up @@ -144,6 +144,9 @@ func (l *Listener) CreateQingCloudListener() error {
},
},
}
if l.Protocol == "udp" {
input.Listeners[0].HealthyCheckMethod = qcservice.String("udp")
}
listener, err := l.listenerExec.CreateListener(input)
if err != nil {
return err
Expand Down Expand Up @@ -238,7 +241,7 @@ func (l *Listener) UpdateQingCloudListener() error {

func checkPortInService(service *corev1.Service, port int) *corev1.ServicePort {
for index, p := range service.Spec.Ports {
if p.Protocol != v1.ProtocolUDP && int(p.Port) == port {
if int(p.Port) == port {
return &service.Spec.Ports[index]
}
}
Expand Down
13 changes: 4 additions & 9 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

v1 "k8s.io/api/core/v1"
"k8s.io/klog"
)

const (
Expand All @@ -20,17 +19,13 @@ const (

// GetPortsOfService return service ports and nodeports
func GetPortsOfService(service *v1.Service) ([]int, []int) {
k8sTCPPorts := []int{}
k8sPorts := []int{}
k8sNodePorts := []int{}
for _, port := range service.Spec.Ports {
if port.Protocol == v1.ProtocolUDP{
klog.Warningf("qingcloud not support udp port, skip [%v]", port.Port)
} else {
k8sTCPPorts = append(k8sTCPPorts, int(port.Port))
k8sNodePorts = append(k8sNodePorts, int(port.NodePort))
}
k8sPorts = append(k8sPorts, int(port.Port))
k8sNodePorts = append(k8sNodePorts, int(port.NodePort))
}
return k8sTCPPorts, k8sNodePorts
return k8sPorts, k8sNodePorts
}

func GetNodePort(service *v1.Service, port int32, protocol v1.Protocol) (nodePort int32, found bool) {
Expand Down
2 changes: 2 additions & 0 deletions test/pkg/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var _ = Describe("E2e", func() {
Eventually(func() int { return e2eutil.GerServiceResponse(testip, 8090) }, time.Second*20, time.Second*5).Should(Equal(http.StatusOK))
log.Println("Successfully get a 200 response")
})

It("Should try to use available ips when user does not specify the ip", func() {
service1Path := workspace + "/test/test_cases/eip/use_available.yaml"
serviceName := "mylbapp"
Expand All @@ -66,6 +67,7 @@ var _ = Describe("E2e", func() {
}, 3*time.Minute, 20*time.Second).Should(Succeed())
log.Println("Successfully assign a ip")
})

It("Should work as expected when using sample yamls", func() {
//apply service
service1Path := workspace + "/test/test_cases/service.yaml"
Expand Down
2 changes: 2 additions & 0 deletions test/pkg/e2eutil/e2eutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ func WaitForLoadBalancerDeleted(lbService *service.LoadBalancerService) error {
unaccept1 := "pending"
unaccept2 := "active"
key := "k8s_lb_kubernetes"
owner := os.Getenv("API_OWNER")
input := &service.DescribeLoadBalancersInput{
Status: []*string{&unaccept1, &unaccept2},
SearchWord: &key,
Owner: &owner,
}
output, err := lbService.DescribeLoadBalancers(input)
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions test/test_cases/udp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: udp-server-deployment
spec:
replicas: 2
selector:
matchLabels:
app: udp-server
template:
metadata:
labels:
app: udp-server
spec:
containers:
- name: udp-server
image: jpoon/udp-server
imagePullPolicy: IfNotPresent
ports:
- containerPort: 10001
protocol: UDP


---
apiVersion: v1
kind: Service
metadata:
name: udp-server-service
annotations:
service.beta.kubernetes.io/qingcloud-load-balancer-eip-ids: "eip-vmldumvv"
service.beta.kubernetes.io/qingcloud-load-balancer-type: "0"
labels:
app: udp-server
spec:
type: LoadBalancer
ports:
- port: 10001
protocol: UDP
selector:
app: udp-server

0 comments on commit a53eeaa

Please sign in to comment.