From 4e57dede58a3fa87cc6de397f1bf2e81af55b512 Mon Sep 17 00:00:00 2001 From: pratap0007 Date: Thu, 13 Apr 2023 21:13:30 +0530 Subject: [PATCH] Remove resource command As Pipelineresources have been removed in 0.46 pipeline so this patch removes resource command Closes part of: #1657 Signed-off-by: Shiv Verma --- pkg/cmd/pipelineresource/create.go | 392 -------- pkg/cmd/pipelineresource/create_test.go | 840 ------------------ pkg/cmd/pipelineresource/delete.go | 112 --- pkg/cmd/pipelineresource/delete_test.go | 182 ---- pkg/cmd/pipelineresource/describe.go | 197 ---- pkg/cmd/pipelineresource/describe_test.go | 195 ---- pkg/cmd/pipelineresource/list.go | 216 ----- pkg/cmd/pipelineresource/list_test.go | 236 ----- pkg/cmd/pipelineresource/pipelineresource.go | 45 - .../pipelineresource/pipelineresource_test.go | 31 - pkg/cmd/pipelineresource/resource_testUtil.go | 91 -- ...PipelineResourceDescribe_WithParams.golden | 10 - ...neResourceDescribe_WithSecretParams.golden | 16 - ...PipelineResourceList-All_Namespaces.golden | 7 - ...estPipelineResourceList-By_template.golden | 5 - ...ist-Empty_Pipeline_Resource_by_type.golden | 2 - ...elineResourceList-Invalid_namespace.golden | 2 - ...-Multiple_Pipeline_Resource_by_type.golden | 4 - ...rceList-Multiple_pipeline_resources.golden | 6 - ...TestPipelineResourceList-No_Headers.golden | 5 - ...st-Single_Pipeline_Resource_by_type.golden | 3 - ...sourceList-Single_pipeline_resource.golden | 3 - pkg/cmd/root.go | 2 - pkg/cmd/testdata/TestPluginList.golden | 1 - pkg/pipelineresource/sort/by_namespace.go | 48 - .../sort/by_namespace_test.go | 200 ----- pkg/pipelineresource/sort/by_type_and_name.go | 39 - .../sort/by_type_and_name_test.go | 87 -- 28 files changed, 2977 deletions(-) delete mode 100644 pkg/cmd/pipelineresource/create.go delete mode 100644 pkg/cmd/pipelineresource/create_test.go delete mode 100644 pkg/cmd/pipelineresource/delete.go delete mode 100644 pkg/cmd/pipelineresource/delete_test.go delete mode 100644 pkg/cmd/pipelineresource/describe.go delete mode 100644 pkg/cmd/pipelineresource/describe_test.go delete mode 100644 pkg/cmd/pipelineresource/list.go delete mode 100644 pkg/cmd/pipelineresource/list_test.go delete mode 100644 pkg/cmd/pipelineresource/pipelineresource.go delete mode 100644 pkg/cmd/pipelineresource/pipelineresource_test.go delete mode 100644 pkg/cmd/pipelineresource/resource_testUtil.go delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceDescribe_WithParams.golden delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceDescribe_WithSecretParams.golden delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-All_Namespaces.golden delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-By_template.golden delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Empty_Pipeline_Resource_by_type.golden delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Invalid_namespace.golden delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Multiple_Pipeline_Resource_by_type.golden delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Multiple_pipeline_resources.golden delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-No_Headers.golden delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Single_Pipeline_Resource_by_type.golden delete mode 100644 pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Single_pipeline_resource.golden delete mode 100644 pkg/pipelineresource/sort/by_namespace.go delete mode 100644 pkg/pipelineresource/sort/by_namespace_test.go delete mode 100644 pkg/pipelineresource/sort/by_type_and_name.go delete mode 100644 pkg/pipelineresource/sort/by_type_and_name_test.go diff --git a/pkg/cmd/pipelineresource/create.go b/pkg/cmd/pipelineresource/create.go deleted file mode 100644 index 8d5a66c093..0000000000 --- a/pkg/cmd/pipelineresource/create.go +++ /dev/null @@ -1,392 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "context" - "errors" - "fmt" - "os" - "sort" - - "github.com/AlecAivazis/survey/v2" - "github.com/AlecAivazis/survey/v2/terminal" - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - cliopts "k8s.io/cli-runtime/pkg/genericclioptions" -) - -type Resource struct { - Params cli.Params - stream *cli.Stream - AskOpts survey.AskOpt - PipelineResource v1alpha1.PipelineResource -} - -func createCommand(p cli.Params) *cobra.Command { - res := &Resource{Params: p, - AskOpts: func(opt *survey.AskOptions) error { - opt.Stdio = terminal.Stdio{ - In: os.Stdin, - Out: os.Stdout, - Err: os.Stderr, - } - return nil - }, - } - f := cliopts.NewPrintFlags("create") - eg := `Creates new PipelineResource as per the given input: - - tkn resource create -n namespace` - - c := &cobra.Command{ - Use: "create", - DisableFlagsInUseLine: true, - Short: "Create a pipeline resource in a namespace", - Example: eg, - SilenceUsage: true, - Annotations: map[string]string{ - "commandType": "main", - }, - - RunE: func(cmd *cobra.Command, args []string) error { - - res.stream = &cli.Stream{ - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - - return res.createInteractive() - }, - } - f.AddFlags(c) - c.Deprecated = "PipelineResource commands are deprecated, they will be removed soon as it get removed from API." - return c -} - -func (res *Resource) createInteractive() error { - res.PipelineResource.Namespace = res.Params.Namespace() - - // ask for the object meta data name, namespace - if err := res.AskMeta(); err != nil { - return err - } - - // below all the question mostly belongs to pipelineresource spec - // ask for the resource type - if err := res.askType(); err != nil { - return err - } - - resourceTypeParams := map[v1alpha1.PipelineResourceType]func() error{ - v1alpha1.PipelineResourceTypeGit: res.AskGitParams, - v1alpha1.PipelineResourceTypeStorage: res.AskStorageParams, - v1alpha1.PipelineResourceTypeImage: res.AskImageParams, - v1alpha1.PipelineResourceTypePullRequest: res.AskPullRequestParams, - } - if res.PipelineResource.Spec.Type != "" { - if err := resourceTypeParams[res.PipelineResource.Spec.Type](); err != nil { - return err - } - } - - cls, err := res.Params.Clients() - if err != nil { - return err - } - - newRes, err := cls.Resource.TektonV1alpha1().PipelineResources(res.Params.Namespace()).Create(context.Background(), &res.PipelineResource, metav1.CreateOptions{}) - if err != nil { - return err - } - - fmt.Fprintf(res.stream.Out, "New %s resource \"%s\" has been created\n", newRes.Spec.Type, newRes.Name) - return nil -} - -func (res *Resource) AskMeta() error { - var answer string - var qs = []*survey.Question{{ - Name: "resource name", - Prompt: &survey.Input{ - Message: "Enter a name for a pipeline resource :", - }, - Validate: survey.Required, - }} - - err := survey.Ask(qs, &answer, res.AskOpts) - if err != nil { - return Error(err) - } - if err := validate(answer, res.Params); err != nil { - return err - } - - res.PipelineResource.Name = answer - - return nil -} - -func (res *Resource) askType() error { - var answer string - var qs = []*survey.Question{{ - Name: "pipelineResource", - Prompt: &survey.Select{ - Message: "Select a resource type to create :", - Options: allResourceType(), - }, - }} - - err := survey.Ask(qs, &answer, res.AskOpts) - if err != nil { - return Error(err) - } - - res.PipelineResource.Spec.Type = cast(answer) - - return nil -} - -func (res *Resource) AskGitParams() error { - urlParam, err := askParam("url", res.AskOpts) - if err != nil { - return err - } - if urlParam.Name != "" { - res.PipelineResource.Spec.Params = append(res.PipelineResource.Spec.Params, urlParam) - } - - revisionParam, err := askParam("revision", res.AskOpts) - if err != nil { - return err - } - if revisionParam.Name != "" { - res.PipelineResource.Spec.Params = append(res.PipelineResource.Spec.Params, revisionParam) - } - - return nil -} - -func (res *Resource) AskStorageParams() error { - options := []string{"gcs", "build-gcs"} - - storageType, err := askToSelect("Select a storage type", options, res.AskOpts) - if err != nil { - return err - } - param := v1alpha1.ResourceParam{} - param.Name, param.Value = "type", storageType - res.PipelineResource.Spec.Params = append(res.PipelineResource.Spec.Params, param) - - switch storageType { - case "gcs": - locationParam, err := askParam("location", res.AskOpts) - if err != nil { - return err - } - if locationParam.Name != "" { - res.PipelineResource.Spec.Params = append(res.PipelineResource.Spec.Params, locationParam) - } - - dirParam, err := askParam("dir", res.AskOpts) - if err != nil { - return err - } - if dirParam.Name != "" { - res.PipelineResource.Spec.Params = append(res.PipelineResource.Spec.Params, dirParam) - } - - case "build-gcs": - locationParam, err := askParam("location", res.AskOpts) - if err != nil { - return err - } - if locationParam.Name != "" { - res.PipelineResource.Spec.Params = append(res.PipelineResource.Spec.Params, locationParam) - } - - artifactOpts := []string{"ZipArchive", "TarGzArchive", "Manifest"} - artifactType, err := askToSelect("Select an artifact type", artifactOpts, res.AskOpts) - if err != nil { - return err - } - artifactParam := v1alpha1.ResourceParam{} - artifactParam.Name, artifactParam.Value = "artifactType", artifactType - res.PipelineResource.Spec.Params = append(res.PipelineResource.Spec.Params, artifactParam) - } - - // ask secret - secret, err := askSecret("GOOGLE_APPLICATION_CREDENTIALS", res.AskOpts) - if err != nil { - return err - } - res.PipelineResource.Spec.SecretParams = append(res.PipelineResource.Spec.SecretParams, secret) - - return nil -} - -func (res *Resource) AskImageParams() error { - urlParam, err := askParam("url", res.AskOpts) - if err != nil { - return err - } - if urlParam.Name != "" { - res.PipelineResource.Spec.Params = append(res.PipelineResource.Spec.Params, urlParam) - } - - digestParam, err := askParam("digest", res.AskOpts) - if err != nil { - return err - } - if digestParam.Name != "" { - res.PipelineResource.Spec.Params = append(res.PipelineResource.Spec.Params, digestParam) - } - - return nil -} - -func (res *Resource) AskPullRequestParams() error { - urlParam, err := askParam("url", res.AskOpts) - if err != nil { - return err - } - if urlParam.Name != "" { - res.PipelineResource.Spec.Params = append(res.PipelineResource.Spec.Params, urlParam) - } - - // ask for the secrets - qsOpts := []string{"Yes", "No"} - qs := "Do you want to set secrets ?" - - ans, e := askToSelect(qs, qsOpts, res.AskOpts) - if e != nil { - return e - } - if ans == qsOpts[1] { - return nil - } - - secret, err := askSecret("githubToken", res.AskOpts) - if err != nil { - return err - } - res.PipelineResource.Spec.SecretParams = append(res.PipelineResource.Spec.SecretParams, secret) - - return nil -} - -func askParam(paramName string, askOpts survey.AskOpt) (v1alpha1.ResourceParam, error) { - var param v1alpha1.ResourceParam - var qs = []*survey.Question{{ - Name: "value", - Prompt: &survey.Input{ - Message: fmt.Sprintf("Enter a value for %s : ", paramName), - }, - }} - - err := survey.Ask(qs, ¶m, askOpts) - if err != nil { - return param, Error(err) - } - - if param.Value != "" { - param.Name = paramName - } - - return param, nil -} - -func askSecret(secret string, askOpts survey.AskOpt) (v1alpha1.SecretParam, error) { - var secrect v1alpha1.SecretParam - secrect.FieldName = secret - var qs = []*survey.Question{ - { - Name: "secretKey", - Prompt: &survey.Input{ - Message: fmt.Sprintf("Secret Key for %s :", secret), - }, - }, - { - Name: "secretName", - Prompt: &survey.Input{ - Message: fmt.Sprintf("Secret Name for %s :", secret), - }, - }, - } - - err := survey.Ask(qs, &secrect, askOpts) - if err != nil { - return secrect, Error(err) - } - - return secrect, nil -} - -func askToSelect(message string, options []string, askOpts survey.AskOpt) (string, error) { - var ans string - var qs1 = []*survey.Question{{ - Name: "params", - Prompt: &survey.Select{ - Message: message, - Options: options, - }, - }} - - err := survey.Ask(qs1, &ans, askOpts) - if err != nil { - return "", Error(err) - } - - return ans, nil -} - -func allResourceType() []string { - var resType []string - - for _, val := range v1alpha1.AllResourceTypes { - resType = append(resType, string(val)) - } - - sort.Strings(resType) - return resType -} - -func cast(answer string) v1alpha1.PipelineResourceType { - return answer -} - -func Error(err error) error { - switch err.Error() { - case "interrupt": - return errors.New("interrupt") - default: - return err - } -} - -func validate(name string, p cli.Params) error { - c, err := p.Clients() - if err != nil { - return err - } - - if _, err := c.Resource.TektonV1alpha1().PipelineResources(p.Namespace()).Get(context.Background(), name, metav1.GetOptions{}); err == nil { - return errors.New("resource already exist") - } - - return nil -} diff --git a/pkg/cmd/pipelineresource/create_test.go b/pkg/cmd/pipelineresource/create_test.go deleted file mode 100644 index 510cb42379..0000000000 --- a/pkg/cmd/pipelineresource/create_test.go +++ /dev/null @@ -1,840 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "bytes" - "context" - "errors" - "testing" - - "github.com/AlecAivazis/survey/v2/core" - "github.com/AlecAivazis/survey/v2/terminal" - goexpect "github.com/Netflix/go-expect" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/cli/pkg/test" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - pipelinetest "github.com/tektoncd/pipeline/test" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func init() { - // disable color output for all prompts to simplify testing - core.DisableColor = true -} - -func getPipelineResource() *v1alpha1.PipelineResource { - return &v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "res", - Namespace: "namespace", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - Params: []v1alpha1.ResourceParam{ - { - Name: "url", - Value: "git@github.com:tektoncd/cli.git", - }, - }, - }, - } -} - -func TestPipelineResource_resource_noName(t *testing.T) { - pres := getPipelineResource() - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{ - PipelineResources: []*v1alpha1.PipelineResource{ - pres, - }, - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "namespace", - }, - }, - }, - }) - - tests := []promptTest{ - { - procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Enter a name for a pipeline resource :"); err != nil { - return err - } - - if _, err := c.SendLine(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("Sorry, your reply was invalid: Value is required"); err != nil { - return err - } - - if _, err := c.ExpectString("Enter a name for a pipeline resource :"); err != nil { - return err - } - - if _, err := c.SendLine("res"); err != nil { - return err - } - - if _, err := c.SendLine(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - if err := c.Close(); err != nil { - return err - } - - return nil - }, - }, - } - - res := resOpts("namespace", cs) - for _, test := range tests { - t.Run("no input for name", func(t *testing.T) { - t.Skip("Skipping due of flakiness") - res.RunPromptTest(t, test) - }) - } -} - -func TestPipelineResource_resource_already_exist(t *testing.T) { - t.Skip("Skipping due of flakiness") - pres := getPipelineResource() - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{ - PipelineResources: []*v1alpha1.PipelineResource{ - pres, - }, - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "namespace", - }, - }, - }, - }) - - tests := []promptTest{ - { - procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Enter a name for a pipeline resource :"); err != nil { - return err - } - - if _, err := c.SendLine("res"); err != nil { - return err - } - - if _, err := c.SendLine(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - if err := c.Close(); err != nil { - return err - } - - return nil - }, - }, - } - - res := resOpts("namespace", cs) - for _, test := range tests { - t.Run("pre-existing-resource", func(t *testing.T) { - res.RunPromptTest(t, test) - }) - } -} - -func TestPipelineResource_allResourceType(t *testing.T) { - t.Skip("Skipping due of flakiness") - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{ - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "namespace", - }, - }, - }, - }) - - tests := []promptTest{ - { - procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Enter a name for a pipeline resource :"); err != nil { - return err - } - - if _, err := c.SendLine("res"); err != nil { - return err - } - - if _, err := c.ExpectString("Select a resource type to create :"); err != nil { - return err - } - - if _, err := c.ExpectString("git"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("image"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("pullRequest"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("storage"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("Enter a value for url :"); err != nil { - return err - } - - if _, err := c.SendLine(""); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - if err := c.Close(); err != nil { - return err - } - return nil - }, - }, - } - - res := resOpts("namespace", cs) - for _, test := range tests { - t.Run("check all type of resource", func(t *testing.T) { - res.RunPromptTest(t, test) - }) - } -} - -func TestPipelineResource_create_gitResource(t *testing.T) { - t.Skip("Skipping due of flakiness") - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{ - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "namespace", - }, - }, - }, - }) - - tests := []promptTest{ - { - procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Enter a name for a pipeline resource :"); err != nil { - return err - } - - if _, err := c.SendLine("git-res"); err != nil { - return err - } - - if _, err := c.ExpectString("Select a resource type to create :"); err != nil { - return err - } - - if _, err := c.ExpectString("git"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("Enter a value for url :"); err != nil { - return err - } - - if _, err := c.SendLine("https://github.com/pradeepitm12"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - if _, err := c.ExpectString("Enter a value for revision :"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - // check if the resource is created - res, err := cs.Resource.TektonV1alpha1().PipelineResources("namespace").Get(context.Background(), "git-res", metav1.GetOptions{}) - if err != nil { - return err - } - - if res.Name != "git-res" { - return errors.New("unexpected error") - } - - return nil - }, - }, - } - res := resOpts("namespace", cs) - for _, test := range tests { - t.Run("gitResource", func(t *testing.T) { - res.RunPromptTest(t, test) - }) - } -} - -func TestPipelineResource_create_imageResource(t *testing.T) { - t.Skip("Skipping due of flakiness") - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{ - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "namespace", - }, - }, - }, - }) - - tests := []promptTest{ - { - procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Enter a name for a pipeline resource :"); err != nil { - return err - } - - if _, err := c.SendLine("image-res"); err != nil { - return err - } - - if _, err := c.ExpectString("Select a resource type to create :"); err != nil { - return err - } - - if _, err := c.ExpectString("git"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("image"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("Enter a value for url :"); err != nil { - return err - } - - if _, err := c.SendLine("gcr.io/staging-images/kritis"); err != nil { - return err - } - - if _, err := c.ExpectString("Enter a value for digest :"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - // check if the resource is created - res, err := cs.Resource.TektonV1alpha1().PipelineResources("namespace").Get(context.Background(), "image-res", metav1.GetOptions{}) - if err != nil { - return err - } - - if res.Name != "image-res" { - return errors.New("unexpected error") - } - - return nil - }, - }, - } - res := resOpts("namespace", cs) - for _, test := range tests { - t.Run("imageResource", func(t *testing.T) { - res.RunPromptTest(t, test) - }) - } -} - -func TestPipelineResource_create_pullRequestResource(t *testing.T) { - t.Skip("Skipping due of flakiness") - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{ - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "namespace", - }, - }, - }, - }) - - tests := []promptTest{ - { - procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Enter a name for a pipeline resource :"); err != nil { - return err - } - - if _, err := c.SendLine("pullRequest-res"); err != nil { - return err - } - - if _, err := c.ExpectString("Select a resource type to create :"); err != nil { - return err - } - - if _, err := c.ExpectString("git"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("image"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("pullRequest"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("Enter a value for url :"); err != nil { - return err - } - - if _, err := c.SendLine("https://github.com/tektoncd/cli/pull/1"); err != nil { - return err - } - - if _, err := c.ExpectString("Do you want to set secrets ?"); err != nil { - return err - } - - if _, err := c.ExpectString("Yes"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("Secret Key for githubToken"); err != nil { - return err - } - - if _, err := c.SendLine("githubToken"); err != nil { - return err - } - if _, err := c.ExpectString("Secret Name for githubToken"); err != nil { - return err - } - - if _, err := c.SendLine("github-secrets"); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - // check if the resource is created - res, err := cs.Resource.TektonV1alpha1().PipelineResources("namespace").Get(context.Background(), "pullRequest-res", metav1.GetOptions{}) - if err != nil { - return err - } - - if res.Name != "pullRequest-res" { - return errors.New("unexpected error") - } - - return nil - }, - }, - } - res := resOpts("namespace", cs) - for _, test := range tests { - t.Run("pullRequestResource", func(t *testing.T) { - res.RunPromptTest(t, test) - }) - } -} - -func TestPipelineResource_create_gcsStorageResource(t *testing.T) { - t.Skip("Skipping due of flakiness") - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{ - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "namespace", - }, - }, - }, - }) - - tests := []promptTest{ - { - procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Enter a name for a pipeline resource :"); err != nil { - return err - } - - if _, err := c.SendLine("storage-res"); err != nil { - return err - } - - if _, err := c.ExpectString("Select a resource type to create :"); err != nil { - return err - } - - if _, err := c.ExpectString("git"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("image"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("pullRequest"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("storage"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("gcs"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("Enter a value for location :"); err != nil { - return err - } - - if _, err := c.SendLine("gs://some-bucket"); err != nil { - return err - } - - if _, err := c.ExpectString("Enter a value for dir :"); err != nil { - return err - } - - if _, err := c.SendLine("/home"); err != nil { - return err - } - - if _, err := c.ExpectString("Secret Key for GOOGLE_APPLICATION_CREDENTIALS :"); err != nil { - return err - } - - if _, err := c.SendLine("service_account.json"); err != nil { - return err - } - - if _, err := c.ExpectString("Secret Name for GOOGLE_APPLICATION_CREDENTIALS :"); err != nil { - return err - } - - if _, err := c.SendLine("bucket-sa"); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - // check if the resource is created - res, err := cs.Resource.TektonV1alpha1().PipelineResources("namespace").Get(context.Background(), "storage-res", metav1.GetOptions{}) - if err != nil { - return err - } - - if res.Name != "storage-res" { - return errors.New("unexpected error") - } - - return nil - }, - }, - } - res := resOpts("namespace", cs) - for _, test := range tests { - t.Run("gcsStorageResource", func(t *testing.T) { - res.RunPromptTest(t, test) - }) - } -} - -func TestPipelineResource_create_buildGCSstorageResource(t *testing.T) { - t.Skip("Skipping due of flakiness") - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{ - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "namespace", - }, - }, - }, - }) - - tests := []promptTest{ - { - procedure: func(c *goexpect.Console) error { - if _, err := c.ExpectString("Enter a name for a pipeline resource :"); err != nil { - return err - } - - if _, err := c.SendLine("storage-res"); err != nil { - return err - } - - if _, err := c.ExpectString("Select a resource type to create :"); err != nil { - return err - } - - if _, err := c.ExpectString("git"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("image"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("pullRequest"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("storage"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("gcs"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("build-gcs"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("Enter a value for location :"); err != nil { - return err - } - - if _, err := c.SendLine("gs://build-crd-tests/rules_docker-master.zip"); err != nil { - return err - } - - if _, err := c.ExpectString("Select an artifact type"); err != nil { - return err - } - - if _, err := c.ExpectString("ZipArchive"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("TarGzArchive"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyArrowDown)); err != nil { - return err - } - - if _, err := c.ExpectString("Manifest"); err != nil { - return err - } - - if _, err := c.Send(string(terminal.KeyEnter)); err != nil { - return err - } - - if _, err := c.ExpectString("Secret Key for GOOGLE_APPLICATION_CREDENTIALS :"); err != nil { - return err - } - - if _, err := c.SendLine("service_account.json"); err != nil { - return err - } - - if _, err := c.ExpectString("Secret Name for GOOGLE_APPLICATION_CREDENTIALS :"); err != nil { - return err - } - - if _, err := c.SendLine("bucket-sa"); err != nil { - return err - } - - if _, err := c.ExpectEOF(); err != nil { - return err - } - - // check if the resource is created - res, err := cs.Resource.TektonV1alpha1().PipelineResources("namespace").Get(context.Background(), "storage-res", metav1.GetOptions{}) - if err != nil { - return err - } - - if res.Name != "storage-res" { - return errors.New("unexpected error") - } - - return nil - }, - }, - } - res := resOpts("namespace", cs) - for _, test := range tests { - t.Run("buildGCSstorageResource", func(t *testing.T) { - res.RunPromptTest(t, test) - }) - } -} - -func resOpts(ns string, cs pipelinetest.Clients) *Resource { - - p := test.Params{ - Kube: cs.Kube, - Tekton: cs.Pipeline, - Resource: cs.Resource, - } - out := new(bytes.Buffer) - p.SetNamespace(ns) - resOp := Resource{ - Params: &p, - stream: &cli.Stream{Out: out, Err: out}, - } - - return &resOp -} diff --git a/pkg/cmd/pipelineresource/delete.go b/pkg/cmd/pipelineresource/delete.go deleted file mode 100644 index b6a83b3917..0000000000 --- a/pkg/cmd/pipelineresource/delete.go +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "context" - "fmt" - - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/cli/pkg/deleter" - "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/cli/pkg/options" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - cliopts "k8s.io/cli-runtime/pkg/genericclioptions" -) - -func deleteCommand(p cli.Params) *cobra.Command { - opts := &options.DeleteOptions{Resource: "pipelineresource", ForceDelete: false, DeleteAllNs: false} - f := cliopts.NewPrintFlags("delete") - eg := `Delete PipelineResources with names 'foo' and 'bar' in namespace 'quux': - - tkn resource delete foo bar -n quux - -or - - tkn res rm foo bar -n quux -` - - c := &cobra.Command{ - Use: "delete", - Aliases: []string{"rm"}, - Short: "Delete pipeline resources in a namespace", - Example: eg, - ValidArgsFunction: formatted.ParentCompletion, - Args: cobra.MinimumNArgs(0), - SilenceUsage: true, - Annotations: map[string]string{ - "commandType": "main", - }, - RunE: func(cmd *cobra.Command, args []string) error { - s := &cli.Stream{ - In: cmd.InOrStdin(), - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - - if err := opts.CheckOptions(s, args, p.Namespace()); err != nil { - return err - } - - return deleteResources(s, p, args, opts.DeleteAllNs) - }, - } - f.AddFlags(c) - c.Flags().BoolVarP(&opts.ForceDelete, "force", "f", false, "Whether to force deletion (default: false)") - c.Flags().BoolVarP(&opts.DeleteAllNs, "all", "", false, "Delete all PipelineResources in a namespace (default: false)") - c.Deprecated = "PipelineResource commands are deprecated, they will be removed soon as it get removed from API." - - return c -} - -func deleteResources(s *cli.Stream, p cli.Params, preNames []string, deleteAll bool) error { - cs, err := p.Clients() - if err != nil { - return fmt.Errorf("failed to create tekton client") - } - - d := deleter.New("PipelineResource", func(resourceName string) error { - return cs.Resource.TektonV1alpha1().PipelineResources(p.Namespace()).Delete(context.Background(), resourceName, metav1.DeleteOptions{}) - }) - if deleteAll { - preNames, err = allPipelineResourceNames(p, cs) - if err != nil { - return err - } - } - d.Delete(s, preNames) - - if !deleteAll { - d.PrintSuccesses(s) - } else if deleteAll { - if d.Errors() == nil { - fmt.Fprintf(s.Out, "All PipelineResources deleted in namespace %q\n", p.Namespace()) - } - } - return d.Errors() -} - -func allPipelineResourceNames(p cli.Params, cs *cli.Clients) ([]string, error) { - resources, err := cs.Resource.TektonV1alpha1().PipelineResources(p.Namespace()).List(context.Background(), metav1.ListOptions{}) - if err != nil { - return nil, err - } - var names []string - for _, resource := range resources.Items { - names = append(names, resource.Name) - } - return names, nil -} diff --git a/pkg/cmd/pipelineresource/delete_test.go b/pkg/cmd/pipelineresource/delete_test.go deleted file mode 100644 index d431fdfb24..0000000000 --- a/pkg/cmd/pipelineresource/delete_test.go +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "io" - "strings" - "testing" - - "github.com/tektoncd/cli/pkg/test" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - pipelinetest "github.com/tektoncd/pipeline/test" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestPipelineResourceDelete(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - seeds := make([]pipelinetest.Clients, 0) - for i := 0; i < 5; i++ { - pres := []*v1alpha1.PipelineResource{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "pre-1", - Namespace: "ns", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - Params: []v1alpha1.ResourceParam{ - { - Name: "URL", - Value: "quay.io/tekton/controller", - }, - }, - }, - }, - } - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{PipelineResources: pres, Namespaces: ns}) - seeds = append(seeds, cs) - } - - testParams := []struct { - name string - command []string - input pipelinetest.Clients - inputStream io.Reader - wantError bool - want string - }{ - { - name: "Invalid namespace", - command: []string{"rm", "pre-1", "-n", "invalid"}, - input: seeds[0], - inputStream: nil, - wantError: true, - want: "failed to delete PipelineResource \"pre-1\": pipelineresources.tekton.dev \"pre-1\" not found", - }, - { - name: "With force delete flag (shorthand)", - command: []string{"rm", "pre-1", "-n", "ns", "-f"}, - input: seeds[0], - inputStream: nil, - wantError: false, - want: "Command \"delete\" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API.\nPipelineResources deleted: \"pre-1\"\n", - }, - { - name: "With force delete flag", - command: []string{"rm", "pre-1", "-n", "ns", "--force"}, - input: seeds[1], - inputStream: nil, - wantError: false, - want: "Command \"delete\" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API.\nPipelineResources deleted: \"pre-1\"\n", - }, - { - name: "Without force delete flag, reply no", - command: []string{"rm", "pre-1", "-n", "ns"}, - input: seeds[2], - inputStream: strings.NewReader("n"), - wantError: true, - want: "canceled deleting pipelineresource(s) \"pre-1\"", - }, - { - name: "Without force delete flag, reply yes", - command: []string{"rm", "pre-1", "-n", "ns"}, - input: seeds[2], - inputStream: strings.NewReader("y"), - wantError: false, - want: "Command \"delete\" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API.\nAre you sure you want to delete pipelineresource(s) \"pre-1\" (y/n): PipelineResources deleted: \"pre-1\"\n", - }, - { - name: "Remove non existent resource", - command: []string{"rm", "nonexistent", "-n", "ns"}, - input: seeds[2], - inputStream: nil, - wantError: true, - want: "failed to delete PipelineResource \"nonexistent\": pipelineresources.tekton.dev \"nonexistent\" not found", - }, - { - name: "Remove multiple non existent resources", - command: []string{"rm", "nonexistent", "nonexistent2", "-n", "ns"}, - input: seeds[2], - inputStream: nil, - wantError: true, - want: "failed to delete PipelineResource \"nonexistent\": pipelineresources.tekton.dev \"nonexistent\" not found; failed to delete PipelineResource \"nonexistent2\": pipelineresources.tekton.dev \"nonexistent2\" not found", - }, - { - name: "Delete all with prompt", - command: []string{"delete", "--all", "-n", "ns"}, - input: seeds[3], - inputStream: strings.NewReader("y"), - wantError: false, - want: "Command \"delete\" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API.\nAre you sure you want to delete all pipelineresources in namespace \"ns\" (y/n): All PipelineResources deleted in namespace \"ns\"\n", - }, - { - name: "Delete all with -f", - command: []string{"delete", "--all", "-f", "-n", "ns"}, - input: seeds[4], - inputStream: nil, - wantError: false, - want: "Command \"delete\" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API.\nAll PipelineResources deleted in namespace \"ns\"\n", - }, - { - name: "Error from using pipelineresource name with --all", - command: []string{"delete", "pipelineresource", "--all", "-n", "ns"}, - input: seeds[4], - inputStream: nil, - wantError: true, - want: "--all flag should not have any arguments or flags specified with it", - }, - { - name: "Error from using resource delete with no names or --all", - command: []string{"delete"}, - input: seeds[4], - inputStream: nil, - wantError: true, - want: "must provide pipelineresource name(s) or use --all flag with delete", - }, - } - - for _, tp := range testParams { - t.Run(tp.name, func(t *testing.T) { - p := &test.Params{Tekton: tp.input.Pipeline, Kube: tp.input.Kube, Resource: tp.input.Resource} - pipelineResource := Command(p) - - if tp.inputStream != nil { - pipelineResource.SetIn(tp.inputStream) - } - - out, err := test.ExecuteCommand(pipelineResource, tp.command...) - if tp.wantError { - if err == nil { - t.Errorf("Error expected here") - } - test.AssertOutput(t, tp.want, err.Error()) - } else { - if err != nil { - t.Errorf("Unexpected Error") - } - test.AssertOutput(t, tp.want, out) - } - }) - } -} diff --git a/pkg/cmd/pipelineresource/describe.go b/pkg/cmd/pipelineresource/describe.go deleted file mode 100644 index c81688db43..0000000000 --- a/pkg/cmd/pipelineresource/describe.go +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "context" - "fmt" - "io" - "os" - "text/tabwriter" - "text/template" - - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/cli/pkg/options" - "github.com/tektoncd/cli/pkg/printer" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - cliopts "k8s.io/cli-runtime/pkg/genericclioptions" -) - -const templ = `{{decorate "bold" "Name"}}: {{ .PipelineResource.Name }} -{{decorate "bold" "Namespace"}}: {{ .PipelineResource.Namespace }} -{{decorate "bold" "PipelineResource Type"}}: {{ .PipelineResource.Spec.Type }} -{{- if ne .PipelineResource.Spec.Description "" }} -{{decorate "bold" "Description"}}: {{ .PipelineResource.Spec.Description }} -{{- end }} - -{{- if ne (len .PipelineResource.Spec.Params) 0 }} - -{{decorate "underline bold" "Params\n"}} - NAME VALUE -{{- range $i, $p := .PipelineResource.Spec.Params }} - {{decorate "bullet" $p.Name }} {{ $p.Value }} -{{- end }} -{{- end }} - -{{- if ne (len .PipelineResource.Spec.SecretParams) 0 }} - -{{decorate "underline bold" "Secret Params\n"}} - FIELDNAME SECRETNAME -{{- range $i, $p := .PipelineResource.Spec.SecretParams }} - {{decorate "bullet" $p.FieldName }} {{ $p.SecretName }} -{{- end }} -{{- end }} -` - -func describeCommand(p cli.Params) *cobra.Command { - opts := &options.DescribeOptions{Params: p} - f := cliopts.NewPrintFlags("describe") - eg := `Describe a PipelineResource of name 'foo' in namespace 'bar': - - tkn resource describe foo -n bar - -or - - tkn res desc foo -n bar -` - - c := &cobra.Command{ - Use: "describe", - Aliases: []string{"desc"}, - Short: "Describes a pipeline resource in a namespace", - Example: eg, - SilenceUsage: true, - Annotations: map[string]string{ - "commandType": "main", - }, - ValidArgsFunction: formatted.ParentCompletion, - RunE: func(cmd *cobra.Command, args []string) error { - s := &cli.Stream{ - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - - output, err := cmd.LocalFlags().GetString("output") - if err != nil { - fmt.Fprint(os.Stderr, "Error: output option not set properly \n") - return err - } - - if len(args) == 0 { - err = askPipelineResourceName(opts, p) - if err != nil { - return err - } - } else { - opts.PipelineResourceName = args[0] - } - - if output != "" { - return describePipelineResourceOutput(cmd.OutOrStdout(), p, f, opts.PipelineResourceName) - } - - return printPipelineResourceDescription(s, p, opts.PipelineResourceName) - }, - } - - f.AddFlags(c) - c.Deprecated = "PipelineResource commands are deprecated, they will be removed soon as it get removed from API." - - return c -} - -func describePipelineResourceOutput(w io.Writer, p cli.Params, f *cliopts.PrintFlags, name string) error { - cs, err := p.Clients() - if err != nil { - return err - } - - c := cs.Resource.TektonV1alpha1().PipelineResources(p.Namespace()) - - pipelineresource, err := c.Get(context.Background(), name, metav1.GetOptions{}) - if err != nil { - return err - } - - // NOTE: this is required for -o json|yaml to work properly since - // tektoncd go client fails to set these; probably a bug - pipelineresource.GetObjectKind().SetGroupVersionKind( - schema.GroupVersionKind{ - Version: "tekton.dev/v1alpha1", - Kind: "PipelineResource", - }) - - return printer.PrintObject(w, pipelineresource, f) -} - -func printPipelineResourceDescription(s *cli.Stream, p cli.Params, preName string) error { - cs, err := p.Clients() - if err != nil { - return fmt.Errorf("failed to create tekton client") - } - - pre, err := cs.Resource.TektonV1alpha1().PipelineResources(p.Namespace()).Get(context.Background(), preName, metav1.GetOptions{}) - if err != nil { - return fmt.Errorf("failed to find pipelineresource %q", preName) - } - - var data = struct { - PipelineResource *v1alpha1.PipelineResource - Params cli.Params - }{ - PipelineResource: pre, - Params: p, - } - - w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent) - FuncMap := template.FuncMap{ - "decorate": formatted.DecorateAttr, - } - t := template.Must(template.New("Describe PipelineResource").Funcs(FuncMap).Parse(templ)) - - err = t.Execute(w, data) - if err != nil { - fmt.Fprintf(s.Err, "Failed to execute template") - return err - } - return w.Flush() -} - -func askPipelineResourceName(opts *options.DescribeOptions, p cli.Params) error { - cliClients, err := p.Clients() - if err != nil { - return err - } - - // the `allPipelineResourceNames( )` func is in delete.go, in the pipelineresource package. - pipelineResourceNames, err := allPipelineResourceNames(p, cliClients) - if err != nil { - return err - } - if len(pipelineResourceNames) == 0 { - return fmt.Errorf("no pipelineresources found") - } - - err = opts.Ask(options.ResourceNamePipelineResource, pipelineResourceNames) - if err != nil { - return err - } - - return nil -} diff --git a/pkg/cmd/pipelineresource/describe_test.go b/pkg/cmd/pipelineresource/describe_test.go deleted file mode 100644 index 86230ecf98..0000000000 --- a/pkg/cmd/pipelineresource/describe_test.go +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "fmt" - "strings" - "testing" - - "github.com/jonboulle/clockwork" - "github.com/tektoncd/cli/pkg/test" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - pipelinetest "github.com/tektoncd/pipeline/test" - "gotest.tools/v3/golden" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestPipelineResourceDescribe_Invalid_Namespace(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: ns}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Resource: cs.Resource} - - res := Command(p) - out, err := test.ExecuteCommand(res, "desc", "bar", "-n", "invalid") - if err == nil { - t.Errorf("Error expected here") - } - - expected := "Command \"describe\" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API.\nError: failed to find pipelineresource \"bar\"\n" - test.AssertOutput(t, expected, out) -} - -func TestPipelineResourceDescribe_Empty(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: ns}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Resource: cs.Resource} - - res := Command(p) - _, err := test.ExecuteCommand(res, "desc", "bar") - if err == nil { - t.Errorf("Error expected here") - } - - expected := "failed to find pipelineresource \"bar\"" - test.AssertOutput(t, expected, err.Error()) -} - -func TestPipelineResourceDescribe_WithParams(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-ns-1", - }, - }, - } - - pres := []*v1alpha1.PipelineResource{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-1", - Namespace: "test-ns-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - Description: "a test description", - Params: []v1alpha1.ResourceParam{ - { - Name: "URL", - Value: "quay.io/tekton/controller", - }, - }, - }, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{PipelineResources: pres, Namespaces: ns}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Resource: cs.Resource} - pipelineresource := Command(p) - out, _ := test.ExecuteCommand(pipelineresource, "desc", "test-1", "-n", "test-ns-1") - golden.Assert(t, out, fmt.Sprintf("%s.golden", t.Name())) -} - -func TestPipelineResourceDescribe_WithSecretParams(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-ns-1", - }, - }, - } - - pres := []*v1alpha1.PipelineResource{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-1", - Namespace: "test-ns-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - Description: "a test description", - Params: []v1alpha1.ResourceParam{ - { - Name: "URL", - Value: "quay.io/tekton/controller", - }, - { - Name: "TAG", - Value: "latest", - }, - }, - SecretParams: []v1alpha1.SecretParam{ - { - FieldName: "githubToken", - SecretKey: "token", - SecretName: "github-secrets", - }, - }, - }, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{PipelineResources: pres, Namespaces: ns}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Resource: cs.Resource} - pipelineresource := Command(p) - out, _ := test.ExecuteCommand(pipelineresource, "desc", "test-1", "-n", "test-ns-1") - golden.Assert(t, out, fmt.Sprintf("%s.golden", t.Name())) -} - -func TestPipelineResourcesDescribe_custom_output(t *testing.T) { - name := "pipeline-resource" - expected := "Command \"describe\" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API.\npipelineresource.tekton.dev/" + name - - clock := clockwork.NewFakeClock() - - prs := []*v1alpha1.PipelineResource{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: "ns", - }, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{ - PipelineResources: prs, - Namespaces: []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - }, - }) - - p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Resource: cs.Resource} - p.SetNamespace("ns") - run := Command(p) - - got, err := test.ExecuteCommand(run, "desc", "-o", "name", name) - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - - got = strings.TrimSpace(got) - if got != expected { - t.Errorf("Result should be '%s' != '%s'", got, expected) - } -} diff --git a/pkg/cmd/pipelineresource/list.go b/pkg/cmd/pipelineresource/list.go deleted file mode 100644 index 64daf3c523..0000000000 --- a/pkg/cmd/pipelineresource/list.go +++ /dev/null @@ -1,216 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "context" - "fmt" - "os" - "strings" - "text/tabwriter" - - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/cli" - pressort "github.com/tektoncd/cli/pkg/pipelineresource/sort" - "github.com/tektoncd/cli/pkg/printer" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - versionedResource "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - cliopts "k8s.io/cli-runtime/pkg/genericclioptions" -) - -const ( - msgNoPREsFound = "No pipelineresources found." -) - -type ListOptions struct { - Type string - NoHeaders bool - AllNamespaces bool -} - -func listCommand(p cli.Params) *cobra.Command { - - opts := &ListOptions{Type: ""} - f := cliopts.NewPrintFlags("list") - eg := `List all PipelineResources in a namespace 'foo': - - tkn pre list -n foo -` - - cmd := &cobra.Command{ - Use: "list", - Aliases: []string{"ls"}, - Short: "Lists pipeline resources in a namespace", - Example: eg, - SilenceUsage: true, - Annotations: map[string]string{ - "commandType": "main", - }, - Args: cobra.MinimumNArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - cs, err := p.Clients() - if err != nil { - return err - } - - valid := false - for _, allowed := range v1alpha1.AllResourceTypes { - if string(allowed) == opts.Type || opts.Type == "" { - valid = true - break - } - } - if !valid { - return fmt.Errorf("failed to list pipelineresources. Invalid resource type %s", opts.Type) - } - - namespace := p.Namespace() - if opts.AllNamespaces { - namespace = "" - } - - pres, err := list(cs.Resource, namespace, opts.Type) - stream := &cli.Stream{ - Out: cmd.OutOrStdout(), - Err: cmd.OutOrStderr(), - } - - if err != nil { - ns := namespace - if opts.AllNamespaces { - ns = "all" - } - fmt.Fprintf(os.Stderr, "Failed to list pipelineresources from %s namespace(s) \n", ns) - return err - } - - output, err := cmd.LocalFlags().GetString("output") - if err != nil { - fmt.Fprint(os.Stderr, "Error: output option not set properly \n") - return err - } - - if output != "" { - return printer.PrintObject(stream.Out, pres, f) - } - - err = printFormatted(stream, pres, opts.NoHeaders, opts.AllNamespaces) - if err != nil { - fmt.Fprint(os.Stderr, "Failed to print Pipelineresources \n") - return err - } - return nil - }, - } - - f.AddFlags(cmd) - cmd.Flags().StringVarP(&opts.Type, "type", "t", "", "Pipeline resource type") - cmd.Flags().BoolVarP(&opts.NoHeaders, "no-headers", "", opts.NoHeaders, "do not print column headers with output (default print column headers with output)") - cmd.Flags().BoolVarP(&opts.AllNamespaces, "all-namespaces", "A", opts.AllNamespaces, "list pipeline resources from all namespaces") - cmd.Deprecated = "PipelineResource commands are deprecated, they will be removed soon as it get removed from API." - - return cmd -} - -func list(client versionedResource.Interface, namespace string, resourceType string) (*v1alpha1.PipelineResourceList, error) { - - prec := client.TektonV1alpha1().PipelineResources(namespace) - pres, err := prec.List(context.Background(), v1.ListOptions{}) - if err != nil { - return nil, err - } - - if resourceType != "" { - pres.Items = filterByType(pres.Items, resourceType) - } - - if len(pres.Items) > 0 { - if namespace == "" { - pressort.SortByNamespace(pres.Items) - } else { - pressort.SortByTypeAndName(pres.Items) - } - } - - // NOTE: this is required for -o json|yaml to work properly since - // tektoncd go client fails to set these; probably a bug - pres.GetObjectKind().SetGroupVersionKind( - schema.GroupVersionKind{ - Version: "tekton.dev/v1alpha1", - Kind: "PipelineResourceList", - }) - - return pres, nil -} - -func printFormatted(s *cli.Stream, pres *v1alpha1.PipelineResourceList, noheaders bool, allnamespaces bool) error { - if len(pres.Items) == 0 { - fmt.Fprintln(s.Err, msgNoPREsFound) - return nil - } - - w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent) - if !noheaders { - headers := "NAME\tTYPE\tDETAILS" - if allnamespaces { - headers = "NAMESPACE\t" + headers - } - fmt.Fprintln(w, headers) - } - for _, pre := range pres.Items { - if allnamespaces { - fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", - pre.Namespace, - pre.Name, - pre.Spec.Type, - details(pre), - ) - } else { - fmt.Fprintf(w, "%s\t%s\t%s\n", - pre.Name, - pre.Spec.Type, - details(pre), - ) - } - } - - return w.Flush() -} - -func details(pre v1alpha1.PipelineResource) string { - var key = "url" - if pre.Spec.Type == v1alpha1.PipelineResourceTypeStorage { - key = "location" - } - - for _, p := range pre.Spec.Params { - if strings.ToLower(p.Name) == key { - return p.Name + ": " + p.Value - } - } - - return "---" -} - -func filterByType(resources []v1alpha1.PipelineResource, resourceType string) (ret []v1alpha1.PipelineResource) { - for _, resource := range resources { - if string(resource.Spec.Type) == resourceType { - ret = append(ret, resource) - } - } - return -} diff --git a/pkg/cmd/pipelineresource/list_test.go b/pkg/cmd/pipelineresource/list_test.go deleted file mode 100644 index ebe3342e8a..0000000000 --- a/pkg/cmd/pipelineresource/list_test.go +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "fmt" - "strings" - "testing" - - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/test" - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - pipelinetest "github.com/tektoncd/pipeline/test" - "gotest.tools/v3/golden" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestPipelineResourceList(t *testing.T) { - - pres := []*v1alpha1.PipelineResource{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test", - Namespace: "test-ns-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeGit, - Params: []v1alpha1.ResourceParam{ - { - Name: "url", - Value: "git@github.com:tektoncd/cli-new.git", - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-1", - Namespace: "test-ns-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - Params: []v1alpha1.ResourceParam{ - { - Name: "URL", - Value: "quey.io/tekton/controller", - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-2", - Namespace: "test-ns-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeGit, - Params: []v1alpha1.ResourceParam{ - { - Name: "url", - Value: "git@github.com:tektoncd/cli.git", - }, - }, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-3", - Namespace: "test-ns-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-4", - Namespace: "test-ns-2", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: v1alpha1.PipelineResourceTypeImage, - Params: []v1alpha1.ResourceParam{ - { - Name: "URL", - Value: "quey.io/tekton/webhook", - }, - }, - }, - }, - } - - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-ns-1", - }, - }, - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-ns-2", - }, - }, - } - - tests := []struct { - name string - command *cobra.Command - args []string - wantError bool - }{ - { - name: "Invalid namespace", - command: command(t, pres, ns), - args: []string{"list", "-n", "invalid"}, - wantError: true, - }, - { - name: "Multiple pipeline resources", - command: command(t, pres, ns), - args: []string{"list", "-n", "test-ns-1"}, - wantError: false, - }, - { - name: "Single pipeline resource", - command: command(t, pres, ns), - args: []string{"list", "-n", "test-ns-2"}, - wantError: false, - }, - { - name: "Single Pipeline Resource by type", - command: command(t, pres, ns), - args: []string{"list", "-n", "test-ns-2", "-t", "image"}, - wantError: false, - }, - { - name: "Multiple Pipeline Resource by type", - command: command(t, pres, ns), - args: []string{"list", "-n", "test-ns-1", "-t", "image"}, - wantError: false, - }, - { - name: "Empty Pipeline Resource by type", - command: command(t, pres, ns), - args: []string{"list", "-n", "test-ns-1", "-t", "storage"}, - wantError: false, - }, - { - name: "By template", - command: command(t, pres, ns), - args: []string{"list", "-n", "test-ns-1", "-o", "jsonpath={range .items[*]}{.metadata.name}{\"\\n\"}{end}"}, - wantError: false, - }, - { - name: "No Headers", - command: command(t, pres, ns), - args: []string{"list", "-n", "test-ns-1", "--no-headers"}, - wantError: false, - }, - { - name: "All Namespaces", - command: command(t, pres, ns), - args: []string{"list", "--all-namespaces"}, - wantError: false, - }, - } - - for _, td := range tests { - t.Run(td.name, func(t *testing.T) { - out, err := test.ExecuteCommand(td.command, td.args...) - - if !td.wantError && err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, out, strings.ReplaceAll(fmt.Sprintf("%s.golden", t.Name()), "/", "-")) - }) - } - -} - -func TestPipelineResourceList_empty(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "test-ns-3", - }, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: ns}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Resource: cs.Resource} - pipelineresource := Command(p) - - out, _ := test.ExecuteCommand(pipelineresource, "list", "-n", "test-ns-3") - test.AssertOutput(t, "Command \"list\" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API.\n"+msgNoPREsFound+"\n", out) -} - -func TestPipelineResourceList_invalidType(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: ns}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Resource: cs.Resource} - c := Command(p) - - _, err := test.ExecuteCommand(c, "list", "-n", "ns", "-t", "registry") - - if err == nil { - t.Error("Expecting an error but it's empty") - } - - test.AssertOutput(t, "failed to list pipelineresources. Invalid resource type registry", err.Error()) -} - -func command(t *testing.T, pres []*v1alpha1.PipelineResource, ns []*corev1.Namespace) *cobra.Command { - cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{PipelineResources: pres, Namespaces: ns}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Resource: cs.Resource} - return Command(p) -} diff --git a/pkg/cmd/pipelineresource/pipelineresource.go b/pkg/cmd/pipelineresource/pipelineresource.go deleted file mode 100644 index cf265923b5..0000000000 --- a/pkg/cmd/pipelineresource/pipelineresource.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "github.com/spf13/cobra" - "github.com/tektoncd/cli/pkg/cli" - "github.com/tektoncd/cli/pkg/cli/prerun" - "github.com/tektoncd/cli/pkg/flags" -) - -func Command(p cli.Params) *cobra.Command { - cmd := &cobra.Command{ - Use: "resource", - Aliases: []string{"res", "resources"}, - Short: "Manage pipeline resources", - Annotations: map[string]string{ - "commandType": "main", - }, - PersistentPreRunE: prerun.PersistentPreRunE(p), - } - - flags.AddTektonOptions(cmd) - cmd.AddCommand( - createCommand(p), - deleteCommand(p), - describeCommand(p), - listCommand(p), - ) - cmd.Deprecated = "PipelineResource commands are deprecated, they will be removed soon as it get removed from API." - - return cmd -} diff --git a/pkg/cmd/pipelineresource/pipelineresource_test.go b/pkg/cmd/pipelineresource/pipelineresource_test.go deleted file mode 100644 index 6332ad7520..0000000000 --- a/pkg/cmd/pipelineresource/pipelineresource_test.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "testing" - - "github.com/tektoncd/cli/pkg/test" -) - -func TestPipelineResources_invalid(t *testing.T) { - p := &test.Params{} - - pipelineresource := Command(p) - out, err := test.ExecuteCommand(pipelineresource, "foobar") - if err == nil { - t.Errorf("No errors was defined. Output: %s", out) - } -} diff --git a/pkg/cmd/pipelineresource/resource_testUtil.go b/pkg/cmd/pipelineresource/resource_testUtil.go deleted file mode 100644 index 707dc325af..0000000000 --- a/pkg/cmd/pipelineresource/resource_testUtil.go +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright © 2019 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 pipelineresource - -import ( - "bytes" - "testing" - - "github.com/AlecAivazis/survey/v2" - "github.com/AlecAivazis/survey/v2/terminal" - goexpect "github.com/Netflix/go-expect" - "github.com/tektoncd/cli/test/helper" - "gotest.tools/v3/assert" -) - -type promptTest struct { - procedure func(*goexpect.Console) error -} - -func (res *Resource) RunPromptTest(t *testing.T, test promptTest) { - test.runTest(t, test.procedure, func(stdio terminal.Stdio) error { - res.AskOpts = WithStdio(stdio) - err := res.createInteractive() - if err != nil { - if err.Error() == "resource already exist" { - return nil - } - return err - } - - return err - }) -} - -func stdio(c *goexpect.Console) terminal.Stdio { - return terminal.Stdio{In: c.Tty(), Out: c.Tty(), Err: c.Tty()} -} - -func (pt *promptTest) runTest(t *testing.T, procedure func(*goexpect.Console) error, test func(terminal.Stdio) error) { - t.Parallel() - - // Multiplex output to a buffer as well for the raw bytes. - buf := new(bytes.Buffer) - c, state, err := helper.NewVT10XConsole(goexpect.WithStdout(buf)) - assert.NilError(t, err) - defer func() { - _ = c.Close() - }() - - donec := make(chan struct{}) - go func() { - defer close(donec) - if err := procedure(c); err != nil { - t.Logf("procedure failed: %v", err) - } - }() - - assert.NilError(t, test(stdio(c))) - - // Close the slave end of the pty, and read the remaining bytes from the master end. - _ = c.Tty().Close() - <-donec - - t.Logf("Raw output: %q", buf.String()) - - // Dump the terminal's screen. - t.Logf("\n%s", goexpect.StripTrailingEmptyLines(state.String())) -} - -// WithStdio helps to test interactive command -// by setting stdio for the ask function -func WithStdio(stdio terminal.Stdio) survey.AskOpt { - return func(options *survey.AskOptions) error { - options.Stdio.In = stdio.In - options.Stdio.Out = stdio.Out - options.Stdio.Err = stdio.Err - return nil - } -} diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceDescribe_WithParams.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceDescribe_WithParams.golden deleted file mode 100644 index abe595c8f8..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceDescribe_WithParams.golden +++ /dev/null @@ -1,10 +0,0 @@ -Command "describe" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -Name: test-1 -Namespace: test-ns-1 -PipelineResource Type: image -Description: a test description - -Params - - NAME VALUE - URL quay.io/tekton/controller diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceDescribe_WithSecretParams.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceDescribe_WithSecretParams.golden deleted file mode 100644 index 82c3406d8f..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceDescribe_WithSecretParams.golden +++ /dev/null @@ -1,16 +0,0 @@ -Command "describe" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -Name: test-1 -Namespace: test-ns-1 -PipelineResource Type: image -Description: a test description - -Params - - NAME VALUE - URL quay.io/tekton/controller - TAG latest - -Secret Params - - FIELDNAME SECRETNAME - githubToken github-secrets diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-All_Namespaces.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-All_Namespaces.golden deleted file mode 100644 index 59c1908ef9..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-All_Namespaces.golden +++ /dev/null @@ -1,7 +0,0 @@ -Command "list" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -NAMESPACE NAME TYPE DETAILS -test-ns-1 test git url: git@github.com:tektoncd/cli-new.git -test-ns-1 test-2 git url: git@github.com:tektoncd/cli.git -test-ns-1 test-1 image URL: quey.io/tekton/controller -test-ns-1 test-3 image --- -test-ns-2 test-4 image URL: quey.io/tekton/webhook diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-By_template.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-By_template.golden deleted file mode 100644 index 1105ce28c9..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-By_template.golden +++ /dev/null @@ -1,5 +0,0 @@ -Command "list" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -test -test-2 -test-1 -test-3 diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Empty_Pipeline_Resource_by_type.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Empty_Pipeline_Resource_by_type.golden deleted file mode 100644 index dab8fb097a..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Empty_Pipeline_Resource_by_type.golden +++ /dev/null @@ -1,2 +0,0 @@ -Command "list" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -No pipelineresources found. diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Invalid_namespace.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Invalid_namespace.golden deleted file mode 100644 index dab8fb097a..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Invalid_namespace.golden +++ /dev/null @@ -1,2 +0,0 @@ -Command "list" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -No pipelineresources found. diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Multiple_Pipeline_Resource_by_type.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Multiple_Pipeline_Resource_by_type.golden deleted file mode 100644 index 3636f1c718..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Multiple_Pipeline_Resource_by_type.golden +++ /dev/null @@ -1,4 +0,0 @@ -Command "list" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -NAME TYPE DETAILS -test-1 image URL: quey.io/tekton/controller -test-3 image --- diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Multiple_pipeline_resources.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Multiple_pipeline_resources.golden deleted file mode 100644 index bc6aac4e15..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Multiple_pipeline_resources.golden +++ /dev/null @@ -1,6 +0,0 @@ -Command "list" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -NAME TYPE DETAILS -test git url: git@github.com:tektoncd/cli-new.git -test-2 git url: git@github.com:tektoncd/cli.git -test-1 image URL: quey.io/tekton/controller -test-3 image --- diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-No_Headers.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-No_Headers.golden deleted file mode 100644 index af92fcef58..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-No_Headers.golden +++ /dev/null @@ -1,5 +0,0 @@ -Command "list" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -test git url: git@github.com:tektoncd/cli-new.git -test-2 git url: git@github.com:tektoncd/cli.git -test-1 image URL: quey.io/tekton/controller -test-3 image --- diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Single_Pipeline_Resource_by_type.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Single_Pipeline_Resource_by_type.golden deleted file mode 100644 index 4fc1c65814..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Single_Pipeline_Resource_by_type.golden +++ /dev/null @@ -1,3 +0,0 @@ -Command "list" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -NAME TYPE DETAILS -test-4 image URL: quey.io/tekton/webhook diff --git a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Single_pipeline_resource.golden b/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Single_pipeline_resource.golden deleted file mode 100644 index 4fc1c65814..0000000000 --- a/pkg/cmd/pipelineresource/testdata/TestPipelineResourceList-Single_pipeline_resource.golden +++ /dev/null @@ -1,3 +0,0 @@ -Command "list" is deprecated, PipelineResource commands are deprecated, they will be removed soon as it get removed from API. -NAME TYPE DETAILS -test-4 image URL: quey.io/tekton/webhook diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 5839c866b3..0e1b6b1f52 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -29,7 +29,6 @@ import ( "github.com/tektoncd/cli/pkg/cmd/completion" "github.com/tektoncd/cli/pkg/cmd/eventlistener" "github.com/tektoncd/cli/pkg/cmd/pipeline" - "github.com/tektoncd/cli/pkg/cmd/pipelineresource" "github.com/tektoncd/cli/pkg/cmd/pipelinerun" "github.com/tektoncd/cli/pkg/cmd/task" "github.com/tektoncd/cli/pkg/cmd/taskrun" @@ -109,7 +108,6 @@ func Root(p cli.Params) *cobra.Command { completion.Command(), eventlistener.Command(p), pipeline.Command(p), - pipelineresource.Command(p), pipelinerun.Command(p), task.Command(p), taskrun.Command(p), diff --git a/pkg/cmd/testdata/TestPluginList.golden b/pkg/cmd/testdata/TestPluginList.golden index 86d3dccb9c..4a4208b920 100644 --- a/pkg/cmd/testdata/TestPluginList.golden +++ b/pkg/cmd/testdata/TestPluginList.golden @@ -14,7 +14,6 @@ Available Commands: hub Interact with tekton hub pipeline Manage pipelines pipelinerun Manage PipelineRuns - resource Manage pipeline resources task Manage Tasks taskrun Manage TaskRuns triggerbinding Manage TriggerBindings diff --git a/pkg/pipelineresource/sort/by_namespace.go b/pkg/pipelineresource/sort/by_namespace.go deleted file mode 100644 index ba31da2320..0000000000 --- a/pkg/pipelineresource/sort/by_namespace.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright © 2020 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 pipelineresource - -import ( - "sort" - - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" -) - -func SortByNamespace(pres []v1alpha1.PipelineResource) { - sort.Sort(byNamespace(pres)) -} - -type byNamespace []v1alpha1.PipelineResource - -func (pres byNamespace) compareNamespace(ins, jns string) (lt, eq bool) { - lt, eq = ins < jns, ins == jns - return lt, eq -} - -func (pres byNamespace) Len() int { return len(pres) } -func (pres byNamespace) Swap(i, j int) { pres[i], pres[j] = pres[j], pres[i] } -func (pres byNamespace) Less(i, j int) bool { - var lt, eq bool - if lt, eq = pres.compareNamespace(pres[i].Namespace, pres[j].Namespace); eq { - if pres[j].Spec.Type < pres[i].Spec.Type { - return false - } - if pres[j].Spec.Type > pres[i].Spec.Type { - return true - } - return pres[j].Name > pres[i].Name - } - return lt -} diff --git a/pkg/pipelineresource/sort/by_namespace_test.go b/pkg/pipelineresource/sort/by_namespace_test.go deleted file mode 100644 index 03ea170a14..0000000000 --- a/pkg/pipelineresource/sort/by_namespace_test.go +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright © 2020 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 pipelineresource - -import ( - "testing" - - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func Test_PipelineResourcesByNamespace(t *testing.T) { - pres01 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "abc", - Name: "pres0-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "pullRequest", - Params: []v1alpha1.ResourceParam{ - {Name: "url", Value: "https://github.com/tektoncd/cli/pull/1"}, - }, - }, - } - - pres02 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "abc", - Name: "pres0-2", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "git", - Params: []v1alpha1.ResourceParam{ - {Name: "le clé", Value: "git@github.com:tektoncd/cli-new.git"}, - }, - }, - } - - pres03 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "abc", - Name: "pres0-3", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "image", - Params: []v1alpha1.ResourceParam{ - {Name: "trolla", Value: "quey.io/tekton/controller"}, - }, - }, - } - - pres11 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "def", - Name: "pres1-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "pullRequest", - Params: []v1alpha1.ResourceParam{ - {Name: "url", Value: "https://github.com/tektoncd/cli/pull/2"}, - }, - }, - } - - pres12 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "def", - Name: "pres1-2", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "git", - Params: []v1alpha1.ResourceParam{ - {Name: "claè nouveau", Value: "git@github.com:tektoncd/cli-new.git"}, - }, - }, - } - - pres13 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "def", - Name: "pres1-3", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "image", - Params: []v1alpha1.ResourceParam{ - {Name: "ouarel", Value: "nay.io/tekton/trolley"}, - }, - }, - } - - pres21 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ghi", - Name: "pres2-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "pullRequest", - Params: []v1alpha1.ResourceParam{ - {Name: "url", Value: "https://github.com/tektoncd/cli/pull/3"}, - }, - }, - } - - pres22 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ghi", - Name: "pres2-2", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "git", - Params: []v1alpha1.ResourceParam{ - {Name: "entrée", Value: "git@github.com:tektoncd/entrypoint.git"}, - }, - }, - } - - pres23 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "ghi", - Name: "pres2-3", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "image", - Params: []v1alpha1.ResourceParam{ - {Name: "ay", Value: "docker.io/not-jenkins/holley"}, - }, - }, - } - - pres := []v1alpha1.PipelineResource{ - pres12, - pres13, - pres22, - pres11, - pres23, - pres02, - pres21, - pres03, - pres01, - } - - SortByNamespace(pres) - - element1 := pres[0].Name - if element1 != "pres0-2" { - t.Errorf("SortPipelineResourcesByNamespace should be pres0-2 but returned: %s", element1) - } - - element2 := pres[1].Name - if element2 != "pres0-3" { - t.Errorf("SortPipelineResourcesByNamespace should be pres0-3 but returned: %s", element2) - } - - element3 := pres[2].Name - if element3 != "pres0-1" { - t.Errorf("SortPipelineResourcesByNamespace should be pres0-1 but returned: %s", element3) - } - - element4 := pres[3].Name - if element4 != "pres1-2" { - t.Errorf("SortPipelineResourcesByNamespace should be pres1-2 but returned: %s", element4) - } - - element5 := pres[4].Name - if element5 != "pres1-3" { - t.Errorf("SortPipelineResourcesByNamespace should be pres1-3 but returned: %s", element5) - } - - element6 := pres[5].Name - if element6 != "pres1-1" { - t.Errorf("SortPipelineResourcesByNamespace should be pres1-1 but returned: %s", element6) - } - - element7 := pres[6].Name - if element7 != "pres2-2" { - t.Errorf("SortPipelineResourcesByNamespace should be pres2-2 but returned: %s", element7) - } - - element8 := pres[7].Name - if element8 != "pres2-3" { - t.Errorf("SortPipelineResourcesByNamespace should be pres2-3 but returned: %s", element8) - } - - element9 := pres[8].Name - if element9 != "pres2-1" { - t.Errorf("SortPipelineResourcesByNamespace should be pres2-1 but returned: %s", element9) - } -} diff --git a/pkg/pipelineresource/sort/by_type_and_name.go b/pkg/pipelineresource/sort/by_type_and_name.go deleted file mode 100644 index b89b794a6a..0000000000 --- a/pkg/pipelineresource/sort/by_type_and_name.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright © 2020 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 pipelineresource - -import ( - "sort" - - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" -) - -func SortByTypeAndName(pres []v1alpha1.PipelineResource) { - sort.Sort(byTypeAndName(pres)) -} - -type byTypeAndName []v1alpha1.PipelineResource - -func (pres byTypeAndName) Len() int { return len(pres) } -func (pres byTypeAndName) Swap(i, j int) { pres[i], pres[j] = pres[j], pres[i] } -func (pres byTypeAndName) Less(i, j int) bool { - if pres[j].Spec.Type < pres[i].Spec.Type { - return false - } - if pres[j].Spec.Type > pres[i].Spec.Type { - return true - } - return pres[j].Name > pres[i].Name -} diff --git a/pkg/pipelineresource/sort/by_type_and_name_test.go b/pkg/pipelineresource/sort/by_type_and_name_test.go deleted file mode 100644 index 992b06c4ea..0000000000 --- a/pkg/pipelineresource/sort/by_type_and_name_test.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright © 2020 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 pipelineresource - -import ( - "testing" - - "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func Test_PipelineResourcesByTypeAndName(t *testing.T) { - pres1 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "abc", - Name: "pres0-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "git", - Params: []v1alpha1.ResourceParam{ - {Name: "url", Value: "git@github.com:tektoncd/cli-new.git"}, - }, - }, - } - - pres2 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "abc", - Name: "pres1-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "image", - Params: []v1alpha1.ResourceParam{ - {Name: "URL", Value: "quey.io/tekton/controller"}, - }, - }, - } - - pres3 := v1alpha1.PipelineResource{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "abc", - Name: "pres2-1", - }, - Spec: v1alpha1.PipelineResourceSpec{ - Type: "pullRequest", - Params: []v1alpha1.ResourceParam{ - {Name: "url", Value: "https://github.com/tektoncd/cli/pull/1"}, - }, - }, - } - - pres := []v1alpha1.PipelineResource{ - pres2, - pres3, - pres1, - } - - SortByTypeAndName(pres) - - element1Type := pres[0].Spec.Type - if element1Type != "git" { - t.Errorf("SortPipelineResourcesByTypeAndName should be git but returned: %s", element1Type) - } - - element2Type := pres[1].Spec.Type - if element2Type != "image" { - t.Errorf("SortPipelineResourcesByTypeAndName should be image but returned: %s", element2Type) - } - - element3Type := pres[2].Spec.Type - if element3Type != "pullRequest" { - t.Errorf("SortPipelineResourcesByTypeAndName should be pullRequest but returned: %s", element3Type) - } - -}