@@ -69,22 +69,23 @@ import (
69
69
70
70
type (
71
71
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
88
89
}
89
90
RuntimeUninstallOptions struct {
90
91
RuntimeName string
@@ -149,11 +150,14 @@ func NewRuntimeCommand() *cobra.Command {
149
150
150
151
func NewRuntimeInstallCommand () * cobra.Command {
151
152
var (
152
- gitIntegrationOpts = apmodel.AddGitIntegrationArgs {
153
+ gitIntegrationCreationOpts = apmodel.AddGitIntegrationArgs {
153
154
SharingPolicy : apmodel .SharingPolicyAllUsersInAccount ,
154
155
}
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
157
161
)
158
162
159
163
cmd := & cobra.Command {
@@ -191,7 +195,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
191
195
"Runtime name" : installationOpts .RuntimeName ,
192
196
"Repository URL" : installationOpts .InsCloneOpts .Repo ,
193
197
"Ingress host" : installationOpts .IngressHost ,
194
- "Ingress class" : installationOpts .IngressClass ,
198
+ "Ingress class" : installationOpts .IngressClass ,
195
199
"Installing demo resources" : strconv .FormatBool (installationOpts .InstallDemoResources ),
196
200
}
197
201
@@ -213,7 +217,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
213
217
cmd .Flags ().StringVar (& installationOpts .versionStr , "version" , "" , "The runtime version to install (default: latest)" )
214
218
cmd .Flags ().BoolVar (& installationOpts .InstallDemoResources , "demo-resources" , true , "Installs demo resources (default: true)" )
215
219
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" )
217
221
cmd .Flags ().BoolVar (& store .Get ().BypassIngressClassCheck , "bypass-ingress-class-check" , false , "Disables the ingress class check during pre-installation" )
218
222
219
223
installationOpts .InsCloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {
@@ -235,16 +239,12 @@ func NewRuntimeInstallCommand() *cobra.Command {
235
239
func runtimeInstallCommandPreRunHandler (cmd * cobra.Command , opts * RuntimeInstallOptions ) error {
236
240
handleCliStep (reporter .InstallPhasePreCheckStart , "Starting pre checks" , nil , false )
237
241
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
245
246
}
246
247
247
- var err error
248
248
if opts .RuntimeName == "" {
249
249
if ! store .Get ().Silent {
250
250
err = getRuntimeNameFromUserInput (& opts .RuntimeName )
@@ -257,19 +257,11 @@ func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstall
257
257
return err
258
258
}
259
259
260
- isValid , err := IsValidName (opts .RuntimeName )
261
- var errMsg string
260
+ err = validateRuntimeName (opts .RuntimeName )
261
+ handleCliStep ( reporter . InstallStepPreCheckRuntimeNameValidation , "Validating runtime name" , err , false )
262
262
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 ))
271
264
}
272
- handleCliStep (reporter .InstallStepPreCheckRuntimeNameValidation , "Validating runtime name" , err , false )
273
265
274
266
err = getKubeContextNameFromUserSelect (cmd , & opts .kubeContext )
275
267
handleCliStep (reporter .InstallStepPreCheckGetKubeContext , "Getting kube context name" , err , false )
@@ -301,6 +293,12 @@ func runtimeInstallCommandPreRunHandler(cmd *cobra.Command, opts *RuntimeInstall
301
293
return err
302
294
}
303
295
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
+
304
302
err = askUserIfToInstallDemoResources (cmd , & opts .InstallDemoResources )
305
303
handleCliStep (reporter .InstallStepPreCheckShouldInstallDemoResources , "Asking user is demo resources should be installed" , err , false )
306
304
if err != nil {
@@ -650,12 +648,18 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
650
648
return util .DecorateErrorWithDocsLink (fmt .Errorf ("failed to complete installation: %w" , timeoutErr ))
651
649
}
652
650
653
- gitIntgErr := addDefaultGitIntegration (ctx , opts .RuntimeName , opts .GitIntegrationOpts )
651
+ gitIntgErr := addDefaultGitIntegration (ctx , opts .RuntimeName , opts .GitIntegrationCreationOpts )
654
652
handleCliStep (reporter .InstallStepCreateDefaultGitIntegration , "Creating a default git integration" , gitIntgErr , true )
655
653
if gitIntgErr != nil {
656
654
return util .DecorateErrorWithDocsLink (fmt .Errorf ("failed to create default git integration: %w" , gitIntgErr ))
657
655
}
658
656
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
+
659
663
installationSuccessMsg := fmt .Sprintf ("Runtime '%s' installed successfully" , opts .RuntimeName )
660
664
summaryArr = append (summaryArr , summaryLog {installationSuccessMsg , Info })
661
665
log .G (ctx ).Infof (installationSuccessMsg )
@@ -678,6 +682,18 @@ func addDefaultGitIntegration(ctx context.Context, runtime string, opts *apmodel
678
682
return nil
679
683
}
680
684
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
+
681
697
func installComponents (ctx context.Context , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
682
698
var err error
683
699
if opts .IngressHost != "" {
@@ -1016,18 +1032,19 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
1016
1032
handleCliStep (reporter .UninstallPhaseStart , "Uninstall phase started" , nil , false )
1017
1033
1018
1034
// check whether the runtime exists
1035
+ var err error
1019
1036
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
1026
1043
}
1027
1044
1028
1045
log .G (ctx ).Infof ("Uninstalling runtime '%s'" , opts .RuntimeName )
1029
1046
1030
- err : = apcmd .RunRepoUninstall (ctx , & apcmd.RepoUninstallOptions {
1047
+ err = apcmd .RunRepoUninstall (ctx , & apcmd.RepoUninstallOptions {
1031
1048
Namespace : opts .RuntimeName ,
1032
1049
Timeout : opts .Timeout ,
1033
1050
CloneOptions : opts .CloneOpts ,
@@ -1202,12 +1219,14 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
1202
1219
infoStr := fmt .Sprintf ("Creating app '%s'" , component .Name )
1203
1220
log .G (ctx ).Infof (infoStr )
1204
1221
err = component .CreateApp (ctx , nil , opts .CloneOpts , opts .RuntimeName , store .Get ().CFComponentType , "" , "" )
1205
- handleCliStep (reporter .UpgradeStepCreateApp , infoStr , err , false )
1206
1222
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
1208
1225
}
1209
1226
}
1210
1227
1228
+ handleCliStep (reporter .UpgradeStepCreateApps , "Creating apps" , err , false )
1229
+
1211
1230
return nil
1212
1231
}
1213
1232
@@ -1668,17 +1687,21 @@ func createCodefreshArgoDashboardAgent(ctx context.Context, path string, cloneOp
1668
1687
func ensureGitIntegrationOpts (opts * RuntimeInstallOptions ) error {
1669
1688
var err error
1670
1689
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 {
1672
1691
return err
1673
1692
}
1674
1693
}
1675
1694
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 {
1678
1697
return err
1679
1698
}
1680
1699
}
1681
1700
1701
+ if opts .GitIntegrationRegistrationOpts .Token == "" {
1702
+ return fmt .Errorf ("git personal access token is missing" )
1703
+ }
1704
+
1682
1705
return nil
1683
1706
}
1684
1707
@@ -1788,3 +1811,29 @@ func createAnalyticsReporter(ctx context.Context, flow reporter.FlowType) {
1788
1811
1789
1812
reporter .Init (user , flow )
1790
1813
}
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