cmd.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package kube
  2. import "github.com/spf13/cobra"
  3. var (
  4. varStringName string
  5. varStringNamespace string
  6. varStringImage string
  7. varStringSecret string
  8. varIntRequestCpu int
  9. varIntRequestMem int
  10. varIntLimitCpu int
  11. varIntLimitMem int
  12. varStringO string
  13. varIntReplicas int
  14. varIntRevisions int
  15. varIntPort int
  16. varIntNodePort int
  17. varIntTargetPort int
  18. varIntMinReplicas int
  19. varIntMaxReplicas int
  20. varStringHome string
  21. varStringRemote string
  22. varStringBranch string
  23. varStringServiceAccount string
  24. varStringImagePullPolicy string
  25. // Cmd describes a kube command.
  26. Cmd = &cobra.Command{
  27. Use: "kube",
  28. Short: "Generate kubernetes files",
  29. }
  30. deployCmd = &cobra.Command{
  31. Use: "deploy",
  32. Short: "Generate deployment yaml file",
  33. RunE: deploymentCommand,
  34. }
  35. )
  36. func init() {
  37. deployCmd.Flags().StringVar(&varStringName, "name", "", "The name of deployment (required)")
  38. deployCmd.Flags().StringVar(&varStringNamespace, "namespace", "", "The namespace of deployment (required)")
  39. deployCmd.Flags().StringVar(&varStringImage, "image", "", "The docker image of deployment (required)")
  40. deployCmd.Flags().StringVar(&varStringSecret, "secret", "", "The secret to image pull from registry")
  41. deployCmd.Flags().IntVar(&varIntRequestCpu, "requestCpu", 500, "The request cpu to deploy")
  42. deployCmd.Flags().IntVar(&varIntRequestMem, "requestMem", 512, "The request memory to deploy")
  43. deployCmd.Flags().IntVar(&varIntLimitCpu, "limitCpu", 1000, "The limit cpu to deploy")
  44. deployCmd.Flags().IntVar(&varIntLimitMem, "limitMem", 1024, "The limit memory to deploy")
  45. deployCmd.Flags().StringVar(&varStringO, "o", "", "The output yaml file (required)")
  46. deployCmd.Flags().IntVar(&varIntReplicas, "replicas", 3, "The number of replicas to deploy")
  47. deployCmd.Flags().IntVar(&varIntRevisions, "revisions", 5, "The number of revision history to limit")
  48. deployCmd.Flags().IntVar(&varIntPort, "port", 0, "The port of the deployment to listen on pod (required)")
  49. deployCmd.Flags().IntVar(&varIntNodePort, "nodePort", 0, "The nodePort of the deployment to expose")
  50. deployCmd.Flags().IntVar(&varIntTargetPort, "targetPort", 0, "The targetPort of the deployment, default to port")
  51. deployCmd.Flags().IntVar(&varIntMinReplicas, "minReplicas", 3, "The min replicas to deploy")
  52. deployCmd.Flags().IntVar(&varIntMaxReplicas, "maxReplicas", 10, "The max replicas to deploy")
  53. deployCmd.Flags().StringVar(&varStringImagePullPolicy, "imagePullPolicy", "", "Image pull policy. One of Always, Never, IfNotPresent")
  54. deployCmd.Flags().StringVar(&varStringHome, "home", "", "The goctl home path of the template, "+
  55. "--home and --remote cannot be set at the same time, if they are, --remote has higher priority")
  56. deployCmd.Flags().StringVar(&varStringRemote, "remote", "", "The remote git repo of the template, "+
  57. "--home and --remote cannot be set at the same time, if they are, --remote has higher priority\nThe git repo "+
  58. "directory must be consistent with the https://github.com/zeromicro/go-zero-template directory structure")
  59. deployCmd.Flags().StringVar(&varStringBranch, "branch", "", "The branch of the remote repo, it "+
  60. "does work with --remote")
  61. deployCmd.Flags().StringVar(&varStringServiceAccount, "serviceAccount", "", "The ServiceAccount "+
  62. "for the deployment")
  63. deployCmd.MarkFlagRequired("name")
  64. deployCmd.MarkFlagRequired("namespace")
  65. deployCmd.MarkFlagRequired("o")
  66. deployCmd.MarkFlagRequired("port")
  67. Cmd.AddCommand(deployCmd)
  68. }