Skip to content

Commit

Permalink
feat: added tkn-tasks sub-command
Browse files Browse the repository at this point in the history
This new command prints tektons tasks in form of multi-document yaml,
these tekton tasks may requird to be installed for some advanced
functionality.

Signed-off-by: Matej Vašek <mvasek@redhat.com>
  • Loading branch information
matejvasek committed Jun 26, 2024
1 parent e82dbef commit 0e8231b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Learn more about Knative at: https://knative.dev`, cfg.Name),
Commands: []*cobra.Command{
NewCompletionCmd(),
NewVersionCmd(cfg.Version),
NewTektonClusterTasksCmd(),
},
},
}
Expand Down
27 changes: 27 additions & 0 deletions cmd/tkn_tasks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"knative.dev/func/pkg/pipelines/tekton"
)

func NewTektonClusterTasksCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "tkn-tasks",
Short: "List tekton cluster tasks as multi-document yaml",
Long: `This command prints tekton tekton task embed in the func binary.
Some advanced functionality like OpenShift's Web Console build my require installation of these tasks.
Installation: func tkn-tasks | kubectl apply -f -
`,
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
_, err := fmt.Fprintln(cmd.OutOrStdout(), tekton.GetClusterTasks())
return err
},
}

return cmd
}
10 changes: 10 additions & 0 deletions pkg/pipelines/tekton/tasks.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tekton

import "strings"

func getBuildpackTask() string {
return `apiVersion: tekton.dev/v1
kind: Task
Expand Down Expand Up @@ -405,3 +407,11 @@ spec:
deploy $(params.path) "$(params.image)"
`
}

// GetClusterTasks returns multi-document yaml containing tekton tasks used by func.
func GetClusterTasks() string {
tasks := getBuildpackTask() + "\n---\n" + getS2ITask() + "\n---\n" + getDeployTask()
tasks = strings.Replace(tasks, "kind: Task", "kind: ClusterTask", -1)
tasks = strings.ReplaceAll(tasks, "apiVersion: tekton.dev/v1", "apiVersion: tekton.dev/v1beta1")
return tasks
}

0 comments on commit 0e8231b

Please sign in to comment.