Skip to content

Commit 93284e6

Browse files
committed
Review comments
1 parent 18b7b79 commit 93284e6

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

cmd/agent/app/options/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ func (o *GrpcProxyAgentOptions) Validate() error {
211211
if _, err := labels.Parse(o.ServerLeaseSelector); err != nil {
212212
return fmt.Errorf("invalid server count lease selector: %w", err)
213213
}
214+
if o.KubeconfigPath == "" {
215+
return fmt.Errorf("kubeconfig path must be provided if server count lease system is enabled")
216+
}
214217
}
215218
if o.KubeconfigPath != "" {
216219
if _, err := os.Stat(o.KubeconfigPath); os.IsNotExist(err) {

cmd/agent/app/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func (a *Agent) runProxyConnection(o *options.GrpcProxyAgentOptions, drainCh, st
155155
serverLeaseSelector,
156156
)
157157
if err != nil {
158+
klog.Errorf("failed to create server lease counter: %v", err)
158159
return nil, fmt.Errorf("failed to create server lease counter: %w", err)
159160
}
160161
cc.ServerLeaseCounter = serverLeaseCounter

cmd/server/app/options/options.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,21 @@ func (o *ProxyRunOptions) Validate() error {
305305
}
306306

307307
// Validate leasing parameters. All must be empty or have a value.
308-
if o.LeaseLabelSelector != "" || o.LeaseDuration != 0 || o.LeaseGCInterval != 0 || o.LeaseRenewalInterval != 0 || o.LeaseNamespace != "" {
308+
if o.IsLeaseCountingEnabled() {
309309
if o.LeaseLabelSelector == "" {
310310
return fmt.Errorf("LeaseLabelSelector cannot be empty when leasing system is enabled")
311311
}
312312
if o.LeaseNamespace == "" {
313313
return fmt.Errorf("LeaseNamespace cannot be empty when leasing system is enabled")
314314
}
315-
if o.LeaseDuration == 0 {
316-
return fmt.Errorf("LeaseDuration cannot be zero when leasing system is enabled")
315+
if o.LeaseDuration <= 0 {
316+
return fmt.Errorf("LeaseDuration cannot be zero or negative when leasing system is enabled")
317317
}
318-
if o.LeaseGCInterval == 0 {
319-
return fmt.Errorf("LeaseGCInterval cannot be zero when leasing system is enabled")
318+
if o.LeaseGCInterval <= 0 {
319+
return fmt.Errorf("LeaseGCInterval cannot be zero or negative when leasing system is enabled")
320320
}
321-
if o.LeaseRenewalInterval == 0 {
322-
return fmt.Errorf("LeaseRenewalInterval cannot be zero when leasing system is enabled")
321+
if o.LeaseRenewalInterval <= 0 {
322+
return fmt.Errorf("LeaseRenewalInterval cannot be zero or negative when leasing system is enabled")
323323
}
324324
}
325325

@@ -398,3 +398,7 @@ func defaultServerID() string {
398398
}
399399
return uuid.New().String()
400400
}
401+
402+
func (o *ProxyRunOptions) IsLeaseCountingEnabled() bool {
403+
return o.LeaseLabelSelector != "" || o.LeaseDuration != 0 || o.LeaseGCInterval != 0 || o.LeaseRenewalInterval != 0 || o.LeaseNamespace != ""
404+
}

cmd/server/app/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ func (p *Proxy) Run(o *options.ProxyRunOptions, stopCh <-chan struct{}) error {
143143
defer frontendStop()
144144
}
145145

146-
if o.LeaseLabelSelector != "" || o.LeaseDuration != 0 || o.LeaseGCInterval != 0 || o.LeaseRenewalInterval != 0 {
146+
if o.IsLeaseCountingEnabled() {
147147
leaseLabels, err := labels.ConvertSelectorToLabelsMap(o.LeaseLabelSelector)
148148
if err != nil {
149-
return fmt.Errorf("could not parse lease label selector: %w", err)
149+
return fmt.Errorf("could not parse lease label selector (%q): %w", o.LeaseLabelSelector, err)
150150
}
151151
leaseController := leases.NewController(k8sClient, o.ServerID, int32(o.LeaseDuration.Seconds()), o.LeaseRenewalInterval, o.LeaseGCInterval, fmt.Sprintf("konnectivity-proxy-server-%v", o.ServerID), o.LeaseNamespace, leaseLabels)
152152
klog.V(1).Infoln("Starting lease acquisition and garbage collection controller.")

0 commit comments

Comments
 (0)