Skip to content

Commit

Permalink
Merge pull request #294 from nginxinc/dynamic-reconfig-for-mergeable-…
Browse files Browse the repository at this point in the history
…ingresses

Support dynamic reconfiguration in mergeable ingresses for Plus
  • Loading branch information
pleshakov authored Jun 13, 2018
2 parents fba5f63 + 7d5cc1d commit bda409f
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions nginx-controller/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ func (cnf *Configurator) AddOrUpdateMergableIngress(mergeableIngs *MergeableIngr
}

func (cnf *Configurator) addOrUpdateMergableIngress(mergeableIngs *MergeableIngresses) {
nginxCfg := cnf.generateNginxCfgForMergeableIngresses(mergeableIngs)
name := objectMetaToFileName(&mergeableIngs.Master.Ingress.ObjectMeta)
cnf.nginx.AddOrUpdateIngress(name, nginxCfg)
cnf.ingresses[name] = mergeableIngs.Master
}

func (cnf *Configurator) generateNginxCfgForMergeableIngresses(mergeableIngs *MergeableIngresses) IngressNginxConfig {
var masterServer Server
var locations []Location
var upstreams []Upstream
Expand All @@ -94,10 +101,9 @@ func (cnf *Configurator) addOrUpdateMergableIngress(mergeableIngs *MergeableIngr

pems, jwtKeyFileName := cnf.updateSecrets(mergeableIngs.Master)
masterNginxCfg := cnf.generateNginxCfg(mergeableIngs.Master, pems, jwtKeyFileName)
name := objectMetaToFileName(&mergeableIngs.Master.Ingress.ObjectMeta)

masterServer = masterNginxCfg.Servers[0]
masterServer.IngressResource = name
masterServer.IngressResource = objectMetaToFileName(&mergeableIngs.Master.Ingress.ObjectMeta)
masterServer.Locations = []Location{}

for _, val := range masterNginxCfg.Upstreams {
Expand Down Expand Up @@ -142,14 +148,11 @@ func (cnf *Configurator) addOrUpdateMergableIngress(mergeableIngs *MergeableIngr
masterServer.HealthChecks = healthChecks
masterServer.Locations = locations

nginxCfg := IngressNginxConfig{
return IngressNginxConfig{
Servers: []Server{masterServer},
Upstreams: upstreams,
Keepalive: keepalive,
}

cnf.nginx.AddOrUpdateIngress(name, nginxCfg)
cnf.ingresses[name] = mergeableIngs.Master
}

func (cnf *Configurator) updateSecrets(ingEx *IngressEx) (map[string]string, string) {
Expand Down Expand Up @@ -915,6 +918,20 @@ func (cnf *Configurator) UpdateEndpoints(ingEx *IngressEx) error {
func (cnf *Configurator) UpdateEndpointsMergeableIngress(mergeableIngs *MergeableIngresses) error {
cnf.addOrUpdateMergableIngress(mergeableIngs)

if cnf.isPlus() {
var err error
for _, ing := range mergeableIngs.Minions {
err = cnf.updatePlusEndpoints(ing)
if err != nil {
glog.Warningf("Couldn't update the endpoints via the API: %v; reloading configuration instead", err)
break
}
}
if err == nil {
return nil
}
}

if err := cnf.nginx.Reload(); err != nil {
return fmt.Errorf("Error reloading NGINX when updating endpoints for %v/%v: %v", mergeableIngs.Master.Ingress.Namespace, mergeableIngs.Master.Ingress.Name, err)
}
Expand Down

0 comments on commit bda409f

Please sign in to comment.