-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.go
30 lines (26 loc) · 900 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package client
import (
"context"
"github.com/aojea/client-go-multidialer/multidialer"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
// NewForConfig creates a resilient client-go that, in case of connection failures,
// tries to connect to all the available apiservers in the cluster.
func NewForConfig(ctx context.Context, config *rest.Config) (*kubernetes.Clientset, error) {
// create the clientset
configShallowCopy := *config
// it wraps the custom dialer if exists
d := multidialer.NewDialer(configShallowCopy.Dial)
// use the multidialier for our clientset
configShallowCopy.Dial = d.DialContext
// create the clientset with our own dialer
cs, err := kubernetes.NewForConfig(&configShallowCopy)
if err != nil {
return cs, err
}
// start the resolver to update the list of available apiservers
// !!! using our own dialer !!!
d.Start(ctx, cs)
return cs, nil
}