Skip to content

Commit

Permalink
Move pr desc to v1 CRDs
Browse files Browse the repository at this point in the history
This will move pr desc to v1 CRD and remove
resources and timeouts field

Also move serviceaccountname and pipelineresults to
respective new fields

use childreferences for taskrun status and
expand params for object type too

Part of #1804
  • Loading branch information
piyush-garg authored and tekton-robot committed Mar 15, 2023
1 parent 794ea8e commit f4d092c
Show file tree
Hide file tree
Showing 64 changed files with 3,895 additions and 513 deletions.
28 changes: 14 additions & 14 deletions pkg/cmd/pipelinerun/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/tektoncd/cli/pkg/actions"
"github.com/tektoncd/cli/pkg/cli"
"github.com/tektoncd/cli/pkg/formatted"
"github.com/tektoncd/cli/pkg/pipelinerun"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
pipelinerunpkg "github.com/tektoncd/cli/pkg/pipelinerun"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -39,7 +40,7 @@ Set to 'CancelledRunFinally' if you want to cancel the current running task and
Set to 'StoppedRunFinally' if you want to cancel the remaining non-final task and directly run the finally tasks.
`

cancelStatus := ""
graceCancelStatus := ""

c := &cobra.Command{
Use: "cancel",
Expand All @@ -60,11 +61,11 @@ Set to 'StoppedRunFinally' if you want to cancel the remaining non-final task an
Err: cmd.OutOrStderr(),
}

return cancelPipelineRun(p, s, pr, cancelStatus)
return cancelPipelineRun(p, s, pr, graceCancelStatus)
},
}

c.Flags().StringVarP(&cancelStatus, "grace", "", "", graceCancelDescription)
c.Flags().StringVarP(&graceCancelStatus, "grace", "", "", graceCancelDescription)
return c
}

Expand All @@ -74,7 +75,8 @@ func cancelPipelineRun(p cli.Params, s *cli.Stream, prName string, graceCancelSt
return fmt.Errorf("failed to create tekton client")
}

pr, err := pipelinerun.Get(cs, prName, metav1.GetOptions{}, p.Namespace())
var pr *v1.PipelineRun
err = actions.GetV1(pipelineRunGroupResource, cs, prName, p.Namespace(), metav1.GetOptions{}, &pr)
if err != nil {
return fmt.Errorf("failed to find PipelineRun: %s", prName)
}
Expand All @@ -85,17 +87,15 @@ func cancelPipelineRun(p cli.Params, s *cli.Stream, prName string, graceCancelSt
}
}

// nolint: staticcheck
cancelStatus := v1beta1.PipelineRunSpecStatusCancelled

cancelStatus := v1.PipelineRunSpecStatusCancelled
switch strings.ToLower(graceCancelStatus) {
case strings.ToLower(v1beta1.PipelineRunSpecStatusCancelledRunFinally):
cancelStatus = v1beta1.PipelineRunSpecStatusCancelledRunFinally
case strings.ToLower(v1beta1.PipelineRunSpecStatusStoppedRunFinally):
cancelStatus = v1beta1.PipelineRunSpecStatusStoppedRunFinally
case strings.ToLower(v1.PipelineRunSpecStatusCancelledRunFinally):
cancelStatus = v1.PipelineRunSpecStatusCancelledRunFinally
case strings.ToLower(v1.PipelineRunSpecStatusStoppedRunFinally):
cancelStatus = v1.PipelineRunSpecStatusStoppedRunFinally
}

if _, err = pipelinerun.Cancel(cs, prName, metav1.PatchOptions{}, cancelStatus, p.Namespace()); err != nil {
if _, err = pipelinerunpkg.Cancel(cs, prName, metav1.PatchOptions{}, cancelStatus, p.Namespace()); err != nil {
return fmt.Errorf("failed to cancel PipelineRun: %s: %v", prName, err)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/pipelinerun/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/tektoncd/cli/pkg/deleter"
"github.com/tektoncd/cli/pkg/formatted"
"github.com/tektoncd/cli/pkg/options"
pr "github.com/tektoncd/cli/pkg/pipelinerun"
prsort "github.com/tektoncd/cli/pkg/pipelinerun/sort"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"go.uber.org/multierr"
Expand All @@ -46,7 +45,8 @@ func prExists(args []string, p cli.Params) ([]string, error) {
var errorList error
ns := p.Namespace()
for _, name := range args {
_, err := pr.Get(c, name, metav1.GetOptions{}, ns)
var pr *v1.PipelineRun
err := actions.GetV1(pipelineRunGroupResource, c, name, ns, metav1.GetOptions{}, &pr)
if err != nil {
errorList = multierr.Append(errorList, err)
continue
Expand Down
7 changes: 2 additions & 5 deletions pkg/cmd/pipelinerun/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (
"github.com/tektoncd/cli/pkg/formatted"
"github.com/tektoncd/cli/pkg/options"
pipelinerunpkg "github.com/tektoncd/cli/pkg/pipelinerun"
prdesc "github.com/tektoncd/cli/pkg/pipelinerun/description"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
cliopts "k8s.io/cli-runtime/pkg/genericclioptions"
)

Expand Down Expand Up @@ -110,11 +108,10 @@ or
}

if output != "" {
pipelineRunGroupResource := schema.GroupVersionResource{Group: "tekton.dev", Resource: "pipelineruns"}
return actions.PrintObject(pipelineRunGroupResource, opts.PipelineRunName, cmd.OutOrStdout(), cs.Dynamic, cs.Tekton.Discovery(), f, p.Namespace())
return actions.PrintObjectV1(pipelineRunGroupResource, opts.PipelineRunName, cmd.OutOrStdout(), cs, f, p.Namespace())
}

return prdesc.PrintPipelineRunDescription(s, opts.PipelineRunName, p)
return pipelinerunpkg.PrintPipelineRunDescription(s.Out, cs, opts.Params.Namespace(), opts.PipelineRunName, opts.Params.Time())
},
}

Expand Down
Loading

0 comments on commit f4d092c

Please sign in to comment.