github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cmd/create/create_addon_prow.go (about) 1 package create 2 3 import ( 4 "github.com/olli-ai/jx/v2/pkg/cmd/create/options" 5 "github.com/olli-ai/jx/v2/pkg/cmd/helper" 6 "github.com/spf13/cobra" 7 8 "fmt" 9 10 "github.com/olli-ai/jx/v2/pkg/cmd/opts" 11 "github.com/olli-ai/jx/v2/pkg/cmd/templates" 12 "github.com/olli-ai/jx/v2/pkg/kube" 13 "github.com/olli-ai/jx/v2/pkg/util" 14 "github.com/pkg/errors" 15 ) 16 17 var ( 18 createAddonProwLong = templates.LongDesc(` 19 Creates the Prow addon for handling webhook events 20 `) 21 22 createAddonProwExample = templates.Examples(` 23 # Create the Prow addon 24 jx create addon prow 25 26 # Create the Prow addon in a custom namespace 27 jx create addon prow -n mynamespace 28 `) 29 ) 30 31 const defaultProwVersion = "" 32 33 // CreateAddonProwOptions the options for the create spring command 34 type CreateAddonProwOptions struct { 35 CreateAddonOptions 36 Password string 37 Chart string 38 Tekton bool 39 ExternalDNS bool 40 } 41 42 // NewCmdCreateAddonProw creates a command object for the "create" command 43 func NewCmdCreateAddonProw(commonOpts *opts.CommonOptions) *cobra.Command { 44 options := &CreateAddonProwOptions{ 45 CreateAddonOptions: CreateAddonOptions{ 46 CreateOptions: options.CreateOptions{ 47 CommonOptions: commonOpts, 48 }, 49 }, 50 } 51 52 cmd := &cobra.Command{ 53 Use: "prow", 54 Short: "Create a Prow addon", 55 Long: createAddonProwLong, 56 Example: createAddonProwExample, 57 Run: func(cmd *cobra.Command, args []string) { 58 options.Cmd = cmd 59 options.Args = args 60 err := options.Run() 61 helper.CheckErr(err) 62 }, 63 } 64 65 options.addFlags(cmd, "", kube.DefaultProwReleaseName, defaultProwVersion) 66 67 cmd.Flags().StringVarP(&options.Prow.Chart, optionChart, "c", kube.ChartProw, "The name of the chart to use") 68 cmd.Flags().StringVarP(&options.Prow.HMACToken, "hmac-token", "", "", "OPTIONAL: The hmac-token is the token that you give to GitHub for validating webhooks. Generate it using any reasonable randomness-generator, eg openssl rand -hex 20") 69 cmd.Flags().StringVarP(&options.Prow.OAUTHToken, "oauth-token", "", "", "OPTIONAL: The oauth-token is an OAuth2 token that has read and write access to the bot account. Generate it from the account's settings -> Personal access tokens -> Generate new token.") 70 cmd.Flags().StringVarP(&options.Password, "password", "", "", "Overwrite the default admin password used to login to the Deck UI") 71 cmd.Flags().BoolVarP(&options.Tekton, "tekton", "t", true, "Enables Tekton. Otherwise we default to use Knative Build") 72 cmd.Flags().BoolVarP(&options.ExternalDNS, "external-dns", "", true, "Installs external-dns into the cluster. ExternalDNS manages service DNS records for your cluster, providing you've setup your domain record") 73 return cmd 74 } 75 76 // Run implements the command 77 func (o *CreateAddonProwOptions) Run() error { 78 if o.ReleaseName == "" { 79 return util.MissingOption(optionRelease) 80 } 81 82 err := o.EnsureHelm() 83 if err != nil { 84 return errors.Wrap(err, "failed to ensure that Helm is present") 85 } 86 _, currentNamespace, err := o.KubeClientAndNamespace() 87 if err != nil { 88 return err 89 } 90 91 o.Prow.Chart = o.Chart 92 o.Prow.Version = o.Version 93 o.Prow.SetValues = o.SetValues 94 o.Namespace = currentNamespace 95 96 isGitOps, _ := o.GetDevEnv() 97 98 _, pipelineUser, err := o.GetPipelineGitAuth() 99 if err != nil { 100 return errors.Wrap(err, "retrieving the pipeline Git Auth") 101 } 102 pipelineUserName := "" 103 if pipelineUser != nil { 104 pipelineUserName = pipelineUser.Username 105 } 106 107 err = o.InstallProw(o.Tekton, o.ExternalDNS, isGitOps, "", pipelineUserName, nil) 108 if err != nil { 109 return fmt.Errorf("failed to install Prow: %v", err) 110 } 111 112 _, devNamespace, err := o.KubeClientAndNamespace() 113 if err != nil { 114 return fmt.Errorf("cannot find a dev team namespace to get existing exposecontroller config from. %v", err) 115 } 116 117 // create the ingress rule 118 err = o.Expose(devNamespace, devNamespace, o.Password) 119 if err != nil { 120 return err 121 } 122 123 return nil 124 }