mirror of
https://github.com/rancher/norman.git
synced 2025-09-13 22:01:34 +00:00
Add timeouts to rest clients
This commit is contained in:
43
restwatch/rest.go
Normal file
43
restwatch/rest.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package restwatch
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
type WatchClient interface {
|
||||
WatchClient() rest.Interface
|
||||
}
|
||||
|
||||
func UnversionedRESTClientFor(config *rest.Config) (rest.Interface, error) {
|
||||
client, err := rest.UnversionedRESTClientFor(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if config.Timeout == 0 {
|
||||
return client, err
|
||||
}
|
||||
|
||||
newConfig := *config
|
||||
newConfig.Timeout = time.Hour
|
||||
watchClient, err := rest.UnversionedRESTClientFor(&newConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &clientWithWatch{
|
||||
RESTClient: client,
|
||||
watchClient: watchClient,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type clientWithWatch struct {
|
||||
*rest.RESTClient
|
||||
watchClient *rest.RESTClient
|
||||
}
|
||||
|
||||
func (c *clientWithWatch) WatchClient() rest.Interface {
|
||||
return c.watchClient
|
||||
}
|
Reference in New Issue
Block a user