Decouple shared functions between controllers (#8829)

* Decouple shared functions between controllers

* Apply suggestions from code review

Co-authored-by: Jintao Zhang <tao12345666333@163.com>

* Fix package names and fmt

Co-authored-by: Jintao Zhang <tao12345666333@163.com>
This commit is contained in:
Ricardo Katz 2022-07-20 15:53:44 -03:00 committed by GitHub
parent 8f9df544ea
commit 4c6a7ee158
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 413 additions and 134 deletions

View file

@ -33,6 +33,8 @@ import (
"k8s.io/ingress-nginx/internal/ingress/controller"
"k8s.io/ingress-nginx/internal/k8s"
"k8s.io/ingress-nginx/internal/nginx"
ingressflags "k8s.io/ingress-nginx/pkg/flags"
"k8s.io/ingress-nginx/pkg/util/process"
)
func TestCreateApiserverClient(t *testing.T) {
@ -83,7 +85,7 @@ func TestHandleSigterm(t *testing.T) {
t.Fatalf("error creating pod %v: %v", pod, err)
}
resetForTesting(func() { t.Fatal("bad parse") })
ingressflags.ResetForTesting(func() { t.Fatal("bad parse") })
os.Setenv("POD_NAME", podName)
os.Setenv("POD_NAMESPACE", namespace)
@ -97,7 +99,7 @@ func TestHandleSigterm(t *testing.T) {
}()
os.Args = []string{"cmd", "--default-backend-service", "ingress-nginx/default-backend-http", "--http-port", "0", "--https-port", "0"}
_, conf, err := parseFlags()
_, conf, err := ingressflags.ParseFlags()
if err != nil {
t.Errorf("Unexpected error creating NGINX controller: %v", err)
}
@ -105,7 +107,7 @@ func TestHandleSigterm(t *testing.T) {
ngx := controller.NewNGINXController(conf, nil)
go handleSigterm(ngx, 10, func(code int) {
go process.HandleSigterm(ngx, 10, func(code int) {
if code != 1 {
t.Errorf("Expected exit code 1 but %d received", code)
}