Export kubernetes client to use externally
parent
48f302945b
commit
7e161b4b3e
|
@ -53,13 +53,13 @@ type Objects struct {
|
||||||
|
|
||||||
// Client encapsulates a client for a Kubernetes cluster.
|
// Client encapsulates a client for a Kubernetes cluster.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
kubeClient kubernetes.Interface
|
KubeClient kubernetes.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchObjects returns the objects from a Kubernetes cluster.
|
// FetchObjects returns the objects from a Kubernetes cluster.
|
||||||
func (c *Client) FetchObjects() (*Objects, error) {
|
func (c *Client) FetchObjects() (*Objects, error) {
|
||||||
client := c.kubeClient.CoreV1()
|
client := c.KubeClient.CoreV1()
|
||||||
admissionControllerClient := c.kubeClient.AdmissionregistrationV1beta1()
|
admissionControllerClient := c.KubeClient.AdmissionregistrationV1beta1()
|
||||||
opts := metav1.ListOptions{}
|
opts := metav1.ListOptions{}
|
||||||
objects := &Objects{}
|
objects := &Objects{}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ func NewClient(configPath, configContext string) (*Client, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
kubeClient: client,
|
KubeClient: client,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +181,6 @@ func BuildClient(yaml []byte) (*Client, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
kubeClient: client,
|
KubeClient: client,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,10 @@ import (
|
||||||
|
|
||||||
func TestFetchObjects(t *testing.T) {
|
func TestFetchObjects(t *testing.T) {
|
||||||
api := &Client{
|
api := &Client{
|
||||||
kubeClient: fake.NewSimpleClientset(),
|
KubeClient: fake.NewSimpleClientset(),
|
||||||
}
|
}
|
||||||
|
|
||||||
api.kubeClient.CoreV1().Namespaces().Create(&corev1.Namespace{
|
api.KubeClient.CoreV1().Namespaces().Create(&corev1.Namespace{
|
||||||
TypeMeta: metav1.TypeMeta{Kind: "Namespace", APIVersion: "v1"},
|
TypeMeta: metav1.TypeMeta{Kind: "Namespace", APIVersion: "v1"},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "kube-system",
|
Name: "kube-system",
|
||||||
|
|
Loading…
Reference in New Issue