Skip to content

Commit

Permalink
Add v1 support for taskrun and pipelinerun cancel
Browse files Browse the repository at this point in the history
This patch adds v1 support for taskrun and pipelinerun
cancel command and also does few refactoring

Part of: tektoncd#1804

Signed-off-by: Shiv Verma <[email protected]>
  • Loading branch information
pratap0007 committed Feb 23, 2023
1 parent 923f2d2 commit 4ba61f4
Show file tree
Hide file tree
Showing 6 changed files with 1,079 additions and 167 deletions.
19 changes: 13 additions & 6 deletions pkg/actions/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,31 @@ package actions

import (
"context"
"fmt"
"os"

"github.com/tektoncd/cli/pkg/cli"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
)

// Patch takes a partial resource, an object name in the cluster, and patch data to be applied to that object, and patches the object using the dynamic client.
func Patch(gr schema.GroupVersionResource, clients *cli.Clients, objName string, data []byte, opt metav1.PatchOptions, ns string) (*unstructured.Unstructured, error) {
func Patch(gr schema.GroupVersionResource, clients *cli.Clients, objName string, data []byte, opt metav1.PatchOptions, ns string, obj interface{}) error {
gvr, err := GetGroupVersionResource(gr, clients.Tekton.Discovery())
if err != nil {
return nil, err
return err
}
patchedObj, err := clients.Dynamic.Resource(*gvr).Namespace(ns).Patch(context.Background(), objName, types.JSONPatchType, data, opt)
unstructuredObj, err := clients.Dynamic.Resource(*gvr).Namespace(ns).Patch(context.Background(), objName, types.JSONPatchType, data, opt)
if err != nil {
return nil, err
fmt.Fprintf(os.Stderr, "Failed to patch object from %s namespace \n", ns)
return err
}

return patchedObj, nil
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredObj.UnstructuredContent(), obj); err != nil {
return err
}

return nil
}
Loading

0 comments on commit 4ba61f4

Please sign in to comment.