diff --git a/config/300-resolutionrequest.yaml b/config/300-resolutionrequest.yaml index 3d58caac07a..b520d8adac4 100644 --- a/config/300-resolutionrequest.yaml +++ b/config/300-resolutionrequest.yaml @@ -55,3 +55,26 @@ spec: - name: Reason type: string jsonPath: ".status.conditions[?(@.type=='Succeeded')].reason" + - name: v1beta1 + served: false + storage: false + subresources: + status: {} + schema: + openAPIV3Schema: + type: object + # One can use x-kubernetes-preserve-unknown-fields: true + # at the root of the schema (and inside any properties, additionalProperties) + # to get the traditional CRD behaviour that nothing is pruned, despite + # setting spec.preserveUnknownProperties: false. + # + # See https://kubernetes.io/blog/2019/06/20/crd-structural-schema/ + # See issue: https://github.com/knative/serving/issues/912 + x-kubernetes-preserve-unknown-fields: true + additionalPrinterColumns: + - name: Succeeded + type: string + jsonPath: ".status.conditions[?(@.type=='Succeeded')].status" + - name: Reason + type: string + jsonPath: ".status.conditions[?(@.type=='Succeeded')].reason" diff --git a/docs/pipeline-api.md b/docs/pipeline-api.md index 0ea7c4abaf1..ee55692e4bf 100644 --- a/docs/pipeline-api.md +++ b/docs/pipeline-api.md @@ -12,6 +12,9 @@ weight: 1000 resolution.tekton.dev/v1alpha1
  • +resolution.tekton.dev/v1beta1 +
  • +
  • tekton.dev/v1
  • @@ -221,6 +224,210 @@ object.


    +

    resolution.tekton.dev/v1beta1

    +
    +
    +Resource Types: + +

    ResolutionRequest +

    +
    +

    ResolutionRequest is an object for requesting the content of +a Tekton resource like a pipeline.yaml.

    +
    + + + + + + + + + + + + + + + + + + + + + +
    FieldDescription
    +metadata
    + + +Kubernetes meta/v1.ObjectMeta + + +
    +(Optional) +Refer to the Kubernetes API documentation for the fields of the +metadata field. +
    +spec
    + + +ResolutionRequestSpec + + +
    +(Optional) +

    Spec holds the information for the request part of the resource request.

    +
    +
    + + + + + +
    +params
    + + +[]Param + + +
    +(Optional) +

    Parameters are the runtime attributes passed to +the resolver to help it figure out how to resolve the +resource being requested. For example: repo URL, commit SHA, +path to file, the kind of authentication to leverage, etc.

    +
    +
    +status
    + + +ResolutionRequestStatus + + +
    +(Optional) +

    Status communicates the state of the request and, ultimately, +the content of the resolved resource.

    +
    +

    ResolutionRequestSpec +

    +

    +(Appears on:ResolutionRequest) +

    +
    +

    ResolutionRequestSpec are all the fields in the spec of the +ResolutionRequest CRD.

    +
    + + + + + + + + + + + + + +
    FieldDescription
    +params
    + + +[]Param + + +
    +(Optional) +

    Parameters are the runtime attributes passed to +the resolver to help it figure out how to resolve the +resource being requested. For example: repo URL, commit SHA, +path to file, the kind of authentication to leverage, etc.

    +
    +

    ResolutionRequestStatus +

    +

    +(Appears on:ResolutionRequest) +

    +
    +

    ResolutionRequestStatus are all the fields in a ResolutionRequest’s +status subresource.

    +
    + + + + + + + + + + + + + + + + + +
    FieldDescription
    +Status
    + + +knative.dev/pkg/apis/duck/v1.Status + + +
    +

    +(Members of Status are embedded into this type.) +

    +
    +ResolutionRequestStatusFields
    + + +ResolutionRequestStatusFields + + +
    +

    +(Members of ResolutionRequestStatusFields are embedded into this type.) +

    +
    +

    ResolutionRequestStatusFields +

    +

    +(Appears on:ResolutionRequestStatus) +

    +
    +

    ResolutionRequestStatusFields are the ResolutionRequest-specific fields +for the status subresource.

    +
    + + + + + + + + + + + + + +
    FieldDescription
    +data
    + +string + +
    +

    Data is a string representation of the resolved content +of the requested resource in-lined into the ResolutionRequest +object.

    +
    +

    tekton.dev/v1

    Package v1 contains API Schema definitions for the pipeline v1 API group

    @@ -8205,7 +8412,7 @@ The names of the params in the Matrix must match the n

    Param

    -(Appears on:RunSpec, CustomRunSpec, Matrix, PipelineRunSpec, PipelineTask, ResolverRef, TaskRunInputs, TaskRunSpec) +(Appears on:RunSpec, CustomRunSpec, Matrix, PipelineRunSpec, PipelineTask, ResolverRef, TaskRunInputs, TaskRunSpec, ResolutionRequestSpec)

    Param declares an ParamValues to use for the parameter called name.

    diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 4ded6bd4579..52fd3bd8d81 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -48,7 +48,7 @@ bash ${REPO_ROOT_DIR}/hack/generate-groups.sh "deepcopy,client,informer,lister" # This generates deepcopy,client,informer and lister for the resolution package (v1alpha1) 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" \ + "resolution:v1alpha1,v1beta1" \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt # Depends on generate-groups.sh to install bin/deepcopy-gen @@ -93,7 +93,7 @@ GOFLAGS="${OLDGOFLAGS}" # This generates the knative inject packages for the resolution package (v1alpha1). bash ${REPO_ROOT_DIR}/hack/generate-knative.sh "injection" \ github.com/tektoncd/pipeline/pkg/client/resolution github.com/tektoncd/pipeline/pkg/apis \ - "resolution:v1alpha1" \ + "resolution:v1alpha1,v1beta1" \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt GOFLAGS="${OLDGOFLAGS}" diff --git a/pkg/apis/resolution/v1alpha1/resolution_request_conversion.go b/pkg/apis/resolution/v1alpha1/resolution_request_conversion.go new file mode 100644 index 00000000000..25a5b98ec60 --- /dev/null +++ b/pkg/apis/resolution/v1alpha1/resolution_request_conversion.go @@ -0,0 +1,95 @@ +/* + Copyright 2022 The Tekton Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +package v1alpha1 + +import ( + "context" + "fmt" + "strings" + + pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" + "knative.dev/pkg/apis" +) + +var _ apis.Convertible = (*ResolutionRequest)(nil) + +// ConvertTo implements apis.Convertible +func (rr *ResolutionRequest) ConvertTo(ctx context.Context, sink apis.Convertible) error { + if apis.IsInDelete(ctx) { + return nil + } + switch sink := sink.(type) { + case *v1beta1.ResolutionRequest: + sink.ObjectMeta = rr.ObjectMeta + return rr.Spec.ConvertTo(ctx, &sink.Spec) + default: + return fmt.Errorf("unknown version, got: %T", sink) + } +} + +// ConvertTo converts a v1alpha1.ResolutionRequestSpec to a v1beta1.ResolutionRequestSpec +func (rrs *ResolutionRequestSpec) ConvertTo(ctx context.Context, sink *v1beta1.ResolutionRequestSpec) error { + for k, v := range rrs.Parameters { + sink.Params = append(sink.Params, pipelinev1beta1.Param{ + Name: k, + Value: pipelinev1beta1.ParamValue{ + Type: pipelinev1beta1.ParamTypeString, + StringVal: v, + }, + }) + } + + return nil +} + +// ConvertFrom implements apis.Convertible +func (rr *ResolutionRequest) ConvertFrom(ctx context.Context, from apis.Convertible) error { + if apis.IsInDelete(ctx) { + return nil + } + switch from := from.(type) { + case *v1beta1.ResolutionRequest: + rr.ObjectMeta = from.ObjectMeta + return rr.Spec.ConvertFrom(ctx, &from.Spec) + default: + return fmt.Errorf("unknown version, got: %T", from) + } +} + +// ConvertFrom converts a v1beta1.ResolutionRequestSpec to a v1alpha1.ResolutionRequestSpec +func (rrs *ResolutionRequestSpec) ConvertFrom(ctx context.Context, from *v1beta1.ResolutionRequestSpec) error { + var nonStringParams []string + + for _, p := range from.Params { + if p.Value.Type != pipelinev1beta1.ParamTypeString { + nonStringParams = append(nonStringParams, p.Name) + } else { + if rrs.Parameters == nil { + rrs.Parameters = make(map[string]string) + } + rrs.Parameters[p.Name] = p.Value.StringVal + } + } + + if len(nonStringParams) > 0 { + return fmt.Errorf("cannot convert v1beta1 to v1alpha, non-string type parameter(s) found: %s", strings.Join(nonStringParams, ", ")) + } + + return nil +} diff --git a/pkg/apis/resolution/v1alpha1/resolution_request_conversion_test.go b/pkg/apis/resolution/v1alpha1/resolution_request_conversion_test.go new file mode 100644 index 00000000000..773073464c3 --- /dev/null +++ b/pkg/apis/resolution/v1alpha1/resolution_request_conversion_test.go @@ -0,0 +1,223 @@ +/* + Copyright 2022 The Tekton Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +package v1alpha1 + +import ( + "context" + "errors" + "testing" + + "github.com/google/go-cmp/cmp" + pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" + "github.com/tektoncd/pipeline/test/diff" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "knative.dev/pkg/apis" +) + +func TestResolutionRequestConversionBadType(t *testing.T) { + good, bad := &ResolutionRequest{}, &pipelinev1beta1.Task{} + + if err := good.ConvertTo(context.Background(), bad); err == nil { + t.Errorf("ConvertTo() = %#v, wanted error", bad) + } + + if err := good.ConvertFrom(context.Background(), bad); err == nil { + t.Errorf("ConvertFrom() = %#v, wanted error", good) + } +} + +func TestResolutionRequestConvertTo(t *testing.T) { + versions := []apis.Convertible{&v1beta1.ResolutionRequest{}} + + testCases := []struct { + name string + in *ResolutionRequest + out apis.Convertible + }{ + { + name: "no params", + in: &ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: ResolutionRequestSpec{ + Parameters: nil, + }, + }, + out: &v1beta1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1beta1.ResolutionRequestSpec{ + Params: nil, + }, + }, + }, { + name: "with params", + in: &ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: ResolutionRequestSpec{ + Parameters: map[string]string{ + "some-param": "some-value", + }, + }, + }, + out: &v1beta1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1beta1.ResolutionRequestSpec{ + Params: []pipelinev1beta1.Param{{ + Name: "some-param", + Value: *pipelinev1beta1.NewStructuredValues("some-value"), + }}, + }, + }, + }, + } + + for _, tc := range testCases { + for _, version := range versions { + t.Run(tc.name, func(t *testing.T) { + got := version + if err := tc.in.ConvertTo(context.Background(), got); err != nil { + t.Fatalf("ConvertTo() = %v", err) + } + t.Logf("ConvertTo() = %#v", got) + if d := cmp.Diff(tc.out, got); d != "" { + t.Errorf("converted ResolutionRequest did not match expected: %s", diff.PrintWantGot(d)) + } + }) + } + } +} + +func TestResolutionRequestConvertFrom(t *testing.T) { + versions := []apis.Convertible{&ResolutionRequest{}} + + testCases := []struct { + name string + in apis.Convertible + out *ResolutionRequest + expectedErr error + }{ + { + name: "no params", + in: &v1beta1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1beta1.ResolutionRequestSpec{ + Params: nil, + }, + }, + out: &ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: ResolutionRequestSpec{ + Parameters: nil, + }, + }, + }, { + name: "with only string params", + in: &v1beta1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1beta1.ResolutionRequestSpec{ + Params: []pipelinev1beta1.Param{{ + Name: "some-param", + Value: *pipelinev1beta1.NewStructuredValues("some-value"), + }}, + }, + }, + out: &ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: ResolutionRequestSpec{ + Parameters: map[string]string{ + "some-param": "some-value", + }, + }, + }, + }, { + name: "with non-string params", + in: &v1beta1.ResolutionRequest{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo", + Namespace: "bar", + }, + Spec: v1beta1.ResolutionRequestSpec{ + Params: []pipelinev1beta1.Param{ + { + Name: "array-val", + Value: *pipelinev1beta1.NewStructuredValues("one", "two"), + }, { + Name: "string-val", + Value: *pipelinev1beta1.NewStructuredValues("a-string"), + }, { + Name: "object-val", + Value: *pipelinev1beta1.NewObject(map[string]string{ + "key-one": "value-one", + "key-two": "value-two", + }), + }, + }, + }, + }, + out: nil, + expectedErr: errors.New("cannot convert v1beta1 to v1alpha, non-string type parameter(s) found: array-val, object-val"), + }, + } + + for _, tc := range testCases { + for _, version := range versions { + t.Run(tc.name, func(t *testing.T) { + got := version + err := got.ConvertFrom(context.Background(), tc.in) + if tc.expectedErr != nil { + if err == nil { + t.Fatalf("expected error '%s', but did not get an error", tc.expectedErr.Error()) + } else if d := cmp.Diff(tc.expectedErr.Error(), err.Error()); d != "" { + t.Fatalf("error did not meet expected: %s", diff.PrintWantGot(d)) + } + return + } else if err != nil { + t.Fatalf("ConvertFrom() = %v", err) + } + t.Logf("ConvertFrom() = %#v", got) + if d := cmp.Diff(tc.out, got); d != "" { + t.Errorf("converted ResolutionRequest did not match expected: %s", diff.PrintWantGot(d)) + } + }) + } + } +} diff --git a/pkg/apis/resolution/v1beta1/doc.go b/pkg/apis/resolution/v1beta1/doc.go new file mode 100644 index 00000000000..b47a2951b3a --- /dev/null +++ b/pkg/apis/resolution/v1beta1/doc.go @@ -0,0 +1,21 @@ +/* +Copyright 2022 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package,register +// +k8s:defaulter-gen=TypeMeta +// +groupName=resolution.tekton.dev +package v1beta1 diff --git a/pkg/apis/resolution/v1beta1/register.go b/pkg/apis/resolution/v1beta1/register.go new file mode 100644 index 00000000000..61eee0858df --- /dev/null +++ b/pkg/apis/resolution/v1beta1/register.go @@ -0,0 +1,54 @@ +/* +Copyright 2022 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + "github.com/tektoncd/pipeline/pkg/apis/resolution" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: resolution.GroupName, Version: "v1beta1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // SchemeBuilder builds a scheme with the types known to the package. + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + // AddToScheme adds the types known to this package to an existing schema. + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &ResolutionRequest{}, + &ResolutionRequestList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/resolution/v1beta1/resolution_request_conversion.go b/pkg/apis/resolution/v1beta1/resolution_request_conversion.go new file mode 100644 index 00000000000..16f57ac2168 --- /dev/null +++ b/pkg/apis/resolution/v1beta1/resolution_request_conversion.go @@ -0,0 +1,43 @@ +/* + Copyright 2022 The Tekton Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +package v1beta1 + +import ( + "context" + "fmt" + + "knative.dev/pkg/apis" +) + +var _ apis.Convertible = (*ResolutionRequest)(nil) + +// ConvertTo implements apis.Convertible +func (rr *ResolutionRequest) ConvertTo(ctx context.Context, sink apis.Convertible) error { + if apis.IsInDelete(ctx) { + return nil + } + return fmt.Errorf("v1beta1 is the highest known version, got: %T", sink) +} + +// ConvertFrom implements apis.Convertible +func (rr *ResolutionRequest) ConvertFrom(ctx context.Context, source apis.Convertible) error { + if apis.IsInDelete(ctx) { + return nil + } + return fmt.Errorf("v1beta1 is the highest known version, got: %T", source) +} diff --git a/pkg/apis/resolution/v1beta1/resolution_request_conversion_test.go b/pkg/apis/resolution/v1beta1/resolution_request_conversion_test.go new file mode 100644 index 00000000000..44b77f51c21 --- /dev/null +++ b/pkg/apis/resolution/v1beta1/resolution_request_conversion_test.go @@ -0,0 +1,37 @@ +/* + Copyright 2022 The Tekton Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +package v1beta1 + +import ( + "context" + "testing" + + pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" +) + +func TestResolutionRequestConversionBadType(t *testing.T) { + good, bad := &ResolutionRequest{}, &pipelinev1beta1.Task{} + + if err := good.ConvertTo(context.Background(), bad); err == nil { + t.Errorf("ConvertTo() = %#v, wanted error", bad) + } + + if err := good.ConvertFrom(context.Background(), bad); err == nil { + t.Errorf("ConvertFrom() = %#v, wanted error", good) + } +} diff --git a/pkg/apis/resolution/v1beta1/resolution_request_defaults.go b/pkg/apis/resolution/v1beta1/resolution_request_defaults.go new file mode 100644 index 00000000000..2d0a2453cad --- /dev/null +++ b/pkg/apis/resolution/v1beta1/resolution_request_defaults.go @@ -0,0 +1,33 @@ +/* +Copyright 2022 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import "context" + +// ManagedByLabelKey is the label key used to mark what is managing this resource +const ManagedByLabelKey = "app.kubernetes.io/managed-by" + +// SetDefaults walks a ResolutionRequest object and sets any default +// values that are required to be set before a reconciler sees it. +func (rr *ResolutionRequest) SetDefaults(ctx context.Context) { + if rr.TypeMeta.Kind == "" { + rr.TypeMeta.Kind = "ResolutionRequest" + } + if rr.TypeMeta.APIVersion == "" { + rr.TypeMeta.APIVersion = "resolution.tekton.dev/v1alpha1" + } +} diff --git a/pkg/apis/resolution/v1beta1/resolution_request_lifecycle.go b/pkg/apis/resolution/v1beta1/resolution_request_lifecycle.go new file mode 100644 index 00000000000..4cf709ea5e4 --- /dev/null +++ b/pkg/apis/resolution/v1beta1/resolution_request_lifecycle.go @@ -0,0 +1,71 @@ +/* +Copyright 2022 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + resolutioncommon "github.com/tektoncd/pipeline/pkg/resolution/common" + "k8s.io/apimachinery/pkg/runtime/schema" + "knative.dev/pkg/apis" +) + +// ResolutionRequests only have apis.ConditionSucceeded for now. +var resolutionRequestCondSet = apis.NewBatchConditionSet() + +// GetGroupVersionKind implements kmeta.OwnerRefable. +func (*ResolutionRequest) GetGroupVersionKind() schema.GroupVersionKind { + return SchemeGroupVersion.WithKind("ResolutionRequest") +} + +// GetConditionSet implements KRShaped. +func (*ResolutionRequest) GetConditionSet() apis.ConditionSet { + return resolutionRequestCondSet +} + +// HasStarted returns whether a ResolutionRequests Status is considered to +// be in-progress. +func (rr *ResolutionRequest) HasStarted() bool { + return rr.Status.GetCondition(apis.ConditionSucceeded).IsUnknown() +} + +// IsDone returns whether a ResolutionRequests Status is considered to be +// in a completed state, independent of success/failure. +func (rr *ResolutionRequest) IsDone() bool { + finalStateIsUnknown := rr.Status.GetCondition(apis.ConditionSucceeded).IsUnknown() + return !finalStateIsUnknown +} + +// InitializeConditions set ths initial values of the conditions. +func (s *ResolutionRequestStatus) InitializeConditions() { + resolutionRequestCondSet.Manage(s).InitializeConditions() +} + +// MarkFailed sets the Succeeded condition to False with an accompanying +// error message. +func (s *ResolutionRequestStatus) MarkFailed(reason, message string) { + resolutionRequestCondSet.Manage(s).MarkFalse(apis.ConditionSucceeded, reason, message) +} + +// MarkSucceeded sets the Succeeded condition to True. +func (s *ResolutionRequestStatus) MarkSucceeded() { + resolutionRequestCondSet.Manage(s).MarkTrue(apis.ConditionSucceeded) +} + +// MarkInProgress updates the Succeeded condition to Unknown with an +// accompanying message. +func (s *ResolutionRequestStatus) MarkInProgress(message string) { + resolutionRequestCondSet.Manage(s).MarkUnknown(apis.ConditionSucceeded, resolutioncommon.ReasonResolutionInProgress, message) +} diff --git a/pkg/apis/resolution/v1beta1/resolution_request_types.go b/pkg/apis/resolution/v1beta1/resolution_request_types.go new file mode 100644 index 00000000000..2fc33139308 --- /dev/null +++ b/pkg/apis/resolution/v1beta1/resolution_request_types.go @@ -0,0 +1,87 @@ +/* +Copyright 2022 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ResolutionRequest is an object for requesting the content of +// a Tekton resource like a pipeline.yaml. +// +// +genclient +// +genreconciler +type ResolutionRequest struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec holds the information for the request part of the resource request. + // +optional + Spec ResolutionRequestSpec `json:"spec,omitempty"` + + // Status communicates the state of the request and, ultimately, + // the content of the resolved resource. + // +optional + Status ResolutionRequestStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ResolutionRequestList is a list of ResolutionRequests. +type ResolutionRequestList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata"` + Items []ResolutionRequest `json:"items"` +} + +// ResolutionRequestSpec are all the fields in the spec of the +// ResolutionRequest CRD. +type ResolutionRequestSpec struct { + // Parameters are the runtime attributes passed to + // the resolver to help it figure out how to resolve the + // resource being requested. For example: repo URL, commit SHA, + // path to file, the kind of authentication to leverage, etc. + // +optional + Params []pipelinev1beta1.Param `json:"params,omitempty"` +} + +// ResolutionRequestStatus are all the fields in a ResolutionRequest's +// status subresource. +type ResolutionRequestStatus struct { + duckv1.Status `json:",inline"` + ResolutionRequestStatusFields `json:",inline"` +} + +// ResolutionRequestStatusFields are the ResolutionRequest-specific fields +// for the status subresource. +type ResolutionRequestStatusFields struct { + // Data is a string representation of the resolved content + // of the requested resource in-lined into the ResolutionRequest + // object. + Data string `json:"data"` +} + +// GetStatus implements KRShaped. +func (rr *ResolutionRequest) GetStatus() *duckv1.Status { + return &rr.Status.Status +} diff --git a/pkg/apis/resolution/v1beta1/resolution_request_validation.go b/pkg/apis/resolution/v1beta1/resolution_request_validation.go new file mode 100644 index 00000000000..a9b1a72744c --- /dev/null +++ b/pkg/apis/resolution/v1beta1/resolution_request_validation.go @@ -0,0 +1,51 @@ +/* +Copyright 2022 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1beta1 + +import ( + "context" + + "github.com/tektoncd/pipeline/pkg/resolution/common" + "knative.dev/pkg/apis" +) + +// Validate checks that a submitted ResolutionRequest is structurally +// sound before the controller receives it. +func (rr *ResolutionRequest) Validate(ctx context.Context) (errs *apis.FieldError) { + errs = errs.Also(validateTypeLabel(rr)) + return errs.Also(rr.Spec.Validate(ctx).ViaField("spec")) +} + +// Validate checks the the spec field of a ResolutionRequest is valid. +func (rs *ResolutionRequestSpec) Validate(ctx context.Context) (errs *apis.FieldError) { + return nil +} + +func validateTypeLabel(rr *ResolutionRequest) *apis.FieldError { + typeLabel := getTypeLabel(rr.ObjectMeta.Labels) + if typeLabel == "" { + return apis.ErrMissingField(common.LabelKeyResolverType).ViaField("labels").ViaField("meta") + } + return nil +} + +func getTypeLabel(labels map[string]string) string { + if labels == nil { + return "" + } + return labels[common.LabelKeyResolverType] +} diff --git a/pkg/apis/resolution/v1beta1/zz_generated.deepcopy.go b/pkg/apis/resolution/v1beta1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..50a75e80beb --- /dev/null +++ b/pkg/apis/resolution/v1beta1/zz_generated.deepcopy.go @@ -0,0 +1,145 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1beta1 + +import ( + pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResolutionRequest) DeepCopyInto(out *ResolutionRequest) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResolutionRequest. +func (in *ResolutionRequest) DeepCopy() *ResolutionRequest { + if in == nil { + return nil + } + out := new(ResolutionRequest) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ResolutionRequest) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResolutionRequestList) DeepCopyInto(out *ResolutionRequestList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ResolutionRequest, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResolutionRequestList. +func (in *ResolutionRequestList) DeepCopy() *ResolutionRequestList { + if in == nil { + return nil + } + out := new(ResolutionRequestList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ResolutionRequestList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResolutionRequestSpec) DeepCopyInto(out *ResolutionRequestSpec) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = make([]pipelinev1beta1.Param, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResolutionRequestSpec. +func (in *ResolutionRequestSpec) DeepCopy() *ResolutionRequestSpec { + if in == nil { + return nil + } + out := new(ResolutionRequestSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResolutionRequestStatus) DeepCopyInto(out *ResolutionRequestStatus) { + *out = *in + in.Status.DeepCopyInto(&out.Status) + out.ResolutionRequestStatusFields = in.ResolutionRequestStatusFields + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResolutionRequestStatus. +func (in *ResolutionRequestStatus) DeepCopy() *ResolutionRequestStatus { + if in == nil { + return nil + } + out := new(ResolutionRequestStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ResolutionRequestStatusFields) DeepCopyInto(out *ResolutionRequestStatusFields) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResolutionRequestStatusFields. +func (in *ResolutionRequestStatusFields) DeepCopy() *ResolutionRequestStatusFields { + if in == nil { + return nil + } + out := new(ResolutionRequestStatusFields) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/client/resolution/clientset/versioned/clientset.go b/pkg/client/resolution/clientset/versioned/clientset.go index b71b9b1e9e0..df12dfc026b 100644 --- a/pkg/client/resolution/clientset/versioned/clientset.go +++ b/pkg/client/resolution/clientset/versioned/clientset.go @@ -23,6 +23,7 @@ import ( "net/http" resolutionv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1" + resolutionv1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -31,6 +32,7 @@ import ( type Interface interface { Discovery() discovery.DiscoveryInterface ResolutionV1alpha1() resolutionv1alpha1.ResolutionV1alpha1Interface + ResolutionV1beta1() resolutionv1beta1.ResolutionV1beta1Interface } // Clientset contains the clients for groups. Each group has exactly one @@ -38,6 +40,7 @@ type Interface interface { type Clientset struct { *discovery.DiscoveryClient resolutionV1alpha1 *resolutionv1alpha1.ResolutionV1alpha1Client + resolutionV1beta1 *resolutionv1beta1.ResolutionV1beta1Client } // ResolutionV1alpha1 retrieves the ResolutionV1alpha1Client @@ -45,6 +48,11 @@ func (c *Clientset) ResolutionV1alpha1() resolutionv1alpha1.ResolutionV1alpha1In return c.resolutionV1alpha1 } +// ResolutionV1beta1 retrieves the ResolutionV1beta1Client +func (c *Clientset) ResolutionV1beta1() resolutionv1beta1.ResolutionV1beta1Interface { + return c.resolutionV1beta1 +} + // Discovery retrieves the DiscoveryClient func (c *Clientset) Discovery() discovery.DiscoveryInterface { if c == nil { @@ -93,6 +101,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, if err != nil { return nil, err } + cs.resolutionV1beta1, err = resolutionv1beta1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) if err != nil { @@ -115,6 +127,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { func New(c rest.Interface) *Clientset { var cs Clientset cs.resolutionV1alpha1 = resolutionv1alpha1.New(c) + cs.resolutionV1beta1 = resolutionv1beta1.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) return &cs diff --git a/pkg/client/resolution/clientset/versioned/fake/clientset_generated.go b/pkg/client/resolution/clientset/versioned/fake/clientset_generated.go index 8717312d332..b8bae4b809d 100644 --- a/pkg/client/resolution/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/resolution/clientset/versioned/fake/clientset_generated.go @@ -22,6 +22,8 @@ import ( clientset "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned" resolutionv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1" fakeresolutionv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1/fake" + resolutionv1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1" + fakeresolutionv1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/discovery" @@ -83,3 +85,8 @@ var ( func (c *Clientset) ResolutionV1alpha1() resolutionv1alpha1.ResolutionV1alpha1Interface { return &fakeresolutionv1alpha1.FakeResolutionV1alpha1{Fake: &c.Fake} } + +// ResolutionV1beta1 retrieves the ResolutionV1beta1Client +func (c *Clientset) ResolutionV1beta1() resolutionv1beta1.ResolutionV1beta1Interface { + return &fakeresolutionv1beta1.FakeResolutionV1beta1{Fake: &c.Fake} +} diff --git a/pkg/client/resolution/clientset/versioned/fake/register.go b/pkg/client/resolution/clientset/versioned/fake/register.go index 3768dbbd30a..70d792b35d6 100644 --- a/pkg/client/resolution/clientset/versioned/fake/register.go +++ b/pkg/client/resolution/clientset/versioned/fake/register.go @@ -20,6 +20,7 @@ package fake import ( resolutionv1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1" + resolutionv1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -32,6 +33,7 @@ var codecs = serializer.NewCodecFactory(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ resolutionv1alpha1.AddToScheme, + resolutionv1beta1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/client/resolution/clientset/versioned/scheme/register.go b/pkg/client/resolution/clientset/versioned/scheme/register.go index 5f7b6278f67..9fe0d86a62e 100644 --- a/pkg/client/resolution/clientset/versioned/scheme/register.go +++ b/pkg/client/resolution/clientset/versioned/scheme/register.go @@ -20,6 +20,7 @@ package scheme import ( resolutionv1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1" + resolutionv1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -32,6 +33,7 @@ var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ resolutionv1alpha1.AddToScheme, + resolutionv1beta1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/doc.go b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/doc.go new file mode 100644 index 00000000000..acfb8c0b67d --- /dev/null +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1beta1 diff --git a/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/doc.go b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/doc.go new file mode 100644 index 00000000000..1a72e0befe2 --- /dev/null +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/fake_resolution_client.go b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/fake_resolution_client.go new file mode 100644 index 00000000000..fbe98e38802 --- /dev/null +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/fake_resolution_client.go @@ -0,0 +1,40 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeResolutionV1beta1 struct { + *testing.Fake +} + +func (c *FakeResolutionV1beta1) ResolutionRequests(namespace string) v1beta1.ResolutionRequestInterface { + return &FakeResolutionRequests{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeResolutionV1beta1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} 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 new file mode 100644 index 00000000000..29f0cb2a9d6 --- /dev/null +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/fake/fake_resolutionrequest.go @@ -0,0 +1,142 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeResolutionRequests implements ResolutionRequestInterface +type FakeResolutionRequests struct { + Fake *FakeResolutionV1beta1 + ns string +} + +var resolutionrequestsResource = schema.GroupVersionResource{Group: "resolution.tekton.dev", Version: "v1beta1", Resource: "resolutionrequests"} + +var resolutionrequestsKind = schema.GroupVersionKind{Group: "resolution.tekton.dev", Version: "v1beta1", Kind: "ResolutionRequest"} + +// 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) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(resolutionrequestsResource, c.ns, name), &v1beta1.ResolutionRequest{}) + + if obj == nil { + return nil, 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) { + obj, err := c.Fake. + Invokes(testing.NewListAction(resolutionrequestsResource, resolutionrequestsKind, c.ns, opts), &v1beta1.ResolutionRequestList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.ResolutionRequestList{ListMeta: obj.(*v1beta1.ResolutionRequestList).ListMeta} + for _, item := range obj.(*v1beta1.ResolutionRequestList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested resolutionRequests. +func (c *FakeResolutionRequests) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(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) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(resolutionrequestsResource, c.ns, resolutionRequest), &v1beta1.ResolutionRequest{}) + + if obj == nil { + return nil, 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) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(resolutionrequestsResource, c.ns, resolutionRequest), &v1beta1.ResolutionRequest{}) + + if obj == nil { + return nil, 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) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(resolutionrequestsResource, "status", c.ns, resolutionRequest), &v1beta1.ResolutionRequest{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ResolutionRequest), err +} + +// Delete takes name of the resolutionRequest and deletes it. Returns an error if one occurs. +func (c *FakeResolutionRequests) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(resolutionrequestsResource, c.ns, name, opts), &v1beta1.ResolutionRequest{}) + + return err +} + +// 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) + + _, err := c.Fake.Invokes(action, &v1beta1.ResolutionRequestList{}) + return err +} + +// 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) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(resolutionrequestsResource, c.ns, name, pt, data, subresources...), &v1beta1.ResolutionRequest{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.ResolutionRequest), err +} diff --git a/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/generated_expansion.go b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/generated_expansion.go new file mode 100644 index 00000000000..85d49c121a5 --- /dev/null +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/generated_expansion.go @@ -0,0 +1,21 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +type ResolutionRequestExpansion interface{} diff --git a/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/resolution_client.go b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/resolution_client.go new file mode 100644 index 00000000000..8d13b836c0f --- /dev/null +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/resolution_client.go @@ -0,0 +1,107 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "net/http" + + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" + "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" +) + +type ResolutionV1beta1Interface interface { + RESTClient() rest.Interface + ResolutionRequestsGetter +} + +// ResolutionV1beta1Client is used to interact with features provided by the resolution.tekton.dev group. +type ResolutionV1beta1Client struct { + restClient rest.Interface +} + +func (c *ResolutionV1beta1Client) ResolutionRequests(namespace string) ResolutionRequestInterface { + return newResolutionRequests(c, namespace) +} + +// NewForConfig creates a new ResolutionV1beta1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ResolutionV1beta1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new ResolutionV1beta1Client for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ResolutionV1beta1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &ResolutionV1beta1Client{client}, nil +} + +// NewForConfigOrDie creates a new ResolutionV1beta1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ResolutionV1beta1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new ResolutionV1beta1Client for the given RESTClient. +func New(c rest.Interface) *ResolutionV1beta1Client { + return &ResolutionV1beta1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1beta1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ResolutionV1beta1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/resolutionrequest.go b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/resolutionrequest.go new file mode 100644 index 00000000000..e09ca18da6b --- /dev/null +++ b/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1/resolutionrequest.go @@ -0,0 +1,195 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +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" +) + +// ResolutionRequestsGetter has a method to return a ResolutionRequestInterface. +// A group's client should implement this interface. +type ResolutionRequestsGetter interface { + ResolutionRequests(namespace string) ResolutionRequestInterface +} + +// ResolutionRequestInterface has methods to work with ResolutionRequest resources. +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) + 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 + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.ResolutionRequest, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.ResolutionRequestList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ResolutionRequest, err error) + ResolutionRequestExpansion +} + +// resolutionRequests implements ResolutionRequestInterface +type resolutionRequests struct { + client rest.Interface + ns string +} + +// newResolutionRequests returns a ResolutionRequests +func newResolutionRequests(c *ResolutionV1beta1Client, namespace string) *resolutionRequests { + return &resolutionRequests{ + client: c.RESTClient(), + ns: namespace, + } +} + +// 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/generic.go b/pkg/client/resolution/informers/externalversions/generic.go index 5868bb3df3c..a6c63df2d48 100644 --- a/pkg/client/resolution/informers/externalversions/generic.go +++ b/pkg/client/resolution/informers/externalversions/generic.go @@ -22,6 +22,7 @@ import ( "fmt" v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1" + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" ) @@ -56,6 +57,10 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case v1alpha1.SchemeGroupVersion.WithResource("resolutionrequests"): return &genericInformer{resource: resource.GroupResource(), informer: f.Resolution().V1alpha1().ResolutionRequests().Informer()}, nil + // Group=resolution.tekton.dev, Version=v1beta1 + case v1beta1.SchemeGroupVersion.WithResource("resolutionrequests"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Resolution().V1beta1().ResolutionRequests().Informer()}, nil + } return nil, fmt.Errorf("no informer found for %v", resource) diff --git a/pkg/client/resolution/informers/externalversions/resolution/interface.go b/pkg/client/resolution/informers/externalversions/resolution/interface.go index 006bf60e89e..413b9292f99 100644 --- a/pkg/client/resolution/informers/externalversions/resolution/interface.go +++ b/pkg/client/resolution/informers/externalversions/resolution/interface.go @@ -21,12 +21,15 @@ package resolution import ( internalinterfaces "github.com/tektoncd/pipeline/pkg/client/resolution/informers/externalversions/internalinterfaces" v1alpha1 "github.com/tektoncd/pipeline/pkg/client/resolution/informers/externalversions/resolution/v1alpha1" + v1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/informers/externalversions/resolution/v1beta1" ) // Interface provides access to each of this group's versions. type Interface 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 } type group struct { @@ -44,3 +47,8 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList func (g *group) V1alpha1() v1alpha1.Interface { return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) } + +// V1beta1 returns a new v1beta1.Interface. +func (g *group) V1beta1() v1beta1.Interface { + return v1beta1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/resolution/informers/externalversions/resolution/v1beta1/interface.go b/pkg/client/resolution/informers/externalversions/resolution/v1beta1/interface.go new file mode 100644 index 00000000000..de6bf33c018 --- /dev/null +++ b/pkg/client/resolution/informers/externalversions/resolution/v1beta1/interface.go @@ -0,0 +1,45 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + internalinterfaces "github.com/tektoncd/pipeline/pkg/client/resolution/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // ResolutionRequests returns a ResolutionRequestInformer. + ResolutionRequests() ResolutionRequestInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// ResolutionRequests returns a ResolutionRequestInformer. +func (v *version) ResolutionRequests() ResolutionRequestInformer { + return &resolutionRequestInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/resolution/informers/externalversions/resolution/v1beta1/resolutionrequest.go b/pkg/client/resolution/informers/externalversions/resolution/v1beta1/resolutionrequest.go new file mode 100644 index 00000000000..ed770102c7e --- /dev/null +++ b/pkg/client/resolution/informers/externalversions/resolution/v1beta1/resolutionrequest.go @@ -0,0 +1,90 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + time "time" + + resolutionv1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" + versioned "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned" + internalinterfaces "github.com/tektoncd/pipeline/pkg/client/resolution/informers/externalversions/internalinterfaces" + v1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/listers/resolution/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// ResolutionRequestInformer provides access to a shared informer and lister for +// ResolutionRequests. +type ResolutionRequestInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1beta1.ResolutionRequestLister +} + +type resolutionRequestInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewResolutionRequestInformer constructs a new informer for ResolutionRequest type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewResolutionRequestInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredResolutionRequestInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredResolutionRequestInformer constructs a new informer for ResolutionRequest type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredResolutionRequestInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ResolutionV1beta1().ResolutionRequests(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ResolutionV1beta1().ResolutionRequests(namespace).Watch(context.TODO(), options) + }, + }, + &resolutionv1beta1.ResolutionRequest{}, + resyncPeriod, + indexers, + ) +} + +func (f *resolutionRequestInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredResolutionRequestInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *resolutionRequestInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&resolutionv1beta1.ResolutionRequest{}, f.defaultInformer) +} + +func (f *resolutionRequestInformer) Lister() v1beta1.ResolutionRequestLister { + return v1beta1.NewResolutionRequestLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/resolution/injection/client/client.go b/pkg/client/resolution/injection/client/client.go index f57bcb12713..2b357f8253e 100644 --- a/pkg/client/resolution/injection/client/client.go +++ b/pkg/client/resolution/injection/client/client.go @@ -25,8 +25,10 @@ import ( fmt "fmt" v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1" + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" versioned "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned" typedresolutionv1alpha1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1alpha1" + typedresolutionv1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/typed/resolution/v1beta1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" runtime "k8s.io/apimachinery/pkg/runtime" @@ -241,3 +243,149 @@ func (w *wrapResolutionV1alpha1ResolutionRequestImpl) UpdateStatus(ctx context.C func (w *wrapResolutionV1alpha1ResolutionRequestImpl) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return nil, errors.New("NYI: Watch") } + +// ResolutionV1beta1 retrieves the ResolutionV1beta1Client +func (w *wrapClient) ResolutionV1beta1() typedresolutionv1beta1.ResolutionV1beta1Interface { + return &wrapResolutionV1beta1{ + dyn: w.dyn, + } +} + +type wrapResolutionV1beta1 struct { + dyn dynamic.Interface +} + +func (w *wrapResolutionV1beta1) RESTClient() rest.Interface { + panic("RESTClient called on dynamic client!") +} + +func (w *wrapResolutionV1beta1) ResolutionRequests(namespace string) typedresolutionv1beta1.ResolutionRequestInterface { + return &wrapResolutionV1beta1ResolutionRequestImpl{ + dyn: w.dyn.Resource(schema.GroupVersionResource{ + Group: "resolution.tekton.dev", + Version: "v1beta1", + Resource: "resolutionrequests", + }), + + namespace: namespace, + } +} + +type wrapResolutionV1beta1ResolutionRequestImpl struct { + dyn dynamic.NamespaceableResourceInterface + + namespace string +} + +var _ typedresolutionv1beta1.ResolutionRequestInterface = (*wrapResolutionV1beta1ResolutionRequestImpl)(nil) + +func (w *wrapResolutionV1beta1ResolutionRequestImpl) Create(ctx context.Context, in *v1beta1.ResolutionRequest, opts v1.CreateOptions) (*v1beta1.ResolutionRequest, error) { + in.SetGroupVersionKind(schema.GroupVersionKind{ + Group: "resolution.tekton.dev", + Version: "v1beta1", + Kind: "ResolutionRequest", + }) + uo := &unstructured.Unstructured{} + if err := convert(in, uo); err != nil { + return nil, err + } + uo, err := w.dyn.Namespace(w.namespace).Create(ctx, uo, opts) + if err != nil { + return nil, err + } + out := &v1beta1.ResolutionRequest{} + if err := convert(uo, out); err != nil { + return nil, err + } + return out, nil +} + +func (w *wrapResolutionV1beta1ResolutionRequestImpl) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return w.dyn.Namespace(w.namespace).Delete(ctx, name, opts) +} + +func (w *wrapResolutionV1beta1ResolutionRequestImpl) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + return w.dyn.Namespace(w.namespace).DeleteCollection(ctx, opts, listOpts) +} + +func (w *wrapResolutionV1beta1ResolutionRequestImpl) Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.ResolutionRequest, error) { + uo, err := w.dyn.Namespace(w.namespace).Get(ctx, name, opts) + if err != nil { + return nil, err + } + out := &v1beta1.ResolutionRequest{} + if err := convert(uo, out); err != nil { + return nil, err + } + return out, nil +} + +func (w *wrapResolutionV1beta1ResolutionRequestImpl) List(ctx context.Context, opts v1.ListOptions) (*v1beta1.ResolutionRequestList, error) { + uo, err := w.dyn.Namespace(w.namespace).List(ctx, opts) + if err != nil { + return nil, err + } + out := &v1beta1.ResolutionRequestList{} + if err := convert(uo, out); err != nil { + return nil, err + } + return out, nil +} + +func (w *wrapResolutionV1beta1ResolutionRequestImpl) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ResolutionRequest, err error) { + uo, err := w.dyn.Namespace(w.namespace).Patch(ctx, name, pt, data, opts) + if err != nil { + return nil, err + } + out := &v1beta1.ResolutionRequest{} + if err := convert(uo, out); err != nil { + return nil, err + } + return out, nil +} + +func (w *wrapResolutionV1beta1ResolutionRequestImpl) Update(ctx context.Context, in *v1beta1.ResolutionRequest, opts v1.UpdateOptions) (*v1beta1.ResolutionRequest, error) { + in.SetGroupVersionKind(schema.GroupVersionKind{ + Group: "resolution.tekton.dev", + Version: "v1beta1", + Kind: "ResolutionRequest", + }) + uo := &unstructured.Unstructured{} + if err := convert(in, uo); err != nil { + return nil, err + } + uo, err := w.dyn.Namespace(w.namespace).Update(ctx, uo, opts) + if err != nil { + return nil, err + } + out := &v1beta1.ResolutionRequest{} + if err := convert(uo, out); err != nil { + return nil, err + } + return out, nil +} + +func (w *wrapResolutionV1beta1ResolutionRequestImpl) UpdateStatus(ctx context.Context, in *v1beta1.ResolutionRequest, opts v1.UpdateOptions) (*v1beta1.ResolutionRequest, error) { + in.SetGroupVersionKind(schema.GroupVersionKind{ + Group: "resolution.tekton.dev", + Version: "v1beta1", + Kind: "ResolutionRequest", + }) + uo := &unstructured.Unstructured{} + if err := convert(in, uo); err != nil { + return nil, err + } + uo, err := w.dyn.Namespace(w.namespace).UpdateStatus(ctx, uo, opts) + if err != nil { + return nil, err + } + out := &v1beta1.ResolutionRequest{} + if err := convert(uo, out); err != nil { + return nil, err + } + return out, nil +} + +func (w *wrapResolutionV1beta1ResolutionRequestImpl) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return nil, errors.New("NYI: Watch") +} diff --git a/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/fake/fake.go b/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/fake/fake.go new file mode 100644 index 00000000000..96ba2567222 --- /dev/null +++ b/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/fake/fake.go @@ -0,0 +1,40 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package fake + +import ( + context "context" + + fake "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/factory/fake" + resolutionrequest "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest" + controller "knative.dev/pkg/controller" + injection "knative.dev/pkg/injection" +) + +var Get = resolutionrequest.Get + +func init() { + injection.Fake.RegisterInformer(withInformer) +} + +func withInformer(ctx context.Context) (context.Context, controller.Informer) { + f := fake.Get(ctx) + inf := f.Resolution().V1beta1().ResolutionRequests() + return context.WithValue(ctx, resolutionrequest.Key{}, inf), inf.Informer() +} diff --git a/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/filtered/fake/fake.go b/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/filtered/fake/fake.go new file mode 100644 index 00000000000..9e85496f24a --- /dev/null +++ b/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/filtered/fake/fake.go @@ -0,0 +1,52 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package fake + +import ( + context "context" + + factoryfiltered "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/factory/filtered" + filtered "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/filtered" + controller "knative.dev/pkg/controller" + injection "knative.dev/pkg/injection" + logging "knative.dev/pkg/logging" +) + +var Get = filtered.Get + +func init() { + injection.Fake.RegisterFilteredInformers(withInformer) +} + +func withInformer(ctx context.Context) (context.Context, []controller.Informer) { + untyped := ctx.Value(factoryfiltered.LabelKey{}) + if untyped == nil { + logging.FromContext(ctx).Panic( + "Unable to fetch labelkey from context.") + } + labelSelectors := untyped.([]string) + infs := []controller.Informer{} + for _, selector := range labelSelectors { + f := factoryfiltered.Get(ctx, selector) + inf := f.Resolution().V1beta1().ResolutionRequests() + ctx = context.WithValue(ctx, filtered.Key{Selector: selector}, inf) + infs = append(infs, inf.Informer()) + } + return ctx, infs +} diff --git a/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/filtered/resolutionrequest.go b/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/filtered/resolutionrequest.go new file mode 100644 index 00000000000..349589d6a16 --- /dev/null +++ b/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/filtered/resolutionrequest.go @@ -0,0 +1,136 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package filtered + +import ( + context "context" + + apisresolutionv1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" + versioned "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned" + v1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/informers/externalversions/resolution/v1beta1" + client "github.com/tektoncd/pipeline/pkg/client/resolution/injection/client" + filtered "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/factory/filtered" + resolutionv1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/listers/resolution/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + cache "k8s.io/client-go/tools/cache" + controller "knative.dev/pkg/controller" + injection "knative.dev/pkg/injection" + logging "knative.dev/pkg/logging" +) + +func init() { + injection.Default.RegisterFilteredInformers(withInformer) + injection.Dynamic.RegisterDynamicInformer(withDynamicInformer) +} + +// Key is used for associating the Informer inside the context.Context. +type Key struct { + Selector string +} + +func withInformer(ctx context.Context) (context.Context, []controller.Informer) { + untyped := ctx.Value(filtered.LabelKey{}) + if untyped == nil { + logging.FromContext(ctx).Panic( + "Unable to fetch labelkey from context.") + } + labelSelectors := untyped.([]string) + infs := []controller.Informer{} + for _, selector := range labelSelectors { + f := filtered.Get(ctx, selector) + inf := f.Resolution().V1beta1().ResolutionRequests() + ctx = context.WithValue(ctx, Key{Selector: selector}, inf) + infs = append(infs, inf.Informer()) + } + return ctx, infs +} + +func withDynamicInformer(ctx context.Context) context.Context { + untyped := ctx.Value(filtered.LabelKey{}) + if untyped == nil { + logging.FromContext(ctx).Panic( + "Unable to fetch labelkey from context.") + } + labelSelectors := untyped.([]string) + for _, selector := range labelSelectors { + inf := &wrapper{client: client.Get(ctx), selector: selector} + ctx = context.WithValue(ctx, Key{Selector: selector}, inf) + } + return ctx +} + +// Get extracts the typed informer from the context. +func Get(ctx context.Context, selector string) v1beta1.ResolutionRequestInformer { + untyped := ctx.Value(Key{Selector: selector}) + if untyped == nil { + logging.FromContext(ctx).Panicf( + "Unable to fetch github.com/tektoncd/pipeline/pkg/client/resolution/informers/externalversions/resolution/v1beta1.ResolutionRequestInformer with selector %s from context.", selector) + } + return untyped.(v1beta1.ResolutionRequestInformer) +} + +type wrapper struct { + client versioned.Interface + + namespace string + + selector string +} + +var _ v1beta1.ResolutionRequestInformer = (*wrapper)(nil) +var _ resolutionv1beta1.ResolutionRequestLister = (*wrapper)(nil) + +func (w *wrapper) Informer() cache.SharedIndexInformer { + return cache.NewSharedIndexInformer(nil, &apisresolutionv1beta1.ResolutionRequest{}, 0, nil) +} + +func (w *wrapper) Lister() resolutionv1beta1.ResolutionRequestLister { + return w +} + +func (w *wrapper) ResolutionRequests(namespace string) resolutionv1beta1.ResolutionRequestNamespaceLister { + return &wrapper{client: w.client, namespace: namespace, selector: w.selector} +} + +func (w *wrapper) List(selector labels.Selector) (ret []*apisresolutionv1beta1.ResolutionRequest, err error) { + reqs, err := labels.ParseToRequirements(w.selector) + if err != nil { + return nil, err + } + selector = selector.Add(reqs...) + lo, err := w.client.ResolutionV1beta1().ResolutionRequests(w.namespace).List(context.TODO(), v1.ListOptions{ + LabelSelector: selector.String(), + // TODO(mattmoor): Incorporate resourceVersion bounds based on staleness criteria. + }) + if err != nil { + return nil, err + } + for idx := range lo.Items { + ret = append(ret, &lo.Items[idx]) + } + return ret, nil +} + +func (w *wrapper) Get(name string) (*apisresolutionv1beta1.ResolutionRequest, error) { + // TODO(mattmoor): Check that the fetched object matches the selector. + return w.client.ResolutionV1beta1().ResolutionRequests(w.namespace).Get(context.TODO(), name, v1.GetOptions{ + // TODO(mattmoor): Incorporate resourceVersion bounds based on staleness criteria. + }) +} diff --git a/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/resolutionrequest.go b/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/resolutionrequest.go new file mode 100644 index 00000000000..0ae786c677d --- /dev/null +++ b/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest/resolutionrequest.go @@ -0,0 +1,116 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package resolutionrequest + +import ( + context "context" + + apisresolutionv1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" + versioned "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned" + v1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/informers/externalversions/resolution/v1beta1" + client "github.com/tektoncd/pipeline/pkg/client/resolution/injection/client" + factory "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/factory" + resolutionv1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/listers/resolution/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + cache "k8s.io/client-go/tools/cache" + controller "knative.dev/pkg/controller" + injection "knative.dev/pkg/injection" + logging "knative.dev/pkg/logging" +) + +func init() { + injection.Default.RegisterInformer(withInformer) + injection.Dynamic.RegisterDynamicInformer(withDynamicInformer) +} + +// Key is used for associating the Informer inside the context.Context. +type Key struct{} + +func withInformer(ctx context.Context) (context.Context, controller.Informer) { + f := factory.Get(ctx) + inf := f.Resolution().V1beta1().ResolutionRequests() + return context.WithValue(ctx, Key{}, inf), inf.Informer() +} + +func withDynamicInformer(ctx context.Context) context.Context { + inf := &wrapper{client: client.Get(ctx), resourceVersion: injection.GetResourceVersion(ctx)} + return context.WithValue(ctx, Key{}, inf) +} + +// Get extracts the typed informer from the context. +func Get(ctx context.Context) v1beta1.ResolutionRequestInformer { + untyped := ctx.Value(Key{}) + if untyped == nil { + logging.FromContext(ctx).Panic( + "Unable to fetch github.com/tektoncd/pipeline/pkg/client/resolution/informers/externalversions/resolution/v1beta1.ResolutionRequestInformer from context.") + } + return untyped.(v1beta1.ResolutionRequestInformer) +} + +type wrapper struct { + client versioned.Interface + + namespace string + + resourceVersion string +} + +var _ v1beta1.ResolutionRequestInformer = (*wrapper)(nil) +var _ resolutionv1beta1.ResolutionRequestLister = (*wrapper)(nil) + +func (w *wrapper) Informer() cache.SharedIndexInformer { + return cache.NewSharedIndexInformer(nil, &apisresolutionv1beta1.ResolutionRequest{}, 0, nil) +} + +func (w *wrapper) Lister() resolutionv1beta1.ResolutionRequestLister { + return w +} + +func (w *wrapper) ResolutionRequests(namespace string) resolutionv1beta1.ResolutionRequestNamespaceLister { + return &wrapper{client: w.client, namespace: namespace, resourceVersion: w.resourceVersion} +} + +// SetResourceVersion allows consumers to adjust the minimum resourceVersion +// used by the underlying client. It is not accessible via the standard +// lister interface, but can be accessed through a user-defined interface and +// an implementation check e.g. rvs, ok := foo.(ResourceVersionSetter) +func (w *wrapper) SetResourceVersion(resourceVersion string) { + w.resourceVersion = resourceVersion +} + +func (w *wrapper) List(selector labels.Selector) (ret []*apisresolutionv1beta1.ResolutionRequest, err error) { + lo, err := w.client.ResolutionV1beta1().ResolutionRequests(w.namespace).List(context.TODO(), v1.ListOptions{ + LabelSelector: selector.String(), + ResourceVersion: w.resourceVersion, + }) + if err != nil { + return nil, err + } + for idx := range lo.Items { + ret = append(ret, &lo.Items[idx]) + } + return ret, nil +} + +func (w *wrapper) Get(name string) (*apisresolutionv1beta1.ResolutionRequest, error) { + return w.client.ResolutionV1beta1().ResolutionRequests(w.namespace).Get(context.TODO(), name, v1.GetOptions{ + ResourceVersion: w.resourceVersion, + }) +} diff --git a/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest/controller.go b/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest/controller.go new file mode 100644 index 00000000000..c530216356e --- /dev/null +++ b/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest/controller.go @@ -0,0 +1,162 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package resolutionrequest + +import ( + context "context" + fmt "fmt" + reflect "reflect" + strings "strings" + + versionedscheme "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned/scheme" + client "github.com/tektoncd/pipeline/pkg/client/resolution/injection/client" + resolutionrequest "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest" + zap "go.uber.org/zap" + corev1 "k8s.io/api/core/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + scheme "k8s.io/client-go/kubernetes/scheme" + v1 "k8s.io/client-go/kubernetes/typed/core/v1" + record "k8s.io/client-go/tools/record" + kubeclient "knative.dev/pkg/client/injection/kube/client" + controller "knative.dev/pkg/controller" + logging "knative.dev/pkg/logging" + logkey "knative.dev/pkg/logging/logkey" + reconciler "knative.dev/pkg/reconciler" +) + +const ( + defaultControllerAgentName = "resolutionrequest-controller" + defaultFinalizerName = "resolutionrequests.resolution.tekton.dev" +) + +// NewImpl returns a controller.Impl that handles queuing and feeding work from +// the queue through an implementation of controller.Reconciler, delegating to +// the provided Interface and optional Finalizer methods. OptionsFn is used to return +// controller.ControllerOptions to be used by the internal reconciler. +func NewImpl(ctx context.Context, r Interface, optionsFns ...controller.OptionsFn) *controller.Impl { + logger := logging.FromContext(ctx) + + // Check the options function input. It should be 0 or 1. + if len(optionsFns) > 1 { + logger.Fatal("Up to one options function is supported, found: ", len(optionsFns)) + } + + resolutionrequestInformer := resolutionrequest.Get(ctx) + + lister := resolutionrequestInformer.Lister() + + var promoteFilterFunc func(obj interface{}) bool + + rec := &reconcilerImpl{ + LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ + PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + all, err := lister.List(labels.Everything()) + if err != nil { + return err + } + for _, elt := range all { + if promoteFilterFunc != nil { + if ok := promoteFilterFunc(elt); !ok { + continue + } + } + enq(bkt, types.NamespacedName{ + Namespace: elt.GetNamespace(), + Name: elt.GetName(), + }) + } + return nil + }, + }, + Client: client.Get(ctx), + Lister: lister, + reconciler: r, + finalizerName: defaultFinalizerName, + } + + ctrType := reflect.TypeOf(r).Elem() + ctrTypeName := fmt.Sprintf("%s.%s", ctrType.PkgPath(), ctrType.Name()) + ctrTypeName = strings.ReplaceAll(ctrTypeName, "/", ".") + + logger = logger.With( + zap.String(logkey.ControllerType, ctrTypeName), + zap.String(logkey.Kind, "resolution.tekton.dev.ResolutionRequest"), + ) + + impl := controller.NewContext(ctx, rec, controller.ControllerOptions{WorkQueueName: ctrTypeName, Logger: logger}) + agentName := defaultControllerAgentName + + // Pass impl to the options. Save any optional results. + for _, fn := range optionsFns { + opts := fn(impl) + if opts.ConfigStore != nil { + rec.configStore = opts.ConfigStore + } + if opts.FinalizerName != "" { + rec.finalizerName = opts.FinalizerName + } + if opts.AgentName != "" { + agentName = opts.AgentName + } + if opts.SkipStatusUpdates { + rec.skipStatusUpdates = true + } + if opts.DemoteFunc != nil { + rec.DemoteFunc = opts.DemoteFunc + } + if opts.PromoteFilterFunc != nil { + promoteFilterFunc = opts.PromoteFilterFunc + } + } + + rec.Recorder = createRecorder(ctx, agentName) + + return impl +} + +func createRecorder(ctx context.Context, agentName string) record.EventRecorder { + logger := logging.FromContext(ctx) + + recorder := controller.GetEventRecorder(ctx) + if recorder == nil { + // Create event broadcaster + logger.Debug("Creating event broadcaster") + eventBroadcaster := record.NewBroadcaster() + watches := []watch.Interface{ + eventBroadcaster.StartLogging(logger.Named("event-broadcaster").Infof), + eventBroadcaster.StartRecordingToSink( + &v1.EventSinkImpl{Interface: kubeclient.Get(ctx).CoreV1().Events("")}), + } + recorder = eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: agentName}) + go func() { + <-ctx.Done() + for _, w := range watches { + w.Stop() + } + }() + } + + return recorder +} + +func init() { + versionedscheme.AddToScheme(scheme.Scheme) +} diff --git a/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest/reconciler.go b/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest/reconciler.go new file mode 100644 index 00000000000..fb1eca9ce0c --- /dev/null +++ b/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest/reconciler.go @@ -0,0 +1,450 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package resolutionrequest + +import ( + context "context" + json "encoding/json" + fmt "fmt" + + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" + versioned "github.com/tektoncd/pipeline/pkg/client/resolution/clientset/versioned" + resolutionv1beta1 "github.com/tektoncd/pipeline/pkg/client/resolution/listers/resolution/v1beta1" + zap "go.uber.org/zap" + v1 "k8s.io/api/core/v1" + equality "k8s.io/apimachinery/pkg/api/equality" + errors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + sets "k8s.io/apimachinery/pkg/util/sets" + record "k8s.io/client-go/tools/record" + controller "knative.dev/pkg/controller" + kmp "knative.dev/pkg/kmp" + logging "knative.dev/pkg/logging" + reconciler "knative.dev/pkg/reconciler" +) + +// Interface defines the strongly typed interfaces to be implemented by a +// controller reconciling v1beta1.ResolutionRequest. +type Interface interface { + // ReconcileKind implements custom logic to reconcile v1beta1.ResolutionRequest. Any changes + // to the objects .Status or .Finalizers will be propagated to the stored + // object. It is recommended that implementors do not call any update calls + // for the Kind inside of ReconcileKind, it is the responsibility of the calling + // controller to propagate those properties. The resource passed to ReconcileKind + // will always have an empty deletion timestamp. + ReconcileKind(ctx context.Context, o *v1beta1.ResolutionRequest) reconciler.Event +} + +// Finalizer defines the strongly typed interfaces to be implemented by a +// controller finalizing v1beta1.ResolutionRequest. +type Finalizer interface { + // FinalizeKind implements custom logic to finalize v1beta1.ResolutionRequest. Any changes + // to the objects .Status or .Finalizers will be ignored. Returning a nil or + // Normal type reconciler.Event will allow the finalizer to be deleted on + // the resource. The resource passed to FinalizeKind will always have a set + // deletion timestamp. + FinalizeKind(ctx context.Context, o *v1beta1.ResolutionRequest) reconciler.Event +} + +// ReadOnlyInterface defines the strongly typed interfaces to be implemented by a +// controller reconciling v1beta1.ResolutionRequest if they want to process resources for which +// they are not the leader. +type ReadOnlyInterface interface { + // ObserveKind implements logic to observe v1beta1.ResolutionRequest. + // This method should not write to the API. + ObserveKind(ctx context.Context, o *v1beta1.ResolutionRequest) reconciler.Event +} + +type doReconcile func(ctx context.Context, o *v1beta1.ResolutionRequest) reconciler.Event + +// reconcilerImpl implements controller.Reconciler for v1beta1.ResolutionRequest resources. +type reconcilerImpl struct { + // LeaderAwareFuncs is inlined to help us implement reconciler.LeaderAware. + reconciler.LeaderAwareFuncs + + // Client is used to write back status updates. + Client versioned.Interface + + // Listers index properties about resources. + Lister resolutionv1beta1.ResolutionRequestLister + + // Recorder is an event recorder for recording Event resources to the + // Kubernetes API. + Recorder record.EventRecorder + + // configStore allows for decorating a context with config maps. + // +optional + configStore reconciler.ConfigStore + + // reconciler is the implementation of the business logic of the resource. + reconciler Interface + + // finalizerName is the name of the finalizer to reconcile. + finalizerName string + + // skipStatusUpdates configures whether or not this reconciler automatically updates + // the status of the reconciled resource. + skipStatusUpdates bool +} + +// Check that our Reconciler implements controller.Reconciler. +var _ controller.Reconciler = (*reconcilerImpl)(nil) + +// Check that our generated Reconciler is always LeaderAware. +var _ reconciler.LeaderAware = (*reconcilerImpl)(nil) + +func NewReconciler(ctx context.Context, logger *zap.SugaredLogger, client versioned.Interface, lister resolutionv1beta1.ResolutionRequestLister, recorder record.EventRecorder, r Interface, options ...controller.Options) controller.Reconciler { + // Check the options function input. It should be 0 or 1. + if len(options) > 1 { + logger.Fatal("Up to one options struct is supported, found: ", len(options)) + } + + // Fail fast when users inadvertently implement the other LeaderAware interface. + // For the typed reconcilers, Promote shouldn't take any arguments. + if _, ok := r.(reconciler.LeaderAware); ok { + logger.Fatalf("%T implements the incorrect LeaderAware interface. Promote() should not take an argument as genreconciler handles the enqueuing automatically.", r) + } + + rec := &reconcilerImpl{ + LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ + PromoteFunc: func(bkt reconciler.Bucket, enq func(reconciler.Bucket, types.NamespacedName)) error { + all, err := lister.List(labels.Everything()) + if err != nil { + return err + } + for _, elt := range all { + // TODO: Consider letting users specify a filter in options. + enq(bkt, types.NamespacedName{ + Namespace: elt.GetNamespace(), + Name: elt.GetName(), + }) + } + return nil + }, + }, + Client: client, + Lister: lister, + Recorder: recorder, + reconciler: r, + finalizerName: defaultFinalizerName, + } + + for _, opts := range options { + if opts.ConfigStore != nil { + rec.configStore = opts.ConfigStore + } + if opts.FinalizerName != "" { + rec.finalizerName = opts.FinalizerName + } + if opts.SkipStatusUpdates { + rec.skipStatusUpdates = true + } + if opts.DemoteFunc != nil { + rec.DemoteFunc = opts.DemoteFunc + } + } + + return rec +} + +// Reconcile implements controller.Reconciler +func (r *reconcilerImpl) Reconcile(ctx context.Context, key string) error { + logger := logging.FromContext(ctx) + + // Initialize the reconciler state. This will convert the namespace/name + // string into a distinct namespace and name, determine if this instance of + // the reconciler is the leader, and any additional interfaces implemented + // by the reconciler. Returns an error is the resource key is invalid. + s, err := newState(key, r) + if err != nil { + logger.Error("Invalid resource key: ", key) + return nil + } + + // If we are not the leader, and we don't implement either ReadOnly + // observer interfaces, then take a fast-path out. + if s.isNotLeaderNorObserver() { + return controller.NewSkipKey(key) + } + + // If configStore is set, attach the frozen configuration to the context. + if r.configStore != nil { + ctx = r.configStore.ToContext(ctx) + } + + // Add the recorder to context. + ctx = controller.WithEventRecorder(ctx, r.Recorder) + + // Get the resource with this namespace/name. + + getter := r.Lister.ResolutionRequests(s.namespace) + + original, err := getter.Get(s.name) + + if errors.IsNotFound(err) { + // The resource may no longer exist, in which case we stop processing and call + // the ObserveDeletion handler if appropriate. + logger.Debugf("Resource %q no longer exists", key) + if del, ok := r.reconciler.(reconciler.OnDeletionInterface); ok { + return del.ObserveDeletion(ctx, types.NamespacedName{ + Namespace: s.namespace, + Name: s.name, + }) + } + return nil + } else if err != nil { + return err + } + + // Don't modify the informers copy. + resource := original.DeepCopy() + + var reconcileEvent reconciler.Event + + name, do := s.reconcileMethodFor(resource) + // Append the target method to the logger. + logger = logger.With(zap.String("targetMethod", name)) + switch name { + case reconciler.DoReconcileKind: + // Set and update the finalizer on resource if r.reconciler + // implements Finalizer. + if resource, err = r.setFinalizerIfFinalizer(ctx, resource); err != nil { + return fmt.Errorf("failed to set finalizers: %w", err) + } + + if !r.skipStatusUpdates { + reconciler.PreProcessReconcile(ctx, resource) + } + + // Reconcile this copy of the resource and then write back any status + // updates regardless of whether the reconciliation errored out. + reconcileEvent = do(ctx, resource) + + if !r.skipStatusUpdates { + reconciler.PostProcessReconcile(ctx, resource, original) + } + + case reconciler.DoFinalizeKind: + // For finalizing reconcilers, if this resource being marked for deletion + // and reconciled cleanly (nil or normal event), remove the finalizer. + reconcileEvent = do(ctx, resource) + + if resource, err = r.clearFinalizer(ctx, resource, reconcileEvent); err != nil { + return fmt.Errorf("failed to clear finalizers: %w", err) + } + + case reconciler.DoObserveKind: + // Observe any changes to this resource, since we are not the leader. + reconcileEvent = do(ctx, resource) + + } + + // Synchronize the status. + switch { + case r.skipStatusUpdates: + // This reconciler implementation is configured to skip resource updates. + // This may mean this reconciler does not observe spec, but reconciles external changes. + case equality.Semantic.DeepEqual(original.Status, resource.Status): + // If we didn't change anything then don't call updateStatus. + // This is important because the copy we loaded from the injectionInformer's + // cache may be stale and we don't want to overwrite a prior update + // to status with this stale state. + case !s.isLeader: + // High-availability reconcilers may have many replicas watching the resource, but only + // the elected leader is expected to write modifications. + logger.Warn("Saw status changes when we aren't the leader!") + default: + if err = r.updateStatus(ctx, original, resource); err != nil { + logger.Warnw("Failed to update resource status", zap.Error(err)) + r.Recorder.Eventf(resource, v1.EventTypeWarning, "UpdateFailed", + "Failed to update status for %q: %v", resource.Name, err) + return err + } + } + + // Report the reconciler event, if any. + if reconcileEvent != nil { + var event *reconciler.ReconcilerEvent + if reconciler.EventAs(reconcileEvent, &event) { + logger.Infow("Returned an event", zap.Any("event", reconcileEvent)) + r.Recorder.Event(resource, event.EventType, event.Reason, event.Error()) + + // the event was wrapped inside an error, consider the reconciliation as failed + if _, isEvent := reconcileEvent.(*reconciler.ReconcilerEvent); !isEvent { + return reconcileEvent + } + return nil + } + + if controller.IsSkipKey(reconcileEvent) { + // This is a wrapped error, don't emit an event. + } else if ok, _ := controller.IsRequeueKey(reconcileEvent); ok { + // This is a wrapped error, don't emit an event. + } else { + logger.Errorw("Returned an error", zap.Error(reconcileEvent)) + r.Recorder.Event(resource, v1.EventTypeWarning, "InternalError", reconcileEvent.Error()) + } + return reconcileEvent + } + + return nil +} + +func (r *reconcilerImpl) updateStatus(ctx context.Context, existing *v1beta1.ResolutionRequest, desired *v1beta1.ResolutionRequest) error { + existing = existing.DeepCopy() + return reconciler.RetryUpdateConflicts(func(attempts int) (err error) { + // The first iteration tries to use the injectionInformer's state, subsequent attempts fetch the latest state via API. + if attempts > 0 { + + getter := r.Client.ResolutionV1beta1().ResolutionRequests(desired.Namespace) + + existing, err = getter.Get(ctx, desired.Name, metav1.GetOptions{}) + if err != nil { + return err + } + } + + // If there's nothing to update, just return. + if equality.Semantic.DeepEqual(existing.Status, desired.Status) { + return nil + } + + if diff, err := kmp.SafeDiff(existing.Status, desired.Status); err == nil && diff != "" { + logging.FromContext(ctx).Debug("Updating status with: ", diff) + } + + existing.Status = desired.Status + + updater := r.Client.ResolutionV1beta1().ResolutionRequests(existing.Namespace) + + _, err = updater.UpdateStatus(ctx, existing, metav1.UpdateOptions{}) + return err + }) +} + +// updateFinalizersFiltered will update the Finalizers of the resource. +// TODO: this method could be generic and sync all finalizers. For now it only +// updates defaultFinalizerName or its override. +func (r *reconcilerImpl) updateFinalizersFiltered(ctx context.Context, resource *v1beta1.ResolutionRequest) (*v1beta1.ResolutionRequest, error) { + + getter := r.Lister.ResolutionRequests(resource.Namespace) + + actual, err := getter.Get(resource.Name) + if err != nil { + return resource, err + } + + // Don't modify the informers copy. + existing := actual.DeepCopy() + + var finalizers []string + + // If there's nothing to update, just return. + existingFinalizers := sets.NewString(existing.Finalizers...) + desiredFinalizers := sets.NewString(resource.Finalizers...) + + if desiredFinalizers.Has(r.finalizerName) { + if existingFinalizers.Has(r.finalizerName) { + // Nothing to do. + return resource, nil + } + // Add the finalizer. + finalizers = append(existing.Finalizers, r.finalizerName) + } else { + if !existingFinalizers.Has(r.finalizerName) { + // Nothing to do. + return resource, nil + } + // Remove the finalizer. + existingFinalizers.Delete(r.finalizerName) + finalizers = existingFinalizers.List() + } + + mergePatch := map[string]interface{}{ + "metadata": map[string]interface{}{ + "finalizers": finalizers, + "resourceVersion": existing.ResourceVersion, + }, + } + + patch, err := json.Marshal(mergePatch) + if err != nil { + return resource, err + } + + patcher := r.Client.ResolutionV1beta1().ResolutionRequests(resource.Namespace) + + resourceName := resource.Name + updated, err := patcher.Patch(ctx, resourceName, types.MergePatchType, patch, metav1.PatchOptions{}) + if err != nil { + r.Recorder.Eventf(existing, v1.EventTypeWarning, "FinalizerUpdateFailed", + "Failed to update finalizers for %q: %v", resourceName, err) + } else { + r.Recorder.Eventf(updated, v1.EventTypeNormal, "FinalizerUpdate", + "Updated %q finalizers", resource.GetName()) + } + return updated, err +} + +func (r *reconcilerImpl) setFinalizerIfFinalizer(ctx context.Context, resource *v1beta1.ResolutionRequest) (*v1beta1.ResolutionRequest, error) { + if _, ok := r.reconciler.(Finalizer); !ok { + return resource, nil + } + + finalizers := sets.NewString(resource.Finalizers...) + + // If this resource is not being deleted, mark the finalizer. + if resource.GetDeletionTimestamp().IsZero() { + finalizers.Insert(r.finalizerName) + } + + resource.Finalizers = finalizers.List() + + // Synchronize the finalizers filtered by r.finalizerName. + return r.updateFinalizersFiltered(ctx, resource) +} + +func (r *reconcilerImpl) clearFinalizer(ctx context.Context, resource *v1beta1.ResolutionRequest, reconcileEvent reconciler.Event) (*v1beta1.ResolutionRequest, error) { + if _, ok := r.reconciler.(Finalizer); !ok { + return resource, nil + } + if resource.GetDeletionTimestamp().IsZero() { + return resource, nil + } + + finalizers := sets.NewString(resource.Finalizers...) + + if reconcileEvent != nil { + var event *reconciler.ReconcilerEvent + if reconciler.EventAs(reconcileEvent, &event) { + if event.EventType == v1.EventTypeNormal { + finalizers.Delete(r.finalizerName) + } + } + } else { + finalizers.Delete(r.finalizerName) + } + + resource.Finalizers = finalizers.List() + + // Synchronize the finalizers filtered by r.finalizerName. + return r.updateFinalizersFiltered(ctx, resource) +} diff --git a/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest/state.go b/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest/state.go new file mode 100644 index 00000000000..0a11a1da2f2 --- /dev/null +++ b/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest/state.go @@ -0,0 +1,97 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by injection-gen. DO NOT EDIT. + +package resolutionrequest + +import ( + fmt "fmt" + + v1beta1 "github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1" + types "k8s.io/apimachinery/pkg/types" + cache "k8s.io/client-go/tools/cache" + reconciler "knative.dev/pkg/reconciler" +) + +// state is used to track the state of a reconciler in a single run. +type state struct { + // key is the original reconciliation key from the queue. + key string + // namespace is the namespace split from the reconciliation key. + namespace string + // name is the name split from the reconciliation key. + name string + // reconciler is the reconciler. + reconciler Interface + // roi is the read only interface cast of the reconciler. + roi ReadOnlyInterface + // isROI (Read Only Interface) the reconciler only observes reconciliation. + isROI bool + // isLeader the instance of the reconciler is the elected leader. + isLeader bool +} + +func newState(key string, r *reconcilerImpl) (*state, error) { + // Convert the namespace/name string into a distinct namespace and name. + namespace, name, err := cache.SplitMetaNamespaceKey(key) + if err != nil { + return nil, fmt.Errorf("invalid resource key: %s", key) + } + + roi, isROI := r.reconciler.(ReadOnlyInterface) + + isLeader := r.IsLeaderFor(types.NamespacedName{ + Namespace: namespace, + Name: name, + }) + + return &state{ + key: key, + namespace: namespace, + name: name, + reconciler: r.reconciler, + roi: roi, + isROI: isROI, + isLeader: isLeader, + }, nil +} + +// isNotLeaderNorObserver checks to see if this reconciler with the current +// state is enabled to do any work or not. +// isNotLeaderNorObserver returns true when there is no work possible for the +// reconciler. +func (s *state) isNotLeaderNorObserver() bool { + if !s.isLeader && !s.isROI { + // If we are not the leader, and we don't implement the ReadOnly + // interface, then take a fast-path out. + return true + } + return false +} + +func (s *state) reconcileMethodFor(o *v1beta1.ResolutionRequest) (string, doReconcile) { + if o.GetDeletionTimestamp().IsZero() { + if s.isLeader { + return reconciler.DoReconcileKind, s.reconciler.ReconcileKind + } else if s.isROI { + return reconciler.DoObserveKind, s.roi.ObserveKind + } + } else if fin, ok := s.reconciler.(Finalizer); s.isLeader && ok { + return reconciler.DoFinalizeKind, fin.FinalizeKind + } + return "unknown", nil +} diff --git a/pkg/client/resolution/listers/resolution/v1beta1/expansion_generated.go b/pkg/client/resolution/listers/resolution/v1beta1/expansion_generated.go new file mode 100644 index 00000000000..c5e6376e758 --- /dev/null +++ b/pkg/client/resolution/listers/resolution/v1beta1/expansion_generated.go @@ -0,0 +1,27 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1beta1 + +// ResolutionRequestListerExpansion allows custom methods to be added to +// ResolutionRequestLister. +type ResolutionRequestListerExpansion interface{} + +// ResolutionRequestNamespaceListerExpansion allows custom methods to be added to +// ResolutionRequestNamespaceLister. +type ResolutionRequestNamespaceListerExpansion interface{} diff --git a/pkg/client/resolution/listers/resolution/v1beta1/resolutionrequest.go b/pkg/client/resolution/listers/resolution/v1beta1/resolutionrequest.go new file mode 100644 index 00000000000..e990684f0a3 --- /dev/null +++ b/pkg/client/resolution/listers/resolution/v1beta1/resolutionrequest.go @@ -0,0 +1,99 @@ +/* +Copyright 2020 The Tekton Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +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/tools/cache" +) + +// ResolutionRequestLister helps list ResolutionRequests. +// All objects returned here must be treated as read-only. +type ResolutionRequestLister interface { + // List lists all ResolutionRequests in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.ResolutionRequest, err error) + // ResolutionRequests returns an object that can list and get ResolutionRequests. + ResolutionRequests(namespace string) ResolutionRequestNamespaceLister + ResolutionRequestListerExpansion +} + +// resolutionRequestLister implements the ResolutionRequestLister interface. +type resolutionRequestLister struct { + indexer cache.Indexer +} + +// 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 +} + +// ResolutionRequests returns an object that can list and get ResolutionRequests. +func (s *resolutionRequestLister) ResolutionRequests(namespace string) ResolutionRequestNamespaceLister { + return resolutionRequestNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// ResolutionRequestNamespaceLister helps list and get ResolutionRequests. +// All objects returned here must be treated as read-only. +type ResolutionRequestNamespaceLister interface { + // List lists all ResolutionRequests in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.ResolutionRequest, err error) + // Get retrieves the ResolutionRequest from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1beta1.ResolutionRequest, error) + ResolutionRequestNamespaceListerExpansion +} + +// 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 +}