-
Notifications
You must be signed in to change notification settings - Fork 580
/
client_config.go
92 lines (73 loc) · 2.93 KB
/
client_config.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package kubeapi
/*
Copyright 2020 Crunchy Data Solutions, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
crunchydata "github.com/crunchydata/postgres-operator/pkg/generated/clientset/versioned"
crunchydatascheme "github.com/crunchydata/postgres-operator/pkg/generated/clientset/versioned/scheme"
crunchydatav1 "github.com/crunchydata/postgres-operator/pkg/generated/clientset/versioned/typed/crunchydata.com/v1"
)
func init() {
// Register all types of our clientset into the standard scheme.
_ = crunchydatascheme.AddToScheme(scheme.Scheme)
}
type Interface interface {
kubernetes.Interface
CrunchydataV1() crunchydatav1.CrunchydataV1Interface
}
// Interface should satisfy both our typed Interface and the standard one.
var _ crunchydata.Interface = Interface(nil)
var _ kubernetes.Interface = Interface(nil)
// Client provides methods for interacting with Kubernetes resources.
// It implements both kubernetes and crunchydata clientset Interfaces.
type Client struct {
*rest.Config
*kubernetes.Clientset
crunchydataV1 *crunchydatav1.CrunchydataV1Client
}
// Client should satisfy Interface.
var _ Interface = &Client{}
// CrunchydataV1 retrieves the CrunchydataV1Client
func (c *Client) CrunchydataV1() crunchydatav1.CrunchydataV1Interface { return c.crunchydataV1 }
func loadClientConfig() (*rest.Config, error) {
// The default loading rules try to read from the files specified in the
// environment or from the home directory.
loader := clientcmd.NewDefaultClientConfigLoadingRules()
// The deferred loader tries an in-cluster config if the default loading
// rules produce no results.
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
loader, &clientcmd.ConfigOverrides{},
).ClientConfig()
}
// NewClient returns a kubernetes.Clientset and its underlying configuration.
func NewClient() (*Client, error) {
config, err := loadClientConfig()
if err != nil {
return nil, err
}
// Match the settings applied by sigs.k8s.io/controller-runtime@v0.6.0;
// see https://github.com/kubernetes-sigs/controller-runtime/issues/365.
if config.QPS == 0.0 {
config.QPS = 20.0
config.Burst = 30.0
}
client := &Client{Config: config}
client.Clientset, err = kubernetes.NewForConfig(client.Config)
if err == nil {
client.crunchydataV1, err = crunchydatav1.NewForConfig(client.Config)
}
return client, err
}