mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
Merge pull request #2635 from thockin/public-ip
Enable public IPs even in not createExternal...
This commit is contained in:
commit
6b009f06cd
@ -40,8 +40,7 @@ type serviceInfo struct {
|
||||
timeout time.Duration
|
||||
mu sync.Mutex // protects active
|
||||
active bool
|
||||
// TODO: make this an net.IP address
|
||||
publicIP []string
|
||||
publicIP []string // TODO: make this a []net.IP
|
||||
}
|
||||
|
||||
func (si *serviceInfo) isActive() bool {
|
||||
@ -449,7 +448,7 @@ func (proxier *Proxier) OnUpdate(services []api.Service) {
|
||||
if exists && info.isActive() && info.portalPort == service.Spec.Port && info.portalIP.Equal(serviceIP) {
|
||||
continue
|
||||
}
|
||||
if exists && (info.portalPort != service.Spec.Port || !info.portalIP.Equal(serviceIP) || service.Spec.CreateExternalLoadBalancer != (len(info.publicIP) > 0)) {
|
||||
if exists && (info.portalPort != service.Spec.Port || !info.portalIP.Equal(serviceIP) || !ipsEqual(service.Spec.PublicIPs, info.publicIP)) {
|
||||
glog.V(4).Infof("Something changed for service %q: stopping it", service.Name)
|
||||
err := proxier.closePortal(service.Name, info)
|
||||
if err != nil {
|
||||
@ -468,9 +467,7 @@ func (proxier *Proxier) OnUpdate(services []api.Service) {
|
||||
}
|
||||
info.portalIP = serviceIP
|
||||
info.portalPort = service.Spec.Port
|
||||
if service.Spec.CreateExternalLoadBalancer {
|
||||
info.publicIP = service.Spec.PublicIPs
|
||||
}
|
||||
info.publicIP = service.Spec.PublicIPs
|
||||
err = proxier.openPortal(service.Name, info)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to open portal for %q: %v", service.Name, err)
|
||||
@ -493,6 +490,18 @@ func (proxier *Proxier) OnUpdate(services []api.Service) {
|
||||
}
|
||||
}
|
||||
|
||||
func ipsEqual(lhs, rhs []string) bool {
|
||||
if len(lhs) != len(rhs) {
|
||||
return false
|
||||
}
|
||||
for i := range lhs {
|
||||
if lhs[i] != rhs[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (proxier *Proxier) openPortal(service string, info *serviceInfo) error {
|
||||
args := iptablesPortalArgs(info.portalIP, info.portalPort, info.protocol, proxier.listenAddress, info.proxyPort, service)
|
||||
existed, err := proxier.iptables.EnsureRule(iptables.TableNAT, iptablesProxyChain, args...)
|
||||
|
@ -130,21 +130,21 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var ip net.IP
|
||||
if len(service.Spec.PublicIPs) > 0 {
|
||||
for _, publicIP := range service.Spec.PublicIPs {
|
||||
ip, err = balancer.CreateTCPLoadBalancer(service.Name, zone.Region, net.ParseIP(publicIP), service.Spec.Port, hostsFromMinionList(hosts))
|
||||
_, err = balancer.CreateTCPLoadBalancer(service.Name, zone.Region, net.ParseIP(publicIP), service.Spec.Port, hostsFromMinionList(hosts))
|
||||
if err != nil {
|
||||
break
|
||||
// TODO: have to roll-back any successful calls.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ip, err = balancer.CreateTCPLoadBalancer(service.Name, zone.Region, nil, service.Spec.Port, hostsFromMinionList(hosts))
|
||||
ip, err := balancer.CreateTCPLoadBalancer(service.Name, zone.Region, nil, service.Spec.Port, hostsFromMinionList(hosts))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
service.Spec.PublicIPs = []string{ip.String()}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
service.Spec.PublicIPs = []string{ip.String()}
|
||||
}
|
||||
err := rs.registry.CreateService(ctx, service)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user