This repository has been archived by the owner on Mar 4, 2019. It is now read-only.
forked from kmodules/webhook-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
60 lines (53 loc) · 1.59 KB
/
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
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
package v1
import (
wpi "github.com/appscode/kubernetes-webhook-util/apis/workload/v1"
"github.com/appscode/kutil/discovery"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
ocapps "kmodules.xyz/openshift/apis/apps/v1"
occ "kmodules.xyz/openshift/client/clientset/versioned"
)
type Interface interface {
WorkloadsGetter
}
// Client is used to interact with features provided by the storage.k8s.io group.
type Client struct {
kc kubernetes.Interface
oc occ.Interface
}
func (c *Client) Workloads(namespace string) WorkloadInterface {
return newWorkloads(c.kc, c.oc, namespace)
}
// NewForConfig creates a new Client for the given config.
func NewForConfig(c *rest.Config) (*Client, error) {
kc, err := kubernetes.NewForConfig(c)
if err != nil {
return nil, err
}
var oc occ.Interface
if discovery.IsPreferredAPIResource(kc.Discovery(), ocapps.SchemeGroupVersion.String(), wpi.KindDeploymentConfig) {
oc, err = occ.NewForConfig(c)
if err != nil {
return nil, err
}
}
return &Client{kc, oc}, nil
}
// NewForConfigOrDie creates a new Client for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *Client {
kc := kubernetes.NewForConfigOrDie(c)
var oc occ.Interface
var err error
if discovery.IsPreferredAPIResource(kc.Discovery(), ocapps.SchemeGroupVersion.String(), wpi.KindDeploymentConfig) {
oc, err = occ.NewForConfig(c)
if err != nil {
panic(err)
}
}
return &Client{kc, oc}
}
// New creates a new Client for the given RESTClient.
func New(kc kubernetes.Interface, oc occ.Interface) *Client {
return &Client{kc, oc}
}