github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/pkg/clients/tekton/tasks.go (about) 1 package tekton 2 3 import ( 4 "context" 5 "os/exec" 6 7 pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" 8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 9 "k8s.io/apimachinery/pkg/types" 10 crclient "sigs.k8s.io/controller-runtime/pkg/client" 11 ) 12 13 // Create a tekton task and return the task or error. 14 func (t *TektonController) CreateTask(task *pipeline.Task, ns string) (*pipeline.Task, error) { 15 return t.PipelineClient().TektonV1().Tasks(ns).Create(context.Background(), task, metav1.CreateOptions{}) 16 } 17 18 // CreateSkopeoCopyTask creates a skopeo copy task in the given namespace. 19 func (t *TektonController) CreateSkopeoCopyTask(namespace string) error { 20 _, err := exec.Command( 21 "oc", 22 "apply", 23 "-f", 24 "https://api.hub.tekton.dev/v1/resource/tekton/task/skopeo-copy/0.2/raw", 25 "-n", 26 namespace).Output() 27 28 return err 29 } 30 31 // GetTask returns the requested Task object. 32 func (t *TektonController) GetTask(name, namespace string) (*pipeline.Task, error) { 33 namespacedName := types.NamespacedName{ 34 Name: name, 35 Namespace: namespace, 36 } 37 38 task := pipeline.Task{ 39 ObjectMeta: metav1.ObjectMeta{ 40 Name: name, 41 Namespace: namespace, 42 }, 43 } 44 err := t.KubeRest().Get(context.Background(), namespacedName, &task) 45 if err != nil { 46 return nil, err 47 } 48 return &task, nil 49 } 50 51 // DeleteAllTasksInASpecificNamespace removes all Tasks from a given repository. Useful when creating a lot of resources and wanting to remove all of them. 52 func (t *TektonController) DeleteAllTasksInASpecificNamespace(namespace string) error { 53 return t.KubeRest().DeleteAllOf(context.Background(), &pipeline.Task{}, crclient.InNamespace(namespace)) 54 }