2018-04-02 22:45:10 +00:00
|
|
|
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
|
2019-02-15 20:54:42 +00:00
|
|
|
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
|
|
|
|
}
|