Skip to content

Commit

Permalink
Adds support for detecting if publish-service type
Browse files Browse the repository at this point in the history
  • Loading branch information
rikatz committed Sep 1, 2017
1 parent cda42f9 commit 8043c59
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion controllers/nginx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BUILDTAGS=
TAG?=0.9.0-beta.12
REGISTRY?=gcr.io/google_containers
GOOS?=linux
DOCKER?=gcloud docker --
DOCKER?=docker
SED_I?=sed -i
GOHOSTOS ?= $(shell go env GOHOSTOS)

Expand Down
1 change: 1 addition & 0 deletions controllers/nginx/pkg/cmd/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
IsIPV6Enabled: n.isIPV6Enabled && !cfg.DisableIpv6,
RedirectServers: redirectServers,
IsSSLPassthroughEnabled: n.isSSLPassthroughEnabled,
IsPublishLoadBalancer: n.controller.PublishLoadBalancer(),
ListenPorts: n.ports,
}

Expand Down
1 change: 1 addition & 0 deletions controllers/nginx/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ type TemplateConfig struct {
Cfg Configuration
IsIPV6Enabled bool
IsSSLPassthroughEnabled bool
IsPublishLoadBalancer bool
RedirectServers map[string]string
ListenPorts *ListenPorts
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pid /run/nginx.pid;
{{ if ne .MaxOpenFiles 0 }}
worker_rlimit_nofile {{ .MaxOpenFiles }};
{{ end}}

# Publish Load Balancer: {{ $all.IsPublishLoadBalancer }}
{{/* http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout */}}
{{/* avoid waiting too long during a reload */}}
worker_shutdown_timeout {{ $cfg.WorkerShutdownTimeout }} ;
Expand Down
8 changes: 7 additions & 1 deletion core/pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ type Configuration struct {
DefaultHealthzURL string
DefaultIngressClass string
// optional
PublishService string
PublishService string
IsPublishLoadBalancer bool
// Backend is the particular implementation to be used.
// (for instance NGINX)
Backend ingress.Controller
Expand Down Expand Up @@ -368,6 +369,11 @@ func (ic GenericController) IngressClass() string {
return ic.cfg.IngressClass
}

// PublishLoadBalancer returns a boolean about if publish service is a Load Balancer
func (ic GenericController) PublishLoadBalancer() bool {
return ic.cfg.IsPublishLoadBalancer
}

// GetDefaultBackend returns the default backend
func (ic GenericController) GetDefaultBackend() defaults.Backend {
return ic.cfg.Backend.BackendDefaults()
Expand Down
7 changes: 6 additions & 1 deletion core/pkg/ingress/controller/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,15 @@ func NewIngressController(backend ingress.Controller) *GenericController {
}
glog.Infof("validated %v as the default backend", *defaultSvc)

var isPublishLoadBalancer bool
if *publishSvc != "" {
svc, err := k8s.IsValidService(kubeClient, *publishSvc)
if err != nil {
glog.Fatalf("no service with name %v found: %v", *publishSvc, err)
}

if svc.Spec.Type == "LoadBalancer" {
isPublishLoadBalancer = true
}
if len(svc.Status.LoadBalancer.Ingress) == 0 {
if len(svc.Spec.ExternalIPs) > 0 {
glog.Infof("service %v validated as assigned with externalIP", *publishSvc)
Expand All @@ -147,6 +150,7 @@ func NewIngressController(backend ingress.Controller) *GenericController {
glog.Infof("service %v validated as source of Ingress status", *publishSvc)
}
}
glog.Infof("Setting Publush Load Balancer to: %v", isPublishLoadBalancer)

This comment has been minimized.

Copy link
@boazy

boazy Sep 1, 2017

Typo ;)
Should be 'Publish'


if *watchNamespace != "" {

Expand Down Expand Up @@ -181,6 +185,7 @@ func NewIngressController(backend ingress.Controller) *GenericController {
DefaultSSLCertificate: *defSSLCertificate,
DefaultHealthzURL: *defHealthzURL,
PublishService: *publishSvc,
IsPublishLoadBalancer: isPublishLoadBalancer,
Backend: backend,
ForceNamespaceIsolation: *forceIsolation,
UpdateStatusOnShutdown: *updateStatusOnShutdown,
Expand Down

0 comments on commit 8043c59

Please sign in to comment.