-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
33 changed files
with
1,732 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
111 changes: 111 additions & 0 deletions
111
pkg/clientset/versioned/typed/executor/v1/executor_client.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Oops, something went wrong.