Commit 9cee7bd5 authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

Don't crash when service IPFamiliyPolicy is not set

Service.Spec.IPFamilyPolicy may be a nil pointer on freshly upgraded clusters. Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com>
parent 15ad1632
...@@ -189,7 +189,7 @@ func (h *handler) onChangeNode(key string, node *core.Node) (*core.Node, error) ...@@ -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) ...@@ -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) { ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment