Skip to content

Commit

Permalink
Merge pull request kubernetes#52 from Shopify/match-with-upstream
Browse files Browse the repository at this point in the history
match with upstream
  • Loading branch information
ElvinEfendi authored May 15, 2018
2 parents f01a233 + 3a03f36 commit e2d0518
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 129 deletions.
111 changes: 0 additions & 111 deletions test/e2e/lua/dynamic_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,108 +358,6 @@ var _ = framework.IngressNginxDescribe("Dynamic Configuration", func() {
Expect(len(cookies)).Should(BeNumerically("==", 0))
})
})

Context("when session affinity annotation is present", func() {
It("should use sticky sessions when ingress rules are configured", func() {
cookieName := "STICKYSESSION"

By("Updating affinity annotation on ingress")
ingress, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Get("foo.com", metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
ingress.ObjectMeta.Annotations = map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
"nginx.ingress.kubernetes.io/session-cookie-name": cookieName,
}
_, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Update(ingress)
Expect(err).ToNot(HaveOccurred())
time.Sleep(5 * time.Second)

By("Increasing the number of service replicas")
replicas := 2
err = framework.UpdateDeployment(f.KubeClientSet, f.Namespace.Name, "http-svc", replicas,
func(deployment *appsv1beta1.Deployment) error {
deployment.Spec.Replicas = framework.NewInt32(int32(replicas))
_, err := f.KubeClientSet.AppsV1beta1().Deployments(f.Namespace.Name).Update(deployment)
return err
})
Expect(err).NotTo(HaveOccurred())

By("Making a first request")
host := "foo.com"
resp, _, errs := gorequest.New().
Get(f.NginxHTTPURL).
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))

cookies := (*http.Response)(resp).Cookies()
sessionCookie, err := getCookie(cookieName, cookies)
Expect(err).ToNot(HaveOccurred())

By("Making a second request with the previous session cookie")
resp, _, errs = gorequest.New().
Get(f.NginxHTTPURL).
AddCookie(sessionCookie).
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))

By("Making a third request with no cookie")
resp, _, errs = gorequest.New().
Get(f.NginxHTTPURL).
Set("Host", host).
End()

Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))

log, err := f.NginxLogs()
Expect(err).ToNot(HaveOccurred())
Expect(log).ToNot(BeEmpty())

By("Checking that upstreams are sticky when session cookie is used")
index := strings.Index(log, fmt.Sprintf("reason: 'UPDATE' Ingress %s/foo.com", f.Namespace.Name))
reqLogs := log[index:]
re := regexp.MustCompile(`\d{1,3}(?:\.\d{1,3}){3}(?::\d{1,5})`)
upstreams := re.FindAllString(reqLogs, -1)
Expect(len(upstreams)).Should(BeNumerically("==", 3))
Expect(upstreams[0]).To(Equal(upstreams[1]))
Expect(upstreams[1]).ToNot(Equal(upstreams[2]))
})

It("should NOT use sticky sessions when a default backend and no ingress rules configured", func() {
By("Updating affinity annotation and rules on ingress")
ingress, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Get("foo.com", metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
ingress.Spec = v1beta1.IngressSpec{
Backend: &v1beta1.IngressBackend{
ServiceName: "http-svc",
ServicePort: intstr.FromInt(80),
},
}
ingress.ObjectMeta.Annotations = map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
}
_, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.Namespace.Name).Update(ingress)
Expect(err).ToNot(HaveOccurred())
time.Sleep(5 * time.Second)

By("Making a request")
host := "foo.com"
resp, _, errs := gorequest.New().
Get(f.NginxHTTPURL).
Set("Host", host).
End()
Expect(len(errs)).Should(BeNumerically("==", 0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))

By("Ensuring no cookies are set")
cookies := (*http.Response)(resp).Cookies()
Expect(len(cookies)).Should(BeNumerically("==", 0))
})
})
})

func enableDynamicConfiguration(namespace string, kubeClientSet kubernetes.Interface) error {
Expand Down Expand Up @@ -491,12 +389,3 @@ func getCookie(name string, cookies []*http.Cookie) (*http.Cookie, error) {
}
return &http.Cookie{}, fmt.Errorf("Cookie does not exist")
}

func getCookie(name string, cookies []*http.Cookie) (*http.Cookie, error) {
for _, cookie := range cookies {
if cookie.Name == name {
return cookie, nil
}
}
return &http.Cookie{}, fmt.Errorf("Cookie does not exist")
}
10 changes: 0 additions & 10 deletions test/e2e/settings/no_auth_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var _ = framework.IngressNginxDescribe("No Auth locations", func() {
secretName := "test-secret"
host := "no-auth-locations"
noAuthPath := "/noauth"
var defaultNginxConfigMapData map[string]string = nil

BeforeEach(func() {
err := f.NewEchoDeployment()
Expand All @@ -59,15 +58,6 @@ var _ = framework.IngressNginxDescribe("No Auth locations", func() {
ing, err := f.EnsureIngress(bi)
Expect(err).NotTo(HaveOccurred())
Expect(ing).NotTo(BeNil())

if defaultNginxConfigMapData == nil {
defaultNginxConfigMapData, err = f.GetNginxConfigMapData()
Expect(err).NotTo(HaveOccurred())
Expect(defaultNginxConfigMapData).NotTo(BeNil())
}

err = f.UpdateNginxConfigMapData(setting, noAuthPath)
Expect(err).NotTo(HaveOccurred())
})

AfterEach(func() {
Expand Down
1 change: 0 additions & 1 deletion test/e2e/settings/proxy_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ var _ = framework.IngressNginxDescribe("Proxy Protocol", func() {
f := framework.NewDefaultFramework("proxy-protocol")

setting := "use-proxy-protocol"
var defaultNginxConfigMapData map[string]string = nil

BeforeEach(func() {
err := f.NewEchoDeployment()
Expand Down
7 changes: 0 additions & 7 deletions test/e2e/settings/server_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@ import (
var _ = framework.IngressNginxDescribe("Server Tokens", func() {
f := framework.NewDefaultFramework("server-tokens")
serverTokens := "server-tokens"
var defaultNginxConfigMapData map[string]string = nil

BeforeEach(func() {
err := f.NewEchoDeployment()
Expect(err).NotTo(HaveOccurred())

if defaultNginxConfigMapData == nil {
defaultNginxConfigMapData, err = f.GetNginxConfigMapData()
Expect(err).NotTo(HaveOccurred())
Expect(defaultNginxConfigMapData).NotTo(BeNil())
}
})

AfterEach(func() {
Expand Down

0 comments on commit e2d0518

Please sign in to comment.