From 83394de3b9760336b0f62df54dcfddcc61e0832f Mon Sep 17 00:00:00 2001 From: Lilla Vass Date: Wed, 6 Dec 2023 14:18:56 +0100 Subject: [PATCH] feat: add executor and webhook listers and informers [TKC-631] (#205) * feat: add listeners and informers * feat: lister and informer for test source * fix: improve resources in groupversion for executor group * fix: fix permission error while testing locally --- api/executor/v1/groupversion_info.go | 20 +- api/testsource/v1/groupversion_info.go | 14 +- pkg/clientset/versioned/clientset.go | 20 +- .../versioned/fake/clientset_generated.go | 15 +- pkg/clientset/versioned/fake/register.go | 2 + pkg/clientset/versioned/scheme/register.go | 2 + .../versioned/typed/executor/v1/doc.go | 17 ++ .../versioned/typed/executor/v1/executor.go | 88 ++++++++ .../typed/executor/v1/executor_client.go | 111 ++++++++++ .../versioned/typed/executor/v1/fake/doc.go | 17 ++ .../typed/executor/v1/fake/fake_executor.go | 72 +++++++ .../executor/v1/fake/fake_tests_client.go | 42 ++++ .../typed/executor/v1/fake/fake_webhook.go | 72 +++++++ .../typed/executor/v1/generated_expansion.go | 21 ++ .../versioned/typed/executor/v1/webhook.go | 88 ++++++++ .../typed/tests/v1/fake/fake_tests_client.go | 4 + .../typed/tests/v1/fake/fake_testsource.go | 171 +++++++++++++++ .../typed/tests/v1/generated_expansion.go | 2 + .../versioned/typed/tests/v1/tests_client.go | 9 +- .../versioned/typed/tests/v1/testsource.go | 194 ++++++++++++++++++ .../externalversions/executor/interface.go | 48 +++++ .../externalversions/executor/v1/executor.go | 94 +++++++++ .../externalversions/executor/v1/interface.go | 52 +++++ .../externalversions/executor/v1/webhook.go | 94 +++++++++ pkg/informers/externalversions/factory.go | 13 +- pkg/informers/externalversions/generic.go | 21 ++ .../externalversions/tests/v1/interface.go | 7 + .../externalversions/tests/v1/testsource.go | 94 +++++++++ pkg/listers/executor/v1/executors.go | 101 +++++++++ .../executor/v1/expansion_generated.go | 31 +++ pkg/listers/executor/v1/webhooks.go | 101 +++++++++ pkg/listers/tests/v1/expansion_generated.go | 7 + pkg/listers/tests/v1/testsource.go | 101 +++++++++ 33 files changed, 1732 insertions(+), 13 deletions(-) create mode 100644 pkg/clientset/versioned/typed/executor/v1/doc.go create mode 100644 pkg/clientset/versioned/typed/executor/v1/executor.go create mode 100644 pkg/clientset/versioned/typed/executor/v1/executor_client.go create mode 100644 pkg/clientset/versioned/typed/executor/v1/fake/doc.go create mode 100644 pkg/clientset/versioned/typed/executor/v1/fake/fake_executor.go create mode 100644 pkg/clientset/versioned/typed/executor/v1/fake/fake_tests_client.go create mode 100644 pkg/clientset/versioned/typed/executor/v1/fake/fake_webhook.go create mode 100644 pkg/clientset/versioned/typed/executor/v1/generated_expansion.go create mode 100644 pkg/clientset/versioned/typed/executor/v1/webhook.go create mode 100644 pkg/clientset/versioned/typed/tests/v1/fake/fake_testsource.go create mode 100644 pkg/clientset/versioned/typed/tests/v1/testsource.go create mode 100644 pkg/informers/externalversions/executor/interface.go create mode 100644 pkg/informers/externalversions/executor/v1/executor.go create mode 100644 pkg/informers/externalversions/executor/v1/interface.go create mode 100644 pkg/informers/externalversions/executor/v1/webhook.go create mode 100644 pkg/informers/externalversions/tests/v1/testsource.go create mode 100644 pkg/listers/executor/v1/executors.go create mode 100644 pkg/listers/executor/v1/expansion_generated.go create mode 100644 pkg/listers/executor/v1/webhooks.go create mode 100644 pkg/listers/tests/v1/testsource.go diff --git a/api/executor/v1/groupversion_info.go b/api/executor/v1/groupversion_info.go index ba892040..92d8edc7 100644 --- a/api/executor/v1/groupversion_info.go +++ b/api/executor/v1/groupversion_info.go @@ -25,8 +25,26 @@ import ( ) var ( + // Group represents the API Group + Group = "executor.testkube.io" + + // Version represents the Resource version + Version = "v1" + + // ExecutorResource corresponds to the CRD Kind + ExecutorResource = "Executor" + + // WebhookResource corresponds to the CRD Kind + WebhookResource = "Webhook" + // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "executor.testkube.io", Version: "v1"} + GroupVersion = schema.GroupVersion{Group: Group, Version: Version} + + // ExecutorGroupVersionResource is group, version and resource used to register these objects + ExecutorGroupVersionResource = schema.GroupVersionResource{Group: Group, Version: Version, Resource: ExecutorResource} + + // WebhookGroupVersionResource is group, version and resource used to register these objects + WebhookGroupVersionResource = schema.GroupVersionResource{Group: Group, Version: Version, Resource: WebhookResource} // SchemeBuilder is used to add go types to the GroupVersionKind scheme SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} diff --git a/api/testsource/v1/groupversion_info.go b/api/testsource/v1/groupversion_info.go index c1627d50..eafba8a8 100644 --- a/api/testsource/v1/groupversion_info.go +++ b/api/testsource/v1/groupversion_info.go @@ -25,8 +25,20 @@ import ( ) var ( + // Group represents the API Group + Group = "tests.testkube.io" + + // Version represents the Resource version + Version = "v1" + + // Resource corresponds to the CRD Kind + Resource = "TestSource" + // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "tests.testkube.io", Version: "v1"} + GroupVersion = schema.GroupVersion{Group: Group, Version: Version} + + // GroupVersionResource is group, version and resource used to register these objects + GroupVersionResource = schema.GroupVersionResource{Group: Group, Version: Version, Resource: Resource} // SchemeBuilder is used to add go types to the GroupVersionKind scheme SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} diff --git a/pkg/clientset/versioned/clientset.go b/pkg/clientset/versioned/clientset.go index 9098b726..cfa78488 100644 --- a/pkg/clientset/versioned/clientset.go +++ b/pkg/clientset/versioned/clientset.go @@ -20,6 +20,7 @@ import ( "fmt" "net/http" + executorv1 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/executor/v1" v1 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/tests/v1" v2 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/tests/v2" v3 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/tests/v3" @@ -34,14 +35,16 @@ type Interface interface { TestsV1() v1.TestsV1Interface TestsV2() v2.TestsV2Interface TestsV3() v3.TestsV3Interface + ExecutorV1() executorv1.ExecutorV1Interface } // Clientset contains the clients for groups. Each group has exactly one version included in a Clientset. type Clientset struct { *discovery.DiscoveryClient - testsV1 *v1.TestsV1Client - testsV2 *v2.TestsV2Client - testsV3 *v3.TestsV3Client + testsV1 *v1.TestsV1Client + testsV2 *v2.TestsV2Client + testsV3 *v3.TestsV3Client + executorV1 *executorv1.ExecutorV1Client } // TestsV1 retrieves the TestsV1Client @@ -59,6 +62,11 @@ func (c *Clientset) TestsV3() v3.TestsV3Interface { return c.testsV3 } +// ExecutorV1 retrieves the ExecutorV1Client +func (c *Clientset) ExecutorV1() executorv1.ExecutorV1Interface { + return c.executorV1 +} + // Discovery retrieves the DiscoveryClient func (c *Clientset) Discovery() discovery.DiscoveryInterface { if c == nil { @@ -118,6 +126,11 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, return nil, err } + cs.executorV1, err = executorv1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } + cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err @@ -141,6 +154,7 @@ func New(c rest.Interface) *Clientset { cs.testsV1 = v1.New(c) cs.testsV2 = v2.New(c) cs.testsV3 = v3.New(c) + cs.executorV1 = executorv1.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) return &cs diff --git a/pkg/clientset/versioned/fake/clientset_generated.go b/pkg/clientset/versioned/fake/clientset_generated.go index df064f8d..1cd3bb75 100644 --- a/pkg/clientset/versioned/fake/clientset_generated.go +++ b/pkg/clientset/versioned/fake/clientset_generated.go @@ -18,8 +18,10 @@ package fake import ( "github.com/kubeshop/testkube-operator/pkg/clientset/versioned" - v1 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/tests/v1" - fakev1 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/tests/v1/fake" + executorv1 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/executor/v1" + fakeexecutorv1 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/executor/v1/fake" + testsv1 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/tests/v1" + faketestsv1 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/tests/v1/fake" v2 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/tests/v2" fakev2 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/tests/v2/fake" v3 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/tests/v3" @@ -82,8 +84,8 @@ var ( ) // TestsV1 retrieves the TestsV1Client -func (c *Clientset) TestsV1() v1.TestsV1Interface { - return &fakev1.FakeTestsV1{Fake: &c.Fake} +func (c *Clientset) TestsV1() testsv1.TestsV1Interface { + return &faketestsv1.FakeTestsV1{Fake: &c.Fake} } // TestsV2 retrieves the TestsV2Client @@ -95,3 +97,8 @@ func (c *Clientset) TestsV2() v2.TestsV2Interface { func (c *Clientset) TestsV3() v3.TestsV3Interface { return &fakev3.FakeTestsV3{Fake: &c.Fake} } + +// ExecutorV1 retrieves the ExecutorV1Client +func (c *Clientset) ExecutorV1() executorv1.ExecutorV1Interface { + return &fakeexecutorv1.FakeExecutorV1{Fake: &c.Fake} +} diff --git a/pkg/clientset/versioned/fake/register.go b/pkg/clientset/versioned/fake/register.go index 59f07697..03e23633 100644 --- a/pkg/clientset/versioned/fake/register.go +++ b/pkg/clientset/versioned/fake/register.go @@ -17,6 +17,7 @@ limitations under the License. package fake import ( + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" testsv3 "github.com/kubeshop/testkube-operator/api/tests/v3" testsuitev3 "github.com/kubeshop/testkube-operator/api/testsuite/v3" testtriggersv1 "github.com/kubeshop/testkube-operator/api/testtriggers/v1" @@ -34,6 +35,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{ testtriggersv1.AddToScheme, testsuitev3.AddToScheme, testsv3.AddToScheme, + executorv1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/clientset/versioned/scheme/register.go b/pkg/clientset/versioned/scheme/register.go index 440f31bc..91a719c6 100644 --- a/pkg/clientset/versioned/scheme/register.go +++ b/pkg/clientset/versioned/scheme/register.go @@ -17,6 +17,7 @@ limitations under the License. package scheme import ( + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" testsv3 "github.com/kubeshop/testkube-operator/api/tests/v3" testsuitev3 "github.com/kubeshop/testkube-operator/api/testsuite/v3" testtriggersv1 "github.com/kubeshop/testkube-operator/api/testtriggers/v1" @@ -34,6 +35,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{ testtriggersv1.AddToScheme, testsuitev3.AddToScheme, testsv3.AddToScheme, + executorv1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/clientset/versioned/typed/executor/v1/doc.go b/pkg/clientset/versioned/typed/executor/v1/doc.go new file mode 100644 index 00000000..f8a9fe1f --- /dev/null +++ b/pkg/clientset/versioned/typed/executor/v1/doc.go @@ -0,0 +1,17 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 diff --git a/pkg/clientset/versioned/typed/executor/v1/executor.go b/pkg/clientset/versioned/typed/executor/v1/executor.go new file mode 100644 index 00000000..98148d72 --- /dev/null +++ b/pkg/clientset/versioned/typed/executor/v1/executor.go @@ -0,0 +1,88 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import ( + "context" + "time" + + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" + "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/scheme" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/rest" +) + +// ExecutorGetter has a method to return a ExecutorInterface. +// A group's client should implement this interface. +type ExecutorGetter interface { + Executor(namespace string) ExecutorInterface +} + +// ExecutorInterface has methods to work with Executor resources. +type ExecutorInterface interface { + List(ctx context.Context, opts v1.ListOptions) (*executorv1.ExecutorList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + ExecutorExpansion +} + +// executors implements ExecutorInterface +type executors struct { + client rest.Interface + ns string +} + +// newExecutor returns a Executor +func newExecutor(c *ExecutorV1Client, namespace string) *executors { + return &executors{ + client: c.RESTClient(), + ns: namespace, + } +} + +// List takes label and field selectors, and returns the list of Executor that match those selectors. +func (c *executors) List(ctx context.Context, opts v1.ListOptions) (result *executorv1.ExecutorList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &executorv1.ExecutorList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("executors"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested executors. +func (c *executors) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("executors"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} diff --git a/pkg/clientset/versioned/typed/executor/v1/executor_client.go b/pkg/clientset/versioned/typed/executor/v1/executor_client.go new file mode 100644 index 00000000..0f798848 --- /dev/null +++ b/pkg/clientset/versioned/typed/executor/v1/executor_client.go @@ -0,0 +1,111 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import ( + "net/http" + + "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/scheme" + + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" + "k8s.io/client-go/rest" +) + +type ExecutorV1Interface interface { + RESTClient() rest.Interface + ExecutorGetter + WebhookGetter +} + +// ExecutorV1Client is used to interact with features provided by the executor.testkube.io group. +type ExecutorV1Client struct { + restClient rest.Interface +} + +func (c *ExecutorV1Client) Executor(namespace string) ExecutorInterface { + return newExecutor(c, namespace) +} + +func (c *ExecutorV1Client) Webhook(namespace string) WebhookInterface { + return newWebhook(c, namespace) +} + +// NewForConfig creates a new ExecutorV1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExecutorV1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new ExecutorV1Client for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExecutorV1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &ExecutorV1Client{client}, nil +} + +// NewForConfigOrDie creates a new ExecutorV1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExecutorV1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new ExecutorV1Client for the given RESTClient. +func New(c rest.Interface) *ExecutorV1Client { + return &ExecutorV1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := executorv1.GroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExecutorV1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/clientset/versioned/typed/executor/v1/fake/doc.go b/pkg/clientset/versioned/typed/executor/v1/fake/doc.go new file mode 100644 index 00000000..3487a31c --- /dev/null +++ b/pkg/clientset/versioned/typed/executor/v1/fake/doc.go @@ -0,0 +1,17 @@ +/* +Copyright 2021. + +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. +*/ + +package fake diff --git a/pkg/clientset/versioned/typed/executor/v1/fake/fake_executor.go b/pkg/clientset/versioned/typed/executor/v1/fake/fake_executor.go new file mode 100644 index 00000000..2fb85924 --- /dev/null +++ b/pkg/clientset/versioned/typed/executor/v1/fake/fake_executor.go @@ -0,0 +1,72 @@ +/* +Copyright 2021. + +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. +*/ + +package fake + +import ( + "context" + "fmt" + + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/testing" +) + +// FakeExecutor implements ExecutorInterface +type FakeExecutor struct { + Fake *FakeExecutorV1 + ns string +} + +var executorResource = schema.GroupVersionResource{Group: "executor.testkube.io", Version: "v1", Resource: "Executor"} + +var executorKind = schema.GroupVersionKind{Group: "executor.testkube.io", Version: "v1", Kind: "Executor"} + +// List takes label and field selectors, and returns the list of Executors that match those selectors. +func (c *FakeExecutor) List(ctx context.Context, opts v1.ListOptions) (result *executorv1.ExecutorList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(executorResource, executorKind, c.ns, opts), &executorv1.ExecutorList{}) + + if err != nil { + return nil, err + } + + if obj == nil { + return nil, fmt.Errorf("empty object") + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &executorv1.ExecutorList{ListMeta: obj.(*executorv1.ExecutorList).ListMeta} + for _, item := range obj.(*executorv1.ExecutorList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested Executors. +func (c *FakeExecutor) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(executorResource, c.ns, opts)) +} diff --git a/pkg/clientset/versioned/typed/executor/v1/fake/fake_tests_client.go b/pkg/clientset/versioned/typed/executor/v1/fake/fake_tests_client.go new file mode 100644 index 00000000..a560f7fb --- /dev/null +++ b/pkg/clientset/versioned/typed/executor/v1/fake/fake_tests_client.go @@ -0,0 +1,42 @@ +/* +Copyright 2021. + +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. +*/ + +package fake + +import ( + v1 "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/typed/executor/v1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeExecutorV1 struct { + *testing.Fake +} + +func (c *FakeExecutorV1) Executor(namespace string) v1.ExecutorInterface { + return &FakeExecutor{c, namespace} +} + +func (c *FakeExecutorV1) Webhook(namespace string) v1.WebhookInterface { + return &FakeWebhook{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeExecutorV1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/clientset/versioned/typed/executor/v1/fake/fake_webhook.go b/pkg/clientset/versioned/typed/executor/v1/fake/fake_webhook.go new file mode 100644 index 00000000..2a847707 --- /dev/null +++ b/pkg/clientset/versioned/typed/executor/v1/fake/fake_webhook.go @@ -0,0 +1,72 @@ +/* +Copyright 2021. + +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. +*/ + +package fake + +import ( + "context" + "fmt" + + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/testing" +) + +// FakeWebhook implements WebhookInterface +type FakeWebhook struct { + Fake *FakeExecutorV1 + ns string +} + +var webhookResource = schema.GroupVersionResource{Group: "executor.testkube.io", Version: "v1", Resource: "Webhook"} + +var webhookKind = schema.GroupVersionKind{Group: "executor.testkube.io", Version: "v1", Kind: "Webhook"} + +// List takes label and field selectors, and returns the list of Webhook that match those selectors. +func (c *FakeWebhook) List(ctx context.Context, opts v1.ListOptions) (result *executorv1.WebhookList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(webhookResource, webhookKind, c.ns, opts), &executorv1.WebhookList{}) + + if err != nil { + return nil, err + } + + if obj == nil { + return nil, fmt.Errorf("empty object") + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &executorv1.WebhookList{ListMeta: obj.(*executorv1.WebhookList).ListMeta} + for _, item := range obj.(*executorv1.WebhookList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested Webhooks. +func (c *FakeWebhook) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(webhookResource, c.ns, opts)) +} diff --git a/pkg/clientset/versioned/typed/executor/v1/generated_expansion.go b/pkg/clientset/versioned/typed/executor/v1/generated_expansion.go new file mode 100644 index 00000000..8081a33f --- /dev/null +++ b/pkg/clientset/versioned/typed/executor/v1/generated_expansion.go @@ -0,0 +1,21 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +type ExecutorExpansion interface{} + +type WebhookExpansion interface{} diff --git a/pkg/clientset/versioned/typed/executor/v1/webhook.go b/pkg/clientset/versioned/typed/executor/v1/webhook.go new file mode 100644 index 00000000..1ac531fc --- /dev/null +++ b/pkg/clientset/versioned/typed/executor/v1/webhook.go @@ -0,0 +1,88 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import ( + "context" + "time" + + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" + "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/scheme" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/rest" +) + +// WebhookGetter has a method to return a WebhookInterface. +// A group's client should implement this interface. +type WebhookGetter interface { + Webhook(namespace string) WebhookInterface +} + +// WebhookInterface has methods to work with Webhook resources. +type WebhookInterface interface { + List(ctx context.Context, opts v1.ListOptions) (*executorv1.WebhookList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + WebhookExpansion +} + +// webhooks implements WebhookInterface +type webhooks struct { + client rest.Interface + ns string +} + +// newWebhook returns a Webhook +func newWebhook(c *ExecutorV1Client, namespace string) *webhooks { + return &webhooks{ + client: c.RESTClient(), + ns: namespace, + } +} + +// List takes label and field selectors, and returns the list of Webhook that match those selectors. +func (c *webhooks) List(ctx context.Context, opts v1.ListOptions) (result *executorv1.WebhookList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &executorv1.WebhookList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("webhooks"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested webhooks. +func (c *webhooks) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("webhooks"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} diff --git a/pkg/clientset/versioned/typed/tests/v1/fake/fake_tests_client.go b/pkg/clientset/versioned/typed/tests/v1/fake/fake_tests_client.go index 53b246c9..798d8d8d 100644 --- a/pkg/clientset/versioned/typed/tests/v1/fake/fake_tests_client.go +++ b/pkg/clientset/versioned/typed/tests/v1/fake/fake_tests_client.go @@ -30,6 +30,10 @@ func (c *FakeTestsV1) TestTriggers(namespace string) v1.TestTriggerInterface { return &FakeTestTriggers{c, namespace} } +func (c *FakeTestsV1) TestSource(namespace string) v1.TestSourceInterface { + return &FakeTestSource{c, namespace} +} + // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeTestsV1) RESTClient() rest.Interface { diff --git a/pkg/clientset/versioned/typed/tests/v1/fake/fake_testsource.go b/pkg/clientset/versioned/typed/tests/v1/fake/fake_testsource.go new file mode 100644 index 00000000..b59df96e --- /dev/null +++ b/pkg/clientset/versioned/typed/tests/v1/fake/fake_testsource.go @@ -0,0 +1,171 @@ +/* +Copyright 2021. + +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. +*/ + +package fake + +import ( + "context" + "fmt" + + testsourcev1 "github.com/kubeshop/testkube-operator/api/testsource/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/testing" +) + +// FakeTestSource implements TestSourceInterface +type FakeTestSource struct { + Fake *FakeTestsV1 + ns string +} + +var testSourceResource = schema.GroupVersionResource{Group: "tests.testkube.io", Version: "v1", Resource: "TestSource"} + +var testSourceKind = schema.GroupVersionKind{Group: "tests.testkube.io", Version: "v1", Kind: "TestSource"} + +// Get takes name of the testSource, and returns the corresponding testSource object, and an error if there is any. +func (c *FakeTestSource) Get(ctx context.Context, name string, options v1.GetOptions) (result *testsourcev1.TestSource, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(testSourceResource, c.ns, name), &testsourcev1.TestSource{}) + + if err != nil { + return nil, err + } + + if obj == nil { + return nil, fmt.Errorf("empty object %v", name) + } + + return obj.(*testsourcev1.TestSource), err +} + +// List takes label and field selectors, and returns the list of TestSource that match those selectors. +func (c *FakeTestSource) List(ctx context.Context, opts v1.ListOptions) (result *testsourcev1.TestSourceList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(testSourceResource, testSourceKind, c.ns, opts), &testsourcev1.TestSourceList{}) + + if err != nil { + return nil, err + } + + if obj == nil { + return nil, fmt.Errorf("empty object") + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &testsourcev1.TestSourceList{ListMeta: obj.(*testsourcev1.TestSourceList).ListMeta} + for _, item := range obj.(*testsourcev1.TestSourceList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested testSource. +func (c *FakeTestSource) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(testSourceResource, c.ns, opts)) + +} + +// Create takes the representation of a testSource and creates it. Returns the server's representation of the testSource, and an error, if there is any. +func (c *FakeTestSource) Create(ctx context.Context, testSource *testsourcev1.TestSource, opts v1.CreateOptions) (result *testsourcev1.TestSource, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(testSourceResource, c.ns, testSource), &testsourcev1.TestSource{}) + + if err != nil { + return nil, err + } + + if obj == nil { + return nil, fmt.Errorf("empty object") + } + + return obj.(*testsourcev1.TestSource), err +} + +// Update takes the representation of a testSource and updates it. Returns the server's representation of the testSource, and an error, if there is any. +func (c *FakeTestSource) Update(ctx context.Context, testSource *testsourcev1.TestSource, opts v1.UpdateOptions) (result *testsourcev1.TestSource, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(testSourceResource, c.ns, testSource), &testsourcev1.TestSource{}) + + if err != nil { + return nil, err + } + + if obj == nil { + return nil, fmt.Errorf("empty object") + } + + return obj.(*testsourcev1.TestSource), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeTestSource) UpdateStatus(ctx context.Context, testSource *testsourcev1.TestSource, opts v1.UpdateOptions) (*testsourcev1.TestSource, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(testSourceResource, "status", c.ns, testSource), &testsourcev1.TestSource{}) + + if err != nil { + return nil, err + } + + if obj == nil { + return nil, fmt.Errorf("empty object") + } + + return obj.(*testsourcev1.TestSource), err +} + +// Delete takes name of the testSource and deletes it. Returns an error if one occurs. +func (c *FakeTestSource) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(testSourceResource, c.ns, name, opts), &testsourcev1.TestSource{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeTestSource) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(testSourceResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &testsourcev1.TestSourceList{}) + return err +} + +// Patch applies the patch and returns the patched testSource. +func (c *FakeTestSource) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *testsourcev1.TestSource, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(testSourceResource, c.ns, name, pt, data, subresources...), &testsourcev1.TestSource{}) + + if err != nil { + return nil, err + } + + if obj == nil { + return nil, fmt.Errorf("empty object") + } + + return obj.(*testsourcev1.TestSource), err +} diff --git a/pkg/clientset/versioned/typed/tests/v1/generated_expansion.go b/pkg/clientset/versioned/typed/tests/v1/generated_expansion.go index d234e4a7..bfc26d75 100644 --- a/pkg/clientset/versioned/typed/tests/v1/generated_expansion.go +++ b/pkg/clientset/versioned/typed/tests/v1/generated_expansion.go @@ -17,3 +17,5 @@ limitations under the License. package v1 type TestTriggerExpansion interface{} + +type TestSourceExpansion interface{} diff --git a/pkg/clientset/versioned/typed/tests/v1/tests_client.go b/pkg/clientset/versioned/typed/tests/v1/tests_client.go index 291f43ae..df48635c 100644 --- a/pkg/clientset/versioned/typed/tests/v1/tests_client.go +++ b/pkg/clientset/versioned/typed/tests/v1/tests_client.go @@ -17,16 +17,19 @@ limitations under the License. package v1 import ( - "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/scheme" "net/http" + "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/scheme" + testtriggersv1 "github.com/kubeshop/testkube-operator/api/testtriggers/v1" + "k8s.io/client-go/rest" ) type TestsV1Interface interface { RESTClient() rest.Interface TestTriggersGetter + TestSourceGetter } // TestsV1Client is used to interact with features provided by the tests.testkube.io group. @@ -38,6 +41,10 @@ func (c *TestsV1Client) TestTriggers(namespace string) TestTriggerInterface { return newTestTriggers(c, namespace) } +func (c *TestsV1Client) TestSource(namespace string) TestSourceInterface { + return newTestSource(c, namespace) +} + // NewForConfig creates a new TestsV1Client for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). diff --git a/pkg/clientset/versioned/typed/tests/v1/testsource.go b/pkg/clientset/versioned/typed/tests/v1/testsource.go new file mode 100644 index 00000000..e1fb073e --- /dev/null +++ b/pkg/clientset/versioned/typed/tests/v1/testsource.go @@ -0,0 +1,194 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import ( + "context" + "time" + + testsourcev1 "github.com/kubeshop/testkube-operator/api/testsource/v1" + "github.com/kubeshop/testkube-operator/pkg/clientset/versioned/scheme" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/rest" +) + +// TestSourceGetter has a method to return a TestSourceInterface. +// A group's client should implement this interface. +type TestSourceGetter interface { + TestSource(namespace string) TestSourceInterface +} + +// TestSourceInterface has methods to work with TestSource resources. +type TestSourceInterface interface { + Create(ctx context.Context, testSource *testsourcev1.TestSource, opts v1.CreateOptions) (*testsourcev1.TestSource, error) + Update(ctx context.Context, testSource *testsourcev1.TestSource, opts v1.UpdateOptions) (*testsourcev1.TestSource, error) + UpdateStatus(ctx context.Context, testSource *testsourcev1.TestSource, opts v1.UpdateOptions) (*testsourcev1.TestSource, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*testsourcev1.TestSource, error) + List(ctx context.Context, opts v1.ListOptions) (*testsourcev1.TestSourceList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *testsourcev1.TestSource, err error) + TestSourceExpansion +} + +// testSource implements TestSourceInterface +type testSource struct { + client rest.Interface + ns string +} + +// newTestSource returns a TestSource +func newTestSource(c *TestsV1Client, namespace string) *testSource { + return &testSource{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the testSource, and returns the corresponding testSource object, and an error if there is any. +func (c *testSource) Get(ctx context.Context, name string, options v1.GetOptions) (result *testsourcev1.TestSource, err error) { + result = &testsourcev1.TestSource{} + err = c.client.Get(). + Namespace(c.ns). + Resource("testsources"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of TestSource that match those selectors. +func (c *testSource) List(ctx context.Context, opts v1.ListOptions) (result *testsourcev1.TestSourceList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &testsourcev1.TestSourceList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("testsources"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested testSource. +func (c *testSource) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("testsources"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a testSource and creates it. Returns the server's representation of the testSource, and an error, if there is any. +func (c *testSource) Create(ctx context.Context, testSource *testsourcev1.TestSource, opts v1.CreateOptions) (result *testsourcev1.TestSource, err error) { + result = &testsourcev1.TestSource{} + err = c.client.Post(). + Namespace(c.ns). + Resource("testsources"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(testSource). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a testSource and updates it. Returns the server's representation of the testSource, and an error, if there is any. +func (c *testSource) Update(ctx context.Context, testSource *testsourcev1.TestSource, opts v1.UpdateOptions) (result *testsourcev1.TestSource, err error) { + result = &testsourcev1.TestSource{} + err = c.client.Put(). + Namespace(c.ns). + Resource("testsources"). + Name(testSource.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(testSource). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *testSource) UpdateStatus(ctx context.Context, testSource *testsourcev1.TestSource, opts v1.UpdateOptions) (result *testsourcev1.TestSource, err error) { + result = &testsourcev1.TestSource{} + err = c.client.Put(). + Namespace(c.ns). + Resource("testsources"). + Name(testSource.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(testSource). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the testSource and deletes it. Returns an error if one occurs. +func (c *testSource) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("testsources"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *testSource) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("testsources"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched testSource. +func (c *testSource) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *testsourcev1.TestSource, err error) { + result = &testsourcev1.TestSource{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("testsources"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/informers/externalversions/executor/interface.go b/pkg/informers/externalversions/executor/interface.go new file mode 100644 index 00000000..b8661e35 --- /dev/null +++ b/pkg/informers/externalversions/executor/interface.go @@ -0,0 +1,48 @@ +/* +Copyright 2021. + +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. +*/ + +package executor + +import ( + v1 "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/executor/v1" + "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1 version. + V1() v1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New( + f internalinterfaces.SharedInformerFactory, + namespace string, + tweakListOptions internalinterfaces.TweakListOptionsFunc, +) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/informers/externalversions/executor/v1/executor.go b/pkg/informers/externalversions/executor/v1/executor.go new file mode 100644 index 00000000..ad6ae051 --- /dev/null +++ b/pkg/informers/externalversions/executor/v1/executor.go @@ -0,0 +1,94 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import ( + "context" + "time" + + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" + "github.com/kubeshop/testkube-operator/pkg/clientset/versioned" + "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/internalinterfaces" + executorlisterv1 "github.com/kubeshop/testkube-operator/pkg/listers/executor/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" +) + +// ExecutorInformer provides access to a shared informer and lister for Executor. +type ExecutorInformer interface { + Informer() cache.SharedIndexInformer + Lister() executorlisterv1.ExecutorLister +} + +type executorInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewExecutorInformer constructs a new informer for Executor type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory print and number of connections to the server. +func NewExecutorInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredExecutorInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredExecutorInformer constructs a new informer for Executor type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory print and number of connections to the server. +func NewFilteredExecutorInformer( + client versioned.Interface, + namespace string, + resyncPeriod time.Duration, + indexers cache.Indexers, + tweakListOptions internalinterfaces.TweakListOptionsFunc, +) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExecutorV1().Executor(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExecutorV1().Executor(namespace).Watch(context.TODO(), options) + }, + }, + &executorv1.Executor{}, + resyncPeriod, + indexers, + ) +} + +func (f *executorInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredExecutorInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *executorInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&executorv1.Executor{}, f.defaultInformer) +} + +func (f *executorInformer) Lister() executorlisterv1.ExecutorLister { + return executorlisterv1.NewExecutorLister(f.Informer().GetIndexer()) +} diff --git a/pkg/informers/externalversions/executor/v1/interface.go b/pkg/informers/externalversions/executor/v1/interface.go new file mode 100644 index 00000000..71e12744 --- /dev/null +++ b/pkg/informers/externalversions/executor/v1/interface.go @@ -0,0 +1,52 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/internalinterfaces" + +// Interface provides access to all the informers in this group version. +type Interface interface { + // Executor returns an ExecutorInformer. + Executor() ExecutorInformer + // Webhook returns a WebhookInformer. + Webhook() WebhookInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New( + f internalinterfaces.SharedInformerFactory, + namespace string, + tweakListOptions internalinterfaces.TweakListOptionsFunc, +) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// Executor returns an ExecutorInformer. +func (v *version) Executor() ExecutorInformer { + return &executorInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + +// Webhook returns a WebhookInformer. +func (v *version) Webhook() WebhookInformer { + return &webhookInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/informers/externalversions/executor/v1/webhook.go b/pkg/informers/externalversions/executor/v1/webhook.go new file mode 100644 index 00000000..223337c2 --- /dev/null +++ b/pkg/informers/externalversions/executor/v1/webhook.go @@ -0,0 +1,94 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import ( + "context" + "time" + + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" + "github.com/kubeshop/testkube-operator/pkg/clientset/versioned" + "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/internalinterfaces" + executorlisterv1 "github.com/kubeshop/testkube-operator/pkg/listers/executor/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" +) + +// WebhookInformer provides access to a shared informer and lister for Webhook. +type WebhookInformer interface { + Informer() cache.SharedIndexInformer + Lister() executorlisterv1.WebhookLister +} + +type webhookInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewWebhookInformer constructs a new informer for Webhook type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory print and number of connections to the server. +func NewWebhookInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredWebhookInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredWebhookInformer constructs a new informer for Webhook type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory print and number of connections to the server. +func NewFilteredWebhookInformer( + client versioned.Interface, + namespace string, + resyncPeriod time.Duration, + indexers cache.Indexers, + tweakListOptions internalinterfaces.TweakListOptionsFunc, +) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExecutorV1().Webhook(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExecutorV1().Webhook(namespace).Watch(context.TODO(), options) + }, + }, + &executorv1.Webhook{}, + resyncPeriod, + indexers, + ) +} + +func (f *webhookInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredWebhookInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *webhookInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&executorv1.Webhook{}, f.defaultInformer) +} + +func (f *webhookInformer) Lister() executorlisterv1.WebhookLister { + return executorlisterv1.NewWebhookLister(f.Informer().GetIndexer()) +} diff --git a/pkg/informers/externalversions/factory.go b/pkg/informers/externalversions/factory.go index 5a9c1f9f..4350297e 100644 --- a/pkg/informers/externalversions/factory.go +++ b/pkg/informers/externalversions/factory.go @@ -17,13 +17,15 @@ limitations under the License. package externalversions import ( - "github.com/kubeshop/testkube-operator/pkg/clientset/versioned" - "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/internalinterfaces" - "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/tests" reflect "reflect" sync "sync" time "time" + "github.com/kubeshop/testkube-operator/pkg/clientset/versioned" + "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/executor" + "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/internalinterfaces" + "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/tests" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -169,8 +171,13 @@ type SharedInformerFactory interface { WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool Tests() tests.Interface + Executor() executor.Interface } func (f *sharedInformerFactory) Tests() tests.Interface { return tests.New(f, f.namespace, f.tweakListOptions) } + +func (f *sharedInformerFactory) Executor() executor.Interface { + return executor.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/informers/externalversions/generic.go b/pkg/informers/externalversions/generic.go index 4f39a45f..eb6f2e2a 100644 --- a/pkg/informers/externalversions/generic.go +++ b/pkg/informers/externalversions/generic.go @@ -17,9 +17,12 @@ limitations under the License. package externalversions import ( + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" testsv3 "github.com/kubeshop/testkube-operator/api/tests/v3" + testsourcev1 "github.com/kubeshop/testkube-operator/api/testsource/v1" testsuitev3 "github.com/kubeshop/testkube-operator/api/testsuite/v3" testtriggersv1 "github.com/kubeshop/testkube-operator/api/testtriggers/v1" + "github.com/pkg/errors" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -70,6 +73,24 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource resource: resource.GroupResource(), informer: f.Tests().V3().Tests().Informer(), }, nil + // Group=executor.testkube.io, Version=v1 + case executorv1.ExecutorGroupVersionResource: + return &genericInformer{ + resource: resource.GroupResource(), + informer: f.Executor().V1().Executor().Informer(), + }, nil + // Group=executor.testkube.io, Version=v1 + case executorv1.WebhookGroupVersionResource: + return &genericInformer{ + resource: resource.GroupResource(), + informer: f.Executor().V1().Webhook().Informer(), + }, nil + // Group=tests.testkube.io, Version=v1 + case testsourcev1.GroupVersionResource: + return &genericInformer{ + resource: resource.GroupResource(), + informer: f.Tests().V1().TestSource().Informer(), + }, nil } return nil, errors.Errorf("no informer found for %v", resource) diff --git a/pkg/informers/externalversions/tests/v1/interface.go b/pkg/informers/externalversions/tests/v1/interface.go index 8364102a..23432fb8 100644 --- a/pkg/informers/externalversions/tests/v1/interface.go +++ b/pkg/informers/externalversions/tests/v1/interface.go @@ -22,6 +22,8 @@ import "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/int type Interface interface { // TestTriggers returns a TestTriggerInformer. TestTriggers() TestTriggerInformer + // TestSource returns a TestSourceInformer. + TestSource() TestSourceInformer } type version struct { @@ -43,3 +45,8 @@ func New( func (v *version) TestTriggers() TestTriggerInformer { return &testTriggerInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } + +// TestSource returns a TestTriggerInformer. +func (v *version) TestSource() TestSourceInformer { + return &testSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/informers/externalversions/tests/v1/testsource.go b/pkg/informers/externalversions/tests/v1/testsource.go new file mode 100644 index 00000000..682997af --- /dev/null +++ b/pkg/informers/externalversions/tests/v1/testsource.go @@ -0,0 +1,94 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import ( + "context" + "time" + + testsourcev1 "github.com/kubeshop/testkube-operator/api/testsource/v1" + "github.com/kubeshop/testkube-operator/pkg/clientset/versioned" + "github.com/kubeshop/testkube-operator/pkg/informers/externalversions/internalinterfaces" + testsourcelisterv1 "github.com/kubeshop/testkube-operator/pkg/listers/tests/v1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" +) + +// TestSourceInformer provides access to a shared informer and lister for TestSource. +type TestSourceInformer interface { + Informer() cache.SharedIndexInformer + Lister() testsourcelisterv1.TestSourceLister +} + +type testSourceInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewTestSourceInformer constructs a new informer for TestSource type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory print and number of connections to the server. +func NewTestSourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestSourceInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredTestSourceInformer constructs a new informer for TestSource type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory print and number of connections to the server. +func NewFilteredTestSourceInformer( + client versioned.Interface, + namespace string, + resyncPeriod time.Duration, + indexers cache.Indexers, + tweakListOptions internalinterfaces.TweakListOptionsFunc, +) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.TestsV1().TestSource(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.TestsV1().TestSource(namespace).Watch(context.TODO(), options) + }, + }, + &testsourcev1.TestSource{}, + resyncPeriod, + indexers, + ) +} + +func (f *testSourceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestSourceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *testSourceInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&testsourcev1.TestSource{}, f.defaultInformer) +} + +func (f *testSourceInformer) Lister() testsourcelisterv1.TestSourceLister { + return testsourcelisterv1.NewTestSourceLister(f.Informer().GetIndexer()) +} diff --git a/pkg/listers/executor/v1/executors.go b/pkg/listers/executor/v1/executors.go new file mode 100644 index 00000000..2608bbe1 --- /dev/null +++ b/pkg/listers/executor/v1/executors.go @@ -0,0 +1,101 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import ( + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/tools/cache" +) + +// ExecutorLister helps list Executors. +// All objects returned here must be treated as read-only. +type ExecutorLister interface { + // List lists all Executors in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*executorv1.Executor, err error) + // Executors returns an object that can list and get Executors. + Executors(namespace string) ExecutorNamespaceLister + ExecutorListerExpansion +} + +// executorLister implements the ExecutorLister interface. +type executorLister struct { + indexer cache.Indexer +} + +// NewExecutorLister returns a new ExecutorLister. +func NewExecutorLister(indexer cache.Indexer) ExecutorLister { + return &executorLister{indexer: indexer} +} + +// List lists all Executors in the indexer. +func (s *executorLister) List(selector labels.Selector) (ret []*executorv1.Executor, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*executorv1.Executor)) + }) + return ret, err +} + +// Executors returns an object that can list and get Executors. +func (s *executorLister) Executors(namespace string) ExecutorNamespaceLister { + return executorNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// ExecutorNamespaceLister helps list and get Executors. +// All objects returned here must be treated as read-only. +type ExecutorNamespaceLister interface { + // List lists all Executors in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*executorv1.Executor, err error) + // Get retrieves the Executor from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*executorv1.Executor, error) + ExecutorNamespaceListerExpansion +} + +// executorNamespaceLister implements the ExecutorNamespaceLister +// interface. +type executorNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Executors in the indexer for a given namespace. +func (s executorNamespaceLister) List(selector labels.Selector) (ret []*executorv1.Executor, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*executorv1.Executor)) + }) + return ret, err +} + +// Get retrieves the Executor from the indexer for a given namespace and name. +func (s executorNamespaceLister) Get(name string) (*executorv1.Executor, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound( + schema.GroupResource{Group: executorv1.GroupVersion.Group, Resource: executorv1.ExecutorResource}, + name, + ) + } + return obj.(*executorv1.Executor), nil +} diff --git a/pkg/listers/executor/v1/expansion_generated.go b/pkg/listers/executor/v1/expansion_generated.go new file mode 100644 index 00000000..30a233f6 --- /dev/null +++ b/pkg/listers/executor/v1/expansion_generated.go @@ -0,0 +1,31 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +// ExecutorListerExpansion allows custom methods to be added to ExecutorLister. +type ExecutorListerExpansion interface{} + +// ExecutorNamespaceListerExpansion allows custom methods to be added to +// ExecutorNamespaceLister. +type ExecutorNamespaceListerExpansion interface{} + +// WebhookListerExpansion allows custom methods to be added to WebhookLister. +type WebhookListerExpansion interface{} + +// WebhookNamespaceListerExpansion allows custom methods to be added to +// WebhookNamespaceLister. +type WebhookNamespaceListerExpansion interface{} diff --git a/pkg/listers/executor/v1/webhooks.go b/pkg/listers/executor/v1/webhooks.go new file mode 100644 index 00000000..e892185e --- /dev/null +++ b/pkg/listers/executor/v1/webhooks.go @@ -0,0 +1,101 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import ( + executorv1 "github.com/kubeshop/testkube-operator/api/executor/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/tools/cache" +) + +// WebhookLister helps list Webhooks. +// All objects returned here must be treated as read-only. +type WebhookLister interface { + // List lists all Webhooks in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*executorv1.Webhook, err error) + // Webhooks returns an object that can list and get Webhooks. + Webhooks(namespace string) WebhookNamespaceLister + WebhookListerExpansion +} + +// webhookLister implements the WebhookLister interface. +type webhookLister struct { + indexer cache.Indexer +} + +// NewWebhookLister returns a new WebhookLister. +func NewWebhookLister(indexer cache.Indexer) WebhookLister { + return &webhookLister{indexer: indexer} +} + +// List lists all Webhooks in the indexer. +func (s *webhookLister) List(selector labels.Selector) (ret []*executorv1.Webhook, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*executorv1.Webhook)) + }) + return ret, err +} + +// Webhooks returns an object that can list and get Webhooks. +func (s *webhookLister) Webhooks(namespace string) WebhookNamespaceLister { + return webhookNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// WebhookNamespaceLister helps list and get Webhooks. +// All objects returned here must be treated as read-only. +type WebhookNamespaceLister interface { + // List lists all Webhooks in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*executorv1.Webhook, err error) + // Get retrieves the Webhook from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*executorv1.Webhook, error) + WebhookNamespaceListerExpansion +} + +// webhookNamespaceLister implements the WebhookNamespaceLister +// interface. +type webhookNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Webhooks in the indexer for a given namespace. +func (s webhookNamespaceLister) List(selector labels.Selector) (ret []*executorv1.Webhook, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*executorv1.Webhook)) + }) + return ret, err +} + +// Get retrieves the Webhook from the indexer for a given namespace and name. +func (s webhookNamespaceLister) Get(name string) (*executorv1.Webhook, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound( + schema.GroupResource{Group: executorv1.GroupVersion.Group, Resource: executorv1.WebhookResource}, + name, + ) + } + return obj.(*executorv1.Webhook), nil +} diff --git a/pkg/listers/tests/v1/expansion_generated.go b/pkg/listers/tests/v1/expansion_generated.go index 94be48b5..9c22b09d 100644 --- a/pkg/listers/tests/v1/expansion_generated.go +++ b/pkg/listers/tests/v1/expansion_generated.go @@ -22,3 +22,10 @@ type TestTriggerListerExpansion interface{} // TestTriggerNamespaceListerExpansion allows custom methods to be added to // TestTriggerNamespaceLister. type TestTriggerNamespaceListerExpansion interface{} + +// TestSourceListerExpansion allows custom methods to be added to TestSourceLister. +type TestSourceListerExpansion interface{} + +// TestSourceNamespaceListerExpansion allows custom methods to be added to +// TestSourceNamespaceLister. +type TestSourceNamespaceListerExpansion interface{} diff --git a/pkg/listers/tests/v1/testsource.go b/pkg/listers/tests/v1/testsource.go new file mode 100644 index 00000000..109d9fa9 --- /dev/null +++ b/pkg/listers/tests/v1/testsource.go @@ -0,0 +1,101 @@ +/* +Copyright 2021. + +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. +*/ + +package v1 + +import ( + testsourcev1 "github.com/kubeshop/testkube-operator/api/testsource/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/tools/cache" +) + +// TestSourceLister helps list TestSources. +// All objects returned here must be treated as read-only. +type TestSourceLister interface { + // List lists all TestSources in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*testsourcev1.TestSource, err error) + // TestSources returns an object that can list and get TestSources. + TestSources(namespace string) TestSourceNamespaceLister + TestSourceListerExpansion +} + +// testSourceLister implements the TestSourceLister interface. +type testSourceLister struct { + indexer cache.Indexer +} + +// NewTestSourceLister returns a new TestSourceLister. +func NewTestSourceLister(indexer cache.Indexer) TestSourceLister { + return &testSourceLister{indexer: indexer} +} + +// List lists all TestSources in the indexer. +func (s *testSourceLister) List(selector labels.Selector) (ret []*testsourcev1.TestSource, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*testsourcev1.TestSource)) + }) + return ret, err +} + +// TestSources returns an object that can list and get TestSources. +func (s *testSourceLister) TestSources(namespace string) TestSourceNamespaceLister { + return testSourceNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// TestSourceNamespaceLister helps list and get TestSources. +// All objects returned here must be treated as read-only. +type TestSourceNamespaceLister interface { + // List lists all TestSources in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*testsourcev1.TestSource, err error) + // Get retrieves the TestSource from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*testsourcev1.TestSource, error) + TestSourceNamespaceListerExpansion +} + +// testSourceNamespaceLister implements the TestSourceNamespaceLister +// interface. +type testSourceNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all TestSources in the indexer for a given namespace. +func (s testSourceNamespaceLister) List(selector labels.Selector) (ret []*testsourcev1.TestSource, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*testsourcev1.TestSource)) + }) + return ret, err +} + +// Get retrieves the TestSource from the indexer for a given namespace and name. +func (s testSourceNamespaceLister) Get(name string) (*testsourcev1.TestSource, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound( + schema.GroupResource{Group: testsourcev1.GroupVersion.Group, Resource: testsourcev1.Resource}, + name, + ) + } + return obj.(*testsourcev1.TestSource), nil +}