Skip to content

Commit 9715e68

Browse files
add the default proxy strategy
1 parent 1ffc0f0 commit 9715e68

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

cmd/server/main.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ func (o *ProxyRunOptions) Validate() error {
297297
if o.proxyStrategies != "" {
298298
pss := strings.Split(o.proxyStrategies, ",")
299299
for _, ps := range pss {
300-
if ps != string(server.ProxyStrategyDestHost) {
300+
switch ps {
301+
case string(server.ProxyStrategyDestHost):
302+
case string(server.ProxyStrategyDefault):
303+
default:
301304
return fmt.Errorf("unknown proxy strategy: %s, available strategy is: destHost", ps)
302305
}
303306
}
@@ -330,7 +333,7 @@ func newProxyRunOptions() *ProxyRunOptions {
330333
agentServiceAccount: "",
331334
kubeconfigPath: "",
332335
authenticationAudience: "",
333-
proxyStrategies: "",
336+
proxyStrategies: "default",
334337
}
335338
return &o
336339
}
@@ -381,7 +384,10 @@ func (p *Proxy) run(o *ProxyRunOptions) error {
381384
AuthenticationAudience: o.authenticationAudience,
382385
}
383386
klog.V(1).Infoln("Starting master server for client connections.")
384-
ps := server.GenProxyStrategiesFromStr(o.proxyStrategies)
387+
ps, err := server.GenProxyStrategiesFromStr(o.proxyStrategies)
388+
if err != nil {
389+
return err
390+
}
385391
server := server.NewProxyServer(o.serverID, ps, int(o.serverCount), authOpt)
386392

387393
masterStop, err := p.runMasterServer(ctx, o, server)

pkg/server/backend_manager.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,26 @@ import (
3333
type ProxyStrategy string
3434

3535
const (
36+
ProxyStrategyDefault ProxyStrategy = "default"
3637
ProxyStrategyDestHost ProxyStrategy = "destHost"
3738
)
3839

3940
// GenProxyStrategiesFromStr generates the list of proxy strategies from the
4041
// comma-seperated string, i.e., destHost.
41-
func GenProxyStrategiesFromStr(proxyStrategies string) []ProxyStrategy {
42+
func GenProxyStrategiesFromStr(proxyStrategies string) ([]ProxyStrategy, error) {
4243
var ps []ProxyStrategy
4344
strs := strings.Split(proxyStrategies, ",")
4445
for _, s := range strs {
4546
switch s {
4647
case string(ProxyStrategyDestHost):
4748
ps = append(ps, ProxyStrategyDestHost)
49+
case string(ProxyStrategyDefault):
50+
ps = append(ps, ProxyStrategyDefault)
4851
default:
49-
klog.V(4).InfoS("Unknown proxy strategy", "strategy", s)
52+
return nil, fmt.Errorf("Unknown proxy strategy %s", s)
5053
}
5154
}
52-
return ps
55+
return ps, nil
5356
}
5457

5558
type Backend interface {
@@ -168,7 +171,7 @@ func containIdType(idTypes []pkgagent.IdentifierType, idType pkgagent.Identifier
168171
// AddBackend adds a backend.
169172
func (s *DefaultBackendStorage) AddBackend(identifier string, idType pkgagent.IdentifierType, conn agent.AgentService_ConnectServer) Backend {
170173
if !containIdType(s.idTypes, idType) {
171-
klog.V(4).InfoS("fial to add backend", "backend", identifier, "error", &ErrWrongIDType{idType, s.idTypes})
174+
klog.V(4).InfoS("fail to add backend", "backend", identifier, "error", &ErrWrongIDType{idType, s.idTypes})
172175
return nil
173176
}
174177
klog.V(2).InfoS("Register backend for agent", "connection", conn, "agentID", identifier)

pkg/server/server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,12 @@ func NewProxyServer(serverID string, proxyStrategies []ProxyStrategy, serverCoun
296296
switch ps {
297297
case ProxyStrategyDestHost:
298298
bms = append(bms, NewDestHostBackendManager())
299+
case ProxyStrategyDefault:
300+
bms = append(bms, NewDefaultBackendManager())
299301
default:
302+
klog.V(4).InfoS("Unknonw proxy strategy", "strategy", ps)
300303
}
301304
}
302-
bms = append(bms, NewDefaultBackendManager())
303305

304306
return &ProxyServer{
305307
frontends: make(map[string](map[int64]*ProxyClientConnection)),

0 commit comments

Comments
 (0)