Skip to content

Commit

Permalink
Replace v1beta1.PipelineObject with *v1beta1.Pipeline in PipelineRun …
Browse files Browse the repository at this point in the history
…Reconciler

This commit replaces the v1beta1.PipelineObject interface with v1beta1.Pipeline pointer
since it is the only object that implements the interface. It gets the reconciler codebase
prepared for v1 storage swap.
  • Loading branch information
JeromeJu committed Mar 30, 2023
1 parent 40763d8 commit f93f367
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pkg/reconciler/pipelinerun/pipelinespec/pipelinespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

// GetPipeline is a function used to retrieve Pipelines.
type GetPipeline func(context.Context, string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error)
type GetPipeline func(context.Context, string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error)

// GetPipelineData will retrieve the Pipeline metadata and Spec associated with the
// provided PipelineRun. This can come from a reference Pipeline or from the PipelineRun's
Expand Down
14 changes: 7 additions & 7 deletions pkg/reconciler/pipelinerun/pipelinespec/pipelinespec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestGetPipelineSpec_Ref(t *testing.T) {
},
},
}
gt := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
return pipeline, nil, nil
}
resolvedObjectMeta, pipelineSpec, err := GetPipelineData(context.Background(), pr, gt)
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestGetPipelineSpec_Embedded(t *testing.T) {
},
},
}
gt := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
return nil, nil, errors.New("shouldn't be called")
}
resolvedObjectMeta, pipelineSpec, err := GetPipelineData(context.Background(), pr, gt)
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestGetPipelineSpec_Invalid(t *testing.T) {
Name: "mypipelinerun",
},
}
gt := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
return nil, nil, errors.New("shouldn't be called")
}
_, _, err := GetPipelineData(context.Background(), tr, gt)
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestGetPipelineData_ResolutionSuccess(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ctx := cfgtesting.SetDefaults(context.Background(), t, tc.defaults)
getPipeline := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
getPipeline := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
return &v1beta1.Pipeline{
ObjectMeta: *tc.sourceMeta.DeepCopy(),
Spec: *tc.sourceSpec.DeepCopy(),
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestGetPipelineSpec_Error(t *testing.T) {
},
},
}
gt := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
gt := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
return nil, nil, errors.New("something went wrong")
}
_, _, err := GetPipelineData(context.Background(), tr, gt)
Expand All @@ -274,7 +274,7 @@ func TestGetPipelineData_ResolutionError(t *testing.T) {
},
},
}
getPipeline := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
getPipeline := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
return nil, nil, errors.New("something went wrong")
}
ctx := context.Background()
Expand All @@ -297,7 +297,7 @@ func TestGetPipelineData_ResolvedNilPipeline(t *testing.T) {
},
},
}
getPipeline := func(ctx context.Context, n string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
getPipeline := func(ctx context.Context, n string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
return nil, nil, nil
}
ctx := context.Background()
Expand Down
20 changes: 10 additions & 10 deletions pkg/reconciler/pipelinerun/resources/pipelineref.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GetPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clien
// if the spec is already in the status, do not try to fetch it again, just use it as source of truth.
// Same for the Source field in the Status.Provenance.
if pipelineRun.Status.PipelineSpec != nil {
return func(_ context.Context, name string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
return func(_ context.Context, name string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
var configSource *v1beta1.ConfigSource
if pipelineRun.Status.Provenance != nil {
configSource = pipelineRun.Status.Provenance.ConfigSource
Expand All @@ -67,7 +67,7 @@ func GetPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clien
case cfg.FeatureFlags.EnableTektonOCIBundles && pr != nil && pr.Bundle != "":
// Return an inline function that implements GetTask by calling Resolver.Get with the specified task type and
// casting it to a PipelineObject.
return func(ctx context.Context, name string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
return func(ctx context.Context, name string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
// If there is a bundle url at all, construct an OCI resolver to fetch the pipeline.
kc, err := k8schain.New(ctx, k8s, k8schain.Options{
Namespace: namespace,
Expand All @@ -80,7 +80,7 @@ func GetPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clien
return resolvePipeline(ctx, resolver, name)
}
case pr != nil && pr.Resolver != "" && requester != nil:
return func(ctx context.Context, name string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
return func(ctx context.Context, name string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
stringReplacements, arrayReplacements, objectReplacements := paramsFromPipelineRun(ctx, pipelineRun)
for k, v := range GetContextReplacements("", pipelineRun) {
stringReplacements[k] = v
Expand All @@ -103,7 +103,7 @@ func GetPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clien
// verify the pipeline if there are matching verification policies
func GetVerifiedPipelineFunc(ctx context.Context, k8s kubernetes.Interface, tekton clientset.Interface, requester remoteresource.Requester, pipelineRun *v1beta1.PipelineRun, verificationpolicies []*v1alpha1.VerificationPolicy) rprp.GetPipeline {
get := GetPipelineFunc(ctx, k8s, tekton, requester, pipelineRun)
return func(context.Context, string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
return func(context.Context, string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
p, s, err := get(ctx, pipelineRun.Spec.PipelineRef.Name)
if err != nil {
return nil, nil, fmt.Errorf("failed to get pipeline: %w", err)
Expand Down Expand Up @@ -133,7 +133,7 @@ type LocalPipelineRefResolver struct {
// return an error if it can't find an appropriate Pipeline for any reason.
// TODO: if we want to set source for in-cluster pipeline, set it here.
// https://github.com/tektoncd/pipeline/issues/5522
func (l *LocalPipelineRefResolver) GetPipeline(ctx context.Context, name string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
func (l *LocalPipelineRefResolver) GetPipeline(ctx context.Context, name string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
// If we are going to resolve this reference locally, we need a namespace scope.
if l.Namespace == "" {
return nil, nil, fmt.Errorf("Must specify namespace to resolve reference to pipeline %s", name)
Expand All @@ -149,8 +149,8 @@ func (l *LocalPipelineRefResolver) GetPipeline(ctx context.Context, name string)
// resolvePipeline accepts an impl of remote.Resolver and attempts to
// fetch a pipeline with given name. An error is returned if the
// resolution doesn't work or the returned data isn't a valid
// v1beta1.PipelineObject.
func resolvePipeline(ctx context.Context, resolver remote.Resolver, name string) (v1beta1.PipelineObject, *v1beta1.ConfigSource, error) {
// *v1beta1.Pipeline.
func resolvePipeline(ctx context.Context, resolver remote.Resolver, name string) (*v1beta1.Pipeline, *v1beta1.ConfigSource, error) {
obj, configSource, err := resolver.Get(ctx, "pipeline", name)
if err != nil {
return nil, nil, err
Expand All @@ -163,15 +163,15 @@ func resolvePipeline(ctx context.Context, resolver remote.Resolver, name string)
}

// readRuntimeObjectAsPipeline tries to convert a generic runtime.Object
// into a v1beta1.PipelineObject type so that its meta and spec fields
// into a *v1beta1.Pipeline type so that its meta and spec fields
// can be read. v1 object will be converted to v1beta1 and returned.
// An error is returned if the given object is not a
// PipelineObject or if there is an error validating or upgrading an
// older PipelineObject into its v1beta1 equivalent.
// TODO(#5541): convert v1beta1 obj to v1 once we use v1 as the stored version
func readRuntimeObjectAsPipeline(ctx context.Context, obj runtime.Object) (v1beta1.PipelineObject, error) {
func readRuntimeObjectAsPipeline(ctx context.Context, obj runtime.Object) (*v1beta1.Pipeline, error) {
switch obj := obj.(type) {
case v1beta1.PipelineObject:
case *v1beta1.Pipeline:
return obj, nil
case *v1.Pipeline:
t := &v1beta1.Pipeline{
Expand Down
14 changes: 7 additions & 7 deletions pkg/reconciler/pipelinerun/resources/pipelineref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,43 +696,43 @@ func TestGetVerifiedPipelineFunc_VerifyError(t *testing.T) {
name: "unsigned pipeline fails verification with fail no match policy",
requester: requesterUnsigned,
verificationNoMatchPolicy: config.FailNoMatchPolicy,
expected: nil,
expected: (*v1beta1.Pipeline)(nil),
expectedErr: trustedresources.ErrResourceVerificationFailed,
}, {
name: "unsigned pipeline fails verification with warn no match policy",
requester: requesterUnsigned,
verificationNoMatchPolicy: config.WarnNoMatchPolicy,
expected: nil,
expected: (*v1beta1.Pipeline)(nil),
expectedErr: trustedresources.ErrResourceVerificationFailed,
}, {
name: "unsigned pipeline fails verification with ignore no match policy",
requester: requesterUnsigned,
verificationNoMatchPolicy: config.IgnoreNoMatchPolicy,
expected: nil,
expected: (*v1beta1.Pipeline)(nil),
expectedErr: trustedresources.ErrResourceVerificationFailed,
}, {
name: "modified pipeline fails verification with fail no match policy",
requester: requesterModified,
verificationNoMatchPolicy: config.FailNoMatchPolicy,
expected: nil,
expected: (*v1beta1.Pipeline)(nil),
expectedErr: trustedresources.ErrResourceVerificationFailed,
}, {
name: "modified pipeline fails verification with warn no match policy",
requester: requesterModified,
verificationNoMatchPolicy: config.WarnNoMatchPolicy,
expected: nil,
expected: (*v1beta1.Pipeline)(nil),
expectedErr: trustedresources.ErrResourceVerificationFailed,
}, {
name: "modified pipeline fails verification with ignore no match policy",
requester: requesterModified,
verificationNoMatchPolicy: config.IgnoreNoMatchPolicy,
expected: nil,
expected: (*v1beta1.Pipeline)(nil),
expectedErr: trustedresources.ErrResourceVerificationFailed,
}, {
name: "unmatched pipeline fails with fail no match policy",
requester: requesterUnmatched,
verificationNoMatchPolicy: config.FailNoMatchPolicy,
expected: nil,
expected: (*v1beta1.Pipeline)(nil),
expectedErr: trustedresources.ErrResourceVerificationFailed,
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/trustedresources/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func VerifyTask(ctx context.Context, taskObj v1beta1.TaskObject, k8s kubernetes.
// Return an error when no policies are found and trusted-resources-verification-no-match-policy is set to fail,
// or the resource fails to pass matched enforce verification policy
// source is from ConfigSource.URI, which will be used to match policy patterns. k8s is used to fetch secret from cluster
func VerifyPipeline(ctx context.Context, pipelineObj v1beta1.PipelineObject, k8s kubernetes.Interface, source string, verificationpolicies []*v1alpha1.VerificationPolicy) error {
func VerifyPipeline(ctx context.Context, pipelineObj *v1beta1.Pipeline, k8s kubernetes.Interface, source string, verificationpolicies []*v1alpha1.VerificationPolicy) error {
matchedPolicies, err := getMatchedPolicies(pipelineObj.PipelineMetadata().Name, source, verificationpolicies)
if err != nil {
if errors.Is(err, ErrNoMatchedPolicies) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/trustedresources/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func TestVerifyPipeline_Success(t *testing.T) {
mismatchedSource := "wrong source"
tcs := []struct {
name string
pipeline v1beta1.PipelineObject
pipeline *v1beta1.Pipeline
source string
verificationNoMatchPolicy string
}{{
Expand Down Expand Up @@ -421,7 +421,7 @@ func TestVerifyPipeline_Error(t *testing.T) {
mismatchedSource := "wrong source"
tcs := []struct {
name string
pipeline v1beta1.PipelineObject
pipeline *v1beta1.Pipeline
source string
verificationPolicy []*v1alpha1.VerificationPolicy
}{{
Expand Down

0 comments on commit f93f367

Please sign in to comment.