Merge pull request #2346 from Shopify/e2e-config-update-refactor
Move ConfigMap updating methods into e2e/framework
This commit is contained in:
commit
54874d49af
5 changed files with 92 additions and 28 deletions
|
@ -61,6 +61,9 @@ type Framework struct {
|
|||
// should abort, the AfterSuite hook should run all Cleanup actions.
|
||||
cleanupHandle CleanupActionHandle
|
||||
|
||||
// Map to hold the default nginx-configuration configmap data before a test run
|
||||
DefaultNginxConfigMapData map[string]string
|
||||
|
||||
NginxHTTPURL string
|
||||
NginxHTTPSURL string
|
||||
}
|
||||
|
@ -69,7 +72,8 @@ type Framework struct {
|
|||
// you (you can write additional before/after each functions).
|
||||
func NewDefaultFramework(baseName string) *Framework {
|
||||
f := &Framework{
|
||||
BaseName: baseName,
|
||||
BaseName: baseName,
|
||||
DefaultNginxConfigMapData: nil,
|
||||
}
|
||||
|
||||
BeforeEach(f.BeforeEach)
|
||||
|
@ -101,6 +105,13 @@ func (f *Framework) BeforeEach() {
|
|||
By("Building NGINX HTTPS URL")
|
||||
f.NginxHTTPSURL, err = f.GetNginxURL(HTTPS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Persist nginx-configuration configMap Data")
|
||||
if f.DefaultNginxConfigMapData == nil {
|
||||
f.DefaultNginxConfigMapData, err = f.GetNginxConfigMapData()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(f.DefaultNginxConfigMapData).NotTo(BeNil())
|
||||
}
|
||||
}
|
||||
|
||||
// AfterEach deletes the namespace, after reading its events.
|
||||
|
@ -114,6 +125,10 @@ func (f *Framework) AfterEach() {
|
|||
By("Waiting for test namespace to no longer exist")
|
||||
err = WaitForNoPodsInNamespace(f.KubeClientSet, f.Namespace.Name)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Reset nginx-configuration configMap to default state")
|
||||
err = f.SetNginxConfigMapData(f.DefaultNginxConfigMapData)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
// IngressNginxDescribe wrapper function for ginkgo describe. Adds namespacing.
|
||||
|
@ -259,6 +274,68 @@ func (f *Framework) matchNginxConditions(name string, matcher func(cfg string) b
|
|||
}
|
||||
}
|
||||
|
||||
func (f *Framework) getNginxConfigMap() (*v1.ConfigMap, error) {
|
||||
if f.KubeClientSet == nil {
|
||||
return nil, fmt.Errorf("KubeClientSet not initialized")
|
||||
}
|
||||
|
||||
config, err := f.KubeClientSet.CoreV1().ConfigMaps("ingress-nginx").Get("nginx-configuration", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return config, err
|
||||
}
|
||||
|
||||
// GetNginxConfigMapData gets ingress-nginx's nginx-configuration map's data
|
||||
func (f *Framework) GetNginxConfigMapData() (map[string]string, error) {
|
||||
config, err := f.getNginxConfigMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if config.Data == nil {
|
||||
config.Data = map[string]string{}
|
||||
}
|
||||
|
||||
return config.Data, err
|
||||
}
|
||||
|
||||
// SetNginxConfigMapData sets ingress-nginx's nginx-configuration configMap data
|
||||
func (f *Framework) SetNginxConfigMapData(cmData map[string]string) error {
|
||||
// Needs to do a Get and Set, Update will not take just the Data field
|
||||
// or a configMap that is not the very last revision
|
||||
config, err := f.getNginxConfigMap()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if config == nil {
|
||||
return fmt.Errorf("Unable to get nginx-configuration configMap")
|
||||
}
|
||||
|
||||
config.Data = cmData
|
||||
|
||||
_, err = f.KubeClientSet.CoreV1().ConfigMaps("ingress-nginx").Update(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateNginxConfigMapData updates single field in ingress-nginx's nginx-configuration map data
|
||||
func (f *Framework) UpdateNginxConfigMapData(key string, value string) error {
|
||||
config, err := f.GetNginxConfigMapData()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config[key] = value
|
||||
|
||||
return f.SetNginxConfigMapData(config)
|
||||
}
|
||||
|
||||
// UpdateDeployment runs the given updateFunc on the deployment and waits for it to be updated
|
||||
func UpdateDeployment(kubeClientSet kubernetes.Interface, namespace string, name string, replicas int, updateFunc func(d *appsv1beta1.Deployment) error) error {
|
||||
deployment, err := kubeClientSet.AppsV1beta1().Deployments(namespace).Get(name, metav1.GetOptions{})
|
||||
|
|
|
@ -210,6 +210,7 @@ var _ = framework.IngressNginxDescribe("Dynamic Configuration", func() {
|
|||
return err
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
By("Making a first request")
|
||||
host := "foo.com"
|
||||
|
|
|
@ -51,7 +51,8 @@ var _ = framework.IngressNginxDescribe("No Auth locations", func() {
|
|||
Expect(s).NotTo(BeNil())
|
||||
Expect(s.ObjectMeta).NotTo(BeNil())
|
||||
|
||||
updateConfigmap(setting, noAuthPath, f.KubeClientSet)
|
||||
err = f.UpdateNginxConfigMapData(setting, noAuthPath)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
bi := buildBasicAuthIngressWithSecondPath(host, f.Namespace.Name, s.Name, noAuthPath)
|
||||
ing, err := f.EnsureIngress(bi)
|
||||
|
@ -60,7 +61,6 @@ var _ = framework.IngressNginxDescribe("No Auth locations", func() {
|
|||
})
|
||||
|
||||
AfterEach(func() {
|
||||
updateConfigmap(setting, "/.well-known/acme-challenge", f.KubeClientSet)
|
||||
})
|
||||
|
||||
It("should return status code 401 when accessing '/' unauthentication", func() {
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"io/ioutil"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
@ -29,7 +28,6 @@ import (
|
|||
"k8s.io/api/extensions/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
||||
|
@ -41,16 +39,19 @@ var _ = framework.IngressNginxDescribe("Proxy Protocol", func() {
|
|||
BeforeEach(func() {
|
||||
err := f.NewEchoDeployment()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = f.UpdateNginxConfigMapData(setting, "false")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
updateConfigmap(setting, "false", f.KubeClientSet)
|
||||
})
|
||||
|
||||
It("should respect port passed by the PROXY Protocol", func() {
|
||||
host := "proxy-protocol"
|
||||
|
||||
updateConfigmap(setting, "true", f.KubeClientSet)
|
||||
err := f.UpdateNginxConfigMapData(setting, "true")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
ing, err := f.EnsureIngress(&v1beta1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
@ -111,19 +112,3 @@ var _ = framework.IngressNginxDescribe("Proxy Protocol", func() {
|
|||
Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-for=192.168.0.1")))
|
||||
})
|
||||
})
|
||||
|
||||
func updateConfigmap(k, v string, c kubernetes.Interface) {
|
||||
By(fmt.Sprintf("updating configuration configmap setting %v to '%v'", k, v))
|
||||
config, err := c.CoreV1().ConfigMaps("ingress-nginx").Get("nginx-configuration", metav1.GetOptions{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(config).NotTo(BeNil())
|
||||
|
||||
if config.Data == nil {
|
||||
config.Data = map[string]string{}
|
||||
}
|
||||
|
||||
config.Data[k] = v
|
||||
_, err = c.CoreV1().ConfigMaps("ingress-nginx").Update(config)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
|
|
|
@ -38,11 +38,11 @@ var _ = framework.IngressNginxDescribe("Server Tokens", func() {
|
|||
})
|
||||
|
||||
AfterEach(func() {
|
||||
updateConfigmap(serverTokens, "false", f.KubeClientSet)
|
||||
})
|
||||
|
||||
It("should not exist Server header in the response", func() {
|
||||
updateConfigmap(serverTokens, "false", f.KubeClientSet)
|
||||
It("should not exists Server header in the response", func() {
|
||||
err := f.UpdateNginxConfigMapData(serverTokens, "false")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
ing, err := f.EnsureIngress(&v1beta1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
@ -83,8 +83,9 @@ var _ = framework.IngressNginxDescribe("Server Tokens", func() {
|
|||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("should exist Server header in the response when is enabled", func() {
|
||||
updateConfigmap(serverTokens, "true", f.KubeClientSet)
|
||||
It("should exists Server header in the response when is enabled", func() {
|
||||
err := f.UpdateNginxConfigMapData(serverTokens, "true")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
ing, err := f.EnsureIngress(&v1beta1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
Loading…
Reference in a new issue