Skip to content

Commit

Permalink
Merge 4fe53f5 into b373e36
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad Fahim Abrar committed Apr 18, 2019
2 parents b373e36 + 4fe53f5 commit bc968a4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 11 deletions.
87 changes: 79 additions & 8 deletions e2e/test/ccm_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,35 @@ var _ = Describe("CloudControllerManager", func() {
Expect(err).NotTo(HaveOccurred())
}

var createServiceWithSelector = func(selector map[string]string, ports []core.ServicePort) {
err = f.LoadBalancer.CreateService(selector, nil, ports)
var createServiceWithSelector = func(selector map[string]string, ports []core.ServicePort, isSessionAffinityClientIP bool) {
err = f.LoadBalancer.CreateService(selector, nil, ports, isSessionAffinityClientIP)
Expect(err).NotTo(HaveOccurred())
}

var createServiceWithAnnotations = func(labels map[string]string, annotations map[string]string, ports []core.ServicePort) {
err = f.LoadBalancer.CreateService(labels, annotations, ports)
var createServiceWithAnnotations = func(labels map[string]string, annotations map[string]string, ports []core.ServicePort, isSessionAffinityClientIP bool) {
err = f.LoadBalancer.CreateService(labels, annotations, ports, isSessionAffinityClientIP)
Expect(err).NotTo(HaveOccurred())
}

var getResponseFromSamePod = func(link string) {
var oldResp, newResp string
Eventually(func() string {
resp, _ := sh.Command("curl", "-s", link).Output()
oldResp = string(resp)
log.Println(oldResp)
return oldResp
}).ShouldNot(Equal(""))

for i := 0; i <= 10; i++{
resp, err := sh.Command("curl", "-s", link).Output()
newResp = string(resp)
log.Println(newResp)
if err == nil{
Expect(oldResp == newResp).Should(BeTrue())
}
}
}

Describe("Test", func() {
Context("Simple", func() {
Context("Load Balancer", func() {
Expand Down Expand Up @@ -102,7 +121,7 @@ var _ = Describe("CloudControllerManager", func() {
createPodWithLabel(pods, ports, framework.TestServerImage, labels, true)

By("Creating Service")
createServiceWithSelector(labels, servicePorts)
createServiceWithSelector(labels, servicePorts, false)
})

AfterEach(func() {
Expand Down Expand Up @@ -190,7 +209,7 @@ var _ = Describe("CloudControllerManager", func() {
Expect(err).NotTo(HaveOccurred())

By("Creating Service")
createServiceWithAnnotations(labels, annotations, servicePorts)
createServiceWithAnnotations(labels, annotations, servicePorts, false)
})

AfterEach(func() {
Expand Down Expand Up @@ -270,7 +289,7 @@ var _ = Describe("CloudControllerManager", func() {
Expect(err).NotTo(HaveOccurred())

By("Creating Service")
createServiceWithAnnotations(labels, annotations, servicePorts)
createServiceWithAnnotations(labels, annotations, servicePorts, false)
})

AfterEach(func() {
Expand Down Expand Up @@ -339,7 +358,7 @@ var _ = Describe("CloudControllerManager", func() {
createPodWithLabel(pods, ports, framework.TestServerImage, labels, true)

By("Creating Service")
createServiceWithSelector(labels, servicePorts)
createServiceWithSelector(labels, servicePorts, false)
})

AfterEach(func() {
Expand All @@ -363,6 +382,58 @@ var _ = Describe("CloudControllerManager", func() {
}
})
})

Context("With SessionAffinity", func() {
var (
pods []string
labels map[string]string
)

BeforeEach(func() {
pods = []string{"test-pod-1", "test-pod-2"}
ports := []core.ContainerPort{
{
Name: "http-1",
ContainerPort: 8080,
},
}
servicePorts := []core.ServicePort{
{
Name: "http-1",
Port: 80,
TargetPort: intstr.FromInt(8080),
Protocol: "TCP",
},
}
labels = map[string]string{
"app": "test-loadbalancer",
}

By("Creating Pods")
createPodWithLabel(pods, ports, framework.TestServerImage, labels, false)

By("Creating Service")
createServiceWithSelector(labels, servicePorts, true)
})

AfterEach(func() {
By("Deleting the Pods")
deletePods(pods)

By("Deleting the Service")
deleteService()
})

It("should reach the same pod every time it requests", func() {
By("Checking TCP Response")
eps, err := f.LoadBalancer.GetHTTPEndpoints()
Expect(err).NotTo(HaveOccurred())
Expect(len(eps)).Should(BeNumerically(">=", 1))

By("Waiting for Response from the LoadBalancer url: " + eps[0])
getResponseFromSamePod(eps[0])
})
})
})
})
})
13 changes: 10 additions & 3 deletions e2e/test/framework/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
)

func (i *lbInvocation) CreateService(selector, annotations map[string]string, ports []core.ServicePort) error {
_, err := i.kubeClient.CoreV1().Services(i.Namespace()).Create(&core.Service{
func (i *lbInvocation) CreateService(selector, annotations map[string]string, ports []core.ServicePort, isSessionAffinityClientIP bool) error {
var sessionAffinity core.ServiceAffinity = "None"
if isSessionAffinityClientIP {
sessionAffinity = "ClientIP"
}
svc := &core.Service{
ObjectMeta: metav1.ObjectMeta{
Name: testServerResourceName,
Namespace: i.Namespace(),
Expand All @@ -27,8 +31,11 @@ func (i *lbInvocation) CreateService(selector, annotations map[string]string, po
Ports: ports,
Selector: selector,
Type: core.ServiceTypeLoadBalancer,
SessionAffinity: sessionAffinity,
},
})
}

_, err := i.kubeClient.CoreV1().Services(i.Namespace()).Create(svc)
if err != nil {
return err
}
Expand Down

0 comments on commit bc968a4

Please sign in to comment.