2022-03-22 11:03:15 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-07-14 15:15:31 -04:00
|
|
|
"context"
|
2022-03-22 11:03:15 -04:00
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2022-06-29 09:26:29 -04:00
|
|
|
"github.com/edgelesssys/constellation/bootstrapper/internal/kubernetes/k8sapi/resources"
|
2022-03-22 11:03:15 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2022-06-30 09:24:36 -04:00
|
|
|
"go.uber.org/goleak"
|
2022-03-22 11:03:15 -04:00
|
|
|
"google.golang.org/protobuf/proto"
|
2022-07-14 15:15:31 -04:00
|
|
|
appsv1 "k8s.io/api/apps/v1"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
2022-03-22 11:03:15 -04:00
|
|
|
k8s "k8s.io/api/core/v1"
|
2022-08-04 10:15:52 -04:00
|
|
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
|
|
|
apiextensionsclientv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
|
2022-03-22 11:03:15 -04:00
|
|
|
"k8s.io/apimachinery/pkg/api/meta"
|
|
|
|
"k8s.io/apimachinery/pkg/api/meta/testrestmapper"
|
2022-07-14 15:15:31 -04:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2022-03-22 11:03:15 -04:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/serializer/json"
|
2022-08-04 10:15:52 -04:00
|
|
|
"k8s.io/apimachinery/pkg/watch"
|
2022-03-22 11:03:15 -04:00
|
|
|
"k8s.io/cli-runtime/pkg/resource"
|
|
|
|
"k8s.io/client-go/kubernetes/fake"
|
|
|
|
"k8s.io/client-go/kubernetes/scheme"
|
|
|
|
restfake "k8s.io/client-go/rest/fake"
|
|
|
|
"k8s.io/client-go/restmapper"
|
|
|
|
)
|
|
|
|
|
2022-06-30 09:24:36 -04:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
goleak.VerifyTestMain(m)
|
|
|
|
}
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
var (
|
|
|
|
corev1GV = schema.GroupVersion{Version: "v1"}
|
2022-07-14 15:15:31 -04:00
|
|
|
nginxDeployment = &appsv1.Deployment{
|
|
|
|
TypeMeta: metav1.TypeMeta{
|
2022-03-22 11:03:15 -04:00
|
|
|
APIVersion: "apps/v1",
|
|
|
|
Kind: "Deployment",
|
|
|
|
},
|
2022-07-14 15:15:31 -04:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2022-03-22 11:03:15 -04:00
|
|
|
Labels: map[string]string{
|
|
|
|
"app": "nginx",
|
|
|
|
},
|
|
|
|
Name: "my-nginx",
|
|
|
|
},
|
2022-07-14 15:15:31 -04:00
|
|
|
Spec: appsv1.DeploymentSpec{
|
2022-03-22 11:03:15 -04:00
|
|
|
Replicas: proto.Int32(3),
|
2022-07-14 15:15:31 -04:00
|
|
|
Selector: &metav1.LabelSelector{
|
2022-03-22 11:03:15 -04:00
|
|
|
MatchLabels: map[string]string{
|
|
|
|
"app": "nginx",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Template: k8s.PodTemplateSpec{
|
2022-07-14 15:15:31 -04:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2022-03-22 11:03:15 -04:00
|
|
|
Labels: map[string]string{
|
|
|
|
"app": "nginx",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: k8s.PodSpec{
|
|
|
|
Containers: []k8s.Container{
|
|
|
|
{
|
|
|
|
Name: "nginx",
|
|
|
|
Image: "nginx:1.14.2",
|
|
|
|
Ports: []k8s.ContainerPort{
|
|
|
|
{
|
|
|
|
ContainerPort: 80,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-07-26 04:10:34 -04:00
|
|
|
tolerationsDeployment = appsv1.Deployment{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2022-07-28 10:07:29 -04:00
|
|
|
Namespace: "test-ns",
|
|
|
|
Name: "test-deployment",
|
2022-07-26 04:10:34 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
selectorsDeployment = appsv1.Deployment{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2022-07-28 10:07:29 -04:00
|
|
|
Namespace: "test-ns",
|
|
|
|
Name: "test-deployment",
|
2022-07-26 04:10:34 -04:00
|
|
|
},
|
|
|
|
Spec: appsv1.DeploymentSpec{
|
|
|
|
Template: k8s.PodTemplateSpec{
|
|
|
|
Spec: k8s.PodSpec{
|
|
|
|
NodeSelector: map[string]string{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-03-22 11:03:15 -04:00
|
|
|
nginxDeplJSON, _ = marshalJSON(nginxDeployment)
|
|
|
|
nginxDeplYAML, _ = marshalYAML(nginxDeployment)
|
|
|
|
)
|
|
|
|
|
|
|
|
type unmarshableResource struct{}
|
|
|
|
|
|
|
|
func (*unmarshableResource) Marshal() ([]byte, error) {
|
|
|
|
return nil, errors.New("someErr")
|
|
|
|
}
|
|
|
|
|
|
|
|
func stringBody(body string) io.ReadCloser {
|
|
|
|
return io.NopCloser(bytes.NewReader([]byte(body)))
|
|
|
|
}
|
|
|
|
|
|
|
|
func fakeClientWith(t *testing.T, testName string, data map[string]string) resource.FakeClientFunc {
|
|
|
|
return func(version schema.GroupVersion) (resource.RESTClient, error) {
|
|
|
|
return &restfake.RESTClient{
|
|
|
|
GroupVersion: corev1GV,
|
|
|
|
NegotiatedSerializer: scheme.Codecs.WithoutConversion(),
|
|
|
|
Client: restfake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
|
|
|
p := req.URL.Path
|
|
|
|
q := req.URL.RawQuery
|
|
|
|
if len(q) != 0 {
|
|
|
|
p = p + "?" + q
|
|
|
|
}
|
|
|
|
body, ok := data[p]
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("%s: unexpected request: %s (%s)\n%#v", testName, p, req.URL, req)
|
|
|
|
}
|
|
|
|
header := http.Header{}
|
|
|
|
header.Set("Content-Type", runtime.ContentTypeJSON)
|
|
|
|
return &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
Header: header,
|
|
|
|
Body: stringBody(body),
|
|
|
|
}, nil
|
|
|
|
}),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newClientWithFakes(t *testing.T, data map[string]string, objects ...runtime.Object) Client {
|
|
|
|
clientset := fake.NewSimpleClientset(objects...)
|
|
|
|
builder := resource.NewFakeBuilder(
|
|
|
|
fakeClientWith(t, "", data),
|
|
|
|
func() (meta.RESTMapper, error) {
|
|
|
|
return testrestmapper.TestOnlyStaticRESTMapper(scheme.Scheme), nil
|
|
|
|
},
|
|
|
|
func() (restmapper.CategoryExpander, error) {
|
|
|
|
return resource.FakeCategoryExpander, nil
|
|
|
|
}).
|
|
|
|
Unstructured()
|
|
|
|
client := Client{
|
|
|
|
clientset: clientset,
|
|
|
|
builder: builder,
|
|
|
|
}
|
|
|
|
return client
|
|
|
|
}
|
|
|
|
|
|
|
|
func failingClient() resource.FakeClientFunc {
|
|
|
|
return func(version schema.GroupVersion) (resource.RESTClient, error) {
|
|
|
|
return &restfake.RESTClient{
|
|
|
|
GroupVersion: corev1GV,
|
|
|
|
NegotiatedSerializer: scheme.Codecs.WithoutConversion(),
|
|
|
|
Resp: &http.Response{StatusCode: 501},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFailingClient(objects ...runtime.Object) Client {
|
|
|
|
clientset := fake.NewSimpleClientset(objects...)
|
|
|
|
builder := resource.NewFakeBuilder(
|
|
|
|
failingClient(),
|
|
|
|
func() (meta.RESTMapper, error) {
|
|
|
|
return testrestmapper.TestOnlyStaticRESTMapper(scheme.Scheme), nil
|
|
|
|
},
|
|
|
|
func() (restmapper.CategoryExpander, error) {
|
|
|
|
return resource.FakeCategoryExpander, nil
|
|
|
|
}).
|
|
|
|
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
|
|
|
client := Client{
|
|
|
|
clientset: clientset,
|
|
|
|
builder: builder,
|
|
|
|
}
|
|
|
|
return client
|
|
|
|
}
|
|
|
|
|
|
|
|
func marshalJSON(obj runtime.Object) ([]byte, error) {
|
|
|
|
serializer := json.NewSerializer(json.DefaultMetaFactory, nil, nil, false)
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := serializer.Encode(obj, &buf); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func marshalYAML(obj runtime.Object) ([]byte, error) {
|
|
|
|
serializer := json.NewYAMLSerializer(json.DefaultMetaFactory, nil, nil)
|
|
|
|
var buf bytes.Buffer
|
|
|
|
if err := serializer.Encode(obj, &buf); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestApplyOneObject(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
httpResponseData map[string]string
|
2022-04-26 10:54:05 -04:00
|
|
|
wantObj runtime.Object
|
2022-03-22 11:03:15 -04:00
|
|
|
resourcesYAML string
|
|
|
|
failingClient bool
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr bool
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"apply works": {
|
|
|
|
httpResponseData: map[string]string{
|
2022-06-29 09:26:29 -04:00
|
|
|
"/deployments/my-nginx?fieldManager=constellation-bootstrapper&force=true": string(nginxDeplJSON),
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantObj: nginxDeployment,
|
2022-03-22 11:03:15 -04:00
|
|
|
resourcesYAML: string(nginxDeplYAML),
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: false,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"apply fails": {
|
|
|
|
httpResponseData: map[string]string{},
|
2022-04-26 10:54:05 -04:00
|
|
|
wantObj: nginxDeployment,
|
2022-03-22 11:03:15 -04:00
|
|
|
resourcesYAML: string(nginxDeplYAML),
|
|
|
|
failingClient: true,
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
var client Client
|
|
|
|
if tc.failingClient {
|
2022-04-26 10:54:05 -04:00
|
|
|
client = newFailingClient(tc.wantObj)
|
2022-03-22 11:03:15 -04:00
|
|
|
} else {
|
2022-04-26 10:54:05 -04:00
|
|
|
client = newClientWithFakes(t, tc.httpResponseData, tc.wantObj)
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
reader := bytes.NewReader([]byte(tc.resourcesYAML))
|
|
|
|
res := client.builder.
|
|
|
|
ContinueOnError().
|
|
|
|
Stream(reader, "yaml").
|
|
|
|
Flatten().
|
|
|
|
Do()
|
|
|
|
assert.NoError(res.Err())
|
|
|
|
infos, err := res.Infos()
|
|
|
|
assert.NoError(err)
|
|
|
|
require.Len(infos, 1)
|
|
|
|
|
|
|
|
err = client.ApplyOneObject(infos[0], true)
|
|
|
|
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetObjects(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-04-26 10:54:05 -04:00
|
|
|
wantResources resources.Marshaler
|
|
|
|
httpResponseData map[string]string
|
|
|
|
resourcesYAML string
|
|
|
|
wantErr bool
|
2022-03-22 11:03:15 -04:00
|
|
|
}{
|
|
|
|
"GetObjects works on cluster-autoscaler deployment": {
|
2022-07-21 08:41:07 -04:00
|
|
|
wantResources: resources.NewDefaultAutoscalerDeployment(nil, nil, nil, ""),
|
2022-04-26 10:54:05 -04:00
|
|
|
resourcesYAML: string(nginxDeplYAML),
|
|
|
|
wantErr: false,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"GetObjects works on cloud-controller-manager deployment": {
|
2022-05-24 04:04:42 -04:00
|
|
|
wantResources: resources.NewDefaultCloudControllerManagerDeployment("someProvider", "someImage", "somePath", "someCIDR", nil, nil, nil, nil),
|
2022-04-26 10:54:05 -04:00
|
|
|
resourcesYAML: string(nginxDeplYAML),
|
|
|
|
wantErr: false,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
"GetObjects Marshal failure detected": {
|
2022-04-26 10:54:05 -04:00
|
|
|
wantResources: &unmarshableResource{},
|
|
|
|
resourcesYAML: string(nginxDeplYAML),
|
|
|
|
wantErr: true,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
client := newClientWithFakes(t, tc.httpResponseData)
|
2022-04-26 10:54:05 -04:00
|
|
|
infos, err := client.GetObjects(tc.wantResources)
|
2022-03-22 11:03:15 -04:00
|
|
|
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
assert.NotNil(infos)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-07-14 15:15:31 -04:00
|
|
|
|
|
|
|
func TestAddTolerationsToDeployment(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-07-28 10:07:29 -04:00
|
|
|
namespace string
|
2022-07-14 15:15:31 -04:00
|
|
|
name string
|
|
|
|
tolerations []corev1.Toleration
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"Success": {
|
2022-07-28 10:07:29 -04:00
|
|
|
namespace: "test-ns",
|
|
|
|
name: "test-deployment",
|
2022-07-14 15:15:31 -04:00
|
|
|
},
|
|
|
|
"Specifying non-existent deployment fails": {
|
2022-07-28 10:07:29 -04:00
|
|
|
namespace: "test-ns",
|
|
|
|
name: "wrong-name",
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Wrong namespace": {
|
|
|
|
name: "test-deployment",
|
2022-07-26 04:10:34 -04:00
|
|
|
wantErr: true,
|
2022-07-14 15:15:31 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
2022-07-26 04:10:34 -04:00
|
|
|
client := newClientWithFakes(t, map[string]string{}, &tolerationsDeployment)
|
2022-07-28 10:07:29 -04:00
|
|
|
err := client.AddTolerationsToDeployment(context.Background(), tc.tolerations, tc.name, tc.namespace)
|
2022-07-14 15:15:31 -04:00
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-07-26 04:10:34 -04:00
|
|
|
|
|
|
|
func TestAddNodeSelectorsToDeployment(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-07-28 10:07:29 -04:00
|
|
|
namespace string
|
2022-07-26 04:10:34 -04:00
|
|
|
name string
|
|
|
|
selectors map[string]string
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"Success": {
|
2022-07-28 10:07:29 -04:00
|
|
|
namespace: "test-ns",
|
2022-07-26 04:10:34 -04:00
|
|
|
name: "test-deployment",
|
|
|
|
selectors: map[string]string{"some-key": "some-value"},
|
|
|
|
},
|
|
|
|
"Specifying non-existent deployment fails": {
|
2022-07-28 10:07:29 -04:00
|
|
|
namespace: "test-ns",
|
|
|
|
name: "wrong-name",
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"Wrong namespace": {
|
|
|
|
name: "test-deployment",
|
2022-07-26 04:10:34 -04:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
client := newClientWithFakes(t, map[string]string{}, &selectorsDeployment)
|
2022-07-28 10:07:29 -04:00
|
|
|
err := client.AddNodeSelectorsToDeployment(context.Background(), tc.selectors, tc.name, tc.namespace)
|
2022-07-26 04:10:34 -04:00
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-08-04 10:15:52 -04:00
|
|
|
|
|
|
|
func TestWaitForCRD(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
crd string
|
|
|
|
events []watch.Event
|
|
|
|
watchErr error
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
"Success": {
|
|
|
|
crd: "test-crd",
|
|
|
|
events: []watch.Event{
|
|
|
|
{
|
|
|
|
Type: watch.Added,
|
|
|
|
Object: &apiextensionsv1.CustomResourceDefinition{
|
|
|
|
Status: apiextensionsv1.CustomResourceDefinitionStatus{
|
|
|
|
Conditions: []apiextensionsv1.CustomResourceDefinitionCondition{
|
|
|
|
{
|
|
|
|
Type: apiextensionsv1.Established,
|
|
|
|
Status: apiextensionsv1.ConditionTrue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"watch error": {
|
|
|
|
crd: "test-crd",
|
|
|
|
watchErr: errors.New("watch error"),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"crd deleted": {
|
|
|
|
crd: "test-crd",
|
|
|
|
events: []watch.Event{{Type: watch.Deleted}},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
"other error": {
|
|
|
|
crd: "test-crd",
|
|
|
|
events: []watch.Event{{Type: watch.Error}},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
client := Client{
|
|
|
|
apiextensionClient: &stubCRDWatcher{events: tc.events, watchErr: tc.watchErr},
|
|
|
|
}
|
|
|
|
err := client.WaitForCRD(context.Background(), tc.crd)
|
|
|
|
if tc.wantErr {
|
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubCRDWatcher struct {
|
|
|
|
events []watch.Event
|
|
|
|
watchErr error
|
|
|
|
|
|
|
|
apiextensionsclientv1.ApiextensionsV1Interface
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *stubCRDWatcher) CustomResourceDefinitions() apiextensionsclientv1.CustomResourceDefinitionInterface {
|
|
|
|
return &stubCustomResourceDefinitions{
|
|
|
|
events: w.events,
|
|
|
|
watchErr: w.watchErr,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubCustomResourceDefinitions struct {
|
|
|
|
events []watch.Event
|
|
|
|
watchErr error
|
|
|
|
|
|
|
|
apiextensionsclientv1.CustomResourceDefinitionInterface
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *stubCustomResourceDefinitions) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
|
|
|
|
eventChan := make(chan watch.Event, len(c.events))
|
|
|
|
for _, event := range c.events {
|
|
|
|
eventChan <- event
|
|
|
|
}
|
|
|
|
return &stubCRDWatch{events: eventChan}, c.watchErr
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubCRDWatch struct {
|
|
|
|
events chan watch.Event
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *stubCRDWatch) Stop() {
|
|
|
|
close(w.events)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *stubCRDWatch) ResultChan() <-chan watch.Event {
|
|
|
|
return w.events
|
|
|
|
}
|