From c8cd83a14ccd2fc6bb153b94a61bf262ebcf642c Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 28 Jan 2025 18:49:09 +0100 Subject: [PATCH] Updates codegen scripts from hack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the update of k8s dependencies, most of the codegen commands changed (different flags, …), so this is adapting them. Signed-off-by: Vincent Demeester --- hack/generate-groups.sh | 14 +- hack/update-codegen.sh | 22 +-- hack/update-openapigen.sh | 15 +- pkg/apis/pipeline/v1/openapi_generated.go | 2 - .../pipeline/v1alpha1/openapi_generated.go | 2 - .../pipeline/v1beta1/openapi_generated.go | 2 - .../versioned/fake/clientset_generated.go | 6 +- .../typed/pipeline/v1/fake/fake_pipeline.go | 29 ++-- .../pipeline/v1/fake/fake_pipelinerun.go | 36 +++-- .../typed/pipeline/v1/fake/fake_task.go | 29 ++-- .../typed/pipeline/v1/fake/fake_taskrun.go | 36 +++-- .../versioned/typed/pipeline/v1/pipeline.go | 129 ++-------------- .../typed/pipeline/v1/pipelinerun.go | 146 ++---------------- .../versioned/typed/pipeline/v1/task.go | 129 ++-------------- .../versioned/typed/pipeline/v1/taskrun.go | 146 ++---------------- .../typed/pipeline/v1alpha1/fake/fake_run.go | 36 +++-- .../pipeline/v1alpha1/fake/fake_stepaction.go | 29 ++-- .../v1alpha1/fake/fake_verificationpolicy.go | 29 ++-- .../versioned/typed/pipeline/v1alpha1/run.go | 146 ++---------------- .../typed/pipeline/v1alpha1/stepaction.go | 129 ++-------------- .../pipeline/v1alpha1/verificationpolicy.go | 129 ++-------------- .../typed/pipeline/v1beta1/clustertask.go | 119 ++------------ .../typed/pipeline/v1beta1/customrun.go | 146 ++---------------- .../pipeline/v1beta1/fake/fake_clustertask.go | 29 ++-- .../pipeline/v1beta1/fake/fake_customrun.go | 36 +++-- .../pipeline/v1beta1/fake/fake_pipeline.go | 29 ++-- .../pipeline/v1beta1/fake/fake_pipelinerun.go | 36 +++-- .../pipeline/v1beta1/fake/fake_stepaction.go | 29 ++-- .../typed/pipeline/v1beta1/fake/fake_task.go | 29 ++-- .../pipeline/v1beta1/fake/fake_taskrun.go | 36 +++-- .../typed/pipeline/v1beta1/pipeline.go | 129 ++-------------- .../typed/pipeline/v1beta1/pipelinerun.go | 146 ++---------------- .../typed/pipeline/v1beta1/stepaction.go | 129 ++-------------- .../versioned/typed/pipeline/v1beta1/task.go | 129 ++-------------- .../typed/pipeline/v1beta1/taskrun.go | 146 ++---------------- .../informers/externalversions/factory.go | 1 + .../externalversions/pipeline/interface.go | 14 +- pkg/client/listers/pipeline/v1/pipeline.go | 39 +---- pkg/client/listers/pipeline/v1/pipelinerun.go | 39 +---- pkg/client/listers/pipeline/v1/task.go | 39 +---- pkg/client/listers/pipeline/v1/taskrun.go | 39 +---- pkg/client/listers/pipeline/v1alpha1/run.go | 39 +---- .../listers/pipeline/v1alpha1/stepaction.go | 39 +---- .../pipeline/v1alpha1/verificationpolicy.go | 39 +---- .../listers/pipeline/v1beta1/clustertask.go | 26 +--- .../listers/pipeline/v1beta1/customrun.go | 39 +---- .../listers/pipeline/v1beta1/pipeline.go | 39 +---- .../listers/pipeline/v1beta1/pipelinerun.go | 39 +---- .../listers/pipeline/v1beta1/stepaction.go | 39 +---- pkg/client/listers/pipeline/v1beta1/task.go | 39 +---- .../listers/pipeline/v1beta1/taskrun.go | 39 +---- .../versioned/fake/clientset_generated.go | 6 +- .../v1alpha1/fake/fake_resolutionrequest.go | 36 +++-- .../resolution/v1alpha1/resolutionrequest.go | 146 ++---------------- .../v1beta1/fake/fake_resolutionrequest.go | 36 +++-- .../resolution/v1beta1/resolutionrequest.go | 146 ++---------------- .../informers/externalversions/factory.go | 1 + .../resolution/v1alpha1/resolutionrequest.go | 39 +---- .../resolution/v1beta1/resolutionrequest.go | 39 +---- .../versioned/fake/clientset_generated.go | 6 +- .../v1alpha1/fake/fake_pipelineresource.go | 29 ++-- .../resource/v1alpha1/pipelineresource.go | 129 ++-------------- .../informers/externalversions/factory.go | 1 + .../resource/v1alpha1/pipelineresource.go | 39 +---- 64 files changed, 617 insertions(+), 2993 deletions(-) diff --git a/hack/generate-groups.sh b/hack/generate-groups.sh index d164b5402fd..6c285de41a5 100755 --- a/hack/generate-groups.sh +++ b/hack/generate-groups.sh @@ -18,7 +18,6 @@ set -o errexit set -o nounset set -o pipefail - # generate-groups generates everything for a project with external types only, e.g. a project based # on CustomResourceDefinitions. @@ -40,6 +39,7 @@ fi GENS="$1" OUTPUT_PKG="$2" +OUTPUT_PATH=".${OUTPUT_PKG#github.com/tektoncd/pipeline}" APIS_PKG="$3" GROUPS_WITH_VERSIONS="$4" shift 4 @@ -68,25 +68,25 @@ done if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then echo "Generating deepcopy funcs for ${GROUPS_WITH_VERSIONS}" - "${PREFIX}/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" "$@" + "${PREFIX}/deepcopy-gen" --output-file zz_generated.deepcopy.go --bounding-dirs "${APIS_PKG}" "$@" $(codegen::join " " "${FQ_APIS[@]}") fi if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" - "${PREFIX}/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@" + "${PREFIX}/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${FQ_APIS[@]}")" --output-pkg "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" --output-dir "${OUTPUT_PATH}/${CLIENTSET_PKG_NAME:-clientset}" "$@" fi if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers" - "${PREFIX}/lister-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@" + "${PREFIX}/lister-gen" --output-pkg "${OUTPUT_PKG}/listers" --output-dir "${OUTPUT_PATH}/listers" "$@" $(codegen::join " " "${FQ_APIS[@]}") fi if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers" "${PREFIX}/informer-gen" \ - --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \ --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \ --listers-package "${OUTPUT_PKG}/listers" \ - --output-package "${OUTPUT_PKG}/informers" \ - "$@" + --output-pkg "${OUTPUT_PKG}/informers" \ + --output-dir "${OUTPUT_PATH}/informers" \ + "$@" $(codegen::join " " "${FQ_APIS[@]}") fi diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 49e88afde99..c85be7849d1 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -47,7 +47,7 @@ bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" github.com/tektoncd/pipeline/pkg/client github.com/tektoncd/pipeline/pkg/apis \ "pipeline:v1alpha1,v1beta1,v1" \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt -# This generates deepcopy,client,informer and lister for the resolution package (v1alpha1) +# This generates deepcopy,client,informer and lister for the resolution package (v1alpha1, v1beta1) bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" \ github.com/tektoncd/pipeline/pkg/client/resolution github.com/tektoncd/pipeline/pkg/apis \ "resolution:v1alpha1,v1beta1" \ @@ -55,29 +55,29 @@ bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" # Depends on generate-groups.sh to install bin/deepcopy-gen ${PREFIX}/deepcopy-gen \ - -O zz_generated.deepcopy \ + --output-file zz_generated.deepcopy.go \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \ - -i github.com/tektoncd/pipeline/pkg/apis/config + github.com/tektoncd/pipeline/pkg/apis/config ${PREFIX}/deepcopy-gen \ - -O zz_generated.deepcopy \ + --output-file zz_generated.deepcopy.go \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \ - -i github.com/tektoncd/pipeline/pkg/spire/config + github.com/tektoncd/pipeline/pkg/spire/config ${PREFIX}/deepcopy-gen \ - -O zz_generated.deepcopy \ + --output-file zz_generated.deepcopy.go \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \ - -i github.com/tektoncd/pipeline/pkg/apis/config/resolver + github.com/tektoncd/pipeline/pkg/apis/config/resolver ${PREFIX}/deepcopy-gen \ - -O zz_generated.deepcopy \ + --output-file zz_generated.deepcopy.go \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \ --i github.com/tektoncd/pipeline/pkg/apis/pipeline/pod + github.com/tektoncd/pipeline/pkg/apis/pipeline/pod ${PREFIX}/deepcopy-gen \ - -O zz_generated.deepcopy \ + --output-file zz_generated.deepcopy.go \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \ --i github.com/tektoncd/pipeline/pkg/apis/run/v1alpha1 + github.com/tektoncd/pipeline/pkg/apis/run/v1alpha1 # Knative Injection diff --git a/hack/update-openapigen.sh b/hack/update-openapigen.sh index bb0eb8880fa..0ae374da526 100755 --- a/hack/update-openapigen.sh +++ b/hack/update-openapigen.sh @@ -36,18 +36,21 @@ trap cleanup EXIT for APIVERSION in "v1alpha1" "v1beta1" "v1" do - input_dirs=./pkg/apis/pipeline/${APIVERSION},./pkg/apis/pipeline/pod,knative.dev/pkg/apis,knative.dev/pkg/apis/duck/v1beta1 + input_dirs="./pkg/apis/pipeline/${APIVERSION} ./pkg/apis/pipeline/pod knative.dev/pkg/apis knative.dev/pkg/apis/duck/v1beta1" if [ ${APIVERSION} = "v1beta1" ] then - input_dirs=${input_dirs},./pkg/apis/resolution/v1beta1 + input_dirs="${input_dirs} ./pkg/apis/resolution/v1beta1" fi + set -x + echo "Generating OpenAPI specification for ${APIVERSION} ..." - go run k8s.io/kube-openapi/cmd/openapi-gen \ - --input-dirs ${input_dirs} \ - --output-package ./pkg/apis/pipeline/${APIVERSION} -o ./ \ + GOFLAGS="-mod=mod" go run k8s.io/kube-openapi/cmd/openapi-gen \ + --output-pkg github.com/tektoncd/pipeline/pkg/apis/pipeline/${APIVERSION} \ + --output-dir ./pkg/apis/pipeline/${APIVERSION} \ + --output-file openapi_generated.go \ --go-header-file hack/boilerplate/boilerplate.go.txt \ - -r "${TMP_DIFFROOT}/api-report" + -r "${TMP_DIFFROOT}/api-report" ${input_dirs} violations=$(diff --changed-group-format='%>' --unchanged-group-format='' <(sort "hack/ignored-openapi-violations.list") <(sort "${TMP_DIFFROOT}/api-report") || echo "") if [ -n "${violations}" ]; then diff --git a/pkg/apis/pipeline/v1/openapi_generated.go b/pkg/apis/pipeline/v1/openapi_generated.go index d05c2178e31..abea4cef535 100644 --- a/pkg/apis/pipeline/v1/openapi_generated.go +++ b/pkg/apis/pipeline/v1/openapi_generated.go @@ -19,8 +19,6 @@ limitations under the License. // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v1 import ( diff --git a/pkg/apis/pipeline/v1alpha1/openapi_generated.go b/pkg/apis/pipeline/v1alpha1/openapi_generated.go index cbcdc1ddf82..230c128f4ba 100644 --- a/pkg/apis/pipeline/v1alpha1/openapi_generated.go +++ b/pkg/apis/pipeline/v1alpha1/openapi_generated.go @@ -19,8 +19,6 @@ limitations under the License. // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v1alpha1 import ( diff --git a/pkg/apis/pipeline/v1beta1/openapi_generated.go b/pkg/apis/pipeline/v1beta1/openapi_generated.go index 145e72b083a..b87eecea0bf 100644 --- a/pkg/apis/pipeline/v1beta1/openapi_generated.go +++ b/pkg/apis/pipeline/v1beta1/openapi_generated.go @@ -19,8 +19,6 @@ limitations under the License. // Code generated by openapi-gen. DO NOT EDIT. -// This file was autogenerated by openapi-gen. Do not edit it manually! - package v1beta1 import ( diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index 98218788986..9dc230fb65d 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -35,8 +35,12 @@ import ( // NewSimpleClientset returns a clientset that will respond with the provided objects. // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement // for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). func NewSimpleClientset(objects ...runtime.Object) *Clientset { o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) for _, obj := range objects { diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_pipeline.go b/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_pipeline.go index 8df2f03e7c3..a4269ba0dad 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_pipeline.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_pipeline.go @@ -41,22 +41,24 @@ var pipelinesKind = v1.SchemeGroupVersion.WithKind("Pipeline") // Get takes name of the pipeline, and returns the corresponding pipeline object, and an error if there is any. func (c *FakePipelines) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Pipeline, err error) { + emptyResult := &v1.Pipeline{} obj, err := c.Fake. - Invokes(testing.NewGetAction(pipelinesResource, c.ns, name), &v1.Pipeline{}) + Invokes(testing.NewGetActionWithOptions(pipelinesResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.Pipeline), err } // List takes label and field selectors, and returns the list of Pipelines that match those selectors. func (c *FakePipelines) List(ctx context.Context, opts metav1.ListOptions) (result *v1.PipelineList, err error) { + emptyResult := &v1.PipelineList{} obj, err := c.Fake. - Invokes(testing.NewListAction(pipelinesResource, pipelinesKind, c.ns, opts), &v1.PipelineList{}) + Invokes(testing.NewListActionWithOptions(pipelinesResource, pipelinesKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,28 +77,30 @@ func (c *FakePipelines) List(ctx context.Context, opts metav1.ListOptions) (resu // Watch returns a watch.Interface that watches the requested pipelines. func (c *FakePipelines) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(pipelinesResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(pipelinesResource, c.ns, opts)) } // Create takes the representation of a pipeline and creates it. Returns the server's representation of the pipeline, and an error, if there is any. func (c *FakePipelines) Create(ctx context.Context, pipeline *v1.Pipeline, opts metav1.CreateOptions) (result *v1.Pipeline, err error) { + emptyResult := &v1.Pipeline{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(pipelinesResource, c.ns, pipeline), &v1.Pipeline{}) + Invokes(testing.NewCreateActionWithOptions(pipelinesResource, c.ns, pipeline, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.Pipeline), err } // Update takes the representation of a pipeline and updates it. Returns the server's representation of the pipeline, and an error, if there is any. func (c *FakePipelines) Update(ctx context.Context, pipeline *v1.Pipeline, opts metav1.UpdateOptions) (result *v1.Pipeline, err error) { + emptyResult := &v1.Pipeline{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(pipelinesResource, c.ns, pipeline), &v1.Pipeline{}) + Invokes(testing.NewUpdateActionWithOptions(pipelinesResource, c.ns, pipeline, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.Pipeline), err } @@ -111,7 +115,7 @@ func (c *FakePipelines) Delete(ctx context.Context, name string, opts metav1.Del // DeleteCollection deletes a collection of objects. func (c *FakePipelines) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionAction(pipelinesResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(pipelinesResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1.PipelineList{}) return err @@ -119,11 +123,12 @@ func (c *FakePipelines) DeleteCollection(ctx context.Context, opts metav1.Delete // Patch applies the patch and returns the patched pipeline. func (c *FakePipelines) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Pipeline, err error) { + emptyResult := &v1.Pipeline{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(pipelinesResource, c.ns, name, pt, data, subresources...), &v1.Pipeline{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(pipelinesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.Pipeline), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_pipelinerun.go b/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_pipelinerun.go index ab54060792c..08d3d1488bd 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_pipelinerun.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_pipelinerun.go @@ -41,22 +41,24 @@ var pipelinerunsKind = v1.SchemeGroupVersion.WithKind("PipelineRun") // Get takes name of the pipelineRun, and returns the corresponding pipelineRun object, and an error if there is any. func (c *FakePipelineRuns) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.PipelineRun, err error) { + emptyResult := &v1.PipelineRun{} obj, err := c.Fake. - Invokes(testing.NewGetAction(pipelinerunsResource, c.ns, name), &v1.PipelineRun{}) + Invokes(testing.NewGetActionWithOptions(pipelinerunsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.PipelineRun), err } // List takes label and field selectors, and returns the list of PipelineRuns that match those selectors. func (c *FakePipelineRuns) List(ctx context.Context, opts metav1.ListOptions) (result *v1.PipelineRunList, err error) { + emptyResult := &v1.PipelineRunList{} obj, err := c.Fake. - Invokes(testing.NewListAction(pipelinerunsResource, pipelinerunsKind, c.ns, opts), &v1.PipelineRunList{}) + Invokes(testing.NewListActionWithOptions(pipelinerunsResource, pipelinerunsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,40 +77,43 @@ func (c *FakePipelineRuns) List(ctx context.Context, opts metav1.ListOptions) (r // Watch returns a watch.Interface that watches the requested pipelineRuns. func (c *FakePipelineRuns) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(pipelinerunsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(pipelinerunsResource, c.ns, opts)) } // Create takes the representation of a pipelineRun and creates it. Returns the server's representation of the pipelineRun, and an error, if there is any. func (c *FakePipelineRuns) Create(ctx context.Context, pipelineRun *v1.PipelineRun, opts metav1.CreateOptions) (result *v1.PipelineRun, err error) { + emptyResult := &v1.PipelineRun{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(pipelinerunsResource, c.ns, pipelineRun), &v1.PipelineRun{}) + Invokes(testing.NewCreateActionWithOptions(pipelinerunsResource, c.ns, pipelineRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.PipelineRun), err } // Update takes the representation of a pipelineRun and updates it. Returns the server's representation of the pipelineRun, and an error, if there is any. func (c *FakePipelineRuns) Update(ctx context.Context, pipelineRun *v1.PipelineRun, opts metav1.UpdateOptions) (result *v1.PipelineRun, err error) { + emptyResult := &v1.PipelineRun{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(pipelinerunsResource, c.ns, pipelineRun), &v1.PipelineRun{}) + Invokes(testing.NewUpdateActionWithOptions(pipelinerunsResource, c.ns, pipelineRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.PipelineRun), 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 *FakePipelineRuns) UpdateStatus(ctx context.Context, pipelineRun *v1.PipelineRun, opts metav1.UpdateOptions) (*v1.PipelineRun, error) { +func (c *FakePipelineRuns) UpdateStatus(ctx context.Context, pipelineRun *v1.PipelineRun, opts metav1.UpdateOptions) (result *v1.PipelineRun, err error) { + emptyResult := &v1.PipelineRun{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(pipelinerunsResource, "status", c.ns, pipelineRun), &v1.PipelineRun{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(pipelinerunsResource, "status", c.ns, pipelineRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.PipelineRun), err } @@ -123,7 +128,7 @@ func (c *FakePipelineRuns) Delete(ctx context.Context, name string, opts metav1. // DeleteCollection deletes a collection of objects. func (c *FakePipelineRuns) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionAction(pipelinerunsResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(pipelinerunsResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1.PipelineRunList{}) return err @@ -131,11 +136,12 @@ func (c *FakePipelineRuns) DeleteCollection(ctx context.Context, opts metav1.Del // Patch applies the patch and returns the patched pipelineRun. func (c *FakePipelineRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.PipelineRun, err error) { + emptyResult := &v1.PipelineRun{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(pipelinerunsResource, c.ns, name, pt, data, subresources...), &v1.PipelineRun{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(pipelinerunsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.PipelineRun), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_task.go b/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_task.go index 926feffe082..fb356b31968 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_task.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_task.go @@ -41,22 +41,24 @@ var tasksKind = v1.SchemeGroupVersion.WithKind("Task") // Get takes name of the task, and returns the corresponding task object, and an error if there is any. func (c *FakeTasks) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Task, err error) { + emptyResult := &v1.Task{} obj, err := c.Fake. - Invokes(testing.NewGetAction(tasksResource, c.ns, name), &v1.Task{}) + Invokes(testing.NewGetActionWithOptions(tasksResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.Task), err } // List takes label and field selectors, and returns the list of Tasks that match those selectors. func (c *FakeTasks) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TaskList, err error) { + emptyResult := &v1.TaskList{} obj, err := c.Fake. - Invokes(testing.NewListAction(tasksResource, tasksKind, c.ns, opts), &v1.TaskList{}) + Invokes(testing.NewListActionWithOptions(tasksResource, tasksKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,28 +77,30 @@ func (c *FakeTasks) List(ctx context.Context, opts metav1.ListOptions) (result * // Watch returns a watch.Interface that watches the requested tasks. func (c *FakeTasks) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(tasksResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(tasksResource, c.ns, opts)) } // Create takes the representation of a task and creates it. Returns the server's representation of the task, and an error, if there is any. func (c *FakeTasks) Create(ctx context.Context, task *v1.Task, opts metav1.CreateOptions) (result *v1.Task, err error) { + emptyResult := &v1.Task{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(tasksResource, c.ns, task), &v1.Task{}) + Invokes(testing.NewCreateActionWithOptions(tasksResource, c.ns, task, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.Task), err } // Update takes the representation of a task and updates it. Returns the server's representation of the task, and an error, if there is any. func (c *FakeTasks) Update(ctx context.Context, task *v1.Task, opts metav1.UpdateOptions) (result *v1.Task, err error) { + emptyResult := &v1.Task{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(tasksResource, c.ns, task), &v1.Task{}) + Invokes(testing.NewUpdateActionWithOptions(tasksResource, c.ns, task, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.Task), err } @@ -111,7 +115,7 @@ func (c *FakeTasks) Delete(ctx context.Context, name string, opts metav1.DeleteO // DeleteCollection deletes a collection of objects. func (c *FakeTasks) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionAction(tasksResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(tasksResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1.TaskList{}) return err @@ -119,11 +123,12 @@ func (c *FakeTasks) DeleteCollection(ctx context.Context, opts metav1.DeleteOpti // Patch applies the patch and returns the patched task. func (c *FakeTasks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Task, err error) { + emptyResult := &v1.Task{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(tasksResource, c.ns, name, pt, data, subresources...), &v1.Task{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(tasksResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.Task), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_taskrun.go b/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_taskrun.go index 95773426ad6..a0662f16ec3 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_taskrun.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1/fake/fake_taskrun.go @@ -41,22 +41,24 @@ var taskrunsKind = v1.SchemeGroupVersion.WithKind("TaskRun") // Get takes name of the taskRun, and returns the corresponding taskRun object, and an error if there is any. func (c *FakeTaskRuns) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TaskRun, err error) { + emptyResult := &v1.TaskRun{} obj, err := c.Fake. - Invokes(testing.NewGetAction(taskrunsResource, c.ns, name), &v1.TaskRun{}) + Invokes(testing.NewGetActionWithOptions(taskrunsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TaskRun), err } // List takes label and field selectors, and returns the list of TaskRuns that match those selectors. func (c *FakeTaskRuns) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TaskRunList, err error) { + emptyResult := &v1.TaskRunList{} obj, err := c.Fake. - Invokes(testing.NewListAction(taskrunsResource, taskrunsKind, c.ns, opts), &v1.TaskRunList{}) + Invokes(testing.NewListActionWithOptions(taskrunsResource, taskrunsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,40 +77,43 @@ func (c *FakeTaskRuns) List(ctx context.Context, opts metav1.ListOptions) (resul // Watch returns a watch.Interface that watches the requested taskRuns. func (c *FakeTaskRuns) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(taskrunsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(taskrunsResource, c.ns, opts)) } // Create takes the representation of a taskRun and creates it. Returns the server's representation of the taskRun, and an error, if there is any. func (c *FakeTaskRuns) Create(ctx context.Context, taskRun *v1.TaskRun, opts metav1.CreateOptions) (result *v1.TaskRun, err error) { + emptyResult := &v1.TaskRun{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(taskrunsResource, c.ns, taskRun), &v1.TaskRun{}) + Invokes(testing.NewCreateActionWithOptions(taskrunsResource, c.ns, taskRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TaskRun), err } // Update takes the representation of a taskRun and updates it. Returns the server's representation of the taskRun, and an error, if there is any. func (c *FakeTaskRuns) Update(ctx context.Context, taskRun *v1.TaskRun, opts metav1.UpdateOptions) (result *v1.TaskRun, err error) { + emptyResult := &v1.TaskRun{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(taskrunsResource, c.ns, taskRun), &v1.TaskRun{}) + Invokes(testing.NewUpdateActionWithOptions(taskrunsResource, c.ns, taskRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TaskRun), 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 *FakeTaskRuns) UpdateStatus(ctx context.Context, taskRun *v1.TaskRun, opts metav1.UpdateOptions) (*v1.TaskRun, error) { +func (c *FakeTaskRuns) UpdateStatus(ctx context.Context, taskRun *v1.TaskRun, opts metav1.UpdateOptions) (result *v1.TaskRun, err error) { + emptyResult := &v1.TaskRun{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(taskrunsResource, "status", c.ns, taskRun), &v1.TaskRun{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(taskrunsResource, "status", c.ns, taskRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TaskRun), err } @@ -123,7 +128,7 @@ func (c *FakeTaskRuns) Delete(ctx context.Context, name string, opts metav1.Dele // DeleteCollection deletes a collection of objects. func (c *FakeTaskRuns) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionAction(taskrunsResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(taskrunsResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1.TaskRunList{}) return err @@ -131,11 +136,12 @@ func (c *FakeTaskRuns) DeleteCollection(ctx context.Context, opts metav1.DeleteO // Patch applies the patch and returns the patched taskRun. func (c *FakeTaskRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TaskRun, err error) { + emptyResult := &v1.TaskRun{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(taskrunsResource, c.ns, name, pt, data, subresources...), &v1.TaskRun{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(taskrunsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TaskRun), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1/pipeline.go b/pkg/client/clientset/versioned/typed/pipeline/v1/pipeline.go index 38a3b33f02d..436d074ee3a 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1/pipeline.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1/pipeline.go @@ -20,14 +20,13 @@ package v1 import ( "context" - "time" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // PipelinesGetter has a method to return a PipelineInterface. @@ -51,128 +50,18 @@ type PipelineInterface interface { // pipelines implements PipelineInterface type pipelines struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1.Pipeline, *v1.PipelineList] } // newPipelines returns a Pipelines func newPipelines(c *TektonV1Client, namespace string) *pipelines { return &pipelines{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1.Pipeline, *v1.PipelineList]( + "pipelines", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1.Pipeline { return &v1.Pipeline{} }, + func() *v1.PipelineList { return &v1.PipelineList{} }), } } - -// Get takes name of the pipeline, and returns the corresponding pipeline object, and an error if there is any. -func (c *pipelines) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Pipeline, err error) { - result = &v1.Pipeline{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelines"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Pipelines that match those selectors. -func (c *pipelines) List(ctx context.Context, opts metav1.ListOptions) (result *v1.PipelineList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.PipelineList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelines"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested pipelines. -func (c *pipelines) Watch(ctx context.Context, opts metav1.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("pipelines"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a pipeline and creates it. Returns the server's representation of the pipeline, and an error, if there is any. -func (c *pipelines) Create(ctx context.Context, pipeline *v1.Pipeline, opts metav1.CreateOptions) (result *v1.Pipeline, err error) { - result = &v1.Pipeline{} - err = c.client.Post(). - Namespace(c.ns). - Resource("pipelines"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipeline). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a pipeline and updates it. Returns the server's representation of the pipeline, and an error, if there is any. -func (c *pipelines) Update(ctx context.Context, pipeline *v1.Pipeline, opts metav1.UpdateOptions) (result *v1.Pipeline, err error) { - result = &v1.Pipeline{} - err = c.client.Put(). - Namespace(c.ns). - Resource("pipelines"). - Name(pipeline.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipeline). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the pipeline and deletes it. Returns an error if one occurs. -func (c *pipelines) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("pipelines"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *pipelines) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.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("pipelines"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched pipeline. -func (c *pipelines) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Pipeline, err error) { - result = &v1.Pipeline{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("pipelines"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1/pipelinerun.go b/pkg/client/clientset/versioned/typed/pipeline/v1/pipelinerun.go index 0f37e00bc6a..a458b09d321 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1/pipelinerun.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1/pipelinerun.go @@ -20,14 +20,13 @@ package v1 import ( "context" - "time" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // PipelineRunsGetter has a method to return a PipelineRunInterface. @@ -40,6 +39,7 @@ type PipelineRunsGetter interface { type PipelineRunInterface interface { Create(ctx context.Context, pipelineRun *v1.PipelineRun, opts metav1.CreateOptions) (*v1.PipelineRun, error) Update(ctx context.Context, pipelineRun *v1.PipelineRun, opts metav1.UpdateOptions) (*v1.PipelineRun, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, pipelineRun *v1.PipelineRun, opts metav1.UpdateOptions) (*v1.PipelineRun, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error @@ -52,144 +52,18 @@ type PipelineRunInterface interface { // pipelineRuns implements PipelineRunInterface type pipelineRuns struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1.PipelineRun, *v1.PipelineRunList] } // newPipelineRuns returns a PipelineRuns func newPipelineRuns(c *TektonV1Client, namespace string) *pipelineRuns { return &pipelineRuns{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1.PipelineRun, *v1.PipelineRunList]( + "pipelineruns", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1.PipelineRun { return &v1.PipelineRun{} }, + func() *v1.PipelineRunList { return &v1.PipelineRunList{} }), } } - -// Get takes name of the pipelineRun, and returns the corresponding pipelineRun object, and an error if there is any. -func (c *pipelineRuns) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.PipelineRun, err error) { - result = &v1.PipelineRun{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelineruns"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of PipelineRuns that match those selectors. -func (c *pipelineRuns) List(ctx context.Context, opts metav1.ListOptions) (result *v1.PipelineRunList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.PipelineRunList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelineruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested pipelineRuns. -func (c *pipelineRuns) Watch(ctx context.Context, opts metav1.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("pipelineruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a pipelineRun and creates it. Returns the server's representation of the pipelineRun, and an error, if there is any. -func (c *pipelineRuns) Create(ctx context.Context, pipelineRun *v1.PipelineRun, opts metav1.CreateOptions) (result *v1.PipelineRun, err error) { - result = &v1.PipelineRun{} - err = c.client.Post(). - Namespace(c.ns). - Resource("pipelineruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipelineRun). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a pipelineRun and updates it. Returns the server's representation of the pipelineRun, and an error, if there is any. -func (c *pipelineRuns) Update(ctx context.Context, pipelineRun *v1.PipelineRun, opts metav1.UpdateOptions) (result *v1.PipelineRun, err error) { - result = &v1.PipelineRun{} - err = c.client.Put(). - Namespace(c.ns). - Resource("pipelineruns"). - Name(pipelineRun.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipelineRun). - 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 *pipelineRuns) UpdateStatus(ctx context.Context, pipelineRun *v1.PipelineRun, opts metav1.UpdateOptions) (result *v1.PipelineRun, err error) { - result = &v1.PipelineRun{} - err = c.client.Put(). - Namespace(c.ns). - Resource("pipelineruns"). - Name(pipelineRun.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipelineRun). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the pipelineRun and deletes it. Returns an error if one occurs. -func (c *pipelineRuns) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("pipelineruns"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *pipelineRuns) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.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("pipelineruns"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched pipelineRun. -func (c *pipelineRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.PipelineRun, err error) { - result = &v1.PipelineRun{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("pipelineruns"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1/task.go b/pkg/client/clientset/versioned/typed/pipeline/v1/task.go index d900e6f6122..3ddad1a5b24 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1/task.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1/task.go @@ -20,14 +20,13 @@ package v1 import ( "context" - "time" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // TasksGetter has a method to return a TaskInterface. @@ -51,128 +50,18 @@ type TaskInterface interface { // tasks implements TaskInterface type tasks struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1.Task, *v1.TaskList] } // newTasks returns a Tasks func newTasks(c *TektonV1Client, namespace string) *tasks { return &tasks{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1.Task, *v1.TaskList]( + "tasks", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1.Task { return &v1.Task{} }, + func() *v1.TaskList { return &v1.TaskList{} }), } } - -// Get takes name of the task, and returns the corresponding task object, and an error if there is any. -func (c *tasks) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Task, err error) { - result = &v1.Task{} - err = c.client.Get(). - Namespace(c.ns). - Resource("tasks"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Tasks that match those selectors. -func (c *tasks) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TaskList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.TaskList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("tasks"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested tasks. -func (c *tasks) Watch(ctx context.Context, opts metav1.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("tasks"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a task and creates it. Returns the server's representation of the task, and an error, if there is any. -func (c *tasks) Create(ctx context.Context, task *v1.Task, opts metav1.CreateOptions) (result *v1.Task, err error) { - result = &v1.Task{} - err = c.client.Post(). - Namespace(c.ns). - Resource("tasks"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(task). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a task and updates it. Returns the server's representation of the task, and an error, if there is any. -func (c *tasks) Update(ctx context.Context, task *v1.Task, opts metav1.UpdateOptions) (result *v1.Task, err error) { - result = &v1.Task{} - err = c.client.Put(). - Namespace(c.ns). - Resource("tasks"). - Name(task.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(task). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the task and deletes it. Returns an error if one occurs. -func (c *tasks) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("tasks"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *tasks) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.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("tasks"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched task. -func (c *tasks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Task, err error) { - result = &v1.Task{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("tasks"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1/taskrun.go b/pkg/client/clientset/versioned/typed/pipeline/v1/taskrun.go index 34145a97323..e5a06dadc59 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1/taskrun.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1/taskrun.go @@ -20,14 +20,13 @@ package v1 import ( "context" - "time" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // TaskRunsGetter has a method to return a TaskRunInterface. @@ -40,6 +39,7 @@ type TaskRunsGetter interface { type TaskRunInterface interface { Create(ctx context.Context, taskRun *v1.TaskRun, opts metav1.CreateOptions) (*v1.TaskRun, error) Update(ctx context.Context, taskRun *v1.TaskRun, opts metav1.UpdateOptions) (*v1.TaskRun, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, taskRun *v1.TaskRun, opts metav1.UpdateOptions) (*v1.TaskRun, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error @@ -52,144 +52,18 @@ type TaskRunInterface interface { // taskRuns implements TaskRunInterface type taskRuns struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1.TaskRun, *v1.TaskRunList] } // newTaskRuns returns a TaskRuns func newTaskRuns(c *TektonV1Client, namespace string) *taskRuns { return &taskRuns{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1.TaskRun, *v1.TaskRunList]( + "taskruns", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1.TaskRun { return &v1.TaskRun{} }, + func() *v1.TaskRunList { return &v1.TaskRunList{} }), } } - -// Get takes name of the taskRun, and returns the corresponding taskRun object, and an error if there is any. -func (c *taskRuns) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TaskRun, err error) { - result = &v1.TaskRun{} - err = c.client.Get(). - Namespace(c.ns). - Resource("taskruns"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of TaskRuns that match those selectors. -func (c *taskRuns) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TaskRunList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.TaskRunList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("taskruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested taskRuns. -func (c *taskRuns) Watch(ctx context.Context, opts metav1.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("taskruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a taskRun and creates it. Returns the server's representation of the taskRun, and an error, if there is any. -func (c *taskRuns) Create(ctx context.Context, taskRun *v1.TaskRun, opts metav1.CreateOptions) (result *v1.TaskRun, err error) { - result = &v1.TaskRun{} - err = c.client.Post(). - Namespace(c.ns). - Resource("taskruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(taskRun). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a taskRun and updates it. Returns the server's representation of the taskRun, and an error, if there is any. -func (c *taskRuns) Update(ctx context.Context, taskRun *v1.TaskRun, opts metav1.UpdateOptions) (result *v1.TaskRun, err error) { - result = &v1.TaskRun{} - err = c.client.Put(). - Namespace(c.ns). - Resource("taskruns"). - Name(taskRun.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(taskRun). - 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 *taskRuns) UpdateStatus(ctx context.Context, taskRun *v1.TaskRun, opts metav1.UpdateOptions) (result *v1.TaskRun, err error) { - result = &v1.TaskRun{} - err = c.client.Put(). - Namespace(c.ns). - Resource("taskruns"). - Name(taskRun.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(taskRun). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the taskRun and deletes it. Returns an error if one occurs. -func (c *taskRuns) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("taskruns"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *taskRuns) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.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("taskruns"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched taskRun. -func (c *taskRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TaskRun, err error) { - result = &v1.TaskRun{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("taskruns"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_run.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_run.go index 065047adb5f..9e95e5f93c3 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_run.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_run.go @@ -41,22 +41,24 @@ var runsKind = v1alpha1.SchemeGroupVersion.WithKind("Run") // Get takes name of the run, and returns the corresponding run object, and an error if there is any. func (c *FakeRuns) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Run, err error) { + emptyResult := &v1alpha1.Run{} obj, err := c.Fake. - Invokes(testing.NewGetAction(runsResource, c.ns, name), &v1alpha1.Run{}) + Invokes(testing.NewGetActionWithOptions(runsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.Run), err } // List takes label and field selectors, and returns the list of Runs that match those selectors. func (c *FakeRuns) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.RunList, err error) { + emptyResult := &v1alpha1.RunList{} obj, err := c.Fake. - Invokes(testing.NewListAction(runsResource, runsKind, c.ns, opts), &v1alpha1.RunList{}) + Invokes(testing.NewListActionWithOptions(runsResource, runsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,40 +77,43 @@ func (c *FakeRuns) List(ctx context.Context, opts v1.ListOptions) (result *v1alp // Watch returns a watch.Interface that watches the requested runs. func (c *FakeRuns) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(runsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(runsResource, c.ns, opts)) } // Create takes the representation of a run and creates it. Returns the server's representation of the run, and an error, if there is any. func (c *FakeRuns) Create(ctx context.Context, run *v1alpha1.Run, opts v1.CreateOptions) (result *v1alpha1.Run, err error) { + emptyResult := &v1alpha1.Run{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(runsResource, c.ns, run), &v1alpha1.Run{}) + Invokes(testing.NewCreateActionWithOptions(runsResource, c.ns, run, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.Run), err } // Update takes the representation of a run and updates it. Returns the server's representation of the run, and an error, if there is any. func (c *FakeRuns) Update(ctx context.Context, run *v1alpha1.Run, opts v1.UpdateOptions) (result *v1alpha1.Run, err error) { + emptyResult := &v1alpha1.Run{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(runsResource, c.ns, run), &v1alpha1.Run{}) + Invokes(testing.NewUpdateActionWithOptions(runsResource, c.ns, run, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.Run), 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 *FakeRuns) UpdateStatus(ctx context.Context, run *v1alpha1.Run, opts v1.UpdateOptions) (*v1alpha1.Run, error) { +func (c *FakeRuns) UpdateStatus(ctx context.Context, run *v1alpha1.Run, opts v1.UpdateOptions) (result *v1alpha1.Run, err error) { + emptyResult := &v1alpha1.Run{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(runsResource, "status", c.ns, run), &v1alpha1.Run{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(runsResource, "status", c.ns, run, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.Run), err } @@ -123,7 +128,7 @@ func (c *FakeRuns) Delete(ctx context.Context, name string, opts v1.DeleteOption // DeleteCollection deletes a collection of objects. func (c *FakeRuns) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(runsResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(runsResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1alpha1.RunList{}) return err @@ -131,11 +136,12 @@ func (c *FakeRuns) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, // Patch applies the patch and returns the patched run. func (c *FakeRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Run, err error) { + emptyResult := &v1alpha1.Run{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(runsResource, c.ns, name, pt, data, subresources...), &v1alpha1.Run{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(runsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.Run), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_stepaction.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_stepaction.go index 7e3430c1143..a0d80727afe 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_stepaction.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_stepaction.go @@ -41,22 +41,24 @@ var stepactionsKind = v1alpha1.SchemeGroupVersion.WithKind("StepAction") // Get takes name of the stepAction, and returns the corresponding stepAction object, and an error if there is any. func (c *FakeStepActions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.StepAction, err error) { + emptyResult := &v1alpha1.StepAction{} obj, err := c.Fake. - Invokes(testing.NewGetAction(stepactionsResource, c.ns, name), &v1alpha1.StepAction{}) + Invokes(testing.NewGetActionWithOptions(stepactionsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.StepAction), err } // List takes label and field selectors, and returns the list of StepActions that match those selectors. func (c *FakeStepActions) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.StepActionList, err error) { + emptyResult := &v1alpha1.StepActionList{} obj, err := c.Fake. - Invokes(testing.NewListAction(stepactionsResource, stepactionsKind, c.ns, opts), &v1alpha1.StepActionList{}) + Invokes(testing.NewListActionWithOptions(stepactionsResource, stepactionsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,28 +77,30 @@ func (c *FakeStepActions) List(ctx context.Context, opts v1.ListOptions) (result // Watch returns a watch.Interface that watches the requested stepActions. func (c *FakeStepActions) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(stepactionsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(stepactionsResource, c.ns, opts)) } // Create takes the representation of a stepAction and creates it. Returns the server's representation of the stepAction, and an error, if there is any. func (c *FakeStepActions) Create(ctx context.Context, stepAction *v1alpha1.StepAction, opts v1.CreateOptions) (result *v1alpha1.StepAction, err error) { + emptyResult := &v1alpha1.StepAction{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(stepactionsResource, c.ns, stepAction), &v1alpha1.StepAction{}) + Invokes(testing.NewCreateActionWithOptions(stepactionsResource, c.ns, stepAction, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.StepAction), err } // Update takes the representation of a stepAction and updates it. Returns the server's representation of the stepAction, and an error, if there is any. func (c *FakeStepActions) Update(ctx context.Context, stepAction *v1alpha1.StepAction, opts v1.UpdateOptions) (result *v1alpha1.StepAction, err error) { + emptyResult := &v1alpha1.StepAction{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(stepactionsResource, c.ns, stepAction), &v1alpha1.StepAction{}) + Invokes(testing.NewUpdateActionWithOptions(stepactionsResource, c.ns, stepAction, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.StepAction), err } @@ -111,7 +115,7 @@ func (c *FakeStepActions) Delete(ctx context.Context, name string, opts v1.Delet // DeleteCollection deletes a collection of objects. func (c *FakeStepActions) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(stepactionsResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(stepactionsResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1alpha1.StepActionList{}) return err @@ -119,11 +123,12 @@ func (c *FakeStepActions) DeleteCollection(ctx context.Context, opts v1.DeleteOp // Patch applies the patch and returns the patched stepAction. func (c *FakeStepActions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.StepAction, err error) { + emptyResult := &v1alpha1.StepAction{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(stepactionsResource, c.ns, name, pt, data, subresources...), &v1alpha1.StepAction{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(stepactionsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.StepAction), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_verificationpolicy.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_verificationpolicy.go index 65df77d070a..a523cf5e2c8 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_verificationpolicy.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/fake/fake_verificationpolicy.go @@ -41,22 +41,24 @@ var verificationpoliciesKind = v1alpha1.SchemeGroupVersion.WithKind("Verificatio // Get takes name of the verificationPolicy, and returns the corresponding verificationPolicy object, and an error if there is any. func (c *FakeVerificationPolicies) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.VerificationPolicy, err error) { + emptyResult := &v1alpha1.VerificationPolicy{} obj, err := c.Fake. - Invokes(testing.NewGetAction(verificationpoliciesResource, c.ns, name), &v1alpha1.VerificationPolicy{}) + Invokes(testing.NewGetActionWithOptions(verificationpoliciesResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.VerificationPolicy), err } // List takes label and field selectors, and returns the list of VerificationPolicies that match those selectors. func (c *FakeVerificationPolicies) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.VerificationPolicyList, err error) { + emptyResult := &v1alpha1.VerificationPolicyList{} obj, err := c.Fake. - Invokes(testing.NewListAction(verificationpoliciesResource, verificationpoliciesKind, c.ns, opts), &v1alpha1.VerificationPolicyList{}) + Invokes(testing.NewListActionWithOptions(verificationpoliciesResource, verificationpoliciesKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,28 +77,30 @@ func (c *FakeVerificationPolicies) List(ctx context.Context, opts v1.ListOptions // Watch returns a watch.Interface that watches the requested verificationPolicies. func (c *FakeVerificationPolicies) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(verificationpoliciesResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(verificationpoliciesResource, c.ns, opts)) } // Create takes the representation of a verificationPolicy and creates it. Returns the server's representation of the verificationPolicy, and an error, if there is any. func (c *FakeVerificationPolicies) Create(ctx context.Context, verificationPolicy *v1alpha1.VerificationPolicy, opts v1.CreateOptions) (result *v1alpha1.VerificationPolicy, err error) { + emptyResult := &v1alpha1.VerificationPolicy{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(verificationpoliciesResource, c.ns, verificationPolicy), &v1alpha1.VerificationPolicy{}) + Invokes(testing.NewCreateActionWithOptions(verificationpoliciesResource, c.ns, verificationPolicy, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.VerificationPolicy), err } // Update takes the representation of a verificationPolicy and updates it. Returns the server's representation of the verificationPolicy, and an error, if there is any. func (c *FakeVerificationPolicies) Update(ctx context.Context, verificationPolicy *v1alpha1.VerificationPolicy, opts v1.UpdateOptions) (result *v1alpha1.VerificationPolicy, err error) { + emptyResult := &v1alpha1.VerificationPolicy{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(verificationpoliciesResource, c.ns, verificationPolicy), &v1alpha1.VerificationPolicy{}) + Invokes(testing.NewUpdateActionWithOptions(verificationpoliciesResource, c.ns, verificationPolicy, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.VerificationPolicy), err } @@ -111,7 +115,7 @@ func (c *FakeVerificationPolicies) Delete(ctx context.Context, name string, opts // DeleteCollection deletes a collection of objects. func (c *FakeVerificationPolicies) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(verificationpoliciesResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(verificationpoliciesResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1alpha1.VerificationPolicyList{}) return err @@ -119,11 +123,12 @@ func (c *FakeVerificationPolicies) DeleteCollection(ctx context.Context, opts v1 // Patch applies the patch and returns the patched verificationPolicy. func (c *FakeVerificationPolicies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.VerificationPolicy, err error) { + emptyResult := &v1alpha1.VerificationPolicy{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(verificationpoliciesResource, c.ns, name, pt, data, subresources...), &v1alpha1.VerificationPolicy{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(verificationpoliciesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.VerificationPolicy), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/run.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/run.go index 417dd82120d..f61dab4f699 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/run.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/run.go @@ -20,14 +20,13 @@ package v1alpha1 import ( "context" - "time" v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // RunsGetter has a method to return a RunInterface. @@ -40,6 +39,7 @@ type RunsGetter interface { type RunInterface interface { Create(ctx context.Context, run *v1alpha1.Run, opts v1.CreateOptions) (*v1alpha1.Run, error) Update(ctx context.Context, run *v1alpha1.Run, opts v1.UpdateOptions) (*v1alpha1.Run, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, run *v1alpha1.Run, opts v1.UpdateOptions) (*v1alpha1.Run, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error @@ -52,144 +52,18 @@ type RunInterface interface { // runs implements RunInterface type runs struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1alpha1.Run, *v1alpha1.RunList] } // newRuns returns a Runs func newRuns(c *TektonV1alpha1Client, namespace string) *runs { return &runs{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1alpha1.Run, *v1alpha1.RunList]( + "runs", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1alpha1.Run { return &v1alpha1.Run{} }, + func() *v1alpha1.RunList { return &v1alpha1.RunList{} }), } } - -// Get takes name of the run, and returns the corresponding run object, and an error if there is any. -func (c *runs) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Run, err error) { - result = &v1alpha1.Run{} - err = c.client.Get(). - Namespace(c.ns). - Resource("runs"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Runs that match those selectors. -func (c *runs) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.RunList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.RunList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("runs"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested runs. -func (c *runs) 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("runs"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a run and creates it. Returns the server's representation of the run, and an error, if there is any. -func (c *runs) Create(ctx context.Context, run *v1alpha1.Run, opts v1.CreateOptions) (result *v1alpha1.Run, err error) { - result = &v1alpha1.Run{} - err = c.client.Post(). - Namespace(c.ns). - Resource("runs"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(run). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a run and updates it. Returns the server's representation of the run, and an error, if there is any. -func (c *runs) Update(ctx context.Context, run *v1alpha1.Run, opts v1.UpdateOptions) (result *v1alpha1.Run, err error) { - result = &v1alpha1.Run{} - err = c.client.Put(). - Namespace(c.ns). - Resource("runs"). - Name(run.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(run). - 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 *runs) UpdateStatus(ctx context.Context, run *v1alpha1.Run, opts v1.UpdateOptions) (result *v1alpha1.Run, err error) { - result = &v1alpha1.Run{} - err = c.client.Put(). - Namespace(c.ns). - Resource("runs"). - Name(run.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(run). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the run and deletes it. Returns an error if one occurs. -func (c *runs) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("runs"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *runs) 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("runs"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched run. -func (c *runs) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Run, err error) { - result = &v1alpha1.Run{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("runs"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/stepaction.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/stepaction.go index 5b5e9ebd4e8..d813f39d900 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/stepaction.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/stepaction.go @@ -20,14 +20,13 @@ package v1alpha1 import ( "context" - "time" v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // StepActionsGetter has a method to return a StepActionInterface. @@ -51,128 +50,18 @@ type StepActionInterface interface { // stepActions implements StepActionInterface type stepActions struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1alpha1.StepAction, *v1alpha1.StepActionList] } // newStepActions returns a StepActions func newStepActions(c *TektonV1alpha1Client, namespace string) *stepActions { return &stepActions{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1alpha1.StepAction, *v1alpha1.StepActionList]( + "stepactions", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1alpha1.StepAction { return &v1alpha1.StepAction{} }, + func() *v1alpha1.StepActionList { return &v1alpha1.StepActionList{} }), } } - -// Get takes name of the stepAction, and returns the corresponding stepAction object, and an error if there is any. -func (c *stepActions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.StepAction, err error) { - result = &v1alpha1.StepAction{} - err = c.client.Get(). - Namespace(c.ns). - Resource("stepactions"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of StepActions that match those selectors. -func (c *stepActions) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.StepActionList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.StepActionList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("stepactions"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested stepActions. -func (c *stepActions) 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("stepactions"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a stepAction and creates it. Returns the server's representation of the stepAction, and an error, if there is any. -func (c *stepActions) Create(ctx context.Context, stepAction *v1alpha1.StepAction, opts v1.CreateOptions) (result *v1alpha1.StepAction, err error) { - result = &v1alpha1.StepAction{} - err = c.client.Post(). - Namespace(c.ns). - Resource("stepactions"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(stepAction). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a stepAction and updates it. Returns the server's representation of the stepAction, and an error, if there is any. -func (c *stepActions) Update(ctx context.Context, stepAction *v1alpha1.StepAction, opts v1.UpdateOptions) (result *v1alpha1.StepAction, err error) { - result = &v1alpha1.StepAction{} - err = c.client.Put(). - Namespace(c.ns). - Resource("stepactions"). - Name(stepAction.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(stepAction). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the stepAction and deletes it. Returns an error if one occurs. -func (c *stepActions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("stepactions"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *stepActions) 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("stepactions"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched stepAction. -func (c *stepActions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.StepAction, err error) { - result = &v1alpha1.StepAction{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("stepactions"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/verificationpolicy.go b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/verificationpolicy.go index 92f534093ff..68546254751 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/verificationpolicy.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1alpha1/verificationpolicy.go @@ -20,14 +20,13 @@ package v1alpha1 import ( "context" - "time" v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // VerificationPoliciesGetter has a method to return a VerificationPolicyInterface. @@ -51,128 +50,18 @@ type VerificationPolicyInterface interface { // verificationPolicies implements VerificationPolicyInterface type verificationPolicies struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1alpha1.VerificationPolicy, *v1alpha1.VerificationPolicyList] } // newVerificationPolicies returns a VerificationPolicies func newVerificationPolicies(c *TektonV1alpha1Client, namespace string) *verificationPolicies { return &verificationPolicies{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1alpha1.VerificationPolicy, *v1alpha1.VerificationPolicyList]( + "verificationpolicies", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1alpha1.VerificationPolicy { return &v1alpha1.VerificationPolicy{} }, + func() *v1alpha1.VerificationPolicyList { return &v1alpha1.VerificationPolicyList{} }), } } - -// Get takes name of the verificationPolicy, and returns the corresponding verificationPolicy object, and an error if there is any. -func (c *verificationPolicies) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.VerificationPolicy, err error) { - result = &v1alpha1.VerificationPolicy{} - err = c.client.Get(). - Namespace(c.ns). - Resource("verificationpolicies"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of VerificationPolicies that match those selectors. -func (c *verificationPolicies) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.VerificationPolicyList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.VerificationPolicyList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("verificationpolicies"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested verificationPolicies. -func (c *verificationPolicies) 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("verificationpolicies"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a verificationPolicy and creates it. Returns the server's representation of the verificationPolicy, and an error, if there is any. -func (c *verificationPolicies) Create(ctx context.Context, verificationPolicy *v1alpha1.VerificationPolicy, opts v1.CreateOptions) (result *v1alpha1.VerificationPolicy, err error) { - result = &v1alpha1.VerificationPolicy{} - err = c.client.Post(). - Namespace(c.ns). - Resource("verificationpolicies"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(verificationPolicy). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a verificationPolicy and updates it. Returns the server's representation of the verificationPolicy, and an error, if there is any. -func (c *verificationPolicies) Update(ctx context.Context, verificationPolicy *v1alpha1.VerificationPolicy, opts v1.UpdateOptions) (result *v1alpha1.VerificationPolicy, err error) { - result = &v1alpha1.VerificationPolicy{} - err = c.client.Put(). - Namespace(c.ns). - Resource("verificationpolicies"). - Name(verificationPolicy.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(verificationPolicy). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the verificationPolicy and deletes it. Returns an error if one occurs. -func (c *verificationPolicies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("verificationpolicies"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *verificationPolicies) 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("verificationpolicies"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched verificationPolicy. -func (c *verificationPolicies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.VerificationPolicy, err error) { - result = &v1alpha1.VerificationPolicy{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("verificationpolicies"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/clustertask.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/clustertask.go index 80c11ff5a95..7fe66809358 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/clustertask.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/clustertask.go @@ -20,14 +20,13 @@ package v1beta1 import ( "context" - "time" v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // ClusterTasksGetter has a method to return a ClusterTaskInterface. @@ -51,118 +50,18 @@ type ClusterTaskInterface interface { // clusterTasks implements ClusterTaskInterface type clusterTasks struct { - client rest.Interface + *gentype.ClientWithList[*v1beta1.ClusterTask, *v1beta1.ClusterTaskList] } // newClusterTasks returns a ClusterTasks func newClusterTasks(c *TektonV1beta1Client) *clusterTasks { return &clusterTasks{ - client: c.RESTClient(), + gentype.NewClientWithList[*v1beta1.ClusterTask, *v1beta1.ClusterTaskList]( + "clustertasks", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *v1beta1.ClusterTask { return &v1beta1.ClusterTask{} }, + func() *v1beta1.ClusterTaskList { return &v1beta1.ClusterTaskList{} }), } } - -// Get takes name of the clusterTask, and returns the corresponding clusterTask object, and an error if there is any. -func (c *clusterTasks) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.ClusterTask, err error) { - result = &v1beta1.ClusterTask{} - err = c.client.Get(). - Resource("clustertasks"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ClusterTasks that match those selectors. -func (c *clusterTasks) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.ClusterTaskList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1beta1.ClusterTaskList{} - err = c.client.Get(). - Resource("clustertasks"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested clusterTasks. -func (c *clusterTasks) 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(). - Resource("clustertasks"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a clusterTask and creates it. Returns the server's representation of the clusterTask, and an error, if there is any. -func (c *clusterTasks) Create(ctx context.Context, clusterTask *v1beta1.ClusterTask, opts v1.CreateOptions) (result *v1beta1.ClusterTask, err error) { - result = &v1beta1.ClusterTask{} - err = c.client.Post(). - Resource("clustertasks"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTask). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a clusterTask and updates it. Returns the server's representation of the clusterTask, and an error, if there is any. -func (c *clusterTasks) Update(ctx context.Context, clusterTask *v1beta1.ClusterTask, opts v1.UpdateOptions) (result *v1beta1.ClusterTask, err error) { - result = &v1beta1.ClusterTask{} - err = c.client.Put(). - Resource("clustertasks"). - Name(clusterTask.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTask). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the clusterTask and deletes it. Returns an error if one occurs. -func (c *clusterTasks) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Resource("clustertasks"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *clusterTasks) 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(). - Resource("clustertasks"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched clusterTask. -func (c *clusterTasks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ClusterTask, err error) { - result = &v1beta1.ClusterTask{} - err = c.client.Patch(pt). - Resource("clustertasks"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/customrun.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/customrun.go index a5755045bde..553d517089e 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/customrun.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/customrun.go @@ -20,14 +20,13 @@ package v1beta1 import ( "context" - "time" v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // CustomRunsGetter has a method to return a CustomRunInterface. @@ -40,6 +39,7 @@ type CustomRunsGetter interface { type CustomRunInterface interface { Create(ctx context.Context, customRun *v1beta1.CustomRun, opts v1.CreateOptions) (*v1beta1.CustomRun, error) Update(ctx context.Context, customRun *v1beta1.CustomRun, opts v1.UpdateOptions) (*v1beta1.CustomRun, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, customRun *v1beta1.CustomRun, opts v1.UpdateOptions) (*v1beta1.CustomRun, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error @@ -52,144 +52,18 @@ type CustomRunInterface interface { // customRuns implements CustomRunInterface type customRuns struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1beta1.CustomRun, *v1beta1.CustomRunList] } // newCustomRuns returns a CustomRuns func newCustomRuns(c *TektonV1beta1Client, namespace string) *customRuns { return &customRuns{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1beta1.CustomRun, *v1beta1.CustomRunList]( + "customruns", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1beta1.CustomRun { return &v1beta1.CustomRun{} }, + func() *v1beta1.CustomRunList { return &v1beta1.CustomRunList{} }), } } - -// Get takes name of the customRun, and returns the corresponding customRun object, and an error if there is any. -func (c *customRuns) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.CustomRun, err error) { - result = &v1beta1.CustomRun{} - err = c.client.Get(). - Namespace(c.ns). - Resource("customruns"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of CustomRuns that match those selectors. -func (c *customRuns) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.CustomRunList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1beta1.CustomRunList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("customruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested customRuns. -func (c *customRuns) 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("customruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a customRun and creates it. Returns the server's representation of the customRun, and an error, if there is any. -func (c *customRuns) Create(ctx context.Context, customRun *v1beta1.CustomRun, opts v1.CreateOptions) (result *v1beta1.CustomRun, err error) { - result = &v1beta1.CustomRun{} - err = c.client.Post(). - Namespace(c.ns). - Resource("customruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(customRun). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a customRun and updates it. Returns the server's representation of the customRun, and an error, if there is any. -func (c *customRuns) Update(ctx context.Context, customRun *v1beta1.CustomRun, opts v1.UpdateOptions) (result *v1beta1.CustomRun, err error) { - result = &v1beta1.CustomRun{} - err = c.client.Put(). - Namespace(c.ns). - Resource("customruns"). - Name(customRun.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(customRun). - 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 *customRuns) UpdateStatus(ctx context.Context, customRun *v1beta1.CustomRun, opts v1.UpdateOptions) (result *v1beta1.CustomRun, err error) { - result = &v1beta1.CustomRun{} - err = c.client.Put(). - Namespace(c.ns). - Resource("customruns"). - Name(customRun.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(customRun). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the customRun and deletes it. Returns an error if one occurs. -func (c *customRuns) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("customruns"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *customRuns) 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("customruns"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched customRun. -func (c *customRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.CustomRun, err error) { - result = &v1beta1.CustomRun{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("customruns"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_clustertask.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_clustertask.go index ef1f26c49a5..2fcf6a04080 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_clustertask.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_clustertask.go @@ -40,20 +40,22 @@ var clustertasksKind = v1beta1.SchemeGroupVersion.WithKind("ClusterTask") // Get takes name of the clusterTask, and returns the corresponding clusterTask object, and an error if there is any. func (c *FakeClusterTasks) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.ClusterTask, err error) { + emptyResult := &v1beta1.ClusterTask{} obj, err := c.Fake. - Invokes(testing.NewRootGetAction(clustertasksResource, name), &v1beta1.ClusterTask{}) + Invokes(testing.NewRootGetActionWithOptions(clustertasksResource, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.ClusterTask), err } // List takes label and field selectors, and returns the list of ClusterTasks that match those selectors. func (c *FakeClusterTasks) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.ClusterTaskList, err error) { + emptyResult := &v1beta1.ClusterTaskList{} obj, err := c.Fake. - Invokes(testing.NewRootListAction(clustertasksResource, clustertasksKind, opts), &v1beta1.ClusterTaskList{}) + Invokes(testing.NewRootListActionWithOptions(clustertasksResource, clustertasksKind, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -72,25 +74,27 @@ func (c *FakeClusterTasks) List(ctx context.Context, opts v1.ListOptions) (resul // Watch returns a watch.Interface that watches the requested clusterTasks. func (c *FakeClusterTasks) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewRootWatchAction(clustertasksResource, opts)) + InvokesWatch(testing.NewRootWatchActionWithOptions(clustertasksResource, opts)) } // Create takes the representation of a clusterTask and creates it. Returns the server's representation of the clusterTask, and an error, if there is any. func (c *FakeClusterTasks) Create(ctx context.Context, clusterTask *v1beta1.ClusterTask, opts v1.CreateOptions) (result *v1beta1.ClusterTask, err error) { + emptyResult := &v1beta1.ClusterTask{} obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(clustertasksResource, clusterTask), &v1beta1.ClusterTask{}) + Invokes(testing.NewRootCreateActionWithOptions(clustertasksResource, clusterTask, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.ClusterTask), err } // Update takes the representation of a clusterTask and updates it. Returns the server's representation of the clusterTask, and an error, if there is any. func (c *FakeClusterTasks) Update(ctx context.Context, clusterTask *v1beta1.ClusterTask, opts v1.UpdateOptions) (result *v1beta1.ClusterTask, err error) { + emptyResult := &v1beta1.ClusterTask{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(clustertasksResource, clusterTask), &v1beta1.ClusterTask{}) + Invokes(testing.NewRootUpdateActionWithOptions(clustertasksResource, clusterTask, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.ClusterTask), err } @@ -104,7 +108,7 @@ func (c *FakeClusterTasks) Delete(ctx context.Context, name string, opts v1.Dele // DeleteCollection deletes a collection of objects. func (c *FakeClusterTasks) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(clustertasksResource, listOpts) + action := testing.NewRootDeleteCollectionActionWithOptions(clustertasksResource, opts, listOpts) _, err := c.Fake.Invokes(action, &v1beta1.ClusterTaskList{}) return err @@ -112,10 +116,11 @@ func (c *FakeClusterTasks) DeleteCollection(ctx context.Context, opts v1.DeleteO // Patch applies the patch and returns the patched clusterTask. func (c *FakeClusterTasks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ClusterTask, err error) { + emptyResult := &v1beta1.ClusterTask{} obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertasksResource, name, pt, data, subresources...), &v1beta1.ClusterTask{}) + Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertasksResource, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.ClusterTask), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_customrun.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_customrun.go index 593b2d2f192..11db6fdb290 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_customrun.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_customrun.go @@ -41,22 +41,24 @@ var customrunsKind = v1beta1.SchemeGroupVersion.WithKind("CustomRun") // Get takes name of the customRun, and returns the corresponding customRun object, and an error if there is any. func (c *FakeCustomRuns) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.CustomRun, err error) { + emptyResult := &v1beta1.CustomRun{} obj, err := c.Fake. - Invokes(testing.NewGetAction(customrunsResource, c.ns, name), &v1beta1.CustomRun{}) + Invokes(testing.NewGetActionWithOptions(customrunsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.CustomRun), err } // List takes label and field selectors, and returns the list of CustomRuns that match those selectors. func (c *FakeCustomRuns) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.CustomRunList, err error) { + emptyResult := &v1beta1.CustomRunList{} obj, err := c.Fake. - Invokes(testing.NewListAction(customrunsResource, customrunsKind, c.ns, opts), &v1beta1.CustomRunList{}) + Invokes(testing.NewListActionWithOptions(customrunsResource, customrunsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,40 +77,43 @@ func (c *FakeCustomRuns) List(ctx context.Context, opts v1.ListOptions) (result // Watch returns a watch.Interface that watches the requested customRuns. func (c *FakeCustomRuns) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(customrunsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(customrunsResource, c.ns, opts)) } // Create takes the representation of a customRun and creates it. Returns the server's representation of the customRun, and an error, if there is any. func (c *FakeCustomRuns) Create(ctx context.Context, customRun *v1beta1.CustomRun, opts v1.CreateOptions) (result *v1beta1.CustomRun, err error) { + emptyResult := &v1beta1.CustomRun{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(customrunsResource, c.ns, customRun), &v1beta1.CustomRun{}) + Invokes(testing.NewCreateActionWithOptions(customrunsResource, c.ns, customRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.CustomRun), err } // Update takes the representation of a customRun and updates it. Returns the server's representation of the customRun, and an error, if there is any. func (c *FakeCustomRuns) Update(ctx context.Context, customRun *v1beta1.CustomRun, opts v1.UpdateOptions) (result *v1beta1.CustomRun, err error) { + emptyResult := &v1beta1.CustomRun{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(customrunsResource, c.ns, customRun), &v1beta1.CustomRun{}) + Invokes(testing.NewUpdateActionWithOptions(customrunsResource, c.ns, customRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.CustomRun), 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 *FakeCustomRuns) UpdateStatus(ctx context.Context, customRun *v1beta1.CustomRun, opts v1.UpdateOptions) (*v1beta1.CustomRun, error) { +func (c *FakeCustomRuns) UpdateStatus(ctx context.Context, customRun *v1beta1.CustomRun, opts v1.UpdateOptions) (result *v1beta1.CustomRun, err error) { + emptyResult := &v1beta1.CustomRun{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(customrunsResource, "status", c.ns, customRun), &v1beta1.CustomRun{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(customrunsResource, "status", c.ns, customRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.CustomRun), err } @@ -123,7 +128,7 @@ func (c *FakeCustomRuns) Delete(ctx context.Context, name string, opts v1.Delete // DeleteCollection deletes a collection of objects. func (c *FakeCustomRuns) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(customrunsResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(customrunsResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1beta1.CustomRunList{}) return err @@ -131,11 +136,12 @@ func (c *FakeCustomRuns) DeleteCollection(ctx context.Context, opts v1.DeleteOpt // Patch applies the patch and returns the patched customRun. func (c *FakeCustomRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.CustomRun, err error) { + emptyResult := &v1beta1.CustomRun{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(customrunsResource, c.ns, name, pt, data, subresources...), &v1beta1.CustomRun{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(customrunsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.CustomRun), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_pipeline.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_pipeline.go index 6dc5ec66237..c0cced1ef17 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_pipeline.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_pipeline.go @@ -41,22 +41,24 @@ var pipelinesKind = v1beta1.SchemeGroupVersion.WithKind("Pipeline") // Get takes name of the pipeline, and returns the corresponding pipeline object, and an error if there is any. func (c *FakePipelines) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.Pipeline, err error) { + emptyResult := &v1beta1.Pipeline{} obj, err := c.Fake. - Invokes(testing.NewGetAction(pipelinesResource, c.ns, name), &v1beta1.Pipeline{}) + Invokes(testing.NewGetActionWithOptions(pipelinesResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.Pipeline), err } // List takes label and field selectors, and returns the list of Pipelines that match those selectors. func (c *FakePipelines) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.PipelineList, err error) { + emptyResult := &v1beta1.PipelineList{} obj, err := c.Fake. - Invokes(testing.NewListAction(pipelinesResource, pipelinesKind, c.ns, opts), &v1beta1.PipelineList{}) + Invokes(testing.NewListActionWithOptions(pipelinesResource, pipelinesKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,28 +77,30 @@ func (c *FakePipelines) List(ctx context.Context, opts v1.ListOptions) (result * // Watch returns a watch.Interface that watches the requested pipelines. func (c *FakePipelines) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(pipelinesResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(pipelinesResource, c.ns, opts)) } // Create takes the representation of a pipeline and creates it. Returns the server's representation of the pipeline, and an error, if there is any. func (c *FakePipelines) Create(ctx context.Context, pipeline *v1beta1.Pipeline, opts v1.CreateOptions) (result *v1beta1.Pipeline, err error) { + emptyResult := &v1beta1.Pipeline{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(pipelinesResource, c.ns, pipeline), &v1beta1.Pipeline{}) + Invokes(testing.NewCreateActionWithOptions(pipelinesResource, c.ns, pipeline, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.Pipeline), err } // Update takes the representation of a pipeline and updates it. Returns the server's representation of the pipeline, and an error, if there is any. func (c *FakePipelines) Update(ctx context.Context, pipeline *v1beta1.Pipeline, opts v1.UpdateOptions) (result *v1beta1.Pipeline, err error) { + emptyResult := &v1beta1.Pipeline{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(pipelinesResource, c.ns, pipeline), &v1beta1.Pipeline{}) + Invokes(testing.NewUpdateActionWithOptions(pipelinesResource, c.ns, pipeline, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.Pipeline), err } @@ -111,7 +115,7 @@ func (c *FakePipelines) Delete(ctx context.Context, name string, opts v1.DeleteO // DeleteCollection deletes a collection of objects. func (c *FakePipelines) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(pipelinesResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(pipelinesResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1beta1.PipelineList{}) return err @@ -119,11 +123,12 @@ func (c *FakePipelines) DeleteCollection(ctx context.Context, opts v1.DeleteOpti // Patch applies the patch and returns the patched pipeline. func (c *FakePipelines) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.Pipeline, err error) { + emptyResult := &v1beta1.Pipeline{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(pipelinesResource, c.ns, name, pt, data, subresources...), &v1beta1.Pipeline{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(pipelinesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.Pipeline), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_pipelinerun.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_pipelinerun.go index c7eb52ee29d..8559294a42d 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_pipelinerun.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_pipelinerun.go @@ -41,22 +41,24 @@ var pipelinerunsKind = v1beta1.SchemeGroupVersion.WithKind("PipelineRun") // Get takes name of the pipelineRun, and returns the corresponding pipelineRun object, and an error if there is any. func (c *FakePipelineRuns) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.PipelineRun, err error) { + emptyResult := &v1beta1.PipelineRun{} obj, err := c.Fake. - Invokes(testing.NewGetAction(pipelinerunsResource, c.ns, name), &v1beta1.PipelineRun{}) + Invokes(testing.NewGetActionWithOptions(pipelinerunsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.PipelineRun), err } // List takes label and field selectors, and returns the list of PipelineRuns that match those selectors. func (c *FakePipelineRuns) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.PipelineRunList, err error) { + emptyResult := &v1beta1.PipelineRunList{} obj, err := c.Fake. - Invokes(testing.NewListAction(pipelinerunsResource, pipelinerunsKind, c.ns, opts), &v1beta1.PipelineRunList{}) + Invokes(testing.NewListActionWithOptions(pipelinerunsResource, pipelinerunsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,40 +77,43 @@ func (c *FakePipelineRuns) List(ctx context.Context, opts v1.ListOptions) (resul // Watch returns a watch.Interface that watches the requested pipelineRuns. func (c *FakePipelineRuns) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(pipelinerunsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(pipelinerunsResource, c.ns, opts)) } // Create takes the representation of a pipelineRun and creates it. Returns the server's representation of the pipelineRun, and an error, if there is any. func (c *FakePipelineRuns) Create(ctx context.Context, pipelineRun *v1beta1.PipelineRun, opts v1.CreateOptions) (result *v1beta1.PipelineRun, err error) { + emptyResult := &v1beta1.PipelineRun{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(pipelinerunsResource, c.ns, pipelineRun), &v1beta1.PipelineRun{}) + Invokes(testing.NewCreateActionWithOptions(pipelinerunsResource, c.ns, pipelineRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.PipelineRun), err } // Update takes the representation of a pipelineRun and updates it. Returns the server's representation of the pipelineRun, and an error, if there is any. func (c *FakePipelineRuns) Update(ctx context.Context, pipelineRun *v1beta1.PipelineRun, opts v1.UpdateOptions) (result *v1beta1.PipelineRun, err error) { + emptyResult := &v1beta1.PipelineRun{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(pipelinerunsResource, c.ns, pipelineRun), &v1beta1.PipelineRun{}) + Invokes(testing.NewUpdateActionWithOptions(pipelinerunsResource, c.ns, pipelineRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.PipelineRun), 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 *FakePipelineRuns) UpdateStatus(ctx context.Context, pipelineRun *v1beta1.PipelineRun, opts v1.UpdateOptions) (*v1beta1.PipelineRun, error) { +func (c *FakePipelineRuns) UpdateStatus(ctx context.Context, pipelineRun *v1beta1.PipelineRun, opts v1.UpdateOptions) (result *v1beta1.PipelineRun, err error) { + emptyResult := &v1beta1.PipelineRun{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(pipelinerunsResource, "status", c.ns, pipelineRun), &v1beta1.PipelineRun{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(pipelinerunsResource, "status", c.ns, pipelineRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.PipelineRun), err } @@ -123,7 +128,7 @@ func (c *FakePipelineRuns) Delete(ctx context.Context, name string, opts v1.Dele // DeleteCollection deletes a collection of objects. func (c *FakePipelineRuns) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(pipelinerunsResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(pipelinerunsResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1beta1.PipelineRunList{}) return err @@ -131,11 +136,12 @@ func (c *FakePipelineRuns) DeleteCollection(ctx context.Context, opts v1.DeleteO // Patch applies the patch and returns the patched pipelineRun. func (c *FakePipelineRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.PipelineRun, err error) { + emptyResult := &v1beta1.PipelineRun{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(pipelinerunsResource, c.ns, name, pt, data, subresources...), &v1beta1.PipelineRun{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(pipelinerunsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.PipelineRun), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_stepaction.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_stepaction.go index 048c9e56c34..1e0de700383 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_stepaction.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_stepaction.go @@ -41,22 +41,24 @@ var stepactionsKind = v1beta1.SchemeGroupVersion.WithKind("StepAction") // Get takes name of the stepAction, and returns the corresponding stepAction object, and an error if there is any. func (c *FakeStepActions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.StepAction, err error) { + emptyResult := &v1beta1.StepAction{} obj, err := c.Fake. - Invokes(testing.NewGetAction(stepactionsResource, c.ns, name), &v1beta1.StepAction{}) + Invokes(testing.NewGetActionWithOptions(stepactionsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.StepAction), err } // List takes label and field selectors, and returns the list of StepActions that match those selectors. func (c *FakeStepActions) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.StepActionList, err error) { + emptyResult := &v1beta1.StepActionList{} obj, err := c.Fake. - Invokes(testing.NewListAction(stepactionsResource, stepactionsKind, c.ns, opts), &v1beta1.StepActionList{}) + Invokes(testing.NewListActionWithOptions(stepactionsResource, stepactionsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,28 +77,30 @@ func (c *FakeStepActions) List(ctx context.Context, opts v1.ListOptions) (result // Watch returns a watch.Interface that watches the requested stepActions. func (c *FakeStepActions) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(stepactionsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(stepactionsResource, c.ns, opts)) } // Create takes the representation of a stepAction and creates it. Returns the server's representation of the stepAction, and an error, if there is any. func (c *FakeStepActions) Create(ctx context.Context, stepAction *v1beta1.StepAction, opts v1.CreateOptions) (result *v1beta1.StepAction, err error) { + emptyResult := &v1beta1.StepAction{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(stepactionsResource, c.ns, stepAction), &v1beta1.StepAction{}) + Invokes(testing.NewCreateActionWithOptions(stepactionsResource, c.ns, stepAction, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.StepAction), err } // Update takes the representation of a stepAction and updates it. Returns the server's representation of the stepAction, and an error, if there is any. func (c *FakeStepActions) Update(ctx context.Context, stepAction *v1beta1.StepAction, opts v1.UpdateOptions) (result *v1beta1.StepAction, err error) { + emptyResult := &v1beta1.StepAction{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(stepactionsResource, c.ns, stepAction), &v1beta1.StepAction{}) + Invokes(testing.NewUpdateActionWithOptions(stepactionsResource, c.ns, stepAction, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.StepAction), err } @@ -111,7 +115,7 @@ func (c *FakeStepActions) Delete(ctx context.Context, name string, opts v1.Delet // DeleteCollection deletes a collection of objects. func (c *FakeStepActions) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(stepactionsResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(stepactionsResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1beta1.StepActionList{}) return err @@ -119,11 +123,12 @@ func (c *FakeStepActions) DeleteCollection(ctx context.Context, opts v1.DeleteOp // Patch applies the patch and returns the patched stepAction. func (c *FakeStepActions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.StepAction, err error) { + emptyResult := &v1beta1.StepAction{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(stepactionsResource, c.ns, name, pt, data, subresources...), &v1beta1.StepAction{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(stepactionsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.StepAction), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_task.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_task.go index a98ccdad0f0..70622bfe41c 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_task.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_task.go @@ -41,22 +41,24 @@ var tasksKind = v1beta1.SchemeGroupVersion.WithKind("Task") // Get takes name of the task, and returns the corresponding task object, and an error if there is any. func (c *FakeTasks) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.Task, err error) { + emptyResult := &v1beta1.Task{} obj, err := c.Fake. - Invokes(testing.NewGetAction(tasksResource, c.ns, name), &v1beta1.Task{}) + Invokes(testing.NewGetActionWithOptions(tasksResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.Task), err } // List takes label and field selectors, and returns the list of Tasks that match those selectors. func (c *FakeTasks) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.TaskList, err error) { + emptyResult := &v1beta1.TaskList{} obj, err := c.Fake. - Invokes(testing.NewListAction(tasksResource, tasksKind, c.ns, opts), &v1beta1.TaskList{}) + Invokes(testing.NewListActionWithOptions(tasksResource, tasksKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,28 +77,30 @@ func (c *FakeTasks) List(ctx context.Context, opts v1.ListOptions) (result *v1be // Watch returns a watch.Interface that watches the requested tasks. func (c *FakeTasks) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(tasksResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(tasksResource, c.ns, opts)) } // Create takes the representation of a task and creates it. Returns the server's representation of the task, and an error, if there is any. func (c *FakeTasks) Create(ctx context.Context, task *v1beta1.Task, opts v1.CreateOptions) (result *v1beta1.Task, err error) { + emptyResult := &v1beta1.Task{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(tasksResource, c.ns, task), &v1beta1.Task{}) + Invokes(testing.NewCreateActionWithOptions(tasksResource, c.ns, task, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.Task), err } // Update takes the representation of a task and updates it. Returns the server's representation of the task, and an error, if there is any. func (c *FakeTasks) Update(ctx context.Context, task *v1beta1.Task, opts v1.UpdateOptions) (result *v1beta1.Task, err error) { + emptyResult := &v1beta1.Task{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(tasksResource, c.ns, task), &v1beta1.Task{}) + Invokes(testing.NewUpdateActionWithOptions(tasksResource, c.ns, task, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.Task), err } @@ -111,7 +115,7 @@ func (c *FakeTasks) Delete(ctx context.Context, name string, opts v1.DeleteOptio // DeleteCollection deletes a collection of objects. func (c *FakeTasks) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(tasksResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(tasksResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1beta1.TaskList{}) return err @@ -119,11 +123,12 @@ func (c *FakeTasks) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, // Patch applies the patch and returns the patched task. func (c *FakeTasks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.Task, err error) { + emptyResult := &v1beta1.Task{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(tasksResource, c.ns, name, pt, data, subresources...), &v1beta1.Task{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(tasksResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.Task), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_taskrun.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_taskrun.go index 68b3b40e231..7e54015f8ec 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_taskrun.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/fake/fake_taskrun.go @@ -41,22 +41,24 @@ var taskrunsKind = v1beta1.SchemeGroupVersion.WithKind("TaskRun") // Get takes name of the taskRun, and returns the corresponding taskRun object, and an error if there is any. func (c *FakeTaskRuns) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.TaskRun, err error) { + emptyResult := &v1beta1.TaskRun{} obj, err := c.Fake. - Invokes(testing.NewGetAction(taskrunsResource, c.ns, name), &v1beta1.TaskRun{}) + Invokes(testing.NewGetActionWithOptions(taskrunsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.TaskRun), err } // List takes label and field selectors, and returns the list of TaskRuns that match those selectors. func (c *FakeTaskRuns) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.TaskRunList, err error) { + emptyResult := &v1beta1.TaskRunList{} obj, err := c.Fake. - Invokes(testing.NewListAction(taskrunsResource, taskrunsKind, c.ns, opts), &v1beta1.TaskRunList{}) + Invokes(testing.NewListActionWithOptions(taskrunsResource, taskrunsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,40 +77,43 @@ func (c *FakeTaskRuns) List(ctx context.Context, opts v1.ListOptions) (result *v // Watch returns a watch.Interface that watches the requested taskRuns. func (c *FakeTaskRuns) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(taskrunsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(taskrunsResource, c.ns, opts)) } // Create takes the representation of a taskRun and creates it. Returns the server's representation of the taskRun, and an error, if there is any. func (c *FakeTaskRuns) Create(ctx context.Context, taskRun *v1beta1.TaskRun, opts v1.CreateOptions) (result *v1beta1.TaskRun, err error) { + emptyResult := &v1beta1.TaskRun{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(taskrunsResource, c.ns, taskRun), &v1beta1.TaskRun{}) + Invokes(testing.NewCreateActionWithOptions(taskrunsResource, c.ns, taskRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.TaskRun), err } // Update takes the representation of a taskRun and updates it. Returns the server's representation of the taskRun, and an error, if there is any. func (c *FakeTaskRuns) Update(ctx context.Context, taskRun *v1beta1.TaskRun, opts v1.UpdateOptions) (result *v1beta1.TaskRun, err error) { + emptyResult := &v1beta1.TaskRun{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(taskrunsResource, c.ns, taskRun), &v1beta1.TaskRun{}) + Invokes(testing.NewUpdateActionWithOptions(taskrunsResource, c.ns, taskRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.TaskRun), 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 *FakeTaskRuns) UpdateStatus(ctx context.Context, taskRun *v1beta1.TaskRun, opts v1.UpdateOptions) (*v1beta1.TaskRun, error) { +func (c *FakeTaskRuns) UpdateStatus(ctx context.Context, taskRun *v1beta1.TaskRun, opts v1.UpdateOptions) (result *v1beta1.TaskRun, err error) { + emptyResult := &v1beta1.TaskRun{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(taskrunsResource, "status", c.ns, taskRun), &v1beta1.TaskRun{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(taskrunsResource, "status", c.ns, taskRun, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.TaskRun), err } @@ -123,7 +128,7 @@ func (c *FakeTaskRuns) Delete(ctx context.Context, name string, opts v1.DeleteOp // DeleteCollection deletes a collection of objects. func (c *FakeTaskRuns) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(taskrunsResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(taskrunsResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1beta1.TaskRunList{}) return err @@ -131,11 +136,12 @@ func (c *FakeTaskRuns) DeleteCollection(ctx context.Context, opts v1.DeleteOptio // Patch applies the patch and returns the patched taskRun. func (c *FakeTaskRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.TaskRun, err error) { + emptyResult := &v1beta1.TaskRun{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(taskrunsResource, c.ns, name, pt, data, subresources...), &v1beta1.TaskRun{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(taskrunsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.TaskRun), err } diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/pipeline.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/pipeline.go index 1bfe8d58acd..60ab9b038bb 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/pipeline.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/pipeline.go @@ -20,14 +20,13 @@ package v1beta1 import ( "context" - "time" v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // PipelinesGetter has a method to return a PipelineInterface. @@ -51,128 +50,18 @@ type PipelineInterface interface { // pipelines implements PipelineInterface type pipelines struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1beta1.Pipeline, *v1beta1.PipelineList] } // newPipelines returns a Pipelines func newPipelines(c *TektonV1beta1Client, namespace string) *pipelines { return &pipelines{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1beta1.Pipeline, *v1beta1.PipelineList]( + "pipelines", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1beta1.Pipeline { return &v1beta1.Pipeline{} }, + func() *v1beta1.PipelineList { return &v1beta1.PipelineList{} }), } } - -// Get takes name of the pipeline, and returns the corresponding pipeline object, and an error if there is any. -func (c *pipelines) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.Pipeline, err error) { - result = &v1beta1.Pipeline{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelines"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Pipelines that match those selectors. -func (c *pipelines) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.PipelineList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1beta1.PipelineList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelines"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested pipelines. -func (c *pipelines) 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("pipelines"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a pipeline and creates it. Returns the server's representation of the pipeline, and an error, if there is any. -func (c *pipelines) Create(ctx context.Context, pipeline *v1beta1.Pipeline, opts v1.CreateOptions) (result *v1beta1.Pipeline, err error) { - result = &v1beta1.Pipeline{} - err = c.client.Post(). - Namespace(c.ns). - Resource("pipelines"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipeline). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a pipeline and updates it. Returns the server's representation of the pipeline, and an error, if there is any. -func (c *pipelines) Update(ctx context.Context, pipeline *v1beta1.Pipeline, opts v1.UpdateOptions) (result *v1beta1.Pipeline, err error) { - result = &v1beta1.Pipeline{} - err = c.client.Put(). - Namespace(c.ns). - Resource("pipelines"). - Name(pipeline.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipeline). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the pipeline and deletes it. Returns an error if one occurs. -func (c *pipelines) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("pipelines"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *pipelines) 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("pipelines"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched pipeline. -func (c *pipelines) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.Pipeline, err error) { - result = &v1beta1.Pipeline{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("pipelines"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/pipelinerun.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/pipelinerun.go index 5399858ff16..60309b62b1a 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/pipelinerun.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/pipelinerun.go @@ -20,14 +20,13 @@ package v1beta1 import ( "context" - "time" v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // PipelineRunsGetter has a method to return a PipelineRunInterface. @@ -40,6 +39,7 @@ type PipelineRunsGetter interface { type PipelineRunInterface interface { Create(ctx context.Context, pipelineRun *v1beta1.PipelineRun, opts v1.CreateOptions) (*v1beta1.PipelineRun, error) Update(ctx context.Context, pipelineRun *v1beta1.PipelineRun, opts v1.UpdateOptions) (*v1beta1.PipelineRun, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, pipelineRun *v1beta1.PipelineRun, opts v1.UpdateOptions) (*v1beta1.PipelineRun, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error @@ -52,144 +52,18 @@ type PipelineRunInterface interface { // pipelineRuns implements PipelineRunInterface type pipelineRuns struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1beta1.PipelineRun, *v1beta1.PipelineRunList] } // newPipelineRuns returns a PipelineRuns func newPipelineRuns(c *TektonV1beta1Client, namespace string) *pipelineRuns { return &pipelineRuns{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1beta1.PipelineRun, *v1beta1.PipelineRunList]( + "pipelineruns", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1beta1.PipelineRun { return &v1beta1.PipelineRun{} }, + func() *v1beta1.PipelineRunList { return &v1beta1.PipelineRunList{} }), } } - -// Get takes name of the pipelineRun, and returns the corresponding pipelineRun object, and an error if there is any. -func (c *pipelineRuns) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.PipelineRun, err error) { - result = &v1beta1.PipelineRun{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelineruns"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of PipelineRuns that match those selectors. -func (c *pipelineRuns) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.PipelineRunList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1beta1.PipelineRunList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelineruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested pipelineRuns. -func (c *pipelineRuns) 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("pipelineruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a pipelineRun and creates it. Returns the server's representation of the pipelineRun, and an error, if there is any. -func (c *pipelineRuns) Create(ctx context.Context, pipelineRun *v1beta1.PipelineRun, opts v1.CreateOptions) (result *v1beta1.PipelineRun, err error) { - result = &v1beta1.PipelineRun{} - err = c.client.Post(). - Namespace(c.ns). - Resource("pipelineruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipelineRun). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a pipelineRun and updates it. Returns the server's representation of the pipelineRun, and an error, if there is any. -func (c *pipelineRuns) Update(ctx context.Context, pipelineRun *v1beta1.PipelineRun, opts v1.UpdateOptions) (result *v1beta1.PipelineRun, err error) { - result = &v1beta1.PipelineRun{} - err = c.client.Put(). - Namespace(c.ns). - Resource("pipelineruns"). - Name(pipelineRun.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipelineRun). - 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 *pipelineRuns) UpdateStatus(ctx context.Context, pipelineRun *v1beta1.PipelineRun, opts v1.UpdateOptions) (result *v1beta1.PipelineRun, err error) { - result = &v1beta1.PipelineRun{} - err = c.client.Put(). - Namespace(c.ns). - Resource("pipelineruns"). - Name(pipelineRun.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipelineRun). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the pipelineRun and deletes it. Returns an error if one occurs. -func (c *pipelineRuns) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("pipelineruns"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *pipelineRuns) 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("pipelineruns"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched pipelineRun. -func (c *pipelineRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.PipelineRun, err error) { - result = &v1beta1.PipelineRun{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("pipelineruns"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/stepaction.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/stepaction.go index 388f0629540..4b9853e8447 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/stepaction.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/stepaction.go @@ -20,14 +20,13 @@ package v1beta1 import ( "context" - "time" v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // StepActionsGetter has a method to return a StepActionInterface. @@ -51,128 +50,18 @@ type StepActionInterface interface { // stepActions implements StepActionInterface type stepActions struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1beta1.StepAction, *v1beta1.StepActionList] } // newStepActions returns a StepActions func newStepActions(c *TektonV1beta1Client, namespace string) *stepActions { return &stepActions{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1beta1.StepAction, *v1beta1.StepActionList]( + "stepactions", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1beta1.StepAction { return &v1beta1.StepAction{} }, + func() *v1beta1.StepActionList { return &v1beta1.StepActionList{} }), } } - -// Get takes name of the stepAction, and returns the corresponding stepAction object, and an error if there is any. -func (c *stepActions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.StepAction, err error) { - result = &v1beta1.StepAction{} - err = c.client.Get(). - Namespace(c.ns). - Resource("stepactions"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of StepActions that match those selectors. -func (c *stepActions) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.StepActionList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1beta1.StepActionList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("stepactions"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested stepActions. -func (c *stepActions) 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("stepactions"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a stepAction and creates it. Returns the server's representation of the stepAction, and an error, if there is any. -func (c *stepActions) Create(ctx context.Context, stepAction *v1beta1.StepAction, opts v1.CreateOptions) (result *v1beta1.StepAction, err error) { - result = &v1beta1.StepAction{} - err = c.client.Post(). - Namespace(c.ns). - Resource("stepactions"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(stepAction). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a stepAction and updates it. Returns the server's representation of the stepAction, and an error, if there is any. -func (c *stepActions) Update(ctx context.Context, stepAction *v1beta1.StepAction, opts v1.UpdateOptions) (result *v1beta1.StepAction, err error) { - result = &v1beta1.StepAction{} - err = c.client.Put(). - Namespace(c.ns). - Resource("stepactions"). - Name(stepAction.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(stepAction). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the stepAction and deletes it. Returns an error if one occurs. -func (c *stepActions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("stepactions"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *stepActions) 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("stepactions"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched stepAction. -func (c *stepActions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.StepAction, err error) { - result = &v1beta1.StepAction{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("stepactions"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/task.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/task.go index a024ed714ae..5f54d35347d 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/task.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/task.go @@ -20,14 +20,13 @@ package v1beta1 import ( "context" - "time" v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // TasksGetter has a method to return a TaskInterface. @@ -51,128 +50,18 @@ type TaskInterface interface { // tasks implements TaskInterface type tasks struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1beta1.Task, *v1beta1.TaskList] } // newTasks returns a Tasks func newTasks(c *TektonV1beta1Client, namespace string) *tasks { return &tasks{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1beta1.Task, *v1beta1.TaskList]( + "tasks", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1beta1.Task { return &v1beta1.Task{} }, + func() *v1beta1.TaskList { return &v1beta1.TaskList{} }), } } - -// Get takes name of the task, and returns the corresponding task object, and an error if there is any. -func (c *tasks) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.Task, err error) { - result = &v1beta1.Task{} - err = c.client.Get(). - Namespace(c.ns). - Resource("tasks"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of Tasks that match those selectors. -func (c *tasks) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.TaskList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1beta1.TaskList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("tasks"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested tasks. -func (c *tasks) 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("tasks"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a task and creates it. Returns the server's representation of the task, and an error, if there is any. -func (c *tasks) Create(ctx context.Context, task *v1beta1.Task, opts v1.CreateOptions) (result *v1beta1.Task, err error) { - result = &v1beta1.Task{} - err = c.client.Post(). - Namespace(c.ns). - Resource("tasks"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(task). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a task and updates it. Returns the server's representation of the task, and an error, if there is any. -func (c *tasks) Update(ctx context.Context, task *v1beta1.Task, opts v1.UpdateOptions) (result *v1beta1.Task, err error) { - result = &v1beta1.Task{} - err = c.client.Put(). - Namespace(c.ns). - Resource("tasks"). - Name(task.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(task). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the task and deletes it. Returns an error if one occurs. -func (c *tasks) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("tasks"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *tasks) 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("tasks"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched task. -func (c *tasks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.Task, err error) { - result = &v1beta1.Task{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("tasks"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/taskrun.go b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/taskrun.go index 5611be7d663..f0d0ad887da 100644 --- a/pkg/client/clientset/versioned/typed/pipeline/v1beta1/taskrun.go +++ b/pkg/client/clientset/versioned/typed/pipeline/v1beta1/taskrun.go @@ -20,14 +20,13 @@ package v1beta1 import ( "context" - "time" v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" scheme "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // TaskRunsGetter has a method to return a TaskRunInterface. @@ -40,6 +39,7 @@ type TaskRunsGetter interface { type TaskRunInterface interface { Create(ctx context.Context, taskRun *v1beta1.TaskRun, opts v1.CreateOptions) (*v1beta1.TaskRun, error) Update(ctx context.Context, taskRun *v1beta1.TaskRun, opts v1.UpdateOptions) (*v1beta1.TaskRun, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, taskRun *v1beta1.TaskRun, opts v1.UpdateOptions) (*v1beta1.TaskRun, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error @@ -52,144 +52,18 @@ type TaskRunInterface interface { // taskRuns implements TaskRunInterface type taskRuns struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1beta1.TaskRun, *v1beta1.TaskRunList] } // newTaskRuns returns a TaskRuns func newTaskRuns(c *TektonV1beta1Client, namespace string) *taskRuns { return &taskRuns{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1beta1.TaskRun, *v1beta1.TaskRunList]( + "taskruns", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1beta1.TaskRun { return &v1beta1.TaskRun{} }, + func() *v1beta1.TaskRunList { return &v1beta1.TaskRunList{} }), } } - -// Get takes name of the taskRun, and returns the corresponding taskRun object, and an error if there is any. -func (c *taskRuns) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.TaskRun, err error) { - result = &v1beta1.TaskRun{} - err = c.client.Get(). - Namespace(c.ns). - Resource("taskruns"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of TaskRuns that match those selectors. -func (c *taskRuns) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.TaskRunList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1beta1.TaskRunList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("taskruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested taskRuns. -func (c *taskRuns) 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("taskruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a taskRun and creates it. Returns the server's representation of the taskRun, and an error, if there is any. -func (c *taskRuns) Create(ctx context.Context, taskRun *v1beta1.TaskRun, opts v1.CreateOptions) (result *v1beta1.TaskRun, err error) { - result = &v1beta1.TaskRun{} - err = c.client.Post(). - Namespace(c.ns). - Resource("taskruns"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(taskRun). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a taskRun and updates it. Returns the server's representation of the taskRun, and an error, if there is any. -func (c *taskRuns) Update(ctx context.Context, taskRun *v1beta1.TaskRun, opts v1.UpdateOptions) (result *v1beta1.TaskRun, err error) { - result = &v1beta1.TaskRun{} - err = c.client.Put(). - Namespace(c.ns). - Resource("taskruns"). - Name(taskRun.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(taskRun). - 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 *taskRuns) UpdateStatus(ctx context.Context, taskRun *v1beta1.TaskRun, opts v1.UpdateOptions) (result *v1beta1.TaskRun, err error) { - result = &v1beta1.TaskRun{} - err = c.client.Put(). - Namespace(c.ns). - Resource("taskruns"). - Name(taskRun.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(taskRun). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the taskRun and deletes it. Returns an error if one occurs. -func (c *taskRuns) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("taskruns"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *taskRuns) 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("taskruns"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched taskRun. -func (c *taskRuns) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.TaskRun, err error) { - result = &v1beta1.TaskRun{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("taskruns"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go index 839585d5076..79e8d60fdc0 100644 --- a/pkg/client/informers/externalversions/factory.go +++ b/pkg/client/informers/externalversions/factory.go @@ -228,6 +228,7 @@ type SharedInformerFactory interface { // Start initializes all requested informers. They are handled in goroutines // which run until the stop channel gets closed. + // Warning: Start does not block. When run in a go-routine, it will race with a later WaitForCacheSync. Start(stopCh <-chan struct{}) // Shutdown marks a factory as shutting down. At that point no new diff --git a/pkg/client/informers/externalversions/pipeline/interface.go b/pkg/client/informers/externalversions/pipeline/interface.go index 71e38c57736..a387211878d 100644 --- a/pkg/client/informers/externalversions/pipeline/interface.go +++ b/pkg/client/informers/externalversions/pipeline/interface.go @@ -27,12 +27,12 @@ import ( // Interface provides access to each of this group's versions. type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface // V1alpha1 provides access to shared informers for resources in V1alpha1. V1alpha1() v1alpha1.Interface // V1beta1 provides access to shared informers for resources in V1beta1. V1beta1() v1beta1.Interface - // V1 provides access to shared informers for resources in V1. - V1() v1.Interface } type group struct { @@ -46,6 +46,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList 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) +} + // V1alpha1 returns a new v1alpha1.Interface. func (g *group) V1alpha1() v1alpha1.Interface { return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) @@ -55,8 +60,3 @@ func (g *group) V1alpha1() v1alpha1.Interface { func (g *group) V1beta1() v1beta1.Interface { return v1beta1.New(g.factory, g.namespace, g.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/client/listers/pipeline/v1/pipeline.go b/pkg/client/listers/pipeline/v1/pipeline.go index 4319ad279c9..0cb80aa7c80 100644 --- a/pkg/client/listers/pipeline/v1/pipeline.go +++ b/pkg/client/listers/pipeline/v1/pipeline.go @@ -20,8 +20,8 @@ package v1 import ( v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type PipelineLister interface { // pipelineLister implements the PipelineLister interface. type pipelineLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1.Pipeline] } // NewPipelineLister returns a new PipelineLister. func NewPipelineLister(indexer cache.Indexer) PipelineLister { - return &pipelineLister{indexer: indexer} -} - -// List lists all Pipelines in the indexer. -func (s *pipelineLister) List(selector labels.Selector) (ret []*v1.Pipeline, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Pipeline)) - }) - return ret, err + return &pipelineLister{listers.New[*v1.Pipeline](indexer, v1.Resource("pipeline"))} } // Pipelines returns an object that can list and get Pipelines. func (s *pipelineLister) Pipelines(namespace string) PipelineNamespaceLister { - return pipelineNamespaceLister{indexer: s.indexer, namespace: namespace} + return pipelineNamespaceLister{listers.NewNamespaced[*v1.Pipeline](s.ResourceIndexer, namespace)} } // PipelineNamespaceLister helps list and get Pipelines. @@ -74,26 +66,5 @@ type PipelineNamespaceLister interface { // pipelineNamespaceLister implements the PipelineNamespaceLister // interface. type pipelineNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all Pipelines in the indexer for a given namespace. -func (s pipelineNamespaceLister) List(selector labels.Selector) (ret []*v1.Pipeline, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Pipeline)) - }) - return ret, err -} - -// Get retrieves the Pipeline from the indexer for a given namespace and name. -func (s pipelineNamespaceLister) Get(name string) (*v1.Pipeline, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("pipeline"), name) - } - return obj.(*v1.Pipeline), nil + listers.ResourceIndexer[*v1.Pipeline] } diff --git a/pkg/client/listers/pipeline/v1/pipelinerun.go b/pkg/client/listers/pipeline/v1/pipelinerun.go index 4a16673da05..6c5d24a97c5 100644 --- a/pkg/client/listers/pipeline/v1/pipelinerun.go +++ b/pkg/client/listers/pipeline/v1/pipelinerun.go @@ -20,8 +20,8 @@ package v1 import ( v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type PipelineRunLister interface { // pipelineRunLister implements the PipelineRunLister interface. type pipelineRunLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1.PipelineRun] } // NewPipelineRunLister returns a new PipelineRunLister. func NewPipelineRunLister(indexer cache.Indexer) PipelineRunLister { - return &pipelineRunLister{indexer: indexer} -} - -// List lists all PipelineRuns in the indexer. -func (s *pipelineRunLister) List(selector labels.Selector) (ret []*v1.PipelineRun, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.PipelineRun)) - }) - return ret, err + return &pipelineRunLister{listers.New[*v1.PipelineRun](indexer, v1.Resource("pipelinerun"))} } // PipelineRuns returns an object that can list and get PipelineRuns. func (s *pipelineRunLister) PipelineRuns(namespace string) PipelineRunNamespaceLister { - return pipelineRunNamespaceLister{indexer: s.indexer, namespace: namespace} + return pipelineRunNamespaceLister{listers.NewNamespaced[*v1.PipelineRun](s.ResourceIndexer, namespace)} } // PipelineRunNamespaceLister helps list and get PipelineRuns. @@ -74,26 +66,5 @@ type PipelineRunNamespaceLister interface { // pipelineRunNamespaceLister implements the PipelineRunNamespaceLister // interface. type pipelineRunNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all PipelineRuns in the indexer for a given namespace. -func (s pipelineRunNamespaceLister) List(selector labels.Selector) (ret []*v1.PipelineRun, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.PipelineRun)) - }) - return ret, err -} - -// Get retrieves the PipelineRun from the indexer for a given namespace and name. -func (s pipelineRunNamespaceLister) Get(name string) (*v1.PipelineRun, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("pipelinerun"), name) - } - return obj.(*v1.PipelineRun), nil + listers.ResourceIndexer[*v1.PipelineRun] } diff --git a/pkg/client/listers/pipeline/v1/task.go b/pkg/client/listers/pipeline/v1/task.go index e918f2f8959..1b7eefe0be2 100644 --- a/pkg/client/listers/pipeline/v1/task.go +++ b/pkg/client/listers/pipeline/v1/task.go @@ -20,8 +20,8 @@ package v1 import ( v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type TaskLister interface { // taskLister implements the TaskLister interface. type taskLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1.Task] } // NewTaskLister returns a new TaskLister. func NewTaskLister(indexer cache.Indexer) TaskLister { - return &taskLister{indexer: indexer} -} - -// List lists all Tasks in the indexer. -func (s *taskLister) List(selector labels.Selector) (ret []*v1.Task, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Task)) - }) - return ret, err + return &taskLister{listers.New[*v1.Task](indexer, v1.Resource("task"))} } // Tasks returns an object that can list and get Tasks. func (s *taskLister) Tasks(namespace string) TaskNamespaceLister { - return taskNamespaceLister{indexer: s.indexer, namespace: namespace} + return taskNamespaceLister{listers.NewNamespaced[*v1.Task](s.ResourceIndexer, namespace)} } // TaskNamespaceLister helps list and get Tasks. @@ -74,26 +66,5 @@ type TaskNamespaceLister interface { // taskNamespaceLister implements the TaskNamespaceLister // interface. type taskNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all Tasks in the indexer for a given namespace. -func (s taskNamespaceLister) List(selector labels.Selector) (ret []*v1.Task, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Task)) - }) - return ret, err -} - -// Get retrieves the Task from the indexer for a given namespace and name. -func (s taskNamespaceLister) Get(name string) (*v1.Task, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("task"), name) - } - return obj.(*v1.Task), nil + listers.ResourceIndexer[*v1.Task] } diff --git a/pkg/client/listers/pipeline/v1/taskrun.go b/pkg/client/listers/pipeline/v1/taskrun.go index 7f5e2c028be..55549aab0cb 100644 --- a/pkg/client/listers/pipeline/v1/taskrun.go +++ b/pkg/client/listers/pipeline/v1/taskrun.go @@ -20,8 +20,8 @@ package v1 import ( v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type TaskRunLister interface { // taskRunLister implements the TaskRunLister interface. type taskRunLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1.TaskRun] } // NewTaskRunLister returns a new TaskRunLister. func NewTaskRunLister(indexer cache.Indexer) TaskRunLister { - return &taskRunLister{indexer: indexer} -} - -// List lists all TaskRuns in the indexer. -func (s *taskRunLister) List(selector labels.Selector) (ret []*v1.TaskRun, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TaskRun)) - }) - return ret, err + return &taskRunLister{listers.New[*v1.TaskRun](indexer, v1.Resource("taskrun"))} } // TaskRuns returns an object that can list and get TaskRuns. func (s *taskRunLister) TaskRuns(namespace string) TaskRunNamespaceLister { - return taskRunNamespaceLister{indexer: s.indexer, namespace: namespace} + return taskRunNamespaceLister{listers.NewNamespaced[*v1.TaskRun](s.ResourceIndexer, namespace)} } // TaskRunNamespaceLister helps list and get TaskRuns. @@ -74,26 +66,5 @@ type TaskRunNamespaceLister interface { // taskRunNamespaceLister implements the TaskRunNamespaceLister // interface. type taskRunNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TaskRuns in the indexer for a given namespace. -func (s taskRunNamespaceLister) List(selector labels.Selector) (ret []*v1.TaskRun, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TaskRun)) - }) - return ret, err -} - -// Get retrieves the TaskRun from the indexer for a given namespace and name. -func (s taskRunNamespaceLister) Get(name string) (*v1.TaskRun, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("taskrun"), name) - } - return obj.(*v1.TaskRun), nil + listers.ResourceIndexer[*v1.TaskRun] } diff --git a/pkg/client/listers/pipeline/v1alpha1/run.go b/pkg/client/listers/pipeline/v1alpha1/run.go index 3ce91c00bab..01b15354cf6 100644 --- a/pkg/client/listers/pipeline/v1alpha1/run.go +++ b/pkg/client/listers/pipeline/v1alpha1/run.go @@ -20,8 +20,8 @@ package v1alpha1 import ( v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type RunLister interface { // runLister implements the RunLister interface. type runLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1alpha1.Run] } // NewRunLister returns a new RunLister. func NewRunLister(indexer cache.Indexer) RunLister { - return &runLister{indexer: indexer} -} - -// List lists all Runs in the indexer. -func (s *runLister) List(selector labels.Selector) (ret []*v1alpha1.Run, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Run)) - }) - return ret, err + return &runLister{listers.New[*v1alpha1.Run](indexer, v1alpha1.Resource("run"))} } // Runs returns an object that can list and get Runs. func (s *runLister) Runs(namespace string) RunNamespaceLister { - return runNamespaceLister{indexer: s.indexer, namespace: namespace} + return runNamespaceLister{listers.NewNamespaced[*v1alpha1.Run](s.ResourceIndexer, namespace)} } // RunNamespaceLister helps list and get Runs. @@ -74,26 +66,5 @@ type RunNamespaceLister interface { // runNamespaceLister implements the RunNamespaceLister // interface. type runNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all Runs in the indexer for a given namespace. -func (s runNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Run, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.Run)) - }) - return ret, err -} - -// Get retrieves the Run from the indexer for a given namespace and name. -func (s runNamespaceLister) Get(name string) (*v1alpha1.Run, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("run"), name) - } - return obj.(*v1alpha1.Run), nil + listers.ResourceIndexer[*v1alpha1.Run] } diff --git a/pkg/client/listers/pipeline/v1alpha1/stepaction.go b/pkg/client/listers/pipeline/v1alpha1/stepaction.go index 50aebdf8251..54d681cc073 100644 --- a/pkg/client/listers/pipeline/v1alpha1/stepaction.go +++ b/pkg/client/listers/pipeline/v1alpha1/stepaction.go @@ -20,8 +20,8 @@ package v1alpha1 import ( v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type StepActionLister interface { // stepActionLister implements the StepActionLister interface. type stepActionLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1alpha1.StepAction] } // NewStepActionLister returns a new StepActionLister. func NewStepActionLister(indexer cache.Indexer) StepActionLister { - return &stepActionLister{indexer: indexer} -} - -// List lists all StepActions in the indexer. -func (s *stepActionLister) List(selector labels.Selector) (ret []*v1alpha1.StepAction, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.StepAction)) - }) - return ret, err + return &stepActionLister{listers.New[*v1alpha1.StepAction](indexer, v1alpha1.Resource("stepaction"))} } // StepActions returns an object that can list and get StepActions. func (s *stepActionLister) StepActions(namespace string) StepActionNamespaceLister { - return stepActionNamespaceLister{indexer: s.indexer, namespace: namespace} + return stepActionNamespaceLister{listers.NewNamespaced[*v1alpha1.StepAction](s.ResourceIndexer, namespace)} } // StepActionNamespaceLister helps list and get StepActions. @@ -74,26 +66,5 @@ type StepActionNamespaceLister interface { // stepActionNamespaceLister implements the StepActionNamespaceLister // interface. type stepActionNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all StepActions in the indexer for a given namespace. -func (s stepActionNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.StepAction, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.StepAction)) - }) - return ret, err -} - -// Get retrieves the StepAction from the indexer for a given namespace and name. -func (s stepActionNamespaceLister) Get(name string) (*v1alpha1.StepAction, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("stepaction"), name) - } - return obj.(*v1alpha1.StepAction), nil + listers.ResourceIndexer[*v1alpha1.StepAction] } diff --git a/pkg/client/listers/pipeline/v1alpha1/verificationpolicy.go b/pkg/client/listers/pipeline/v1alpha1/verificationpolicy.go index 7682fa51ba2..b7eb0630027 100644 --- a/pkg/client/listers/pipeline/v1alpha1/verificationpolicy.go +++ b/pkg/client/listers/pipeline/v1alpha1/verificationpolicy.go @@ -20,8 +20,8 @@ package v1alpha1 import ( v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type VerificationPolicyLister interface { // verificationPolicyLister implements the VerificationPolicyLister interface. type verificationPolicyLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1alpha1.VerificationPolicy] } // NewVerificationPolicyLister returns a new VerificationPolicyLister. func NewVerificationPolicyLister(indexer cache.Indexer) VerificationPolicyLister { - return &verificationPolicyLister{indexer: indexer} -} - -// List lists all VerificationPolicies in the indexer. -func (s *verificationPolicyLister) List(selector labels.Selector) (ret []*v1alpha1.VerificationPolicy, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.VerificationPolicy)) - }) - return ret, err + return &verificationPolicyLister{listers.New[*v1alpha1.VerificationPolicy](indexer, v1alpha1.Resource("verificationpolicy"))} } // VerificationPolicies returns an object that can list and get VerificationPolicies. func (s *verificationPolicyLister) VerificationPolicies(namespace string) VerificationPolicyNamespaceLister { - return verificationPolicyNamespaceLister{indexer: s.indexer, namespace: namespace} + return verificationPolicyNamespaceLister{listers.NewNamespaced[*v1alpha1.VerificationPolicy](s.ResourceIndexer, namespace)} } // VerificationPolicyNamespaceLister helps list and get VerificationPolicies. @@ -74,26 +66,5 @@ type VerificationPolicyNamespaceLister interface { // verificationPolicyNamespaceLister implements the VerificationPolicyNamespaceLister // interface. type verificationPolicyNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all VerificationPolicies in the indexer for a given namespace. -func (s verificationPolicyNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.VerificationPolicy, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.VerificationPolicy)) - }) - return ret, err -} - -// Get retrieves the VerificationPolicy from the indexer for a given namespace and name. -func (s verificationPolicyNamespaceLister) Get(name string) (*v1alpha1.VerificationPolicy, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("verificationpolicy"), name) - } - return obj.(*v1alpha1.VerificationPolicy), nil + listers.ResourceIndexer[*v1alpha1.VerificationPolicy] } diff --git a/pkg/client/listers/pipeline/v1beta1/clustertask.go b/pkg/client/listers/pipeline/v1beta1/clustertask.go index bc88cfb67ec..734d32656d1 100644 --- a/pkg/client/listers/pipeline/v1beta1/clustertask.go +++ b/pkg/client/listers/pipeline/v1beta1/clustertask.go @@ -20,8 +20,8 @@ package v1beta1 import ( v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -39,30 +39,10 @@ type ClusterTaskLister interface { // clusterTaskLister implements the ClusterTaskLister interface. type clusterTaskLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1beta1.ClusterTask] } // NewClusterTaskLister returns a new ClusterTaskLister. func NewClusterTaskLister(indexer cache.Indexer) ClusterTaskLister { - return &clusterTaskLister{indexer: indexer} -} - -// List lists all ClusterTasks in the indexer. -func (s *clusterTaskLister) List(selector labels.Selector) (ret []*v1beta1.ClusterTask, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.ClusterTask)) - }) - return ret, err -} - -// Get retrieves the ClusterTask from the index for a given name. -func (s *clusterTaskLister) Get(name string) (*v1beta1.ClusterTask, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1beta1.Resource("clustertask"), name) - } - return obj.(*v1beta1.ClusterTask), nil + return &clusterTaskLister{listers.New[*v1beta1.ClusterTask](indexer, v1beta1.Resource("clustertask"))} } diff --git a/pkg/client/listers/pipeline/v1beta1/customrun.go b/pkg/client/listers/pipeline/v1beta1/customrun.go index 546668a17ea..5f9f2c73ece 100644 --- a/pkg/client/listers/pipeline/v1beta1/customrun.go +++ b/pkg/client/listers/pipeline/v1beta1/customrun.go @@ -20,8 +20,8 @@ package v1beta1 import ( v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type CustomRunLister interface { // customRunLister implements the CustomRunLister interface. type customRunLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1beta1.CustomRun] } // NewCustomRunLister returns a new CustomRunLister. func NewCustomRunLister(indexer cache.Indexer) CustomRunLister { - return &customRunLister{indexer: indexer} -} - -// List lists all CustomRuns in the indexer. -func (s *customRunLister) List(selector labels.Selector) (ret []*v1beta1.CustomRun, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.CustomRun)) - }) - return ret, err + return &customRunLister{listers.New[*v1beta1.CustomRun](indexer, v1beta1.Resource("customrun"))} } // CustomRuns returns an object that can list and get CustomRuns. func (s *customRunLister) CustomRuns(namespace string) CustomRunNamespaceLister { - return customRunNamespaceLister{indexer: s.indexer, namespace: namespace} + return customRunNamespaceLister{listers.NewNamespaced[*v1beta1.CustomRun](s.ResourceIndexer, namespace)} } // CustomRunNamespaceLister helps list and get CustomRuns. @@ -74,26 +66,5 @@ type CustomRunNamespaceLister interface { // customRunNamespaceLister implements the CustomRunNamespaceLister // interface. type customRunNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all CustomRuns in the indexer for a given namespace. -func (s customRunNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.CustomRun, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.CustomRun)) - }) - return ret, err -} - -// Get retrieves the CustomRun from the indexer for a given namespace and name. -func (s customRunNamespaceLister) Get(name string) (*v1beta1.CustomRun, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1beta1.Resource("customrun"), name) - } - return obj.(*v1beta1.CustomRun), nil + listers.ResourceIndexer[*v1beta1.CustomRun] } diff --git a/pkg/client/listers/pipeline/v1beta1/pipeline.go b/pkg/client/listers/pipeline/v1beta1/pipeline.go index cd85d324fe0..acb69fafb71 100644 --- a/pkg/client/listers/pipeline/v1beta1/pipeline.go +++ b/pkg/client/listers/pipeline/v1beta1/pipeline.go @@ -20,8 +20,8 @@ package v1beta1 import ( v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type PipelineLister interface { // pipelineLister implements the PipelineLister interface. type pipelineLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1beta1.Pipeline] } // NewPipelineLister returns a new PipelineLister. func NewPipelineLister(indexer cache.Indexer) PipelineLister { - return &pipelineLister{indexer: indexer} -} - -// List lists all Pipelines in the indexer. -func (s *pipelineLister) List(selector labels.Selector) (ret []*v1beta1.Pipeline, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.Pipeline)) - }) - return ret, err + return &pipelineLister{listers.New[*v1beta1.Pipeline](indexer, v1beta1.Resource("pipeline"))} } // Pipelines returns an object that can list and get Pipelines. func (s *pipelineLister) Pipelines(namespace string) PipelineNamespaceLister { - return pipelineNamespaceLister{indexer: s.indexer, namespace: namespace} + return pipelineNamespaceLister{listers.NewNamespaced[*v1beta1.Pipeline](s.ResourceIndexer, namespace)} } // PipelineNamespaceLister helps list and get Pipelines. @@ -74,26 +66,5 @@ type PipelineNamespaceLister interface { // pipelineNamespaceLister implements the PipelineNamespaceLister // interface. type pipelineNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all Pipelines in the indexer for a given namespace. -func (s pipelineNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.Pipeline, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.Pipeline)) - }) - return ret, err -} - -// Get retrieves the Pipeline from the indexer for a given namespace and name. -func (s pipelineNamespaceLister) Get(name string) (*v1beta1.Pipeline, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1beta1.Resource("pipeline"), name) - } - return obj.(*v1beta1.Pipeline), nil + listers.ResourceIndexer[*v1beta1.Pipeline] } diff --git a/pkg/client/listers/pipeline/v1beta1/pipelinerun.go b/pkg/client/listers/pipeline/v1beta1/pipelinerun.go index 31b7ebb953f..8ebd090142a 100644 --- a/pkg/client/listers/pipeline/v1beta1/pipelinerun.go +++ b/pkg/client/listers/pipeline/v1beta1/pipelinerun.go @@ -20,8 +20,8 @@ package v1beta1 import ( v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type PipelineRunLister interface { // pipelineRunLister implements the PipelineRunLister interface. type pipelineRunLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1beta1.PipelineRun] } // NewPipelineRunLister returns a new PipelineRunLister. func NewPipelineRunLister(indexer cache.Indexer) PipelineRunLister { - return &pipelineRunLister{indexer: indexer} -} - -// List lists all PipelineRuns in the indexer. -func (s *pipelineRunLister) List(selector labels.Selector) (ret []*v1beta1.PipelineRun, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.PipelineRun)) - }) - return ret, err + return &pipelineRunLister{listers.New[*v1beta1.PipelineRun](indexer, v1beta1.Resource("pipelinerun"))} } // PipelineRuns returns an object that can list and get PipelineRuns. func (s *pipelineRunLister) PipelineRuns(namespace string) PipelineRunNamespaceLister { - return pipelineRunNamespaceLister{indexer: s.indexer, namespace: namespace} + return pipelineRunNamespaceLister{listers.NewNamespaced[*v1beta1.PipelineRun](s.ResourceIndexer, namespace)} } // PipelineRunNamespaceLister helps list and get PipelineRuns. @@ -74,26 +66,5 @@ type PipelineRunNamespaceLister interface { // pipelineRunNamespaceLister implements the PipelineRunNamespaceLister // interface. type pipelineRunNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all PipelineRuns in the indexer for a given namespace. -func (s pipelineRunNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.PipelineRun, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.PipelineRun)) - }) - return ret, err -} - -// Get retrieves the PipelineRun from the indexer for a given namespace and name. -func (s pipelineRunNamespaceLister) Get(name string) (*v1beta1.PipelineRun, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1beta1.Resource("pipelinerun"), name) - } - return obj.(*v1beta1.PipelineRun), nil + listers.ResourceIndexer[*v1beta1.PipelineRun] } diff --git a/pkg/client/listers/pipeline/v1beta1/stepaction.go b/pkg/client/listers/pipeline/v1beta1/stepaction.go index 1925738258d..8cbfb06120e 100644 --- a/pkg/client/listers/pipeline/v1beta1/stepaction.go +++ b/pkg/client/listers/pipeline/v1beta1/stepaction.go @@ -20,8 +20,8 @@ package v1beta1 import ( v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type StepActionLister interface { // stepActionLister implements the StepActionLister interface. type stepActionLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1beta1.StepAction] } // NewStepActionLister returns a new StepActionLister. func NewStepActionLister(indexer cache.Indexer) StepActionLister { - return &stepActionLister{indexer: indexer} -} - -// List lists all StepActions in the indexer. -func (s *stepActionLister) List(selector labels.Selector) (ret []*v1beta1.StepAction, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.StepAction)) - }) - return ret, err + return &stepActionLister{listers.New[*v1beta1.StepAction](indexer, v1beta1.Resource("stepaction"))} } // StepActions returns an object that can list and get StepActions. func (s *stepActionLister) StepActions(namespace string) StepActionNamespaceLister { - return stepActionNamespaceLister{indexer: s.indexer, namespace: namespace} + return stepActionNamespaceLister{listers.NewNamespaced[*v1beta1.StepAction](s.ResourceIndexer, namespace)} } // StepActionNamespaceLister helps list and get StepActions. @@ -74,26 +66,5 @@ type StepActionNamespaceLister interface { // stepActionNamespaceLister implements the StepActionNamespaceLister // interface. type stepActionNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all StepActions in the indexer for a given namespace. -func (s stepActionNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.StepAction, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.StepAction)) - }) - return ret, err -} - -// Get retrieves the StepAction from the indexer for a given namespace and name. -func (s stepActionNamespaceLister) Get(name string) (*v1beta1.StepAction, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1beta1.Resource("stepaction"), name) - } - return obj.(*v1beta1.StepAction), nil + listers.ResourceIndexer[*v1beta1.StepAction] } diff --git a/pkg/client/listers/pipeline/v1beta1/task.go b/pkg/client/listers/pipeline/v1beta1/task.go index b13ba17e049..a45729722b1 100644 --- a/pkg/client/listers/pipeline/v1beta1/task.go +++ b/pkg/client/listers/pipeline/v1beta1/task.go @@ -20,8 +20,8 @@ package v1beta1 import ( v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type TaskLister interface { // taskLister implements the TaskLister interface. type taskLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1beta1.Task] } // NewTaskLister returns a new TaskLister. func NewTaskLister(indexer cache.Indexer) TaskLister { - return &taskLister{indexer: indexer} -} - -// List lists all Tasks in the indexer. -func (s *taskLister) List(selector labels.Selector) (ret []*v1beta1.Task, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.Task)) - }) - return ret, err + return &taskLister{listers.New[*v1beta1.Task](indexer, v1beta1.Resource("task"))} } // Tasks returns an object that can list and get Tasks. func (s *taskLister) Tasks(namespace string) TaskNamespaceLister { - return taskNamespaceLister{indexer: s.indexer, namespace: namespace} + return taskNamespaceLister{listers.NewNamespaced[*v1beta1.Task](s.ResourceIndexer, namespace)} } // TaskNamespaceLister helps list and get Tasks. @@ -74,26 +66,5 @@ type TaskNamespaceLister interface { // taskNamespaceLister implements the TaskNamespaceLister // interface. type taskNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all Tasks in the indexer for a given namespace. -func (s taskNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.Task, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.Task)) - }) - return ret, err -} - -// Get retrieves the Task from the indexer for a given namespace and name. -func (s taskNamespaceLister) Get(name string) (*v1beta1.Task, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1beta1.Resource("task"), name) - } - return obj.(*v1beta1.Task), nil + listers.ResourceIndexer[*v1beta1.Task] } diff --git a/pkg/client/listers/pipeline/v1beta1/taskrun.go b/pkg/client/listers/pipeline/v1beta1/taskrun.go index 310c3700f24..580a34c68a4 100644 --- a/pkg/client/listers/pipeline/v1beta1/taskrun.go +++ b/pkg/client/listers/pipeline/v1beta1/taskrun.go @@ -20,8 +20,8 @@ package v1beta1 import ( v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type TaskRunLister interface { // taskRunLister implements the TaskRunLister interface. type taskRunLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1beta1.TaskRun] } // NewTaskRunLister returns a new TaskRunLister. func NewTaskRunLister(indexer cache.Indexer) TaskRunLister { - return &taskRunLister{indexer: indexer} -} - -// List lists all TaskRuns in the indexer. -func (s *taskRunLister) List(selector labels.Selector) (ret []*v1beta1.TaskRun, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.TaskRun)) - }) - return ret, err + return &taskRunLister{listers.New[*v1beta1.TaskRun](indexer, v1beta1.Resource("taskrun"))} } // TaskRuns returns an object that can list and get TaskRuns. func (s *taskRunLister) TaskRuns(namespace string) TaskRunNamespaceLister { - return taskRunNamespaceLister{indexer: s.indexer, namespace: namespace} + return taskRunNamespaceLister{listers.NewNamespaced[*v1beta1.TaskRun](s.ResourceIndexer, namespace)} } // TaskRunNamespaceLister helps list and get TaskRuns. @@ -74,26 +66,5 @@ type TaskRunNamespaceLister interface { // taskRunNamespaceLister implements the TaskRunNamespaceLister // interface. type taskRunNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TaskRuns in the indexer for a given namespace. -func (s taskRunNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.TaskRun, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.TaskRun)) - }) - return ret, err -} - -// Get retrieves the TaskRun from the indexer for a given namespace and name. -func (s taskRunNamespaceLister) Get(name string) (*v1beta1.TaskRun, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1beta1.Resource("taskrun"), name) - } - return obj.(*v1beta1.TaskRun), nil + listers.ResourceIndexer[*v1beta1.TaskRun] } diff --git a/pkg/client/resolution/clientset/versioned/fake/clientset_generated.go b/pkg/client/resolution/clientset/versioned/fake/clientset_generated.go index b8bae4b809d..017b1ff184c 100644 --- a/pkg/client/resolution/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/resolution/clientset/versioned/fake/clientset_generated.go @@ -33,8 +33,12 @@ import ( // NewSimpleClientset returns a clientset that will respond with the provided objects. // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement // for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). func NewSimpleClientset(objects ...runtime.Object) *Clientset { o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) for _, obj := range objects { diff --git a/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1/fake/fake_resolutionrequest.go b/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1/fake/fake_resolutionrequest.go index 027025ed1b4..573f750b45f 100644 --- a/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1/fake/fake_resolutionrequest.go +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1/fake/fake_resolutionrequest.go @@ -41,22 +41,24 @@ var resolutionrequestsKind = v1alpha1.SchemeGroupVersion.WithKind("ResolutionReq // Get takes name of the resolutionRequest, and returns the corresponding resolutionRequest object, and an error if there is any. func (c *FakeResolutionRequests) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ResolutionRequest, err error) { + emptyResult := &v1alpha1.ResolutionRequest{} obj, err := c.Fake. - Invokes(testing.NewGetAction(resolutionrequestsResource, c.ns, name), &v1alpha1.ResolutionRequest{}) + Invokes(testing.NewGetActionWithOptions(resolutionrequestsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.ResolutionRequest), err } // List takes label and field selectors, and returns the list of ResolutionRequests that match those selectors. func (c *FakeResolutionRequests) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ResolutionRequestList, err error) { + emptyResult := &v1alpha1.ResolutionRequestList{} obj, err := c.Fake. - Invokes(testing.NewListAction(resolutionrequestsResource, resolutionrequestsKind, c.ns, opts), &v1alpha1.ResolutionRequestList{}) + Invokes(testing.NewListActionWithOptions(resolutionrequestsResource, resolutionrequestsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,40 +77,43 @@ func (c *FakeResolutionRequests) List(ctx context.Context, opts v1.ListOptions) // Watch returns a watch.Interface that watches the requested resolutionRequests. func (c *FakeResolutionRequests) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(resolutionrequestsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(resolutionrequestsResource, c.ns, opts)) } // Create takes the representation of a resolutionRequest and creates it. Returns the server's representation of the resolutionRequest, and an error, if there is any. func (c *FakeResolutionRequests) Create(ctx context.Context, resolutionRequest *v1alpha1.ResolutionRequest, opts v1.CreateOptions) (result *v1alpha1.ResolutionRequest, err error) { + emptyResult := &v1alpha1.ResolutionRequest{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(resolutionrequestsResource, c.ns, resolutionRequest), &v1alpha1.ResolutionRequest{}) + Invokes(testing.NewCreateActionWithOptions(resolutionrequestsResource, c.ns, resolutionRequest, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.ResolutionRequest), err } // Update takes the representation of a resolutionRequest and updates it. Returns the server's representation of the resolutionRequest, and an error, if there is any. func (c *FakeResolutionRequests) Update(ctx context.Context, resolutionRequest *v1alpha1.ResolutionRequest, opts v1.UpdateOptions) (result *v1alpha1.ResolutionRequest, err error) { + emptyResult := &v1alpha1.ResolutionRequest{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(resolutionrequestsResource, c.ns, resolutionRequest), &v1alpha1.ResolutionRequest{}) + Invokes(testing.NewUpdateActionWithOptions(resolutionrequestsResource, c.ns, resolutionRequest, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.ResolutionRequest), 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 *FakeResolutionRequests) UpdateStatus(ctx context.Context, resolutionRequest *v1alpha1.ResolutionRequest, opts v1.UpdateOptions) (*v1alpha1.ResolutionRequest, error) { +func (c *FakeResolutionRequests) UpdateStatus(ctx context.Context, resolutionRequest *v1alpha1.ResolutionRequest, opts v1.UpdateOptions) (result *v1alpha1.ResolutionRequest, err error) { + emptyResult := &v1alpha1.ResolutionRequest{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(resolutionrequestsResource, "status", c.ns, resolutionRequest), &v1alpha1.ResolutionRequest{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(resolutionrequestsResource, "status", c.ns, resolutionRequest, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.ResolutionRequest), err } @@ -123,7 +128,7 @@ func (c *FakeResolutionRequests) Delete(ctx context.Context, name string, opts v // DeleteCollection deletes a collection of objects. func (c *FakeResolutionRequests) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(resolutionrequestsResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(resolutionrequestsResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1alpha1.ResolutionRequestList{}) return err @@ -131,11 +136,12 @@ func (c *FakeResolutionRequests) DeleteCollection(ctx context.Context, opts v1.D // Patch applies the patch and returns the patched resolutionRequest. func (c *FakeResolutionRequests) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ResolutionRequest, err error) { + emptyResult := &v1alpha1.ResolutionRequest{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(resolutionrequestsResource, c.ns, name, pt, data, subresources...), &v1alpha1.ResolutionRequest{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(resolutionrequestsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.ResolutionRequest), err } diff --git a/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1/resolutionrequest.go b/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1/resolutionrequest.go index 6169f8a3ad3..6a0e32fdcb1 100644 --- a/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1/resolutionrequest.go +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1/resolutionrequest.go @@ -20,14 +20,13 @@ package v1alpha1 import ( "context" - "time" v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1" scheme "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // ResolutionRequestsGetter has a method to return a ResolutionRequestInterface. @@ -40,6 +39,7 @@ type ResolutionRequestsGetter interface { type ResolutionRequestInterface interface { Create(ctx context.Context, resolutionRequest *v1alpha1.ResolutionRequest, opts v1.CreateOptions) (*v1alpha1.ResolutionRequest, error) Update(ctx context.Context, resolutionRequest *v1alpha1.ResolutionRequest, opts v1.UpdateOptions) (*v1alpha1.ResolutionRequest, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, resolutionRequest *v1alpha1.ResolutionRequest, opts v1.UpdateOptions) (*v1alpha1.ResolutionRequest, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error @@ -52,144 +52,18 @@ type ResolutionRequestInterface interface { // resolutionRequests implements ResolutionRequestInterface type resolutionRequests struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1alpha1.ResolutionRequest, *v1alpha1.ResolutionRequestList] } // newResolutionRequests returns a ResolutionRequests func newResolutionRequests(c *ResolutionV1alpha1Client, namespace string) *resolutionRequests { return &resolutionRequests{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1alpha1.ResolutionRequest, *v1alpha1.ResolutionRequestList]( + "resolutionrequests", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1alpha1.ResolutionRequest { return &v1alpha1.ResolutionRequest{} }, + func() *v1alpha1.ResolutionRequestList { return &v1alpha1.ResolutionRequestList{} }), } } - -// Get takes name of the resolutionRequest, and returns the corresponding resolutionRequest object, and an error if there is any. -func (c *resolutionRequests) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.ResolutionRequest, err error) { - result = &v1alpha1.ResolutionRequest{} - err = c.client.Get(). - Namespace(c.ns). - Resource("resolutionrequests"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ResolutionRequests that match those selectors. -func (c *resolutionRequests) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ResolutionRequestList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.ResolutionRequestList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("resolutionrequests"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested resolutionRequests. -func (c *resolutionRequests) 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("resolutionrequests"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a resolutionRequest and creates it. Returns the server's representation of the resolutionRequest, and an error, if there is any. -func (c *resolutionRequests) Create(ctx context.Context, resolutionRequest *v1alpha1.ResolutionRequest, opts v1.CreateOptions) (result *v1alpha1.ResolutionRequest, err error) { - result = &v1alpha1.ResolutionRequest{} - err = c.client.Post(). - Namespace(c.ns). - Resource("resolutionrequests"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(resolutionRequest). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a resolutionRequest and updates it. Returns the server's representation of the resolutionRequest, and an error, if there is any. -func (c *resolutionRequests) Update(ctx context.Context, resolutionRequest *v1alpha1.ResolutionRequest, opts v1.UpdateOptions) (result *v1alpha1.ResolutionRequest, err error) { - result = &v1alpha1.ResolutionRequest{} - err = c.client.Put(). - Namespace(c.ns). - Resource("resolutionrequests"). - Name(resolutionRequest.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(resolutionRequest). - 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 *resolutionRequests) UpdateStatus(ctx context.Context, resolutionRequest *v1alpha1.ResolutionRequest, opts v1.UpdateOptions) (result *v1alpha1.ResolutionRequest, err error) { - result = &v1alpha1.ResolutionRequest{} - err = c.client.Put(). - Namespace(c.ns). - Resource("resolutionrequests"). - Name(resolutionRequest.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(resolutionRequest). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the resolutionRequest and deletes it. Returns an error if one occurs. -func (c *resolutionRequests) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("resolutionrequests"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *resolutionRequests) 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("resolutionrequests"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched resolutionRequest. -func (c *resolutionRequests) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.ResolutionRequest, err error) { - result = &v1alpha1.ResolutionRequest{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("resolutionrequests"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/fake_resolutionrequest.go b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/fake_resolutionrequest.go index 0985e7e5abb..bea0317f87a 100644 --- a/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/fake_resolutionrequest.go +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/fake_resolutionrequest.go @@ -41,22 +41,24 @@ var resolutionrequestsKind = v1beta1.SchemeGroupVersion.WithKind("ResolutionRequ // Get takes name of the resolutionRequest, and returns the corresponding resolutionRequest object, and an error if there is any. func (c *FakeResolutionRequests) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.ResolutionRequest, err error) { + emptyResult := &v1beta1.ResolutionRequest{} obj, err := c.Fake. - Invokes(testing.NewGetAction(resolutionrequestsResource, c.ns, name), &v1beta1.ResolutionRequest{}) + Invokes(testing.NewGetActionWithOptions(resolutionrequestsResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.ResolutionRequest), err } // List takes label and field selectors, and returns the list of ResolutionRequests that match those selectors. func (c *FakeResolutionRequests) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.ResolutionRequestList, err error) { + emptyResult := &v1beta1.ResolutionRequestList{} obj, err := c.Fake. - Invokes(testing.NewListAction(resolutionrequestsResource, resolutionrequestsKind, c.ns, opts), &v1beta1.ResolutionRequestList{}) + Invokes(testing.NewListActionWithOptions(resolutionrequestsResource, resolutionrequestsKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,40 +77,43 @@ func (c *FakeResolutionRequests) List(ctx context.Context, opts v1.ListOptions) // Watch returns a watch.Interface that watches the requested resolutionRequests. func (c *FakeResolutionRequests) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(resolutionrequestsResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(resolutionrequestsResource, c.ns, opts)) } // Create takes the representation of a resolutionRequest and creates it. Returns the server's representation of the resolutionRequest, and an error, if there is any. func (c *FakeResolutionRequests) Create(ctx context.Context, resolutionRequest *v1beta1.ResolutionRequest, opts v1.CreateOptions) (result *v1beta1.ResolutionRequest, err error) { + emptyResult := &v1beta1.ResolutionRequest{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(resolutionrequestsResource, c.ns, resolutionRequest), &v1beta1.ResolutionRequest{}) + Invokes(testing.NewCreateActionWithOptions(resolutionrequestsResource, c.ns, resolutionRequest, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.ResolutionRequest), err } // Update takes the representation of a resolutionRequest and updates it. Returns the server's representation of the resolutionRequest, and an error, if there is any. func (c *FakeResolutionRequests) Update(ctx context.Context, resolutionRequest *v1beta1.ResolutionRequest, opts v1.UpdateOptions) (result *v1beta1.ResolutionRequest, err error) { + emptyResult := &v1beta1.ResolutionRequest{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(resolutionrequestsResource, c.ns, resolutionRequest), &v1beta1.ResolutionRequest{}) + Invokes(testing.NewUpdateActionWithOptions(resolutionrequestsResource, c.ns, resolutionRequest, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.ResolutionRequest), 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 *FakeResolutionRequests) UpdateStatus(ctx context.Context, resolutionRequest *v1beta1.ResolutionRequest, opts v1.UpdateOptions) (*v1beta1.ResolutionRequest, error) { +func (c *FakeResolutionRequests) UpdateStatus(ctx context.Context, resolutionRequest *v1beta1.ResolutionRequest, opts v1.UpdateOptions) (result *v1beta1.ResolutionRequest, err error) { + emptyResult := &v1beta1.ResolutionRequest{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(resolutionrequestsResource, "status", c.ns, resolutionRequest), &v1beta1.ResolutionRequest{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(resolutionrequestsResource, "status", c.ns, resolutionRequest, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.ResolutionRequest), err } @@ -123,7 +128,7 @@ func (c *FakeResolutionRequests) Delete(ctx context.Context, name string, opts v // DeleteCollection deletes a collection of objects. func (c *FakeResolutionRequests) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(resolutionrequestsResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(resolutionrequestsResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1beta1.ResolutionRequestList{}) return err @@ -131,11 +136,12 @@ func (c *FakeResolutionRequests) DeleteCollection(ctx context.Context, opts v1.D // Patch applies the patch and returns the patched resolutionRequest. func (c *FakeResolutionRequests) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ResolutionRequest, err error) { + emptyResult := &v1beta1.ResolutionRequest{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(resolutionrequestsResource, c.ns, name, pt, data, subresources...), &v1beta1.ResolutionRequest{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(resolutionrequestsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1beta1.ResolutionRequest), err } diff --git a/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/resolutionrequest.go b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/resolutionrequest.go index e09ca18da6b..c14de49faff 100644 --- a/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/resolutionrequest.go +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/resolutionrequest.go @@ -20,14 +20,13 @@ package v1beta1 import ( "context" - "time" v1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" scheme "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // ResolutionRequestsGetter has a method to return a ResolutionRequestInterface. @@ -40,6 +39,7 @@ type ResolutionRequestsGetter interface { type ResolutionRequestInterface interface { Create(ctx context.Context, resolutionRequest *v1beta1.ResolutionRequest, opts v1.CreateOptions) (*v1beta1.ResolutionRequest, error) Update(ctx context.Context, resolutionRequest *v1beta1.ResolutionRequest, opts v1.UpdateOptions) (*v1beta1.ResolutionRequest, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, resolutionRequest *v1beta1.ResolutionRequest, opts v1.UpdateOptions) (*v1beta1.ResolutionRequest, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error @@ -52,144 +52,18 @@ type ResolutionRequestInterface interface { // resolutionRequests implements ResolutionRequestInterface type resolutionRequests struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1beta1.ResolutionRequest, *v1beta1.ResolutionRequestList] } // newResolutionRequests returns a ResolutionRequests func newResolutionRequests(c *ResolutionV1beta1Client, namespace string) *resolutionRequests { return &resolutionRequests{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1beta1.ResolutionRequest, *v1beta1.ResolutionRequestList]( + "resolutionrequests", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1beta1.ResolutionRequest { return &v1beta1.ResolutionRequest{} }, + func() *v1beta1.ResolutionRequestList { return &v1beta1.ResolutionRequestList{} }), } } - -// Get takes name of the resolutionRequest, and returns the corresponding resolutionRequest object, and an error if there is any. -func (c *resolutionRequests) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.ResolutionRequest, err error) { - result = &v1beta1.ResolutionRequest{} - err = c.client.Get(). - Namespace(c.ns). - Resource("resolutionrequests"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ResolutionRequests that match those selectors. -func (c *resolutionRequests) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.ResolutionRequestList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1beta1.ResolutionRequestList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("resolutionrequests"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested resolutionRequests. -func (c *resolutionRequests) 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("resolutionrequests"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a resolutionRequest and creates it. Returns the server's representation of the resolutionRequest, and an error, if there is any. -func (c *resolutionRequests) Create(ctx context.Context, resolutionRequest *v1beta1.ResolutionRequest, opts v1.CreateOptions) (result *v1beta1.ResolutionRequest, err error) { - result = &v1beta1.ResolutionRequest{} - err = c.client.Post(). - Namespace(c.ns). - Resource("resolutionrequests"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(resolutionRequest). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a resolutionRequest and updates it. Returns the server's representation of the resolutionRequest, and an error, if there is any. -func (c *resolutionRequests) Update(ctx context.Context, resolutionRequest *v1beta1.ResolutionRequest, opts v1.UpdateOptions) (result *v1beta1.ResolutionRequest, err error) { - result = &v1beta1.ResolutionRequest{} - err = c.client.Put(). - Namespace(c.ns). - Resource("resolutionrequests"). - Name(resolutionRequest.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(resolutionRequest). - 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 *resolutionRequests) UpdateStatus(ctx context.Context, resolutionRequest *v1beta1.ResolutionRequest, opts v1.UpdateOptions) (result *v1beta1.ResolutionRequest, err error) { - result = &v1beta1.ResolutionRequest{} - err = c.client.Put(). - Namespace(c.ns). - Resource("resolutionrequests"). - Name(resolutionRequest.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(resolutionRequest). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the resolutionRequest and deletes it. Returns an error if one occurs. -func (c *resolutionRequests) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("resolutionrequests"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *resolutionRequests) 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("resolutionrequests"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched resolutionRequest. -func (c *resolutionRequests) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ResolutionRequest, err error) { - result = &v1beta1.ResolutionRequest{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("resolutionrequests"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/resolution/informers/externalversions/factory.go b/pkg/client/resolution/informers/externalversions/factory.go index d6e309712f3..c43c4425208 100644 --- a/pkg/client/resolution/informers/externalversions/factory.go +++ b/pkg/client/resolution/informers/externalversions/factory.go @@ -228,6 +228,7 @@ type SharedInformerFactory interface { // Start initializes all requested informers. They are handled in goroutines // which run until the stop channel gets closed. + // Warning: Start does not block. When run in a go-routine, it will race with a later WaitForCacheSync. Start(stopCh <-chan struct{}) // Shutdown marks a factory as shutting down. At that point no new diff --git a/pkg/client/resolution/listers/resolution/v1alpha1/resolutionrequest.go b/pkg/client/resolution/listers/resolution/v1alpha1/resolutionrequest.go index 648ce7c6dc8..bdc753f8609 100644 --- a/pkg/client/resolution/listers/resolution/v1alpha1/resolutionrequest.go +++ b/pkg/client/resolution/listers/resolution/v1alpha1/resolutionrequest.go @@ -20,8 +20,8 @@ package v1alpha1 import ( v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type ResolutionRequestLister interface { // resolutionRequestLister implements the ResolutionRequestLister interface. type resolutionRequestLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1alpha1.ResolutionRequest] } // NewResolutionRequestLister returns a new ResolutionRequestLister. func NewResolutionRequestLister(indexer cache.Indexer) ResolutionRequestLister { - return &resolutionRequestLister{indexer: indexer} -} - -// List lists all ResolutionRequests in the indexer. -func (s *resolutionRequestLister) List(selector labels.Selector) (ret []*v1alpha1.ResolutionRequest, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.ResolutionRequest)) - }) - return ret, err + return &resolutionRequestLister{listers.New[*v1alpha1.ResolutionRequest](indexer, v1alpha1.Resource("resolutionrequest"))} } // ResolutionRequests returns an object that can list and get ResolutionRequests. func (s *resolutionRequestLister) ResolutionRequests(namespace string) ResolutionRequestNamespaceLister { - return resolutionRequestNamespaceLister{indexer: s.indexer, namespace: namespace} + return resolutionRequestNamespaceLister{listers.NewNamespaced[*v1alpha1.ResolutionRequest](s.ResourceIndexer, namespace)} } // ResolutionRequestNamespaceLister helps list and get ResolutionRequests. @@ -74,26 +66,5 @@ type ResolutionRequestNamespaceLister interface { // resolutionRequestNamespaceLister implements the ResolutionRequestNamespaceLister // interface. type resolutionRequestNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all ResolutionRequests in the indexer for a given namespace. -func (s resolutionRequestNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.ResolutionRequest, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.ResolutionRequest)) - }) - return ret, err -} - -// Get retrieves the ResolutionRequest from the indexer for a given namespace and name. -func (s resolutionRequestNamespaceLister) Get(name string) (*v1alpha1.ResolutionRequest, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("resolutionrequest"), name) - } - return obj.(*v1alpha1.ResolutionRequest), nil + listers.ResourceIndexer[*v1alpha1.ResolutionRequest] } diff --git a/pkg/client/resolution/listers/resolution/v1beta1/resolutionrequest.go b/pkg/client/resolution/listers/resolution/v1beta1/resolutionrequest.go index e990684f0a3..8b56552a0a6 100644 --- a/pkg/client/resolution/listers/resolution/v1beta1/resolutionrequest.go +++ b/pkg/client/resolution/listers/resolution/v1beta1/resolutionrequest.go @@ -20,8 +20,8 @@ package v1beta1 import ( v1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type ResolutionRequestLister interface { // resolutionRequestLister implements the ResolutionRequestLister interface. type resolutionRequestLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1beta1.ResolutionRequest] } // NewResolutionRequestLister returns a new ResolutionRequestLister. func NewResolutionRequestLister(indexer cache.Indexer) ResolutionRequestLister { - return &resolutionRequestLister{indexer: indexer} -} - -// List lists all ResolutionRequests in the indexer. -func (s *resolutionRequestLister) List(selector labels.Selector) (ret []*v1beta1.ResolutionRequest, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.ResolutionRequest)) - }) - return ret, err + return &resolutionRequestLister{listers.New[*v1beta1.ResolutionRequest](indexer, v1beta1.Resource("resolutionrequest"))} } // ResolutionRequests returns an object that can list and get ResolutionRequests. func (s *resolutionRequestLister) ResolutionRequests(namespace string) ResolutionRequestNamespaceLister { - return resolutionRequestNamespaceLister{indexer: s.indexer, namespace: namespace} + return resolutionRequestNamespaceLister{listers.NewNamespaced[*v1beta1.ResolutionRequest](s.ResourceIndexer, namespace)} } // ResolutionRequestNamespaceLister helps list and get ResolutionRequests. @@ -74,26 +66,5 @@ type ResolutionRequestNamespaceLister interface { // resolutionRequestNamespaceLister implements the ResolutionRequestNamespaceLister // interface. type resolutionRequestNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all ResolutionRequests in the indexer for a given namespace. -func (s resolutionRequestNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.ResolutionRequest, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1beta1.ResolutionRequest)) - }) - return ret, err -} - -// Get retrieves the ResolutionRequest from the indexer for a given namespace and name. -func (s resolutionRequestNamespaceLister) Get(name string) (*v1beta1.ResolutionRequest, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1beta1.Resource("resolutionrequest"), name) - } - return obj.(*v1beta1.ResolutionRequest), nil + listers.ResourceIndexer[*v1beta1.ResolutionRequest] } diff --git a/pkg/client/resource/clientset/versioned/fake/clientset_generated.go b/pkg/client/resource/clientset/versioned/fake/clientset_generated.go index 1d6881d7b97..183594da94b 100644 --- a/pkg/client/resource/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/resource/clientset/versioned/fake/clientset_generated.go @@ -31,8 +31,12 @@ import ( // NewSimpleClientset returns a clientset that will respond with the provided objects. // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement // for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). func NewSimpleClientset(objects ...runtime.Object) *Clientset { o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) for _, obj := range objects { diff --git a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_pipelineresource.go b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_pipelineresource.go index df7b7245480..d9686ecf574 100644 --- a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_pipelineresource.go +++ b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/fake/fake_pipelineresource.go @@ -41,22 +41,24 @@ var pipelineresourcesKind = v1alpha1.SchemeGroupVersion.WithKind("PipelineResour // Get takes name of the pipelineResource, and returns the corresponding pipelineResource object, and an error if there is any. func (c *FakePipelineResources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PipelineResource, err error) { + emptyResult := &v1alpha1.PipelineResource{} obj, err := c.Fake. - Invokes(testing.NewGetAction(pipelineresourcesResource, c.ns, name), &v1alpha1.PipelineResource{}) + Invokes(testing.NewGetActionWithOptions(pipelineresourcesResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.PipelineResource), err } // List takes label and field selectors, and returns the list of PipelineResources that match those selectors. func (c *FakePipelineResources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PipelineResourceList, err error) { + emptyResult := &v1alpha1.PipelineResourceList{} obj, err := c.Fake. - Invokes(testing.NewListAction(pipelineresourcesResource, pipelineresourcesKind, c.ns, opts), &v1alpha1.PipelineResourceList{}) + Invokes(testing.NewListActionWithOptions(pipelineresourcesResource, pipelineresourcesKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,28 +77,30 @@ func (c *FakePipelineResources) List(ctx context.Context, opts v1.ListOptions) ( // Watch returns a watch.Interface that watches the requested pipelineResources. func (c *FakePipelineResources) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(pipelineresourcesResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(pipelineresourcesResource, c.ns, opts)) } // Create takes the representation of a pipelineResource and creates it. Returns the server's representation of the pipelineResource, and an error, if there is any. func (c *FakePipelineResources) Create(ctx context.Context, pipelineResource *v1alpha1.PipelineResource, opts v1.CreateOptions) (result *v1alpha1.PipelineResource, err error) { + emptyResult := &v1alpha1.PipelineResource{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(pipelineresourcesResource, c.ns, pipelineResource), &v1alpha1.PipelineResource{}) + Invokes(testing.NewCreateActionWithOptions(pipelineresourcesResource, c.ns, pipelineResource, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.PipelineResource), err } // Update takes the representation of a pipelineResource and updates it. Returns the server's representation of the pipelineResource, and an error, if there is any. func (c *FakePipelineResources) Update(ctx context.Context, pipelineResource *v1alpha1.PipelineResource, opts v1.UpdateOptions) (result *v1alpha1.PipelineResource, err error) { + emptyResult := &v1alpha1.PipelineResource{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(pipelineresourcesResource, c.ns, pipelineResource), &v1alpha1.PipelineResource{}) + Invokes(testing.NewUpdateActionWithOptions(pipelineresourcesResource, c.ns, pipelineResource, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.PipelineResource), err } @@ -111,7 +115,7 @@ func (c *FakePipelineResources) Delete(ctx context.Context, name string, opts v1 // DeleteCollection deletes a collection of objects. func (c *FakePipelineResources) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(pipelineresourcesResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(pipelineresourcesResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1alpha1.PipelineResourceList{}) return err @@ -119,11 +123,12 @@ func (c *FakePipelineResources) DeleteCollection(ctx context.Context, opts v1.De // Patch applies the patch and returns the patched pipelineResource. func (c *FakePipelineResources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PipelineResource, err error) { + emptyResult := &v1alpha1.PipelineResource{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(pipelineresourcesResource, c.ns, name, pt, data, subresources...), &v1alpha1.PipelineResource{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(pipelineresourcesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1alpha1.PipelineResource), err } diff --git a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/pipelineresource.go b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/pipelineresource.go index ec03040eebe..1a8a72600da 100644 --- a/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/pipelineresource.go +++ b/pkg/client/resource/clientset/versioned/typed/resource/v1alpha1/pipelineresource.go @@ -20,14 +20,13 @@ package v1alpha1 import ( "context" - "time" v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" scheme "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned/scheme" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" ) // PipelineResourcesGetter has a method to return a PipelineResourceInterface. @@ -51,128 +50,18 @@ type PipelineResourceInterface interface { // pipelineResources implements PipelineResourceInterface type pipelineResources struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1alpha1.PipelineResource, *v1alpha1.PipelineResourceList] } // newPipelineResources returns a PipelineResources func newPipelineResources(c *TektonV1alpha1Client, namespace string) *pipelineResources { return &pipelineResources{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1alpha1.PipelineResource, *v1alpha1.PipelineResourceList]( + "pipelineresources", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1alpha1.PipelineResource { return &v1alpha1.PipelineResource{} }, + func() *v1alpha1.PipelineResourceList { return &v1alpha1.PipelineResourceList{} }), } } - -// Get takes name of the pipelineResource, and returns the corresponding pipelineResource object, and an error if there is any. -func (c *pipelineResources) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.PipelineResource, err error) { - result = &v1alpha1.PipelineResource{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelineresources"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of PipelineResources that match those selectors. -func (c *pipelineResources) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.PipelineResourceList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.PipelineResourceList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("pipelineresources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested pipelineResources. -func (c *pipelineResources) 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("pipelineresources"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a pipelineResource and creates it. Returns the server's representation of the pipelineResource, and an error, if there is any. -func (c *pipelineResources) Create(ctx context.Context, pipelineResource *v1alpha1.PipelineResource, opts v1.CreateOptions) (result *v1alpha1.PipelineResource, err error) { - result = &v1alpha1.PipelineResource{} - err = c.client.Post(). - Namespace(c.ns). - Resource("pipelineresources"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipelineResource). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a pipelineResource and updates it. Returns the server's representation of the pipelineResource, and an error, if there is any. -func (c *pipelineResources) Update(ctx context.Context, pipelineResource *v1alpha1.PipelineResource, opts v1.UpdateOptions) (result *v1alpha1.PipelineResource, err error) { - result = &v1alpha1.PipelineResource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("pipelineresources"). - Name(pipelineResource.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(pipelineResource). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the pipelineResource and deletes it. Returns an error if one occurs. -func (c *pipelineResources) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("pipelineresources"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *pipelineResources) 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("pipelineresources"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched pipelineResource. -func (c *pipelineResources) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.PipelineResource, err error) { - result = &v1alpha1.PipelineResource{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("pipelineresources"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/resource/informers/externalversions/factory.go b/pkg/client/resource/informers/externalversions/factory.go index f03f0976e5e..80a30e9567d 100644 --- a/pkg/client/resource/informers/externalversions/factory.go +++ b/pkg/client/resource/informers/externalversions/factory.go @@ -228,6 +228,7 @@ type SharedInformerFactory interface { // Start initializes all requested informers. They are handled in goroutines // which run until the stop channel gets closed. + // Warning: Start does not block. When run in a go-routine, it will race with a later WaitForCacheSync. Start(stopCh <-chan struct{}) // Shutdown marks a factory as shutting down. At that point no new diff --git a/pkg/client/resource/listers/resource/v1alpha1/pipelineresource.go b/pkg/client/resource/listers/resource/v1alpha1/pipelineresource.go index 9d698cb9431..91c54fd829f 100644 --- a/pkg/client/resource/listers/resource/v1alpha1/pipelineresource.go +++ b/pkg/client/resource/listers/resource/v1alpha1/pipelineresource.go @@ -20,8 +20,8 @@ package v1alpha1 import ( v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" ) @@ -38,25 +38,17 @@ type PipelineResourceLister interface { // pipelineResourceLister implements the PipelineResourceLister interface. type pipelineResourceLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1alpha1.PipelineResource] } // NewPipelineResourceLister returns a new PipelineResourceLister. func NewPipelineResourceLister(indexer cache.Indexer) PipelineResourceLister { - return &pipelineResourceLister{indexer: indexer} -} - -// List lists all PipelineResources in the indexer. -func (s *pipelineResourceLister) List(selector labels.Selector) (ret []*v1alpha1.PipelineResource, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.PipelineResource)) - }) - return ret, err + return &pipelineResourceLister{listers.New[*v1alpha1.PipelineResource](indexer, v1alpha1.Resource("pipelineresource"))} } // PipelineResources returns an object that can list and get PipelineResources. func (s *pipelineResourceLister) PipelineResources(namespace string) PipelineResourceNamespaceLister { - return pipelineResourceNamespaceLister{indexer: s.indexer, namespace: namespace} + return pipelineResourceNamespaceLister{listers.NewNamespaced[*v1alpha1.PipelineResource](s.ResourceIndexer, namespace)} } // PipelineResourceNamespaceLister helps list and get PipelineResources. @@ -74,26 +66,5 @@ type PipelineResourceNamespaceLister interface { // pipelineResourceNamespaceLister implements the PipelineResourceNamespaceLister // interface. type pipelineResourceNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all PipelineResources in the indexer for a given namespace. -func (s pipelineResourceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.PipelineResource, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.PipelineResource)) - }) - return ret, err -} - -// Get retrieves the PipelineResource from the indexer for a given namespace and name. -func (s pipelineResourceNamespaceLister) Get(name string) (*v1alpha1.PipelineResource, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("pipelineresource"), name) - } - return obj.(*v1alpha1.PipelineResource), nil + listers.ResourceIndexer[*v1alpha1.PipelineResource] }