remove httpbin.org as external name in testing

Signed-off-by: James Strong <strong.james.e@gmail.com>
This commit is contained in:
James Strong 2023-04-26 15:04:05 -04:00
parent fa44f2f7cd
commit ae9af6dbc7
Failed to extract signature
3 changed files with 1356 additions and 48 deletions

View file

@ -427,7 +427,7 @@ func (f *Framework) NewDeployment(name, image string, port int32, replicas int32
f.NewDeploymentWithOpts(name, image, port, replicas, nil, nil, nil, nil, nil, true) f.NewDeploymentWithOpts(name, image, port, replicas, nil, nil, nil, nil, nil, true)
} }
// NewDeployment creates a new deployment in a particular namespace. // NewDeploymentWithOpts NewDeployment creates a new deployment in a particular namespace.
func (f *Framework) NewDeploymentWithOpts(name, image string, port int32, replicas int32, command []string, args []string, env []corev1.EnvVar, volumeMounts []corev1.VolumeMount, volumes []corev1.Volume, setProbe bool) { func (f *Framework) NewDeploymentWithOpts(name, image string, port int32, replicas int32, command []string, args []string, env []corev1.EnvVar, volumeMounts []corev1.VolumeMount, volumes []corev1.Volume, setProbe bool) {
deployment := newDeployment(name, f.Namespace, image, port, replicas, command, args, env, volumeMounts, volumes, setProbe) deployment := newDeployment(name, f.Namespace, image, port, replicas, command, args, env, volumeMounts, volumes, setProbe)

View file

@ -38,11 +38,11 @@ import (
func buildHTTPBinExternalNameService(f *framework.Framework, portName string) *corev1.Service { func buildHTTPBinExternalNameService(f *framework.Framework, portName string) *corev1.Service {
return &corev1.Service{ return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: framework.HTTPBinService, Name: "neverssl",
Namespace: f.Namespace, Namespace: f.Namespace,
}, },
Spec: corev1.ServiceSpec{ Spec: corev1.ServiceSpec{
ExternalName: "httpbin.org", ExternalName: "neverssl.com",
Type: corev1.ServiceTypeExternalName, Type: corev1.ServiceTypeExternalName,
Ports: []corev1.ServicePort{ Ports: []corev1.ServicePort{
{ {
@ -56,17 +56,17 @@ func buildHTTPBinExternalNameService(f *framework.Framework, portName string) *c
} }
} }
var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() { var _ = framework.IngressNginxDescribe("[Service] type=ExternalName", func() {
f := framework.NewDefaultFramework("type-externalname") f := framework.NewDefaultFramework("type-externalname")
ginkgo.It("works with external name set to incomplete fqdn", func() { ginkgo.It("works with type=ExternalName set to incomplete fqdn", func() {
f.NewEchoDeployment() f.NewEchoDeployment()
host := "echo" host := "echo"
svc := &corev1.Service{ svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: framework.HTTPBinService, Name: "neverssl",
Namespace: f.Namespace, Namespace: f.Namespace,
}, },
Spec: corev1.ServiceSpec{ Spec: corev1.ServiceSpec{
@ -77,7 +77,7 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
f.EnsureService(svc) f.EnsureService(svc)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.HTTPBinService, 80, nil) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, "neverssl", 80, nil)
f.EnsureIngress(ing) f.EnsureIngress(ing)
f.WaitForNginxServer(host, f.WaitForNginxServer(host,
@ -97,11 +97,11 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
svc := &corev1.Service{ svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: framework.HTTPBinService, Name: "neverssl",
Namespace: f.Namespace, Namespace: f.Namespace,
}, },
Spec: corev1.ServiceSpec{ Spec: corev1.ServiceSpec{
ExternalName: "httpbin.org", ExternalName: "neverssl.com",
Type: corev1.ServiceTypeExternalName, Type: corev1.ServiceTypeExternalName,
}, },
} }
@ -109,9 +109,9 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
f.EnsureService(svc) f.EnsureService(svc)
annotations := map[string]string{ annotations := map[string]string{
"nginx.ingress.kubernetes.io/upstream-vhost": "httpbin.org", "nginx.ingress.kubernetes.io/upstream-vhost": "neverssl.com",
} }
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.HTTPBinService, 80, annotations) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, "neverssl", 80, annotations)
f.EnsureIngress(ing) f.EnsureIngress(ing)
f.WaitForNginxServer(host, f.WaitForNginxServer(host,
@ -120,7 +120,7 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
}) })
f.HTTPTestClient(). f.HTTPTestClient().
GET("/get"). GET("/").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusOK) Status(http.StatusOK)
@ -133,9 +133,9 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
f.EnsureService(svc) f.EnsureService(svc)
annotations := map[string]string{ annotations := map[string]string{
"nginx.ingress.kubernetes.io/upstream-vhost": "httpbin.org", "nginx.ingress.kubernetes.io/upstream-vhost": "neverssl.com",
} }
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.HTTPBinService, 80, annotations) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, "neverssl", 80, annotations)
f.EnsureIngress(ing) f.EnsureIngress(ing)
f.WaitForNginxServer(host, f.WaitForNginxServer(host,
@ -144,7 +144,7 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
}) })
f.HTTPTestClient(). f.HTTPTestClient().
GET("/get"). GET("/").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusOK) Status(http.StatusOK)
@ -155,7 +155,7 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
svc := &corev1.Service{ svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: framework.HTTPBinService, Name: "neverssl",
Namespace: f.Namespace, Namespace: f.Namespace,
}, },
Spec: corev1.ServiceSpec{ Spec: corev1.ServiceSpec{
@ -166,7 +166,7 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
f.EnsureService(svc) f.EnsureService(svc)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.HTTPBinService, 80, nil) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, "neverssl", 80, nil)
f.EnsureIngress(ing) f.EnsureIngress(ing)
f.WaitForNginxServer(host, f.WaitForNginxServer(host,
@ -175,7 +175,7 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
}) })
f.HTTPTestClient(). f.HTTPTestClient().
GET("/get"). GET("/").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
StatusRange(httpexpect.Status5xx) StatusRange(httpexpect.Status5xx)
@ -188,12 +188,12 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
f.EnsureService(svc) f.EnsureService(svc)
annotations := map[string]string{ annotations := map[string]string{
"nginx.ingress.kubernetes.io/upstream-vhost": "httpbin.org", "nginx.ingress.kubernetes.io/upstream-vhost": "neverssl.com",
} }
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.HTTPBinService, 80, annotations) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, "neverssl", 80, annotations)
namedBackend := networking.IngressBackend{ namedBackend := networking.IngressBackend{
Service: &networking.IngressServiceBackend{ Service: &networking.IngressServiceBackend{
Name: framework.HTTPBinService, Name: "neverssl",
Port: networking.ServiceBackendPort{ Port: networking.ServiceBackendPort{
Name: host, Name: host,
}, },
@ -208,7 +208,7 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
}) })
f.HTTPTestClient(). f.HTTPTestClient().
GET("/get"). GET("/").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusOK) Status(http.StatusOK)
@ -219,18 +219,19 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
svc := &corev1.Service{ svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: framework.HTTPBinService, Name: "neverssl",
Namespace: f.Namespace, Namespace: f.Namespace,
}, },
Spec: corev1.ServiceSpec{ Spec: corev1.ServiceSpec{
ExternalName: "httpbin.org.", ExternalName: "github.com.",
Type: corev1.ServiceTypeExternalName, Type: corev1.ServiceTypeExternalName,
}, },
} }
f.EnsureService(svc) f.EnsureService(svc)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.HTTPBinService, 80, nil) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, "neverssl", 80, nil)
f.EnsureIngress(ing) f.EnsureIngress(ing)
f.WaitForNginxServer(host, f.WaitForNginxServer(host,
@ -239,25 +240,25 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
}) })
f.HTTPTestClient(). f.HTTPTestClient().
GET("/get"). GET("/").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusOK) Status(http.StatusMovedPermanently)
}) })
ginkgo.It("should update the external name after a service update", func() { ginkgo.It("should update the type=ExternalName after a service update", func() {
host := "echo" host := "echo"
svc := buildHTTPBinExternalNameService(f, host) svc := buildHTTPBinExternalNameService(f, host)
f.EnsureService(svc) f.EnsureService(svc)
annotations := map[string]string{ annotations := map[string]string{
"nginx.ingress.kubernetes.io/upstream-vhost": "httpbin.org", "nginx.ingress.kubernetes.io/upstream-vhost": "neverssl.com",
} }
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.HTTPBinService, 80, annotations) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, "neverssl", 80, annotations)
namedBackend := networking.IngressBackend{ namedBackend := networking.IngressBackend{
Service: &networking.IngressServiceBackend{ Service: &networking.IngressServiceBackend{
Name: framework.HTTPBinService, Name: "neverssl",
Port: networking.ServiceBackendPort{ Port: networking.ServiceBackendPort{
Name: host, Name: host,
}, },
@ -272,27 +273,27 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
}) })
body := f.HTTPTestClient(). body := f.HTTPTestClient().
GET("/get"). GET("/").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusOK). Status(http.StatusOK).
Body(). Body().
Raw() Raw()
assert.Contains(ginkgo.GinkgoT(), body, `"X-Forwarded-Host": "echo"`) assert.Contains(ginkgo.GinkgoT(), body, `"neverssl.com"`)
svc, err := f.KubeClientSet.CoreV1().Services(f.Namespace).Get(context.TODO(), framework.HTTPBinService, metav1.GetOptions{}) svc, err := f.KubeClientSet.CoreV1().Services(f.Namespace).Get(context.TODO(), "neverssl", metav1.GetOptions{})
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error obtaining httpbin service") assert.Nil(ginkgo.GinkgoT(), err, "unexpected error obtaining service")
svc.Spec.ExternalName = "eu.httpbin.org" svc.Spec.ExternalName = "google.com"
_, err = f.KubeClientSet.CoreV1().Services(f.Namespace).Update(context.Background(), svc, metav1.UpdateOptions{}) _, err = f.KubeClientSet.CoreV1().Services(f.Namespace).Update(context.Background(), svc, metav1.UpdateOptions{})
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error updating httpbin service") assert.Nil(ginkgo.GinkgoT(), err, "unexpected error updating service")
framework.Sleep() framework.Sleep()
body = f.HTTPTestClient(). body = f.HTTPTestClient().
GET("/get"). GET("/").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusOK). Status(http.StatusOK).
@ -301,18 +302,18 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
assert.Contains(ginkgo.GinkgoT(), body, `"X-Forwarded-Host": "echo"`) assert.Contains(ginkgo.GinkgoT(), body, `"X-Forwarded-Host": "echo"`)
ginkgo.By("checking the service is updated to use eu.httpbin.org") ginkgo.By("checking the service is updated to use google.com")
curlCmd := fmt.Sprintf("curl --fail --silent http://localhost:%v/configuration/backends", nginx.StatusPort) curlCmd := fmt.Sprintf("curl --fail --silent http://localhost:%v/configuration/backends", nginx.StatusPort)
output, err := f.ExecIngressPod(curlCmd) output, err := f.ExecIngressPod(curlCmd)
assert.Nil(ginkgo.GinkgoT(), err) assert.Nil(ginkgo.GinkgoT(), err)
assert.Contains(ginkgo.GinkgoT(), output, `{"address":"eu.httpbin.org"`) assert.Contains(ginkgo.GinkgoT(), output, `{"address":"google.com"`)
}) })
ginkgo.It("should sync ingress on external name service addition/deletion", func() { ginkgo.It("should sync ingress on type=ExternalName service addition/deletion", func() {
host := "echo" host := "echo"
// Create the Ingress first // Create the Ingress first
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.HTTPBinService, 80, nil) ing := framework.NewSingleIngress(host, "/", host, f.Namespace, "neverssl", 80, nil)
f.EnsureIngress(ing) f.EnsureIngress(ing)
f.WaitForNginxServer(host, f.WaitForNginxServer(host,
@ -322,7 +323,7 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
// Nginx should return 503 without the underlying service being available // Nginx should return 503 without the underlying service being available
f.HTTPTestClient(). f.HTTPTestClient().
GET("/get"). GET("/").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusServiceUnavailable) Status(http.StatusServiceUnavailable)
@ -335,20 +336,19 @@ var _ = framework.IngressNginxDescribe("[Service] Type ExternalName", func() {
// 503 should change to 200 OK // 503 should change to 200 OK
f.HTTPTestClient(). f.HTTPTestClient().
GET("/get"). GET("/").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusOK) Status(http.StatusOK)
// And back to 503 after deleting the service // And back to 503 after deleting the service
err := f.KubeClientSet.CoreV1().Services(f.Namespace).Delete(context.TODO(), "neverssl", metav1.DeleteOptions{})
err := f.KubeClientSet.CoreV1().Services(f.Namespace).Delete(context.TODO(), framework.HTTPBinService, metav1.DeleteOptions{}) assert.Nil(ginkgo.GinkgoT(), err, "unexpected error deleting service")
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error deleting httpbin service")
framework.Sleep() framework.Sleep()
f.HTTPTestClient(). f.HTTPTestClient().
GET("/get"). GET("/").
WithHeader("Host", host). WithHeader("Host", host).
Expect(). Expect().
Status(http.StatusServiceUnavailable) Status(http.StatusServiceUnavailable)

File diff suppressed because one or more lines are too long