Skip to content

Commit

Permalink
put back community tasks as openshift addonsn
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhelil committed Nov 27, 2024
1 parent 5951f64 commit 538fe90
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spec:
value: "true"
- name: resolverStepActions
value: "true"
- name: communityClusterTasks
value: "true"
params:
- name: createRbacResource
value: "true"
Expand Down
87 changes: 87 additions & 0 deletions pkg/reconciler/openshift/tektonaddon/community_tasks.go
Original file line number Diff line number Diff line change
@@ -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 tektonaddon

import (
"context"
"strings"

mf "github.com/manifestival/manifestival"
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
"github.com/tektoncd/operator/pkg/reconciler/common"
"github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset/client"
)

var communityResourceURLs = []string{
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/jib-maven/0.5/jib-maven.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/helm-upgrade-from-source/0.3/helm-upgrade-from-source.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/helm-upgrade-from-repo/0.2/helm-upgrade-from-repo.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/trigger-jenkins-job/0.1/trigger-jenkins-job.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/pull-request/0.1/pull-request.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/master/task/kubeconfig-creator/0.1/kubeconfig-creator.yaml",
"https://raw.githubusercontent.com/tektoncd/catalog/main/task/argocd-task-sync-and-wait/0.2/argocd-task-sync-and-wait.yaml",
}

func (r *Reconciler) EnsureCommunityTask(ctx context.Context, enable string, ta *v1alpha1.TektonAddon) error {
if len(r.communityTaskManifest.Resources()) == 0 {
return nil
}
manifest := *r.communityTaskManifest
if enable == "true" {
if err := r.installerSetClient.CustomSet(ctx, ta, CommunityTaskInstallerSet, &manifest, filterAndTransformCommunityTask(), nil); err != nil {
return err
}
} else {
if err := r.installerSetClient.CleanupCustomSet(ctx, CommunityTaskInstallerSet); err != nil {
return err
}
}
return nil
}

func filterAndTransformCommunityTask() client.FilterAndTransform {
return func(ctx context.Context, manifest *mf.Manifest, comp v1alpha1.TektonComponent) (*mf.Manifest, error) {
instance := comp.(*v1alpha1.TektonAddon)
addonImages := common.ToLowerCaseKeys(common.ImagesFromEnv(common.AddonsImagePrefix))

extra := []mf.Transformer{
injectLabel(labelProviderType, providerTypeCommunity, overwrite, "Task"),
common.TaskImages(ctx, addonImages),
}
if err := common.Transform(ctx, manifest, instance, extra...); err != nil {
return nil, err
}
return manifest, nil
}
}

func appendCommunityTasks(manifest *mf.Manifest) error {
urls := strings.Join(communityResourceURLs, ",")
m, err := mf.ManifestFrom(mf.Path(urls))
if err != nil {
return err
}
*manifest = manifest.Append(m)
return nil
}

func fetchCommunityTasks(manifest *mf.Manifest) error {
if err := appendCommunityTasks(manifest); err != nil {
return err
}
return nil
}
1 change: 1 addition & 0 deletions pkg/reconciler/openshift/tektonaddon/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
OpenShiftConsoleInstallerSet = "OpenShiftConsole"
VersionedResolverTaskInstallerSet = "VersionedResolverTask"
VersionedResolverStepActionInstallerSet = "VersionedResolverStepAction"
CommunityTaskInstallerSet = "CommunityTask"
versionedClusterTaskPatchChar = "0"
PipelinesTemplateInstallerSet = "PipelinesTemplate"
TriggersResourcesInstallerSet = "TriggersResources"
Expand Down
7 changes: 7 additions & 0 deletions pkg/reconciler/openshift/tektonaddon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro
logger.Fatalf("failed to read console cli from kodata: %v", err)
}

communityTaskManifest := &mf.Manifest{}
if err := fetchCommunityTasks(communityTaskManifest); err != nil {
// if unable to fetch community task, don't fail
logger.Errorf("failed to read community task: %v", err)
}

c := &Reconciler{
crdClientSet: crdClient,
installerSetClient: client.NewInstallerSetClient(tisClient, version, "addon", v1alpha1.KindTektonAddon, metrics),
Expand All @@ -129,6 +135,7 @@ func NewExtendedController(generator common.ExtensionGenerator) injection.Contro
pipelineTemplateManifest: pipelineTemplateManifest,
openShiftConsoleManifest: openShiftConsoleManifest,
consoleCLIManifest: consoleCLIManifest,
communityTaskManifest: communityTaskManifest,
}
impl := tektonAddonreconciler.NewImpl(ctx, c)

Expand Down
9 changes: 9 additions & 0 deletions pkg/reconciler/openshift/tektonaddon/tektonaddon.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Reconciler struct {
pipelineTemplateManifest *mf.Manifest
openShiftConsoleManifest *mf.Manifest
consoleCLIManifest *mf.Manifest
communityTaskManifest *mf.Manifest
}

const (
Expand All @@ -64,6 +65,7 @@ const (
providerTypeRedHat = "redhat"
installerSetNameForResolverTasks = "addon-versioned-resolvertasks"
installerSetNameForResolverStepAction = "addon-versioned-resolverstepactions"
providerTypeCommunity = "community"
)

// Check that our Reconciler implements controller.Reconciler
Expand Down Expand Up @@ -131,6 +133,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon
ptVal, _ := findValue(ta.Spec.Params, v1alpha1.PipelineTemplatesParam)
rtVal, _ := findValue(ta.Spec.Params, v1alpha1.ResolverTasks)
rsaVal, _ := findValue(ta.Spec.Params, v1alpha1.ResolverStepActions)
ctVal, _ := findValue(ta.Spec.Params, v1alpha1.CommunityClusterTasks)

if ptVal == "true" && rtVal == "false" {
ta.Status.MarkNotReady("pipelineTemplates cannot be true if ResolverTask is false")
Expand Down Expand Up @@ -203,6 +206,12 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, ta *v1alpha1.TektonAddon
}
}

if err := r.EnsureCommunityTask(ctx, ctVal, ta); err != nil {
ready = false
errorMsg = fmt.Sprintf("community tasks not yet ready: %v", err)
logger.Error(errorMsg)
}

if !ready {
ta.Status.MarkInstallerSetNotReady(errorMsg)
return nil
Expand Down
1 change: 1 addition & 0 deletions test/resources/tektonaddons.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func AssertTektonInstallerSets(t *testing.T, clients *utils.Clients) {
assertInstallerSets(t, clients, tektonaddon.TriggersResourcesInstallerSet)
assertInstallerSets(t, clients, tektonaddon.ConsoleCLIInstallerSet)
assertInstallerSets(t, clients, tektonaddon.MiscellaneousResourcesInstallerSet)
assertInstallerSets(t, clients, tektonaddon.CommunityTaskInstallerSet)
}

func assertInstallerSets(t *testing.T, clients *utils.Clients, component string) {
Expand Down

0 comments on commit 538fe90

Please sign in to comment.