GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

automate_cmd.go 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. import (
  3. "github.com/spf13/cobra"
  4. "github.com/fluxcd/flux/update"
  5. )
  6. type workloadAutomateOpts struct {
  7. *rootOpts
  8. namespace string
  9. workload string
  10. outputOpts
  11. cause update.Cause
  12. // Deprecated
  13. controller string
  14. }
  15. func newWorkloadAutomate(parent *rootOpts) *workloadAutomateOpts {
  16. return &workloadAutomateOpts{rootOpts: parent}
  17. }
  18. func (opts *workloadAutomateOpts) Command() *cobra.Command {
  19. cmd := &cobra.Command{
  20. Use: "automate",
  21. Short: "Turn on automatic deployment for a workload.",
  22. Example: makeExample(
  23. "fluxctl automate --workload=default:deployment/helloworld",
  24. ),
  25. RunE: opts.RunE,
  26. }
  27. AddOutputFlags(cmd, &opts.outputOpts)
  28. AddCauseFlags(cmd, &opts.cause)
  29. cmd.Flags().StringVarP(&opts.namespace, "namespace", "n", getKubeConfigContextNamespace("default"), "Workload namespace")
  30. cmd.Flags().StringVarP(&opts.workload, "workload", "w", "", "Workload to automate")
  31. // Deprecated
  32. cmd.Flags().StringVarP(&opts.controller, "controller", "c", "", "Controller to automate")
  33. cmd.Flags().MarkDeprecated("controller", "changed to --workload, use that instead")
  34. return cmd
  35. }
  36. func (opts *workloadAutomateOpts) RunE(cmd *cobra.Command, args []string) error {
  37. // Backwards compatibility with --controller until we remove it
  38. switch {
  39. case opts.workload != "" && opts.controller != "":
  40. return newUsageError("can't specify both the controller and workload")
  41. case opts.controller != "":
  42. opts.workload = opts.controller
  43. }
  44. policyOpts := &workloadPolicyOpts{
  45. rootOpts: opts.rootOpts,
  46. outputOpts: opts.outputOpts,
  47. namespace: opts.namespace,
  48. workload: opts.workload,
  49. cause: opts.cause,
  50. automate: true,
  51. }
  52. return policyOpts.RunE(cmd, args)
  53. }