mirror of https://github.com/k3s-io/k3s.git
Don't crash when service IPFamiliyPolicy is not set
Service.Spec.IPFamilyPolicy may be a nil pointer on freshly upgraded clusters. Signed-off-by: Brad Davidson <brad.davidson@rancher.com>pull/5812/head
parent
ff6c233e41
commit
961c8274a9
|
@ -189,7 +189,7 @@ func (h *handler) onChangeNode(key string, node *core.Node) (*core.Node, error)
|
||||||
// updateService ensures that the Service ingress IP address list is in sync
|
// updateService ensures that the Service ingress IP address list is in sync
|
||||||
// with the Nodes actually running pods for this service.
|
// with the Nodes actually running pods for this service.
|
||||||
func (h *handler) updateService(svc *core.Service) (runtime.Object, error) {
|
func (h *handler) updateService(svc *core.Service) (runtime.Object, error) {
|
||||||
if !h.enabled {
|
if !h.enabled || svc.Spec.Type != core.ServiceTypeLoadBalancer {
|
||||||
return svc, nil
|
return svc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ func (h *handler) podIPs(pods []*core.Pod, svc *core.Service) ([]string, error)
|
||||||
|
|
||||||
// filterByIPFamily filters ips based on dual-stack parameters of the service
|
// filterByIPFamily filters ips based on dual-stack parameters of the service
|
||||||
func filterByIPFamily(ips []string, svc *core.Service) ([]string, error) {
|
func filterByIPFamily(ips []string, svc *core.Service) ([]string, error) {
|
||||||
|
var ipFamilyPolicy core.IPFamilyPolicyType
|
||||||
var ipv4Addresses []string
|
var ipv4Addresses []string
|
||||||
var ipv6Addresses []string
|
var ipv6Addresses []string
|
||||||
|
|
||||||
|
@ -314,7 +314,11 @@ func filterByIPFamily(ips []string, svc *core.Service) ([]string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch *svc.Spec.IPFamilyPolicy {
|
if svc.Spec.IPFamilyPolicy != nil {
|
||||||
|
ipFamilyPolicy = *svc.Spec.IPFamilyPolicy
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ipFamilyPolicy {
|
||||||
case core.IPFamilyPolicySingleStack:
|
case core.IPFamilyPolicySingleStack:
|
||||||
if svc.Spec.IPFamilies[0] == core.IPv4Protocol {
|
if svc.Spec.IPFamilies[0] == core.IPv4Protocol {
|
||||||
return ipv4Addresses, nil
|
return ipv4Addresses, nil
|
||||||
|
|
Loading…
Reference in New Issue