Specify backend servers' weight via annotation for kubernetes
This commit is contained in:
parent
f9b1106df2
commit
e8e36bd9d5
8 changed files with 1055 additions and 2 deletions
|
@ -184,6 +184,18 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
|
|||
}
|
||||
templateObjects.TLS = append(templateObjects.TLS, tlsSection...)
|
||||
|
||||
var weightAllocator weightAllocator = &defaultWeightAllocator{}
|
||||
annotationPercentageWeights := getAnnotationName(i.Annotations, annotationKubernetesServiceWeights)
|
||||
if _, ok := i.Annotations[annotationPercentageWeights]; ok {
|
||||
fractionalAllocator, err := newFractionalWeightAllocator(i, k8sClient)
|
||||
if err != nil {
|
||||
log.Errorf("failed to create fractional weight allocator for ingress %s/%s: %v", i.Namespace, i.Name, err)
|
||||
continue
|
||||
}
|
||||
log.Debugf("Created custom weight allocator for %s/%s: %s", i.Namespace, i.Name, fractionalAllocator)
|
||||
weightAllocator = fractionalAllocator
|
||||
}
|
||||
|
||||
for _, r := range i.Spec.Rules {
|
||||
if r.HTTP == nil {
|
||||
log.Warn("Error in ingress: HTTP is nil")
|
||||
|
@ -274,6 +286,7 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
|
|||
templateObjects.Backends[baseName].Buffering = getBuffering(service)
|
||||
|
||||
protocol := label.DefaultProtocol
|
||||
|
||||
for _, port := range service.Spec.Ports {
|
||||
if equalPorts(port, pa.Backend.ServicePort) {
|
||||
if port.Port == 443 || strings.HasPrefix(port.Name, "https") {
|
||||
|
@ -319,9 +332,10 @@ func (p *Provider) loadIngresses(k8sClient Client) (*types.Configuration, error)
|
|||
if address.TargetRef != nil && address.TargetRef.Name != "" {
|
||||
name = address.TargetRef.Name
|
||||
}
|
||||
|
||||
templateObjects.Backends[baseName].Servers[name] = types.Server{
|
||||
URL: url,
|
||||
Weight: label.DefaultWeight,
|
||||
Weight: weightAllocator.getWeight(r.Host, pa.Path, pa.Backend.ServiceName),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue