Skip to content

Commit

Permalink
Replace PAC images in TriggerTemplates
Browse files Browse the repository at this point in the history
Before this commit, the images in TriggerTemplates deployed by Pipelines
as Code are not substituted with images required for OperatorHub
deployment.

This commit adds a transformer that replaces images per the environment
variable `IMAGE_PAC_TRIGGERTEMPLATE_<STEP_NAME>`.
  • Loading branch information
concaf authored and tekton-robot committed Mar 14, 2022
1 parent 569c60d commit 5487942
Show file tree
Hide file tree
Showing 6 changed files with 2,638 additions and 1 deletion.
7 changes: 7 additions & 0 deletions operatorhub/openshift/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ image-substitutions:
containerName: openshift-pipelines-operator
envKeys:
- IMAGE_HUB_TEKTON_HUB_UI
- image: registry.redhat.io/openshift-pipelines/pipelines-pipelines-as-code-rhel8@
replaceLocations:
envTargets:
- deploymentName: openshift-pipelines-operator
containerName: openshift-pipelines-operator
envKeys:
- IMAGE_PAC_TRIGGERTEMPLATE_APPLY_AND_LAUNCH

# add thrid party images which are not replaced by operator
# but pulled directly by tasks here
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/common/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
PipelinesImagePrefix = "IMAGE_PIPELINES_"
TriggersImagePrefix = "IMAGE_TRIGGERS_"
AddonsImagePrefix = "IMAGE_ADDONS_"
PacImagePrefix = "IMAGE_PAC_"
ChainsImagePrefix = "IMAGE_CHAINS_"
HubImagePrefix = "IMAGE_HUB_"

Expand Down
32 changes: 31 additions & 1 deletion pkg/reconciler/openshift/tektonaddon/pipelinesascode.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"os"
"path/filepath"
"strings"

mf "github.com/manifestival/manifestival"
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
Expand Down Expand Up @@ -75,7 +76,13 @@ func (r *Reconciler) ensurePAC(ctx context.Context, ta *v1alpha1.TektonAddon) er
pacManifest = pacManifest.Filter(mf.Not(mf.ByKind("Namespace")))

// Run transformers
if err := r.addonTransform(ctx, &pacManifest, ta); err != nil {
var tfs []mf.Transformer
// don't run the transformer if no replace images are found
if triggerTemplateSteps := pacTriggerTemplateStepImages(); len(triggerTemplateSteps) > 0 {
tfs = append(tfs, replacePACTriggerTemplateImages(triggerTemplateSteps))
}

if err := r.addonTransform(ctx, &pacManifest, ta, tfs...); err != nil {
return err
}

Expand All @@ -86,3 +93,26 @@ func (r *Reconciler) ensurePAC(ctx context.Context, ta *v1alpha1.TektonAddon) er

return nil
}

// pacTriggerTemplateStepImages returns a map[string]string with key as step name and
// value as image name to be replaced with, from the env vars that start with
// IMAGE_PAC_
func pacTriggerTemplateStepImages() map[string]string {
triggerTemplateSteps := make(map[string]string)

// pacImage is a map[string]string which will have key-values like
// "triggertemplate_apply_and_launch": "registry.example.io/pac-image"
pacImages := common.ToLowerCaseKeys(common.ImagesFromEnv(common.PacImagePrefix))
for env, image := range pacImages {
prefix := "triggertemplate_"
if strings.HasPrefix(env, prefix) {
// step 3: "apply-and-launch": "registry.example.io/pac-image"
triggerTemplateSteps[
// step 2: apply_and_launch --> apply-and-launch
strings.ReplaceAll(
// step 1: triggertemplate_apply_and_launch --> apply_and_launch
strings.TrimPrefix(env, prefix), "_", "-")] = image
}
}
return triggerTemplateSteps
}
Loading

0 comments on commit 5487942

Please # to comment.