Skip to content

Commit

Permalink
Use svc.Spec.ExternalTrafficPolicy (#489)
Browse files Browse the repository at this point in the history
Fixes #276
  • Loading branch information
tamalsaha committed Dec 13, 2017
1 parent 9d5f1e7 commit 7a5679d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 0 additions & 3 deletions apis/voyager/v1beta1/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,6 @@ func (r Ingress) ServiceAnnotations(provider string) (map[string]string, bool) {
case "aws":
// ref: https://github.com/kubernetes/kubernetes/blob/release-1.5/pkg/cloudprovider/providers/aws/aws.go#L79
filteredMap["service.beta.kubernetes.io/aws-load-balancer-proxy-protocol"] = "*"
case "gce", "gke", "azure", "acs":
// ref: https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-typeloadbalancer
filteredMap["service.beta.kubernetes.io/external-traffic"] = "OnlyLocal"
}
}
return filteredMap, true
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingress/hostport.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func (c *hostPortController) newPods() *apps.Deployment {
},
Volumes: Volumes(secrets),
HostNetwork: true,
DNSPolicy: apiv1.DNSClusterFirstWithHostNet,
DNSPolicy: apiv1.DNSClusterFirstWithHostNet,
},
},
},
Expand Down
9 changes: 9 additions & 0 deletions pkg/ingress/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,15 @@ func (c *loadBalancerController) newService() *apiv1.Service {
}
}

if c.Ingress.LBType() == api.LBTypeLoadBalancer && c.Ingress.KeepSourceIP() {
switch c.Opt.CloudProvider {
case "gce", "gke", "azure", "acs":
// https://github.com/appscode/voyager/issues/276
// ref: https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-typeloadbalancer
svc.Spec.ExternalTrafficPolicy = apiv1.ServiceExternalTrafficPolicyTypeLocal
}
}

switch c.Opt.CloudProvider {
case "gce", "gke":
if ip := c.Ingress.LoadBalancerIP(); ip != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/ingress/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func (c *controller) serviceRequiresUpdate(current, desired *apiv1.Service, old
current.Spec.LoadBalancerSourceRanges = desired.Spec.LoadBalancerSourceRanges
}

if current.Spec.ExternalTrafficPolicy != desired.Spec.ExternalTrafficPolicy {
needsUpdate = true
current.Spec.ExternalTrafficPolicy = desired.Spec.ExternalTrafficPolicy
}

return current, needsUpdate
}

Expand Down

0 comments on commit 7a5679d

Please sign in to comment.