use functional options to reduce number of methods creating an EchoDeployment (#8199)
This commit is contained in:
parent
0f464333a9
commit
dcd552ceb5
20 changed files with 75 additions and 51 deletions
|
@ -36,7 +36,7 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
|
|||
f := framework.NewDefaultFramework("affinity")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(2)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(2))
|
||||
})
|
||||
|
||||
ginkgo.It("should set sticky cookie SERVERID", func() {
|
||||
|
|
|
@ -34,7 +34,10 @@ var _ = framework.DescribeAnnotation("affinitymode", func() {
|
|||
ginkgo.It("Balanced affinity mode should balance", func() {
|
||||
deploymentName := "affinitybalanceecho"
|
||||
replicas := 5
|
||||
f.NewEchoDeploymentWithNameAndReplicas(deploymentName, replicas)
|
||||
f.NewEchoDeployment(
|
||||
framework.WithDeploymentName(deploymentName),
|
||||
framework.WithDeploymentReplicas(replicas),
|
||||
)
|
||||
|
||||
host := "affinity-mode-balance.com"
|
||||
annotations := make(map[string]string)
|
||||
|
@ -64,7 +67,10 @@ var _ = framework.DescribeAnnotation("affinitymode", func() {
|
|||
ginkgo.It("Check persistent affinity mode", func() {
|
||||
deploymentName := "affinitypersistentecho"
|
||||
replicas := 5
|
||||
f.NewEchoDeploymentWithNameAndReplicas(deploymentName, replicas)
|
||||
f.NewEchoDeployment(
|
||||
framework.WithDeploymentName(deploymentName),
|
||||
framework.WithDeploymentReplicas(replicas),
|
||||
)
|
||||
|
||||
host := "affinity-mode-persistent.com"
|
||||
annotations := make(map[string]string)
|
||||
|
|
|
@ -30,7 +30,7 @@ var _ = framework.DescribeAnnotation("auth-tls-*", func() {
|
|||
f := framework.NewDefaultFramework("authtls")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(2)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(2))
|
||||
})
|
||||
|
||||
ginkgo.It("should set sslClientCertificate, sslVerifyClient and sslVerifyDepth with auth-tls-secret", func() {
|
||||
|
|
|
@ -39,10 +39,10 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
|
|||
|
||||
ginkgo.BeforeEach(func() {
|
||||
// Deployment for main backend
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
f.NewEchoDeployment()
|
||||
|
||||
// Deployment for canary backend
|
||||
f.NewEchoDeploymentWithNameAndReplicas(canaryService, 1)
|
||||
f.NewEchoDeployment(framework.WithDeploymentName(canaryService))
|
||||
})
|
||||
|
||||
ginkgo.Context("when canary is created", func() {
|
||||
|
@ -132,7 +132,7 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
|
|||
|
||||
ginkgo.By("returning a 503 status when the mainline deployment has 0 replicas and a request is sent to the canary")
|
||||
|
||||
f.NewEchoDeploymentWithReplicas(0)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(0))
|
||||
|
||||
resp, _, errs := gorequest.New().
|
||||
Get(f.GetURL(framework.HTTP)).
|
||||
|
@ -145,7 +145,7 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
|
|||
|
||||
ginkgo.By("returning a 200 status when the canary deployment has 0 replicas and a request is sent to the mainline ingress")
|
||||
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
f.NewEchoDeployment()
|
||||
f.NewDeployment(canaryService, "k8s.gcr.io/e2e-test-images/echoserver:2.3", 8080, 0)
|
||||
|
||||
resp, _, errs = gorequest.New().
|
||||
|
|
|
@ -29,7 +29,7 @@ var _ = framework.DescribeAnnotation("cors-*", func() {
|
|||
f := framework.NewDefaultFramework("cors")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(2)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(2))
|
||||
})
|
||||
|
||||
ginkgo.It("should enable cors", func() {
|
||||
|
|
|
@ -101,7 +101,7 @@ var _ = framework.DescribeAnnotation("custom-http-errors", func() {
|
|||
|
||||
ginkgo.By("using the custom default-backend from annotation for upstream")
|
||||
customDefaultBackend := "from-annotation"
|
||||
f.NewEchoDeploymentWithNameAndReplicas(customDefaultBackend, 1)
|
||||
f.NewEchoDeployment(framework.WithDeploymentName(customDefaultBackend))
|
||||
|
||||
err = framework.UpdateIngress(f.KubeClientSet, f.Namespace, host, func(ingress *networking.Ingress) error {
|
||||
ingress.ObjectMeta.Annotations["nginx.ingress.kubernetes.io/default-backend"] = customDefaultBackend
|
||||
|
|
|
@ -150,7 +150,7 @@ var _ = framework.DescribeAnnotation("proxy-ssl-*", func() {
|
|||
ginkgo.It("proxy-ssl-location-only flag should change the nginx config server part", func() {
|
||||
host := "proxyssl.com"
|
||||
|
||||
f.NewEchoDeploymentWithNameAndReplicas("echodeployment", 1)
|
||||
f.NewEchoDeployment(framework.WithDeploymentName("echodeployment"))
|
||||
|
||||
secretName := "secretone"
|
||||
annotations := make(map[string]string)
|
||||
|
|
|
@ -77,7 +77,7 @@ var _ = framework.DescribeAnnotation("upstream-hash-by-*", func() {
|
|||
f := framework.NewDefaultFramework("upstream-hash-by")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(6)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(6))
|
||||
})
|
||||
|
||||
ginkgo.It("should connect to the same pod", func() {
|
||||
|
|
|
@ -40,30 +40,45 @@ const HTTPBinService = "httpbin"
|
|||
// NginxBaseImage use for testing
|
||||
const NginxBaseImage = "k8s.gcr.io/ingress-nginx/nginx:v20210926-g5662db450@sha256:1ef404b5e8741fe49605a1f40c3fdd8ef657aecdb9526ea979d1672eeabd0cd9"
|
||||
|
||||
type deploymentOptions struct {
|
||||
namespace string
|
||||
name string
|
||||
replicas int
|
||||
}
|
||||
|
||||
// WithDeploymentNamespace allows configuring the deployment's namespace
|
||||
func WithDeploymentNamespace(n string) func(*deploymentOptions) {
|
||||
return func(o *deploymentOptions) {
|
||||
o.namespace = n
|
||||
}
|
||||
}
|
||||
|
||||
// WithDeploymentName allows configuring the deployment's names
|
||||
func WithDeploymentName(n string) func(*deploymentOptions) {
|
||||
return func(o *deploymentOptions) {
|
||||
o.name = n
|
||||
}
|
||||
}
|
||||
|
||||
// WithDeploymentReplicas allows configuring the deployment's replicas count
|
||||
func WithDeploymentReplicas(r int) func(*deploymentOptions) {
|
||||
return func(o *deploymentOptions) {
|
||||
o.replicas = r
|
||||
}
|
||||
}
|
||||
|
||||
// NewEchoDeployment creates a new single replica deployment of the echoserver image in a particular namespace
|
||||
func (f *Framework) NewEchoDeployment() {
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
}
|
||||
func (f *Framework) NewEchoDeployment(opts ...func(*deploymentOptions)) {
|
||||
options := &deploymentOptions{
|
||||
namespace: f.Namespace,
|
||||
name: EchoService,
|
||||
replicas: 1,
|
||||
}
|
||||
for _, o := range opts {
|
||||
o(options)
|
||||
}
|
||||
|
||||
// NewEchoDeploymentWithReplicas creates a new deployment of the echoserver image in a particular namespace. Number of
|
||||
// replicas is configurable
|
||||
func (f *Framework) NewEchoDeploymentWithReplicas(replicas int) {
|
||||
f.NewEchoDeploymentWithNameAndReplicas(EchoService, replicas)
|
||||
}
|
||||
|
||||
// NewEchoDeploymentWithNameAndReplicas creates a new deployment of the echoserver image in a particular namespace. Number of
|
||||
// replicas is configurable and
|
||||
// name is configurable
|
||||
func (f *Framework) NewEchoDeploymentWithNameAndReplicas(name string, replicas int) {
|
||||
f.newEchoDeployment(f.Namespace, name, replicas)
|
||||
}
|
||||
|
||||
func (f *Framework) NewEchoDeploymentWithNamespaceAndReplicas(namespace string, replicas int) {
|
||||
f.newEchoDeployment(namespace, EchoService, replicas)
|
||||
}
|
||||
|
||||
func (f *Framework) newEchoDeployment(namespace, name string, replicas int) {
|
||||
deployment := newDeployment(name, namespace, "k8s.gcr.io/ingress-nginx/e2e-test-echo@sha256:131ece0637b29231470cfaa04690c2966a2e0b147d3c9df080a0857b78982410", 80, int32(replicas),
|
||||
deployment := newDeployment(options.name, options.namespace, "k8s.gcr.io/ingress-nginx/e2e-test-echo@sha256:131ece0637b29231470cfaa04690c2966a2e0b147d3c9df080a0857b78982410", 80, int32(options.replicas),
|
||||
nil,
|
||||
[]corev1.VolumeMount{},
|
||||
[]corev1.Volume{},
|
||||
|
@ -73,8 +88,8 @@ func (f *Framework) newEchoDeployment(namespace, name string, replicas int) {
|
|||
|
||||
service := &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
Name: options.name,
|
||||
Namespace: options.namespace,
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
|
@ -86,14 +101,14 @@ func (f *Framework) newEchoDeployment(namespace, name string, replicas int) {
|
|||
},
|
||||
},
|
||||
Selector: map[string]string{
|
||||
"app": name,
|
||||
"app": options.name,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
f.EnsureService(service)
|
||||
|
||||
err := WaitForEndpoints(f.KubeClientSet, DefaultTimeout, name, namespace, replicas)
|
||||
err := WaitForEndpoints(f.KubeClientSet, DefaultTimeout, options.name, options.namespace, options.replicas)
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "waiting for endpoints to become ready")
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ var _ = framework.IngressNginxDescribe("single ingress - multiple hosts", func()
|
|||
f := framework.NewDefaultFramework("simh")
|
||||
pathprefix := networking.PathTypePrefix
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithNameAndReplicas("first-service", 1)
|
||||
f.NewEchoDeploymentWithNameAndReplicas("second-service", 1)
|
||||
f.NewEchoDeployment(framework.WithDeploymentName("first-service"))
|
||||
f.NewEchoDeployment(framework.WithDeploymentName("second-service"))
|
||||
})
|
||||
|
||||
ginkgo.It("should set the correct $service_name NGINX variable", func() {
|
||||
|
|
|
@ -32,7 +32,7 @@ var _ = framework.DescribeSetting("[Load Balancer] EWMA", func() {
|
|||
f := framework.NewDefaultFramework("ewma")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(3)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(3))
|
||||
f.SetNginxConfigMapData(map[string]string{
|
||||
"worker-processes": "2",
|
||||
"load-balance": "ewma"},
|
||||
|
|
|
@ -32,7 +32,7 @@ var _ = framework.DescribeSetting("[Load Balancer] round-robin", func() {
|
|||
f := framework.NewDefaultFramework("round-robin")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(3)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(3))
|
||||
f.UpdateNginxConfigMapData("worker-processes", "1")
|
||||
})
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ var _ = framework.IngressNginxDescribe("[Lua] dynamic configuration", func() {
|
|||
f := framework.NewDefaultFramework("dynamic-configuration")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
f.NewEchoDeployment()
|
||||
ensureIngress(f, "foo.com", framework.EchoService)
|
||||
})
|
||||
|
||||
|
@ -124,7 +124,10 @@ var _ = framework.IngressNginxDescribe("[Lua] dynamic configuration", func() {
|
|||
|
||||
ginkgo.It("handles endpoints only changes consistently (down scaling of replicas vs. empty service)", func() {
|
||||
deploymentName := "scalingecho"
|
||||
f.NewEchoDeploymentWithNameAndReplicas(deploymentName, 0)
|
||||
f.NewEchoDeployment(
|
||||
framework.WithDeploymentName(deploymentName),
|
||||
framework.WithDeploymentReplicas(0),
|
||||
)
|
||||
createIngress(f, "scaling.foo.com", deploymentName)
|
||||
|
||||
resp := f.HTTPTestClient().
|
||||
|
|
|
@ -38,7 +38,7 @@ var _ = framework.IngressNginxDescribe("[SSL] [Flag] default-ssl-certificate", f
|
|||
port := 80
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(1))
|
||||
|
||||
var err error
|
||||
tlsConfig, err = framework.CreateIngressTLSSecret(f.KubeClientSet,
|
||||
|
|
|
@ -34,7 +34,7 @@ var _ = framework.IngressNginxDescribe("[Flag] disable-catch-all", func() {
|
|||
f := framework.NewDefaultFramework("disabled-catch-all")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(1))
|
||||
|
||||
err := f.UpdateIngressControllerDeployment(func(deployment *appsv1.Deployment) error {
|
||||
args := deployment.Spec.Template.Spec.Containers[0].Args
|
||||
|
|
|
@ -35,7 +35,7 @@ var _ = framework.IngressNginxDescribe("[Flag] disable-service-external-name", f
|
|||
f := framework.NewDefaultFramework("disabled-service-external-name")
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(2)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(2))
|
||||
|
||||
err := f.UpdateIngressControllerDeployment(func(deployment *appsv1.Deployment) error {
|
||||
args := deployment.Spec.Template.Spec.Containers[0].Args
|
||||
|
|
|
@ -45,7 +45,7 @@ var _ = framework.IngressNginxDescribe("[Flag] ingress-class", func() {
|
|||
otherController := "k8s.io/other-class"
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
f.NewEchoDeployment(framework.WithDeploymentReplicas(1))
|
||||
|
||||
doOnce.Do(func() {
|
||||
_, err := f.KubeClientSet.NetworkingV1().IngressClasses().
|
||||
|
|
|
@ -37,7 +37,7 @@ var _ = framework.IngressNginxDescribe("[Flag] watch namespace selector", func()
|
|||
prepareTestIngress := func(baseName string, host string, labels map[string]string) string {
|
||||
ns, err := framework.CreateKubeNamespaceWithLabel(f.BaseName, labels, f.KubeClientSet)
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "creating test namespace")
|
||||
f.NewEchoDeploymentWithNamespaceAndReplicas(ns, 1)
|
||||
f.NewEchoDeployment(framework.WithDeploymentNamespace(ns))
|
||||
ing := framework.NewSingleIngressWithIngressClass(host, "/", host, ns, framework.EchoService, f.IngressClass, 80, nil)
|
||||
f.EnsureIngress(ing)
|
||||
return ns
|
||||
|
|
|
@ -69,7 +69,7 @@ var _ = framework.IngressNginxDescribe("[Status] status update", func() {
|
|||
})
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error updating ingress controller deployment flags")
|
||||
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
f.NewEchoDeployment()
|
||||
|
||||
ing := f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil))
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ var _ = framework.IngressNginxDescribe("[TCP] tcp-services", func() {
|
|||
f := framework.NewDefaultFramework("tcp")
|
||||
|
||||
ginkgo.It("should expose a TCP service", func() {
|
||||
f.NewEchoDeploymentWithReplicas(1)
|
||||
f.NewEchoDeployment()
|
||||
|
||||
config, err := f.KubeClientSet.
|
||||
CoreV1().
|
||||
|
|
Loading…
Reference in a new issue