1
0
mirror of https://github.com/rancher/norman.git synced 2025-05-04 22:26:28 +00:00
norman/restwatch/rest.go

50 lines
1.0 KiB
Go
Raw Normal View History

2018-04-02 22:45:10 +00:00
package restwatch
import (
"time"
2024-06-04 10:02:09 +00:00
"github.com/rancher/wrangler/v3/pkg/ratelimit"
2018-04-02 22:45:10 +00:00
"k8s.io/client-go/rest"
)
type WatchClient interface {
WatchClient() rest.Interface
}
func UnversionedRESTClientFor(config *rest.Config) (rest.Interface, error) {
// k8s <= 1.16 would not rate limit when calling UnversionedRESTClientFor(config)
// this keeps that behavior which seems to be relied on in Rancher.
if config.QPS == 0.0 && config.RateLimiter == nil {
config.RateLimiter = ratelimit.None
}
2018-04-02 22:45:10 +00:00
client, err := rest.UnversionedRESTClientFor(config)
if err != nil {
return nil, err
}
if config.Timeout == 0 {
return client, err
}
newConfig := *config
newConfig.Timeout = 30 * time.Minute
2018-04-02 22:45:10 +00:00
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
}