Skip to content

Commit

Permalink
Extract handlers, reduce complexity of creating new Controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Kelly committed Sep 5, 2018
1 parent 5e66437 commit 961e591
Show file tree
Hide file tree
Showing 12 changed files with 665 additions and 521 deletions.
36 changes: 33 additions & 3 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"github.com/golang/glog"

"github.com/nginxinc/kubernetes-ingress/internal/controller"
"github.com/nginxinc/kubernetes-ingress/internal/handlers"
"github.com/nginxinc/kubernetes-ingress/internal/nginx"
"github.com/nginxinc/kubernetes-ingress/internal/nginx/plus"
"github.com/nginxinc/kubernetes-ingress/internal/utils"
api_v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -151,7 +153,7 @@ func main() {
ngxc := nginx.NewNginxController("/etc/nginx/", local)

if *defaultServerSecret != "" {
ns, name, err := controller.ParseNamespaceName(*defaultServerSecret)
ns, name, err := utils.ParseNamespaceName(*defaultServerSecret)
if err != nil {
glog.Fatalf("Error parsing the default-server-tls-secret argument: %v", err)
}
Expand All @@ -175,7 +177,7 @@ func main() {

cfg := nginx.NewDefaultConfig()
if *nginxConfigMaps != "" {
ns, name, err := controller.ParseNamespaceName(*nginxConfigMaps)
ns, name, err := utils.ParseNamespaceName(*nginxConfigMaps)
if err != nil {
glog.Fatalf("Error parsing the nginx-configmaps argument: %v", err)
}
Expand Down Expand Up @@ -234,7 +236,6 @@ func main() {
ResyncPeriod: 30 * time.Second,
Namespace: *watchNamespace,
NginxConfigurator: cnf,
NginxConfigMaps: *nginxConfigMaps,
DefaultServerSecret: *defaultServerSecret,
IsNginxPlus: *nginxPlus,
IngressClass: *ingressClass,
Expand All @@ -244,7 +245,36 @@ func main() {
ReportIngressStatus: *reportIngressStatus,
IsLeaderElectionEnabled: *leaderElectionEnabled,
}

lbc := controller.NewLoadBalancerController(lbcInput)

// create handlers for resources we care about
ingressHandlers := handlers.CreateIngressHandlers(lbc)
secretHandlers := handlers.CreateSecretHandlers(lbc)
serviceHandlers := handlers.CreateServiceHandlers(lbc)
endpointHandlers := handlers.CreateEndpointHandlers(lbc)

lbc.AddSecretHandler(secretHandlers)
lbc.AddIngressHandler(ingressHandlers)
lbc.AddServiceHandler(serviceHandlers)
lbc.AddEndpointHandler(endpointHandlers)

if *nginxConfigMaps != "" {
nginxConfigMapsNS, nginxConfigMapsName, err := utils.ParseNamespaceName(*nginxConfigMaps)
if err != nil {
glog.Warning(err)
} else {
lbc.WatchNginxConfigMaps()
configMapHandlers := handlers.CreateConfigMapHandlers(lbc, nginxConfigMapsName)
lbc.AddConfigMapHandler(configMapHandlers, nginxConfigMapsNS)
}
}

if lbcInput.ReportIngressStatus && lbcInput.IsLeaderElectionEnabled {
leaderHandler := handlers.CreateLeaderHandler(lbc)
lbc.AddLeaderHandler(leaderHandler)
}

go handleTermination(lbc, ngxc, nginxDone)
lbc.Run()

Expand Down
Loading

0 comments on commit 961e591

Please sign in to comment.