|
| 1 | +/* |
| 2 | +Copyright 2024 The Tekton Authors |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package tektonaddon |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "strings" |
| 22 | + |
| 23 | + mf "github.com/manifestival/manifestival" |
| 24 | + "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" |
| 25 | + "github.com/tektoncd/operator/pkg/reconciler/common" |
| 26 | + "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset/client" |
| 27 | +) |
| 28 | + |
| 29 | +var communityResourceURLs = []string{ |
| 30 | + "https://raw.githubusercontent.com/tektoncd/catalog/master/task/jib-maven/0.5/jib-maven.yaml", |
| 31 | + "https://raw.githubusercontent.com/tektoncd/catalog/master/task/helm-upgrade-from-source/0.3/helm-upgrade-from-source.yaml", |
| 32 | + "https://raw.githubusercontent.com/tektoncd/catalog/master/task/helm-upgrade-from-repo/0.2/helm-upgrade-from-repo.yaml", |
| 33 | + "https://raw.githubusercontent.com/tektoncd/catalog/master/task/trigger-jenkins-job/0.1/trigger-jenkins-job.yaml", |
| 34 | + "https://raw.githubusercontent.com/tektoncd/catalog/master/task/pull-request/0.1/pull-request.yaml", |
| 35 | + "https://raw.githubusercontent.com/tektoncd/catalog/master/task/kubeconfig-creator/0.1/kubeconfig-creator.yaml", |
| 36 | + "https://raw.githubusercontent.com/tektoncd/catalog/main/task/argocd-task-sync-and-wait/0.2/argocd-task-sync-and-wait.yaml", |
| 37 | +} |
| 38 | + |
| 39 | +func (r *Reconciler) EnsureCommunityResolverTask(ctx context.Context, enable string, ta *v1alpha1.TektonAddon) error { |
| 40 | + if len(r.communityResolverTaskManifest.Resources()) == 0 { |
| 41 | + return nil |
| 42 | + } |
| 43 | + manifest := *r.communityResolverTaskManifest |
| 44 | + if enable == "true" { |
| 45 | + if err := r.installerSetClient.CustomSet(ctx, ta, CommunityResolverTaskInstallerSet, &manifest, filterAndTransformCommunityResolverTask(), nil); err != nil { |
| 46 | + return err |
| 47 | + } |
| 48 | + } else { |
| 49 | + if err := r.installerSetClient.CleanupCustomSet(ctx, CommunityResolverTaskInstallerSet); err != nil { |
| 50 | + return err |
| 51 | + } |
| 52 | + } |
| 53 | + return nil |
| 54 | +} |
| 55 | + |
| 56 | +func filterAndTransformCommunityResolverTask() client.FilterAndTransform { |
| 57 | + return func(ctx context.Context, manifest *mf.Manifest, comp v1alpha1.TektonComponent) (*mf.Manifest, error) { |
| 58 | + instance := comp.(*v1alpha1.TektonAddon) |
| 59 | + addonImages := common.ToLowerCaseKeys(common.ImagesFromEnv(common.AddonsImagePrefix)) |
| 60 | + |
| 61 | + extra := []mf.Transformer{ |
| 62 | + injectLabel(labelProviderType, providerTypeCommunity, overwrite, "Task"), |
| 63 | + common.TaskImages(ctx, addonImages), |
| 64 | + } |
| 65 | + if err := common.Transform(ctx, manifest, instance, extra...); err != nil { |
| 66 | + return nil, err |
| 67 | + } |
| 68 | + return manifest, nil |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +func appendCommunityResolverTasks(manifest *mf.Manifest) error { |
| 73 | + urls := strings.Join(communityResourceURLs, ",") |
| 74 | + m, err := mf.ManifestFrom(mf.Path(urls)) |
| 75 | + if err != nil { |
| 76 | + return err |
| 77 | + } |
| 78 | + *manifest = manifest.Append(m) |
| 79 | + return nil |
| 80 | +} |
| 81 | + |
| 82 | +func fetchCommunityResolverTasks(manifest *mf.Manifest) error { |
| 83 | + if err := appendCommunityResolverTasks(manifest); err != nil { |
| 84 | + return err |
| 85 | + } |
| 86 | + return nil |
| 87 | +} |
0 commit comments