@@ -69,22 +69,23 @@ import (
6969
7070type (
7171 RuntimeInstallOptions struct {
72- RuntimeName string
73- RuntimeToken string
74- RuntimeStoreIV string
75- IngressHost string
76- IngressClass string
77- IngressController string
78- Insecure bool
79- InstallDemoResources bool
80- Version * semver.Version
81- GsCloneOpts * git.CloneOptions
82- InsCloneOpts * git.CloneOptions
83- GitIntegrationOpts * apmodel.AddGitIntegrationArgs
84- KubeFactory kube.Factory
85- CommonConfig * runtime.CommonConfig
86- versionStr string
87- kubeContext string
72+ RuntimeName string
73+ RuntimeToken string
74+ RuntimeStoreIV string
75+ IngressHost string
76+ IngressClass string
77+ IngressController string
78+ Insecure bool
79+ InstallDemoResources bool
80+ Version * semver.Version
81+ GsCloneOpts * git.CloneOptions
82+ InsCloneOpts * git.CloneOptions
83+ GitIntegrationCreationOpts * apmodel.AddGitIntegrationArgs
84+ GitIntegrationRegistrationOpts * apmodel.RegisterToGitIntegrationArgs
85+ KubeFactory kube.Factory
86+ CommonConfig * runtime.CommonConfig
87+ versionStr string
88+ kubeContext string
8889 }
8990 RuntimeUninstallOptions struct {
9091 RuntimeName string
@@ -149,11 +150,14 @@ func NewRuntimeCommand() *cobra.Command {
149150
150151func NewRuntimeInstallCommand () * cobra.Command {
151152 var (
152- gitIntegrationOpts = apmodel.AddGitIntegrationArgs {
153+ gitIntegrationCreationOpts = apmodel.AddGitIntegrationArgs {
153154 SharingPolicy : apmodel .SharingPolicyAllUsersInAccount ,
154155 }
155- installationOpts = RuntimeInstallOptions {GitIntegrationOpts : & gitIntegrationOpts }
156- finalParameters map [string ]string
156+ installationOpts = RuntimeInstallOptions {
157+ GitIntegrationCreationOpts : & gitIntegrationCreationOpts ,
158+ GitIntegrationRegistrationOpts : & apmodel.RegisterToGitIntegrationArgs {},
159+ }
160+ finalParameters map [string ]string
157161 )
158162
159163 cmd := & cobra.Command {
@@ -191,7 +195,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
191195 "Runtime name" : installationOpts .RuntimeName ,
192196 "Repository URL" : installationOpts .InsCloneOpts .Repo ,
193197 "Ingress host" : installationOpts .IngressHost ,
194- "Ingress class" : installationOpts .IngressClass ,
198+ "Ingress class" : installationOpts .IngressClass ,
195199 "Installing demo resources" : strconv .FormatBool (installationOpts .InstallDemoResources ),
196200 }
197201
@@ -213,7 +217,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
213217 cmd .Flags ().StringVar (& installationOpts .versionStr , "version" , "" , "The runtime version to install (default: latest)" )
214218 cmd .Flags ().BoolVar (& installationOpts .InstallDemoResources , "demo-resources" , true , "Installs demo resources (default: true)" )
215219 cmd .Flags ().DurationVar (& store .Get ().WaitTimeout , "wait-timeout" , store .Get ().WaitTimeout , "How long to wait for the runtime components to be ready" )
216- cmd .Flags ().StringVar (& gitIntegrationOpts .APIURL , "provider-api-url" , "" , "Git provider API url" )
220+ cmd .Flags ().StringVar (& gitIntegrationCreationOpts .APIURL , "provider-api-url" , "" , "Git provider API url" )
217221 cmd .Flags ().BoolVar (& store .Get ().BypassIngressClassCheck , "bypass-ingress-class-check" , false , "Disables the ingress class check during pre-installation" )
218222
219223 installationOpts .InsCloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {
@@ -235,16 +239,12 @@ func NewRuntimeInstallCommand() *cobra.Command {
235239func runtimeInstallCommandPreRunHandler (cmd * cobra.Command , opts * RuntimeInstallOptions ) error {
236240 handleCliStep (reporter .InstallPhasePreCheckStart , "Starting pre checks" , nil , false )
237241
238- if opts .versionStr != "" {
239- version , err := semver .NewVersion (opts .versionStr )
240- handleCliStep (reporter .InstallStepPreCheckValidateRuntimeVersion , "Validating runtime version" , err , false )
241- if err != nil {
242- return err
243- }
244- opts .Version = version
242+ err := getVersionIfExists (opts )
243+ handleCliStep (reporter .InstallStepPreCheckValidateRuntimeVersion , "Validating runtime version" , err , false )
244+ if err != nil {
245+ return err
245246 }
246247
247- var err error
248248 if opts .RuntimeName == "" {
249249 if ! store .Get ().Silent {
250250 err = getRuntimeNameFromUserInput (& opts .RuntimeName )
@@ -257,19 +257,11 @@ func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstall
257257 return err
258258 }
259259
260- isValid , err := IsValidName (opts .RuntimeName )
261- var errMsg string
260+ err = validateRuntimeName (opts .RuntimeName )
261+ handleCliStep ( reporter . InstallStepPreCheckRuntimeNameValidation , "Validating runtime name" , err , false )
262262 if err != nil {
263- errMsg = "failed to check the validity of the runtime name"
264- } else if ! isValid {
265- errMsg = "runtime name cannot have any uppercase letters, must start with a character, end with character or number, and be shorter than 63 chars"
266- }
267-
268- if errMsg != "" {
269- handleCliStep (reporter .InstallStepPreCheckRuntimeNameValidation , "Validating runtime name" , fmt .Errorf (errMsg ), false )
270- log .G (cmd .Context ()).Fatal (errMsg )
263+ log .G (cmd .Context ()).Fatal (fmt .Errorf ("%w" , err ))
271264 }
272- handleCliStep (reporter .InstallStepPreCheckRuntimeNameValidation , "Validating runtime name" , err , false )
273265
274266 err = getKubeContextNameFromUserSelect (cmd , & opts .kubeContext )
275267 handleCliStep (reporter .InstallStepPreCheckGetKubeContext , "Getting kube context name" , err , false )
@@ -301,6 +293,12 @@ func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstall
301293 return err
302294 }
303295
296+ err = ensureGitPAT (cmd , opts )
297+ handleCliStep (reporter .InstallStepPreCheckEnsureGitPAT , "Getting git personal access token" , err , false )
298+ if err != nil {
299+ return err
300+ }
301+
304302 err = askUserIfToInstallDemoResources (cmd , & opts .InstallDemoResources )
305303 handleCliStep (reporter .InstallStepPreCheckShouldInstallDemoResources , "Asking user is demo resources should be installed" , err , false )
306304 if err != nil {
@@ -650,12 +648,18 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
650648 return util .DecorateErrorWithDocsLink (fmt .Errorf ("failed to complete installation: %w" , timeoutErr ))
651649 }
652650
653- gitIntgErr := addDefaultGitIntegration (ctx , opts .RuntimeName , opts .GitIntegrationOpts )
651+ gitIntgErr := addDefaultGitIntegration (ctx , opts .RuntimeName , opts .GitIntegrationCreationOpts )
654652 handleCliStep (reporter .InstallStepCreateDefaultGitIntegration , "Creating a default git integration" , gitIntgErr , true )
655653 if gitIntgErr != nil {
656654 return util .DecorateErrorWithDocsLink (fmt .Errorf ("failed to create default git integration: %w" , gitIntgErr ))
657655 }
658656
657+ gitIntgErr = registerUserToGitIntegration (ctx , opts .RuntimeName , opts .GitIntegrationRegistrationOpts )
658+ handleCliStep (reporter .InstallStepRegisterToDefaultGitIntegration , "Registering user to the default git integration" , gitIntgErr , true )
659+ if gitIntgErr != nil {
660+ return util .DecorateErrorWithDocsLink (fmt .Errorf ("failed to register user to the default git integration: %w" , gitIntgErr ))
661+ }
662+
659663 installationSuccessMsg := fmt .Sprintf ("Runtime '%s' installed successfully" , opts .RuntimeName )
660664 summaryArr = append (summaryArr , summaryLog {installationSuccessMsg , Info })
661665 log .G (ctx ).Infof (installationSuccessMsg )
@@ -678,6 +682,18 @@ func addDefaultGitIntegration(ctx context.Context, runtime string, opts *apmodel
678682 return nil
679683}
680684
685+ func registerUserToGitIntegration (ctx context.Context , runtime string , opts * apmodel.RegisterToGitIntegrationArgs ) error {
686+ appProxyClient , err := cfConfig .NewClient ().AppProxy (ctx , runtime , store .Get ().InsecureIngressHost )
687+ if err != nil {
688+ return fmt .Errorf ("failed to build app-proxy client: %w" , err )
689+ }
690+ if err := RunGitIntegrationRegisterCommand (ctx , appProxyClient , opts ); err != nil {
691+ return err
692+ }
693+
694+ return nil
695+ }
696+
681697func installComponents (ctx context.Context , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
682698 var err error
683699 if opts .IngressHost != "" {
@@ -1016,18 +1032,19 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
10161032 handleCliStep (reporter .UninstallPhaseStart , "Uninstall phase started" , nil , false )
10171033
10181034 // check whether the runtime exists
1035+ var err error
10191036 if ! opts .SkipChecks {
1020- _ , err : = cfConfig .NewClient ().V2 ().Runtime ().Get (ctx , opts .RuntimeName )
1021- handleCliStep ( reporter . UninstallStepCheckRuntimeExists , "Checking if runtime exists" , err , true )
1022- if err != nil {
1023- summaryArr = append ( summaryArr , summaryLog { "you can attempt to uninstall again with the \" --skip-checks \" flag" , Info })
1024- return err
1025- }
1037+ _ , err = cfConfig .NewClient ().V2 ().Runtime ().Get (ctx , opts .RuntimeName )
1038+ }
1039+ handleCliStep ( reporter . UninstallStepCheckRuntimeExists , "Checking if runtime exists" , err , true )
1040+ if err != nil {
1041+ summaryArr = append ( summaryArr , summaryLog { "you can attempt to uninstall again with the \" --skip-checks \" flag" , Info })
1042+ return err
10261043 }
10271044
10281045 log .G (ctx ).Infof ("Uninstalling runtime '%s'" , opts .RuntimeName )
10291046
1030- err : = apcmd .RunRepoUninstall (ctx , & apcmd.RepoUninstallOptions {
1047+ err = apcmd .RunRepoUninstall (ctx , & apcmd.RepoUninstallOptions {
10311048 Namespace : opts .RuntimeName ,
10321049 Timeout : opts .Timeout ,
10331050 CloneOptions : opts .CloneOpts ,
@@ -1202,12 +1219,14 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
12021219 infoStr := fmt .Sprintf ("Creating app '%s'" , component .Name )
12031220 log .G (ctx ).Infof (infoStr )
12041221 err = component .CreateApp (ctx , nil , opts .CloneOpts , opts .RuntimeName , store .Get ().CFComponentType , "" , "" )
1205- handleCliStep (reporter .UpgradeStepCreateApp , infoStr , err , false )
12061222 if err != nil {
1207- return fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
1223+ err = fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
1224+ break
12081225 }
12091226 }
12101227
1228+ handleCliStep (reporter .UpgradeStepCreateApps , "Creating apps" , err , false )
1229+
12111230 return nil
12121231}
12131232
@@ -1668,17 +1687,21 @@ func createCodefreshArgoDashboardAgent(ctx context.Context, path string, cloneOp
16681687func ensureGitIntegrationOpts (opts * RuntimeInstallOptions ) error {
16691688 var err error
16701689 if opts .InsCloneOpts .Provider == "" {
1671- if opts .GitIntegrationOpts .Provider , err = inferProviderFromCloneURL (opts .InsCloneOpts .URL ()); err != nil {
1690+ if opts .GitIntegrationCreationOpts .Provider , err = inferProviderFromCloneURL (opts .InsCloneOpts .URL ()); err != nil {
16721691 return err
16731692 }
16741693 }
16751694
1676- if opts .GitIntegrationOpts .APIURL == "" {
1677- if opts .GitIntegrationOpts .APIURL , err = inferAPIURLForGitProvider (opts .GitIntegrationOpts .Provider ); err != nil {
1695+ if opts .GitIntegrationCreationOpts .APIURL == "" {
1696+ if opts .GitIntegrationCreationOpts .APIURL , err = inferAPIURLForGitProvider (opts .GitIntegrationCreationOpts .Provider ); err != nil {
16781697 return err
16791698 }
16801699 }
16811700
1701+ if opts .GitIntegrationRegistrationOpts .Token == "" {
1702+ return fmt .Errorf ("git personal access token is missing" )
1703+ }
1704+
16821705 return nil
16831706}
16841707
@@ -1788,3 +1811,29 @@ func createAnalyticsReporter(ctx context.Context, flow reporter.FlowType) {
17881811
17891812 reporter .Init (user , flow )
17901813}
1814+
1815+ func validateRuntimeName (runtime string ) error {
1816+ var err error
1817+ isValid , err := IsValidName (runtime )
1818+ if err != nil {
1819+ err = fmt .Errorf ("failed to check the validity of the runtime name: %w" , err )
1820+ } else if ! isValid {
1821+ err = fmt .Errorf ("runtime name cannot have any uppercase letters, must start with a character, end with character or number, and be shorter than 63 chars" )
1822+ }
1823+
1824+ return err
1825+ }
1826+
1827+ func getVersionIfExists (opts * RuntimeInstallOptions ) error {
1828+ if opts .versionStr != "" {
1829+ log .G ().Infof ("vesionStr: %s" , opts .versionStr )
1830+ version , err := semver .NewVersion (opts .versionStr )
1831+ handleCliStep (reporter .InstallStepPreCheckValidateRuntimeVersion , "Validating runtime version" , err , false )
1832+ if err != nil {
1833+ return err
1834+ }
1835+ opts .Version = version
1836+ log .G ().Infof ("opts.Version: %s" , opts .Version )
1837+ }
1838+ return nil
1839+ }
0 commit comments