mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 20:42:26 +00:00
Enable public IPs even in not createExternal...
This allows the proxier to portal Public IPs even if the createExternalLoadBalancer flag is not set. This also fixes what appears to be a bug in the createExternalLoadBalancer path wherein multiple PublicIPs would get truncated.
This commit is contained in:
parent
b614f22935
commit
0c03f6e784
@ -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 {
|
||||
@ -445,7 +444,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 {
|
||||
@ -464,9 +463,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)
|
||||
@ -489,6 +486,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