()
| 59 | deepflow-ctl repo agent create --arch x86 --version-image /root/deepflow-agent --k8s-image registry.cn-beijing.aliyuncs.com/deepflow-ce/deepflowio-agent:latest` |
| 60 | |
| 61 | func registerAgentCommand() *cobra.Command { |
| 62 | agent := &cobra.Command{ |
| 63 | Use: "agent", |
| 64 | Short: "repo agent operation commands", |
| 65 | Run: func(cmd *cobra.Command, args []string) { |
| 66 | fmt.Printf("please run with 'list | create | delete'.\n") |
| 67 | }, |
| 68 | } |
| 69 | |
| 70 | var arch, image, versionImage, k8sImage string |
| 71 | timeout := common.DefaultTimeout |
| 72 | create := &cobra.Command{ |
| 73 | Use: "create", |
| 74 | Short: "create repo agent", |
| 75 | Example: repoAgentCreateExample, |
| 76 | Run: func(cmd *cobra.Command, args []string) { |
| 77 | if len(k8sImage) != 0 && len(image) != 0 { |
| 78 | printutil.ErrorfWithColor("only one flag is supported: 'image' or 'k8s-image'", image, versionImage) |
| 79 | return |
| 80 | } |
| 81 | if strings.HasSuffix(image, ".exe") || len(k8sImage) != 0 { |
| 82 | if versionImage == "" { |
| 83 | printutil.ErrorWithColor("'version-image' must be specified when uploading an image to retrieve its version") |
| 84 | return |
| 85 | } |
| 86 | if _, err := os.Stat(versionImage); errors.Is(err, os.ErrNotExist) { |
| 87 | fmt.Printf("file %s not found\n", versionImage) |
| 88 | return |
| 89 | } |
| 90 | imageName := image |
| 91 | if len(imageName) == 0 { |
| 92 | imageName = k8sImage |
| 93 | } |
| 94 | printutil.WarnfWithColor("make sure %s and %s have the same version", imageName, versionImage) |
| 95 | } |
| 96 | if err := createRepoAgent(cmd, arch, image, versionImage, k8sImage); err != nil { |
| 97 | fmt.Println(err) |
| 98 | } |
| 99 | }, |
| 100 | } |
| 101 | create.Flags().StringVarP(&arch, "arch", "", "", "arch of deepflow-agent") |
| 102 | create.Flags().StringVarP(&image, "image", "", "", "deepflow-agent image to upload") |
| 103 | create.Flags().StringVarP(&versionImage, "version-image", "", "", "deepflow-agent image to get branch, rev_count and commit_id") |
| 104 | create.Flags().StringVarP(&k8sImage, "k8s-image", "", "", "deepflow-agent Kubernetes image: if k8s-image is not empty, the image flag will be ignored.") |
| 105 | create.Flags().DurationVar(&timeout, "timeout", 0, "timeout duration(default: 30s), e.g., 1s 1m 1h") |
| 106 | |
| 107 | list := &cobra.Command{ |
| 108 | Use: "list", |
| 109 | Short: "list repo agent", |
| 110 | Example: "deepflow-ctl repo agent list", |
| 111 | Run: func(cmd *cobra.Command, args []string) { |
| 112 | listRepoAgent(cmd) |
| 113 | }, |
| 114 | } |
| 115 | |
| 116 | delete := &cobra.Command{ |
| 117 | Use: "delete", |
| 118 | Short: "delete repo agent", |
no test coverage detected