Skip to content

Commit

Permalink
Tekton v1: log when converting v1beta1 to v1
Browse files Browse the repository at this point in the history
To have some easily searchable stats about the usage of the deprecated
v1beta1 APIs, log a message any time we retrieve a v1beta1 Pipeline from
a pipelineRef.

Note: this is relevant only for generating PaC configs, not for the
simple build workflow. For a simple build, we never retrieve the whole
Pipeline object. We generate a PipelineRun that includes the pipelineRef
and send the PipelineRun to the cluster, Tekton figures out the rest.

Signed-off-by: Adam Cmiel <[email protected]>
  • Loading branch information
chmeliik committed Oct 27, 2023
1 parent dacde23 commit a00cc3d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions controllers/component_build_controller_pac.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ func (r *ComponentBuildReconciler) generatePaCPipelineRunConfigs(ctx context.Con
l.Audit, "true")

// Get pipeline from the bundle to be expanded to the PipelineRun
pipelineSpec, err := retrievePipelineSpec(pipelineBundle, pipelineName)
pipelineSpec, err := retrievePipelineSpec(ctx, pipelineBundle, pipelineName)
if err != nil {
r.EventRecorder.Event(component, "Warning", "ErrorGettingPipelineFromBundle", err.Error())
return nil, nil, err
Expand Down Expand Up @@ -893,13 +893,13 @@ func createWorkspaceBinding(pipelineWorkspaces []tektonapi.PipelineWorkspaceDecl
}

// retrievePipelineSpec retrieves pipeline definition with given name from the given bundle.
func retrievePipelineSpec(bundleUri, pipelineName string) (*tektonapi.PipelineSpec, error) {
func retrievePipelineSpec(ctx context.Context, bundleUri, pipelineName string) (*tektonapi.PipelineSpec, error) {
log := ctrllog.FromContext(ctx)

var obj runtime.Object
var err error
resolver := oci.NewResolver(bundleUri, authn.DefaultKeychain)

ctx := context.TODO()

if obj, _, err = resolver.Get(ctx, "pipeline", pipelineName); err != nil {
return nil, err
}
Expand All @@ -908,6 +908,7 @@ func retrievePipelineSpec(bundleUri, pipelineName string) (*tektonapi.PipelineSp

if v1beta1Pipeline, ok := obj.(tektonapi_v1beta1.PipelineObject); ok {
v1beta1PipelineSpec := v1beta1Pipeline.PipelineSpec()
log.Info("Converting from v1beta1 to v1", "PipelineName", pipelineName, "Bundle", bundleUri)
err := v1beta1PipelineSpec.ConvertTo(ctx, &pipelineSpec)
if err != nil {
return nil, fmt.Errorf("pipeline %s from bundle %s: failed to convert from v1beta1 to v1: %w", bundleUri, pipelineName, err)
Expand Down

0 comments on commit a00cc3d

Please sign in to comment.