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.

install_cmd.go 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/spf13/cobra"
  6. "github.com/fluxcd/flux/install"
  7. )
  8. type installOpts install.TemplateParameters
  9. func newInstall() *installOpts {
  10. return &installOpts{}
  11. }
  12. func (opts *installOpts) Command() *cobra.Command {
  13. cmd := &cobra.Command{
  14. Use: "install",
  15. Short: "Print and tweak Kubernetes manifests needed to install Flux in a Cluster",
  16. Example: `# Install Flux and make it use Git repository git@github.com:<your username>/flux-get-started
  17. fluxctl install --git-url 'git@github.com:<your username>/flux-get-started' | kubectl -f -`,
  18. RunE: opts.RunE,
  19. }
  20. cmd.Flags().StringVarP(&opts.GitURL, "git-url", "", "",
  21. "URL of the Git repository to be used by Flux, e.g. git@github.com:<your username>/flux-get-started")
  22. cmd.Flags().StringVarP(&opts.GitBranch, "git-branch", "", "master",
  23. "Git branch to be used by Flux")
  24. cmd.Flags().StringSliceVarP(&opts.GitPaths, "git-paths", "", []string{},
  25. "Relative paths within the Git repo for Flux to locate Kubernetes manifests")
  26. cmd.Flags().StringSliceVarP(&opts.GitPaths, "git-path", "", []string{},
  27. "Relative paths within the Git repo for Flux to locate Kubernetes manifests")
  28. cmd.Flags().StringVarP(&opts.GitLabel, "git-label", "", "flux",
  29. "Git label to keep track of Flux's sync progress; overrides both --git-sync-tag and --git-notes-ref")
  30. cmd.Flags().StringVarP(&opts.GitUser, "git-user", "", "Flux",
  31. "Username to use as git committer")
  32. cmd.Flags().StringVarP(&opts.GitEmail, "git-email", "", "",
  33. "Email to use as git committer")
  34. cmd.Flags().StringVarP(&opts.Namespace, "namespace", "", getKubeConfigContextNamespace("default"),
  35. "Cluster namespace where to install flux")
  36. // Hide and deprecate "git-paths", which was wrongly introduced since its inconsistent with fluxd's git-path flag
  37. cmd.Flags().MarkHidden("git-paths")
  38. cmd.Flags().MarkDeprecated("git-paths", "please use --git-path (no ending s) instead")
  39. return cmd
  40. }
  41. func (opts *installOpts) RunE(cmd *cobra.Command, args []string) error {
  42. if opts.GitURL == "" {
  43. return fmt.Errorf("please supply a valid --git-url argument")
  44. }
  45. if opts.GitEmail == "" {
  46. return fmt.Errorf("please supply a valid --git-email argument")
  47. }
  48. manifests, err := install.FillInTemplates(install.TemplateParameters(*opts))
  49. if err != nil {
  50. return err
  51. }
  52. for fileName, content := range manifests {
  53. if _, err := os.Stdout.Write(content); err != nil {
  54. return fmt.Errorf("cannot output manifest file %s: %s", fileName, err)
  55. }
  56. }
  57. return nil
  58. }