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

Use a more unique name for upstreams #4

Closed
wants to merge 2 commits into from
Closed
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
40 changes: 14 additions & 26 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,25 @@ func (lbc *LoadBalancerController) updateNGINX(name string, ing *extensions.Ingr
}

var upstreams []nginx.Upstream
var servers []nginx.Server

for _, rule := range ing.Spec.Rules {
if rule.IngressRuleValue.HTTP == nil {
continue
}

server := nginx.Server{Name: rule.Host}

if pemFile, ok := pems[rule.Host]; ok {
server.SSL = true
server.SSLCertificate = pemFile
server.SSLCertificateKey = pemFile
}

var locations []nginx.Location

for _, path := range rule.HTTP.Paths {
name := ing.Name + "-" + path.Backend.ServiceName
name := path.Backend.ServiceName + "-Ingress-" + rule.Host + "-" + strings.Replace(path.Path, "/", "-", -1)
ups := nginx.NewUpstreamWithDefaultServer(name)

svcKey := ing.Namespace + "/" + path.Backend.ServiceName
Expand All @@ -297,32 +308,9 @@ func (lbc *LoadBalancerController) updateNGINX(name string, ing *extensions.Ingr
}
}

upstreams = append(upstreams, ups)
}
}

var servers []nginx.Server
for _, rule := range ing.Spec.Rules {
server := nginx.Server{Name: rule.Host}

if pemFile, ok := pems[rule.Host]; ok {
server.SSL = true
server.SSLCertificate = pemFile
server.SSLCertificateKey = pemFile
}

var locations []nginx.Location

for _, path := range rule.HTTP.Paths {
loc := nginx.Location{Path: path.Path}
upsName := ing.GetName() + "-" + path.Backend.ServiceName

for _, ups := range upstreams {
if upsName == ups.Name {
loc.Upstream = ups
}
}
loc := nginx.Location{Path: path.Path, Upstream: ups}
locations = append(locations, loc)
upstreams = append(upstreams, ups)
}

server.Locations = locations
Expand Down