Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dynamic reconfiguration in mergeable ingresses for Plus #294

Merged
merged 1 commit into from
Jun 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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