Skip to content

Commit

Permalink
fix: avoid nodePort conflict in forked and canary service (#16)
Browse files Browse the repository at this point in the history
* fix: avoid nodePort conflict in forked and canary service

* feat: set all generated services' type to ClusterIP
  • Loading branch information
Jun Zhang authored Apr 25, 2018
1 parent 8e1c6b1 commit be427e0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion proxies/nginx/controller/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ func (p *Proxy) getUpsteamService(svcCol []*serviceCollection) ([]api.L4Service,
}

// render all needed services
// all generated services' type is ClusterIP
func (p *Proxy) renderService(originObj, canaryObj []runtime.Object, cr *releaseapi.CanaryRelease) ([]*serviceCollection, error) {
services := make([]*serviceCollection, 0, len(cr.Spec.Service))
for _, svc := range cr.Spec.Service {
Expand All @@ -699,7 +700,16 @@ func (p *Proxy) renderService(originObj, canaryObj []runtime.Object, cr *release
// fork origin service
// change it's name and add owner reference
copy := *s.origin
// change forked service name
copy.Name += forkedServiceSuffix
// reset nodePort, avoid conflict
if copy.Spec.Type == core.ServiceTypeNodePort {
for i := range copy.Spec.Ports {
copy.Spec.Ports[i].NodePort = 0
}
}
// change forked service type to ClusterIP
copy.Spec.Type = core.ServiceTypeClusterIP
s.forked = &copy

// get in-cluster service
Expand All @@ -717,7 +727,14 @@ func (p *Proxy) renderService(originObj, canaryObj []runtime.Object, cr *release
}
// change canary service name
s.canary.Name += canaryServiceSuffix

// reset nodePort, avoid conflict
if s.canary.Spec.Type == core.ServiceTypeNodePort {
for i := range s.canary.Spec.Ports {
s.canary.Spec.Ports[i].NodePort = 0
}
}
// change canary service type to ClusterIP
s.canary.Spec.Type = core.ServiceTypeClusterIP
services = append(services, s)
}

Expand Down

0 comments on commit be427e0

Please sign in to comment.