-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kubernetes support externalname service #1149
Changes from 3 commits
0947aa9
0b1dd69
4d3aede
931ee55
96e6c9c
c8cf5f8
1e10fc2
66cc9a0
49466d0
71c7920
4106f0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,6 @@ func (provider *Kubernetes) loadIngresses(k8sClient k8s.Client) (*types.Configur | |
map[string]*types.Backend{}, | ||
map[string]*types.Frontend{}, | ||
} | ||
PassHostHeader := provider.getPassHostHeader() | ||
for _, i := range ingresses { | ||
for _, r := range i.Spec.Rules { | ||
if r.HTTP == nil { | ||
|
@@ -124,6 +123,18 @@ func (provider *Kubernetes) loadIngresses(k8sClient k8s.Client) (*types.Configur | |
}, | ||
} | ||
} | ||
|
||
PassHostHeader := provider.getPassHostHeader() | ||
|
||
passHostHeaderAnnotation := i.Annotations["traefik.frontend.passHostHeader"] | ||
switch passHostHeaderAnnotation { | ||
case "true": | ||
PassHostHeader = true | ||
case "false": | ||
PassHostHeader = false | ||
|
||
} | ||
|
||
if _, exists := templateObjects.Frontends[r.Host+pa.Path]; !exists { | ||
templateObjects.Frontends[r.Host+pa.Path] = &types.Frontend{ | ||
Backend: r.Host + pa.Path, | ||
|
@@ -193,28 +204,38 @@ func (provider *Kubernetes) loadIngresses(k8sClient k8s.Client) (*types.Configur | |
if port.Port == 443 { | ||
protocol = "https" | ||
} | ||
endpoints, exists, err := k8sClient.GetEndpoints(service.ObjectMeta.Namespace, service.ObjectMeta.Name) | ||
if err != nil || !exists { | ||
log.Errorf("Error retrieving endpoints %s/%s: %v", service.ObjectMeta.Namespace, service.ObjectMeta.Name, err) | ||
continue | ||
} | ||
if len(endpoints.Subsets) == 0 { | ||
log.Warnf("Endpoints not found for %s/%s, falling back to Service ClusterIP", service.ObjectMeta.Namespace, service.ObjectMeta.Name) | ||
templateObjects.Backends[r.Host+pa.Path].Servers[string(service.UID)] = types.Server{ | ||
URL: protocol + "://" + service.Spec.ClusterIP + ":" + strconv.Itoa(int(port.Port)), | ||
if service.Spec.Type == "ExternalName" { | ||
url := protocol + "://" + service.Spec.ExternalName | ||
name := url | ||
|
||
templateObjects.Backends[r.Host+pa.Path].Servers[name] = types.Server{ | ||
URL: url, | ||
Weight: 1, | ||
} | ||
} else { | ||
for _, subset := range endpoints.Subsets { | ||
for _, address := range subset.Addresses { | ||
url := protocol + "://" + address.IP + ":" + strconv.Itoa(endpointPortNumber(port, subset.Ports)) | ||
name := url | ||
if address.TargetRef != nil && address.TargetRef.Name != "" { | ||
name = address.TargetRef.Name | ||
} | ||
templateObjects.Backends[r.Host+pa.Path].Servers[name] = types.Server{ | ||
URL: url, | ||
Weight: 1, | ||
endpoints, exists, err := k8sClient.GetEndpoints(service.ObjectMeta.Namespace, service.ObjectMeta.Name) | ||
if err != nil || !exists { | ||
log.Errorf("Error retrieving endpoints %s/%s: %v", service.ObjectMeta.Namespace, service.ObjectMeta.Name, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The log message won't be very useful if we hit the I'd rather use an if/else-if or switch construct to produce two distinct messages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to make the change, but that is how it was before I touched anything. Mostly I don't fully understand what the different between the two is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say let's be good boy scouts and leave the place a bit tidier than how we found it. :-) Which two do you mean? If/else-if and select? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I meant the error and exists. Not sure what the log message for each should be as I don't fully understand what they mean. After a quick look it seems err would mean there was an error in contacting the k8s API and exists would mean there are endpoints in the response. Not 100% sure on that though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's basically right: If some error occurs during the If the API call succeeds but no endpoints were found for the given namespace and name, One last note: If you split up the OR'ed statement in order to make the error message more specific, be sure to check and handle the |
||
continue | ||
} | ||
if len(endpoints.Subsets) == 0 { | ||
log.Warnf("Endpoints not found for %s/%s, falling back to Service ClusterIP", service.ObjectMeta.Namespace, service.ObjectMeta.Name) | ||
templateObjects.Backends[r.Host+pa.Path].Servers[string(service.UID)] = types.Server{ | ||
URL: protocol + "://" + service.Spec.ClusterIP + ":" + strconv.Itoa(int(port.Port)), | ||
Weight: 1, | ||
} | ||
} else { | ||
for _, subset := range endpoints.Subsets { | ||
for _, address := range subset.Addresses { | ||
url := protocol + "://" + address.IP + ":" + strconv.Itoa(endpointPortNumber(port, subset.Ports)) | ||
name := url | ||
if address.TargetRef != nil && address.TargetRef.Name != "" { | ||
name = address.TargetRef.Name | ||
} | ||
templateObjects.Backends[r.Host+pa.Path].Servers[name] = types.Server{ | ||
URL: url, | ||
Weight: 1, | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add a
default
case to log a warning. I'd then also add a test making sure that an invalid value does not change thePassHostHeader
value.