Add APIExtensions ClientSet to airship Client
This change adds the APIExtension ClientSet to airship's client wrapper, allowing interactions with CRDs. Change-Id: Ic156551fde132754915cdb957dd3d82221744cc3
This commit is contained in:
parent
1ec7a24b54
commit
e9f8ac3ac3
@ -17,8 +17,10 @@ package client
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
apix "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
|
|
||||||
"opendev.org/airship/airshipctl/pkg/environment"
|
"opendev.org/airship/airshipctl/pkg/environment"
|
||||||
"opendev.org/airship/airshipctl/pkg/k8s/kubectl"
|
"opendev.org/airship/airshipctl/pkg/k8s/kubectl"
|
||||||
@ -34,6 +36,7 @@ import (
|
|||||||
type Interface interface {
|
type Interface interface {
|
||||||
ClientSet() kubernetes.Interface
|
ClientSet() kubernetes.Interface
|
||||||
DynamicClient() dynamic.Interface
|
DynamicClient() dynamic.Interface
|
||||||
|
ApiextensionsClientSet() apix.Interface
|
||||||
|
|
||||||
Kubectl() kubectl.Interface
|
Kubectl() kubectl.Interface
|
||||||
}
|
}
|
||||||
@ -42,6 +45,7 @@ type Interface interface {
|
|||||||
type Client struct {
|
type Client struct {
|
||||||
clientSet kubernetes.Interface
|
clientSet kubernetes.Interface
|
||||||
dynamicClient dynamic.Interface
|
dynamicClient dynamic.Interface
|
||||||
|
apixClient apix.Interface
|
||||||
|
|
||||||
kubectl kubectl.Interface
|
kubectl kubectl.Interface
|
||||||
}
|
}
|
||||||
@ -70,6 +74,17 @@ func NewClient(settings *environment.AirshipCTLSettings) (Interface, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// kubectl factories can't create CRD clients...
|
||||||
|
config, err := clientcmd.BuildConfigFromFlags("", settings.KubeConfigPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
client.apixClient, err = apix.NewForConfig(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +108,16 @@ func (c *Client) SetDynamicClient(dynamicClient dynamic.Interface) {
|
|||||||
c.dynamicClient = dynamicClient
|
c.dynamicClient = dynamicClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApiextensionsV1 getter for ApiextensionsV1 interface
|
||||||
|
func (c *Client) ApiextensionsClientSet() apix.Interface {
|
||||||
|
return c.apixClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetApiextensionsV1 setter for ApiextensionsV1 interface
|
||||||
|
func (c *Client) SetApiextensionsClientSet(apixClient apix.Interface) {
|
||||||
|
c.apixClient = apixClient
|
||||||
|
}
|
||||||
|
|
||||||
// Kubectl getter for Kubectl interface
|
// Kubectl getter for Kubectl interface
|
||||||
func (c *Client) Kubectl() kubectl.Interface {
|
func (c *Client) Kubectl() kubectl.Interface {
|
||||||
return c.kubectl
|
return c.kubectl
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
package fake
|
package fake
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
apix "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
|
|
||||||
@ -27,9 +28,10 @@ import (
|
|||||||
// per test. Examples of implementations can be found with each interface
|
// per test. Examples of implementations can be found with each interface
|
||||||
// method.
|
// method.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
MockClientSet func() kubernetes.Interface
|
MockClientSet func() kubernetes.Interface
|
||||||
MockDynamicClient func() dynamic.Interface
|
MockDynamicClient func() dynamic.Interface
|
||||||
MockKubectl func() kubectl.Interface
|
MockApiextensionsClientSet func() apix.Interface
|
||||||
|
MockKubectl func() kubectl.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ client.Interface = &Client{}
|
var _ client.Interface = &Client{}
|
||||||
@ -66,6 +68,22 @@ func (c Client) DynamicClient() dynamic.Interface {
|
|||||||
return c.MockDynamicClient()
|
return c.MockDynamicClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApiextensionsClientSet is used to get a mocked implementation of an
|
||||||
|
// Apiextensions clientset. To initialize the mocked client to be returned,
|
||||||
|
// the MockApiextensionsClientSet method must be implemented, ideally returning a
|
||||||
|
// k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake.ClientSet.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// testClient := fake.Client {
|
||||||
|
// MockApiextensionsClientSet: func() apix.Interface {
|
||||||
|
// return apix_fake.NewSimpleClientset()
|
||||||
|
// },
|
||||||
|
// }
|
||||||
|
func (c Client) ApiextensionsClientSet() apix.Interface {
|
||||||
|
return c.MockApiextensionsClientSet()
|
||||||
|
}
|
||||||
|
|
||||||
// Kubectl is used to get a mocked implementation of a Kubectl client.
|
// Kubectl is used to get a mocked implementation of a Kubectl client.
|
||||||
// To initialize the mocked client to be returned, the MockKubectl method
|
// To initialize the mocked client to be returned, the MockKubectl method
|
||||||
// must be implemented.
|
// must be implemented.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user