Skip to content

Commit 62e778d

Browse files
committed
restore int value
Signed-off-by: Karol Szwaj <[email protected]>
1 parent d0471d8 commit 62e778d

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

cmd/agent/app/options/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type GrpcProxyAgentOptions struct {
7979
WarnOnChannelLimit bool
8080

8181
SyncForever bool
82-
XfrChannelSize uint
82+
XfrChannelSize int
8383
}
8484

8585
func (o *GrpcProxyAgentOptions) ClientSetConfig(dialOptions ...grpc.DialOption) *agent.ClientSetConfig {
@@ -121,7 +121,7 @@ func (o *GrpcProxyAgentOptions) Flags() *pflag.FlagSet {
121121
flags.StringVar(&o.AgentIdentifiers, "agent-identifiers", o.AgentIdentifiers, "Identifiers of the agent that will be used by the server when choosing agent. N.B. the list of identifiers must be in URL encoded format. e.g.,host=localhost&host=node1.mydomain.com&cidr=127.0.0.1/16&ipv4=1.2.3.4&ipv4=5.6.7.8&ipv6=:::::&default-route=true")
122122
flags.BoolVar(&o.WarnOnChannelLimit, "warn-on-channel-limit", o.WarnOnChannelLimit, "Turns on a warning if the system is going to push to a full channel. The check involves an unsafe read.")
123123
flags.BoolVar(&o.SyncForever, "sync-forever", o.SyncForever, "If true, the agent continues syncing, in order to support server count changes.")
124-
flags.UintVar(&o.XfrChannelSize, "xfr-channel-size", 150, "Set the size of the channel")
124+
flags.IntVar(&o.XfrChannelSize, "xfr-channel-size", 150, "Set the size of the channel for transferring data between the agent and the proxy server.")
125125
return flags
126126
}
127127

cmd/agent/app/options/options_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestDefaultServerOptions(t *testing.T) {
5050
assertDefaultValue(t, "ServiceAccountTokenPath", defaultAgentOptions.ServiceAccountTokenPath, "")
5151
assertDefaultValue(t, "WarnOnChannelLimit", defaultAgentOptions.WarnOnChannelLimit, false)
5252
assertDefaultValue(t, "SyncForever", defaultAgentOptions.SyncForever, false)
53-
assertDefaultValue(t, "XfrChannelSize", defaultAgentOptions.XfrChannelSize, uint(150))
53+
assertDefaultValue(t, "XfrChannelSize", defaultAgentOptions.XfrChannelSize, 150)
5454
}
5555

5656
func assertDefaultValue(t *testing.T, fieldName string, actual, expected interface{}) {
@@ -148,9 +148,13 @@ func TestValidate(t *testing.T) {
148148
expected: fmt.Errorf("if --enable-contention-profiling is set, --enable-profiling must also be set"),
149149
},
150150
"ZeroXfrChannelSize": {
151-
fieldMap: map[string]interface{}{"XfrChannelSize": uint(0)},
151+
fieldMap: map[string]interface{}{"XfrChannelSize": 0},
152152
expected: fmt.Errorf("channel size 0 must be greater than 0"),
153153
},
154+
"NegativeXfrChannelSize": {
155+
fieldMap: map[string]interface{}{"XfrChannelSize": -10},
156+
expected: fmt.Errorf("channel size -10 must be greater than 0"),
157+
},
154158
} {
155159
t.Run(desc, func(t *testing.T) {
156160
testAgentOptions := NewGrpcProxyAgentOptions()
@@ -168,9 +172,6 @@ func TestValidate(t *testing.T) {
168172
case reflect.Bool:
169173
bvalue := value.(bool)
170174
fv.SetBool(bvalue)
171-
case reflect.Uint:
172-
uvalue := value.(uint)
173-
fv.SetUint(uint64(uvalue))
174175
}
175176
}
176177
actual := testAgentOptions.Validate()

cmd/server/app/options/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type ProxyRunOptions struct {
101101
// NOTE that cipher suites are not configurable for TLS1.3,
102102
// see: https://pkg.go.dev/crypto/tls#Config, so in that case, this option won't have any effect.
103103
CipherSuites []string
104-
XfrChannelSize uint
104+
XfrChannelSize int
105105
}
106106

107107
func (o *ProxyRunOptions) Flags() *pflag.FlagSet {
@@ -137,7 +137,7 @@ func (o *ProxyRunOptions) Flags() *pflag.FlagSet {
137137
flags.StringVar(&o.AuthenticationAudience, "authentication-audience", o.AuthenticationAudience, "Expected agent's token authentication audience (used with agent-namespace, agent-service-account, kubeconfig).")
138138
flags.StringVar(&o.ProxyStrategies, "proxy-strategies", o.ProxyStrategies, "The list of proxy strategies used by the server to pick an agent/tunnel, available strategies are: default, destHost, defaultRoute.")
139139
flags.StringSliceVar(&o.CipherSuites, "cipher-suites", o.CipherSuites, "The comma separated list of allowed cipher suites. Has no effect on TLS1.3. Empty means allow default list.")
140-
flags.UintVar(&o.XfrChannelSize, "xfr-channel-size", o.XfrChannelSize, "The size of the channel for transferring data between the proxy server and the agent.")
140+
flags.IntVar(&o.XfrChannelSize, "xfr-channel-size", o.XfrChannelSize, "The size of the channel for transferring data between the proxy server and the agent.")
141141

142142
flags.Bool("warn-on-channel-limit", true, "This behavior is now thread safe and always on. This flag will be removed in a future release.")
143143
flags.MarkDeprecated("warn-on-channel-limit", "This behavior is now thread safe and always on. This flag will be removed in a future release.")

cmd/server/app/options/options_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestDefaultServerOptions(t *testing.T) {
6161
assertDefaultValue(t, "AuthenticationAudience", defaultServerOptions.AuthenticationAudience, "")
6262
assertDefaultValue(t, "ProxyStrategies", defaultServerOptions.ProxyStrategies, "default")
6363
assertDefaultValue(t, "CipherSuites", defaultServerOptions.CipherSuites, make([]string, 0))
64-
assertDefaultValue(t, "XfrChannelSize", defaultServerOptions.XfrChannelSize, uint(10))
64+
assertDefaultValue(t, "XfrChannelSize", defaultServerOptions.XfrChannelSize, 10)
6565

6666
}
6767

@@ -159,9 +159,14 @@ func TestValidate(t *testing.T) {
159159
},
160160
"ZeroXfrChannelSize": {
161161
field: "XfrChannelSize",
162-
value: uint(0),
162+
value: 0,
163163
expected: fmt.Errorf("channel size 0 must be greater than 0"),
164164
},
165+
"NegativeXfrChannelSize": {
166+
field: "XfrChannelSize",
167+
value: -10,
168+
expected: fmt.Errorf("channel size -10 must be greater than 0"),
169+
},
165170
} {
166171
t.Run(desc, func(t *testing.T) {
167172
testServerOptions := NewProxyRunOptions()
@@ -178,9 +183,6 @@ func TestValidate(t *testing.T) {
178183
case reflect.Int:
179184
ivalue := tc.value.(int)
180185
fv.SetInt(int64(ivalue))
181-
case reflect.Uint:
182-
uvalue := tc.value.(uint)
183-
fv.SetUint(uint64(uvalue))
184186
}
185187
}
186188
actual := testServerOptions.Validate()

pkg/agent/clientset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type ClientSet struct {
6161
// by the server when choosing agent
6262

6363
warnOnChannelLimit bool
64-
xfrChannelSize uint
64+
xfrChannelSize int
6565

6666
syncForever bool // Continue syncing (support dynamic server count).
6767
}
@@ -142,7 +142,7 @@ type ClientSetConfig struct {
142142
ServiceAccountTokenPath string
143143
WarnOnChannelLimit bool
144144
SyncForever bool
145-
XfrChannelSize uint
145+
XfrChannelSize int
146146
}
147147

148148
func (cc *ClientSetConfig) NewAgentClientSet(drainCh, stopCh <-chan struct{}) *ClientSet {

pkg/server/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ type ProxyServer struct {
216216

217217
// TODO: move strategies into BackendStorage
218218
proxyStrategies []ProxyStrategy
219-
xfrChannelSize uint
219+
xfrChannelSize int
220220
}
221221

222222
// AgentTokenAuthenticationOptions contains list of parameters required for agent token based authentication
@@ -375,7 +375,7 @@ func (s *ProxyServer) removeEstablishedForStream(streamUID string) []*ProxyClien
375375
}
376376

377377
// NewProxyServer creates a new ProxyServer instance
378-
func NewProxyServer(serverID string, proxyStrategies []ProxyStrategy, serverCount int, agentAuthenticationOptions *AgentTokenAuthenticationOptions, channelSize uint) *ProxyServer {
378+
func NewProxyServer(serverID string, proxyStrategies []ProxyStrategy, serverCount int, agentAuthenticationOptions *AgentTokenAuthenticationOptions, channelSize int) *ProxyServer {
379379
var bms []BackendManager
380380
for _, ps := range proxyStrategies {
381381
switch ps {
@@ -417,7 +417,7 @@ func (s *ProxyServer) Proxy(stream client.ProxyService_ProxyServer) error {
417417
streamUID := uuid.New().String()
418418
klog.V(5).InfoS("Proxy request from client", "userAgent", userAgent, "serverID", s.serverID, "streamUID", streamUID)
419419

420-
recvCh := make(chan *client.Packet, int(s.xfrChannelSize))
420+
recvCh := make(chan *client.Packet, s.xfrChannelSize)
421421
stopCh := make(chan error, 1)
422422

423423
frontend := GrpcFrontend{

0 commit comments

Comments
 (0)