2019-06-27 14:03:20 +00:00
|
|
|
/*
|
|
|
|
Copyright 2019 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package leaks
|
|
|
|
|
|
|
|
import (
|
2020-03-24 13:44:13 +00:00
|
|
|
"context"
|
2019-06-27 14:03:20 +00:00
|
|
|
"crypto/tls"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2020-02-19 03:08:56 +00:00
|
|
|
"github.com/onsi/ginkgo"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-06-27 14:03:20 +00:00
|
|
|
pool "gopkg.in/go-playground/pool.v3"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
|
|
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
|
|
|
)
|
|
|
|
|
2020-02-16 18:27:58 +00:00
|
|
|
var _ = framework.IngressNginxDescribe("[Memory Leak] Dynamic Certificates", func() {
|
2019-06-27 14:03:20 +00:00
|
|
|
f := framework.NewDefaultFramework("lua-dynamic-certificates")
|
|
|
|
|
2020-02-19 03:08:56 +00:00
|
|
|
ginkgo.BeforeEach(func() {
|
2019-06-27 14:03:20 +00:00
|
|
|
f.NewEchoDeployment()
|
|
|
|
})
|
|
|
|
|
|
|
|
framework.MemoryLeakIt("should not leak memory from ingress SSL certificates or configuration updates", func() {
|
|
|
|
hostCount := 1000
|
|
|
|
iterations := 10
|
|
|
|
|
2020-02-19 03:08:56 +00:00
|
|
|
ginkgo.By("Waiting a minute before starting the test")
|
2020-07-01 21:19:51 +00:00
|
|
|
framework.Sleep(1 * time.Minute)
|
2019-06-27 14:03:20 +00:00
|
|
|
|
|
|
|
for iteration := 1; iteration <= iterations; iteration++ {
|
2020-02-19 03:08:56 +00:00
|
|
|
ginkgo.By(fmt.Sprintf("Running iteration %v", iteration))
|
2019-06-27 14:03:20 +00:00
|
|
|
|
|
|
|
p := pool.NewLimited(200)
|
|
|
|
|
|
|
|
batch := p.Batch()
|
|
|
|
|
|
|
|
for index := 1; index <= hostCount; index++ {
|
|
|
|
host := fmt.Sprintf("hostname-%v", index)
|
|
|
|
batch.Queue(run(host, f))
|
|
|
|
}
|
|
|
|
|
|
|
|
batch.QueueComplete()
|
|
|
|
batch.WaitAll()
|
|
|
|
|
|
|
|
p.Close()
|
|
|
|
|
2020-02-19 03:08:56 +00:00
|
|
|
ginkgo.By("waiting one minute before next iteration")
|
2020-07-01 21:19:51 +00:00
|
|
|
framework.Sleep(1 * time.Minute)
|
2019-06-27 14:03:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-11-27 17:26:53 +00:00
|
|
|
func provisionIngress(hostname string, f *framework.Framework) {
|
2019-09-01 18:16:52 +00:00
|
|
|
ing := f.EnsureIngress(framework.NewSingleIngressWithTLS(hostname, "/", hostname, []string{hostname}, f.Namespace, framework.EchoService, 80, nil))
|
2019-06-27 14:03:20 +00:00
|
|
|
_, err := framework.CreateIngressTLSSecret(f.KubeClientSet,
|
|
|
|
ing.Spec.TLS[0].Hosts,
|
|
|
|
ing.Spec.TLS[0].SecretName,
|
|
|
|
ing.Namespace)
|
2020-02-19 03:08:56 +00:00
|
|
|
assert.Nil(ginkgo.GinkgoT(), err)
|
2019-06-27 14:03:20 +00:00
|
|
|
|
|
|
|
f.WaitForNginxServer(hostname,
|
|
|
|
func(server string) bool {
|
|
|
|
return strings.Contains(server, fmt.Sprintf("server_name %v", hostname)) &&
|
|
|
|
strings.Contains(server, "listen 443")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkIngress(hostname string, f *framework.Framework) {
|
2020-02-19 03:08:56 +00:00
|
|
|
resp := f.HTTPTestClientWithTLSConfig(&tls.Config{
|
|
|
|
ServerName: hostname,
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
}).
|
|
|
|
GET("/").
|
|
|
|
WithURL(f.GetURL(framework.HTTPS)).
|
|
|
|
WithHeader("Host", hostname).
|
|
|
|
Expect().
|
|
|
|
Raw()
|
|
|
|
|
|
|
|
assert.Equal(ginkgo.GinkgoT(), resp.StatusCode, http.StatusOK)
|
2019-06-27 14:03:20 +00:00
|
|
|
|
|
|
|
// check the returned secret is not the fake one
|
|
|
|
cert := resp.TLS.PeerCertificates[0]
|
2020-02-19 03:08:56 +00:00
|
|
|
assert.Equal(ginkgo.GinkgoT(), cert.DNSNames[0], hostname)
|
2019-06-27 14:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func deleteIngress(hostname string, f *framework.Framework) {
|
2020-03-24 13:44:13 +00:00
|
|
|
err := f.KubeClientSet.NetworkingV1beta1().Ingresses(f.Namespace).Delete(context.TODO(), hostname, metav1.DeleteOptions{})
|
2020-02-19 03:08:56 +00:00
|
|
|
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error deleting ingress")
|
2019-06-27 14:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func run(host string, f *framework.Framework) pool.WorkFunc {
|
|
|
|
return func(wu pool.WorkUnit) (interface{}, error) {
|
|
|
|
if wu.IsCancelled() {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2020-02-19 03:08:56 +00:00
|
|
|
ginkgo.By(fmt.Sprintf("\tcreating ingress for host %v", host))
|
2020-11-27 17:26:53 +00:00
|
|
|
provisionIngress(host, f)
|
2019-06-27 14:03:20 +00:00
|
|
|
|
2020-07-01 21:19:51 +00:00
|
|
|
framework.Sleep(100 * time.Millisecond)
|
2019-06-27 14:03:20 +00:00
|
|
|
|
2020-02-19 03:08:56 +00:00
|
|
|
ginkgo.By(fmt.Sprintf("\tchecking ingress for host %v", host))
|
2019-06-27 14:03:20 +00:00
|
|
|
checkIngress(host, f)
|
|
|
|
|
2020-02-19 03:08:56 +00:00
|
|
|
ginkgo.By(fmt.Sprintf("\tdestroying ingress for host %v", host))
|
2019-06-27 14:03:20 +00:00
|
|
|
deleteIngress(host, f)
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|