Skip to content
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

Support more proxy annotations for Ingress #1089

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions pkg/object/ingresscontroller/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import (
"sort"
"strconv"
"strings"
"time"

"github.com/megaease/easegress/v2/pkg/object/httpserver/routers"

"github.com/megaease/easegress/v2/pkg/filters/proxies"
proxy "github.com/megaease/easegress/v2/pkg/filters/proxies/httpproxy"
"github.com/megaease/easegress/v2/pkg/logger"
"github.com/megaease/easegress/v2/pkg/object/httpserver"
Expand Down Expand Up @@ -72,12 +74,50 @@ func newPipelineSpecBuilder(name string) *pipelineSpecBuilder {
}
}

func (b *pipelineSpecBuilder) addProxy(endpoints []string) {
func (b *pipelineSpecBuilder) addProxy(endpoints []string, ingress *apinetv1.Ingress) error {
const name = "proxy"

proxyLoadBalance := ingress.Annotations["easegress.ingress.kubernetes.io/proxy-load-balance"]
proxyHeaderHashKey := ingress.Annotations["easegress.ingress.kubernetes.io/proxy-header-hash-key"]
proxyForwardKey := ingress.Annotations["easegress.ingress.kubernetes.io/proxy-forward-key"]
proxyServerMaxSize := ingress.Annotations["easegress.ingress.kubernetes.io/proxy-server-max-size"]
proxyTimeout := ingress.Annotations["easegress.ingress.kubernetes.io/proxy-timeout"]

switch proxyLoadBalance {
case "":
proxyLoadBalance = proxies.LoadBalancePolicyRoundRobin
case proxies.LoadBalancePolicyRoundRobin, proxies.LoadBalancePolicyRandom,
proxies.LoadBalancePolicyWeightedRandom, proxies.LoadBalancePolicyIPHash,
proxies.LoadBalancePolicyHeaderHash:
default:
return fmt.Errorf("invalid proxy-load-balance: %s", proxyLoadBalance)
}

var maxSize int64 = -1
if proxyServerMaxSize != "" {
result, err := strconv.ParseInt(proxyServerMaxSize, 0, 64)
if err != nil {
return fmt.Errorf("invalid proxy-server-max-size: %v", err)
}
maxSize = result
}

var timeout time.Duration
if proxyTimeout == "" {
result, err := time.ParseDuration(proxyTimeout)
if err != nil {
return fmt.Errorf("invalid proxy-timeout: %v", err)
}
timeout = result
}

pool := &proxy.ServerPoolSpec{
BaseServerPoolSpec: proxy.BaseServerPoolSpec{
LoadBalance: &proxy.LoadBalanceSpec{},
LoadBalance: &proxy.LoadBalanceSpec{
Policy: proxyLoadBalance,
HeaderHashKey: proxyHeaderHashKey,
ForwardKey: proxyForwardKey,
},
},
ServerMaxBodySize: -1,
}
Expand All @@ -88,10 +128,14 @@ func (b *pipelineSpecBuilder) addProxy(endpoints []string) {

b.Flow = append(b.Flow, pipeline.FlowNode{FilterName: name})
b.Filters = append(b.Filters, map[string]interface{}{
"kind": proxy.Kind,
"name": name,
"pools": []*proxy.ServerPoolSpec{pool},
"kind": proxy.Kind,
"name": name,
"pools": []*proxy.ServerPoolSpec{pool},
"serverMaxBodySize": maxSize,
"timeout": timeout,
})

return nil
}

func (b *pipelineSpecBuilder) addWebSocketProxy(endpoints []string, clntMaxMsgSize, svrMaxMsgSize int64, insecure bool, originPatterns []string) {
Expand Down Expand Up @@ -278,7 +322,10 @@ func (st *specTranslator) serviceToPipeline(ingress *apinetv1.Ingress, service *

builder.addWebSocketProxy(endpoints, clntMaxMsgSize, svrMaxMsgSize, insecure, originPatterns)
} else {
builder.addProxy(endpoints)
err := builder.addProxy(endpoints, ingress)
if err != nil {
return nil, fmt.Errorf("failed to add proxy: %v", err)
}
}

spec, err := supervisor.NewSpec(builder.jsonConfig())
Expand All @@ -305,7 +352,11 @@ func (st *specTranslator) translateDefaultPipeline(ingress *apinetv1.Ingress) er
}

builder := newPipelineSpecBuilder(defaultPipelineName)
builder.addProxy(endpoints)
err = builder.addProxy(endpoints, ingress)
if err != nil {
return fmt.Errorf("failed to add proxy: %v", err)
}

spec, err := supervisor.NewSpec(builder.jsonConfig())
if err != nil {
logger.Errorf("failed to generate pipeline spec: %v", err)
Expand Down