github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/testsources/update.go (about) 1 package testsources 2 3 import ( 4 "github.com/spf13/cobra" 5 6 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common" 7 "github.com/kubeshop/testkube/pkg/ui" 8 ) 9 10 func UpdateTestSourceCmd() *cobra.Command { 11 var ( 12 name, uri string 13 sourceType string 14 file string 15 gitUri string 16 gitBranch string 17 gitCommit string 18 gitPath string 19 gitUsername string 20 gitToken string 21 gitWorkingDir string 22 labels map[string]string 23 gitUsernameSecret map[string]string 24 gitTokenSecret map[string]string 25 gitCertificateSecret string 26 gitAuthType string 27 ) 28 29 cmd := &cobra.Command{ 30 Use: "testsource", 31 Aliases: []string{"testsources", "tsc"}, 32 Short: "Update TestSource", 33 Long: `Update TestSource Custom Resource`, 34 Run: func(cmd *cobra.Command, args []string) { 35 if name == "" { 36 ui.Failf("pass valid name (in '--name' flag)") 37 } 38 39 client, namespace, err := common.GetClient(cmd) 40 ui.ExitOnError("getting client", err) 41 42 testSource, _ := client.GetTestSource(name) 43 if name != testSource.Name { 44 ui.Failf("Test source with name '%s' not exists in namespace %s", name, namespace) 45 } 46 47 options, err := NewUpdateTestSourceOptionsFromFlags(cmd) 48 ui.ExitOnError("getting test source options", err) 49 50 _, err = client.UpdateTestSource(options) 51 ui.ExitOnError("updating test source "+name+" in namespace "+namespace, err) 52 53 ui.Success("TestSource updated", name) 54 }, 55 } 56 57 cmd.Flags().StringVarP(&name, "name", "n", "", "unique test source name - mandatory") 58 cmd.Flags().StringToStringVarP(&labels, "label", "l", nil, "label key value pair: --label key1=value1") 59 cmd.Flags().StringVarP(&sourceType, "source-type", "", "", "source type of test one of string|file-uri|git") 60 cmd.Flags().StringVarP(&file, "file", "f", "", "source file - will be read from stdin if not specified") 61 cmd.Flags().StringVarP(&uri, "uri", "u", "", "URI which should be called to get test content") 62 cmd.Flags().StringVarP(&gitUri, "git-uri", "", "", "Git repository uri") 63 cmd.Flags().StringVarP(&gitBranch, "git-branch", "", "", "if uri is git repository we can set additional branch parameter") 64 cmd.Flags().StringVarP(&gitCommit, "git-commit", "", "", "if uri is git repository we can use commit id (sha) parameter") 65 cmd.Flags().StringVarP(&gitPath, "git-path", "", "", "if repository is big we need to define additional path to directory/file to checkout partially") 66 cmd.Flags().StringVarP(&gitUsername, "git-username", "", "", "if git repository is private we can use username as an auth parameter") 67 cmd.Flags().StringVarP(&gitToken, "git-token", "", "", "if git repository is private we can use token as an auth parameter") 68 cmd.Flags().StringToStringVarP(&gitUsernameSecret, "git-username-secret", "", map[string]string{}, "git username secret in a form of secret_name1=secret_key1 for private repository") 69 cmd.Flags().StringToStringVarP(&gitTokenSecret, "git-token-secret", "", map[string]string{}, "git token secret in a form of secret_name1=secret_key1 for private repository") 70 cmd.Flags().StringVarP(&gitCertificateSecret, "git-certificate-secret", "", "", "if git repository is private we can use certificate as an auth parameter stored in a kubernetes secret name") 71 cmd.Flags().StringVarP(&gitWorkingDir, "git-working-dir", "", "", "if repository contains multiple directories with tests (like monorepo) and one starting directory we can set working directory parameter") 72 cmd.Flags().StringVarP(&gitAuthType, "git-auth-type", "", "basic", "auth type for git requests one of basic|header") 73 74 return cmd 75 }