Skip to content

Commit 1fd1127

Browse files
committed
Address suggestions from reviews
1 parent 2aa5f1f commit 1fd1127

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

nginx-controller/controller/controller.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,7 @@ func (lbc *LoadBalancerController) syncSecret(task Task) {
787787
lbc.syncQueue.requeueAfter(task, err, 5*time.Second)
788788
}
789789

790-
glog.V(2).Infof("Found %v Non-Minion Ingress resources with Secret %v", len(nonMinions), key)
791-
glog.V(2).Infof("Found %v Minion Ingress resources with Secret %v", len(minions), key)
790+
glog.V(2).Infof("Found %v Non-Minion and %v Minion Ingress resources with Secret %v", len(nonMinions), len(minions), key)
792791

793792
if !secrExists {
794793
glog.V(2).Infof("Deleting Secret: %v\n", key)
@@ -918,10 +917,7 @@ func (lbc *LoadBalancerController) syncSecret(task Task) {
918917
}
919918
}
920919

921-
func (lbc *LoadBalancerController) findIngressesForSecret(secretNamespace string, secretName string) ([]extensions.Ingress, []extensions.Ingress, error) {
922-
var nonMinions []extensions.Ingress
923-
var minions []extensions.Ingress
924-
920+
func (lbc *LoadBalancerController) findIngressesForSecret(secretNamespace string, secretName string) (nonMinions []extensions.Ingress, minions []extensions.Ingress, error error) {
925921
ings, err := lbc.ingLister.List()
926922
if err != nil {
927923
return nil, nil, fmt.Errorf("Couldn't get the list of Ingress resources: %v", err)
@@ -958,10 +954,11 @@ items:
958954
}
959955

960956
// we're dealing with a minion
961-
// only JWT secrets are allowed in a minion
957+
// minions can only have JWT secrets
962958
if lbc.nginxPlus {
963959
master, err := lbc.findMasterForMinion(&ing)
964960
if err != nil {
961+
glog.Infof("Ignoring Ingress %v(Minion): %v", ing.Name, err)
965962
continue
966963
}
967964

nginx-controller/nginx/configurator.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ func (cnf *Configurator) AddOrUpdateIngress(ingEx *IngressEx) error {
6767

6868
func (cnf *Configurator) addOrUpdateIngress(ingEx *IngressEx) error {
6969
pems, jwtKeyFileName := cnf.updateSecrets(ingEx)
70-
nginxCfg := cnf.generateNginxCfg(ingEx, pems, jwtKeyFileName, false)
70+
isMinion := false
71+
nginxCfg := cnf.generateNginxCfg(ingEx, pems, jwtKeyFileName, isMinion)
7172
name := objectMetaToFileName(&ingEx.Ingress.ObjectMeta)
7273
content, err := cnf.templateExecutor.ExecuteIngressConfigTemplate(&nginxCfg)
7374
if err != nil {
@@ -120,7 +121,8 @@ func (cnf *Configurator) generateNginxCfgForMergeableIngresses(mergeableIngs *Me
120121
}
121122

122123
pems, jwtKeyFileName := cnf.updateSecrets(mergeableIngs.Master)
123-
masterNginxCfg := cnf.generateNginxCfg(mergeableIngs.Master, pems, jwtKeyFileName, false)
124+
isMinion := false
125+
masterNginxCfg := cnf.generateNginxCfg(mergeableIngs.Master, pems, jwtKeyFileName, isMinion)
124126

125127
masterServer = masterNginxCfg.Servers[0]
126128
masterServer.IngressResource = objectMetaToFileName(&mergeableIngs.Master.Ingress.ObjectMeta)
@@ -148,7 +150,8 @@ func (cnf *Configurator) generateNginxCfgForMergeableIngresses(mergeableIngs *Me
148150
}
149151

150152
pems, jwtKeyFileName := cnf.updateSecrets(minion)
151-
nginxCfg := cnf.generateNginxCfg(minion, pems, jwtKeyFileName, true)
153+
isMinion := true
154+
nginxCfg := cnf.generateNginxCfg(minion, pems, jwtKeyFileName, isMinion)
152155

153156
for _, server := range nginxCfg.Servers {
154157
for _, loc := range server.Locations {
@@ -201,7 +204,7 @@ func (cnf *Configurator) updateSecrets(ingEx *IngressEx) (map[string]string, str
201204
return pems, jwtKeyFileName
202205
}
203206

204-
func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]string, jwtKeyFileName string, minion bool) IngressNginxConfig {
207+
func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]string, jwtKeyFileName string, isMinion bool) IngressNginxConfig {
205208
ingCfg := cnf.createConfig(ingEx)
206209

207210
upstreams := make(map[string]Upstream)
@@ -269,7 +272,7 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
269272
server.SSLCertificateKey = pemFile
270273
}
271274

272-
if !minion && jwtKeyFileName != "" {
275+
if !isMinion && jwtKeyFileName != "" {
273276
server.JWTAuth = &JWTAuth{
274277
Key: jwtKeyFileName,
275278
Realm: ingCfg.JWTRealm,
@@ -318,7 +321,7 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
318321

319322
loc := createLocation(pathOrDefault(path.Path), upstreams[upsName], &ingCfg, wsServices[path.Backend.ServiceName], rewrites[path.Backend.ServiceName],
320323
sslServices[path.Backend.ServiceName], grpcServices[path.Backend.ServiceName])
321-
if minion && jwtKeyFileName != "" {
324+
if isMinion && jwtKeyFileName != "" {
322325
loc.JWTAuth = &JWTAuth{
323326
Key: jwtKeyFileName,
324327
Realm: ingCfg.JWTRealm,
@@ -856,7 +859,9 @@ func upstreamMapToSlice(upstreams map[string]Upstream) []Upstream {
856859
keys = append(keys, k)
857860
}
858861

859-
// this ensures that the slice 'result' is sorted, which is needed for repeatable Unit test results
862+
// this ensures that the slice 'result' is sorted, which preserves the order of upstream servers
863+
// in the generated configuration file from one version to another and is also required for repeatable
864+
// Unit test results
860865
sort.Strings(keys)
861866

862867
result := make([]Upstream, 0, len(upstreams))

0 commit comments

Comments
 (0)