@@ -123,15 +123,15 @@ func NewRuntimeInstallCommand() *cobra.Command {
123
123
# To run this command you need to create a personal access token for your git provider
124
124
# and provide it using:
125
125
126
- export INSTALL_GIT_TOKEN =<token>
126
+ export GIT_TOKEN =<token>
127
127
128
128
# or with the flag:
129
129
130
- --install- git-token <token>
130
+ --git-token <token>
131
131
132
132
# Adds a new runtime
133
133
134
- <BIN> runtime install runtime-name --install- repo gitops_repo
134
+ <BIN> runtime install runtime-name --repo gitops_repo
135
135
` ),
136
136
PreRun : func (_ * cobra.Command , _ []string ) {
137
137
if gsCloneOpts .Auth .Password == "" {
@@ -206,6 +206,32 @@ func NewRuntimeInstallCommand() *cobra.Command {
206
206
return cmd
207
207
}
208
208
209
+ func getComponents (rt * runtime.Runtime , opts * RuntimeInstallOptions ) []string {
210
+ var componentNames []string
211
+ for _ , component := range rt .Spec .Components {
212
+ componentNames = append (componentNames , fmt .Sprintf ("%s-%s" , opts .RuntimeName , component .Name ))
213
+ }
214
+
215
+ // should find a more dynamic way to get these additional components
216
+ additionalComponents := []string {"events-reporter" , "workflow-reporter" }
217
+ for _ , additionalComponentName := range additionalComponents {
218
+ componentNames = append (componentNames , fmt .Sprintf ("%s-%s" , opts .RuntimeName , additionalComponentName ))
219
+ }
220
+ componentNames = append (componentNames , "argo-cd" )
221
+
222
+ return componentNames
223
+ }
224
+
225
+ func createRuntimeOnPlatform (ctx context.Context , runtimeName string , server string , runtimeVersion string , ingressHost string , componentNames []string ) (string , error ) {
226
+ runtimeCreationResponse , err := cfConfig .NewClient ().V2 ().Runtime ().Create (ctx , runtimeVersion , server , runtimeVersion , ingressHost , componentNames )
227
+
228
+ if runtimeCreationResponse .ErrorMessage != nil {
229
+ return runtimeCreationResponse .NewAccessToken , fmt .Errorf ("failed to create a new runtime: %s. Error: %w" , * runtimeCreationResponse .ErrorMessage , err )
230
+ }
231
+
232
+ return runtimeCreationResponse .NewAccessToken , nil
233
+ }
234
+
209
235
func RunRuntimeInstall (ctx context.Context , opts * RuntimeInstallOptions ) error {
210
236
if err := preInstallationChecks (ctx , opts ); err != nil {
211
237
return fmt .Errorf ("pre installation checks failed: %w" , err )
@@ -216,17 +242,26 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
216
242
return fmt .Errorf ("failed to download runtime definition: %w" , err )
217
243
}
218
244
219
- runtimeCreationResponse , err := cfConfig . NewClient (). V2 (). Runtime (). Create ( ctx , opts . RuntimeName )
220
- if err != nil {
221
- return fmt . Errorf ( "failed to create a new runtime: %w" , err )
245
+ runtimeVersion := "v99.99.99"
246
+ if rt . Spec . Version != nil { // in dev mode
247
+ runtimeVersion = rt . Spec . Version . String ( )
222
248
}
223
249
224
- opts .RuntimeToken = runtimeCreationResponse .NewAccessToken
225
250
server , err := util .CurrentServer ()
226
251
if err != nil {
227
252
return fmt .Errorf ("failed to get current server address: %w" , err )
228
253
}
229
254
255
+ componentNames := getComponents (rt , opts )
256
+
257
+ token , err := createRuntimeOnPlatform (ctx , opts .RuntimeName , server , runtimeVersion , opts .IngressHost , componentNames )
258
+
259
+ if err != nil {
260
+ return fmt .Errorf ("failed to create a new runtime: %w" , err )
261
+ }
262
+
263
+ opts .RuntimeToken = token
264
+
230
265
rt .Spec .Cluster = server
231
266
rt .Spec .IngressHost = opts .IngressHost
232
267
@@ -388,20 +423,18 @@ func intervalCheckIsRuntimePersisted(milliseconds int, ctx context.Context, runt
388
423
for retries := 20 ; retries > 0 ; <- ticker .C {
389
424
retries --
390
425
fmt .Println ("waiting for the runtime installation to complete..." )
391
- var runtimes []model.Runtime
392
- runtimes , err = cfConfig .NewClient ().V2 ().Runtime ().List (ctx )
426
+ runtime , err := cfConfig .NewClient ().V2 ().Runtime ().Get (ctx , runtimeName )
393
427
if err != nil {
394
- continue
428
+ return fmt . Errorf ( "failed to complete the runtime installation. Error: %w" , err )
395
429
}
396
430
397
- for _ , rt := range runtimes {
398
- if rt .Metadata .Name == runtimeName {
399
- wg .Done ()
400
- ticker .Stop ()
401
- return nil
402
- }
431
+ if runtime .InstallationStatus != model .InstallationStatusCompleted {
432
+ continue
403
433
}
404
434
435
+ wg .Done ()
436
+ ticker .Stop ()
437
+ return nil
405
438
}
406
439
407
440
return fmt .Errorf ("failed to complete the runtime installation due to timeout. Error: %w" , err )
@@ -431,7 +464,7 @@ func RunRuntimeList(ctx context.Context) error {
431
464
}
432
465
433
466
tb := ansiterm .NewTabWriter (os .Stdout , 0 , 0 , 4 , ' ' , 0 )
434
- _ , err = fmt .Fprintln (tb , "NAME\t NAMESPACE\t CLUSTER\t VERSION\t SYNC_STATUS\t HEALTH_STATUS\t HEALTH_MESSAGE" )
467
+ _ , err = fmt .Fprintln (tb , "NAME\t NAMESPACE\t CLUSTER\t VERSION\t SYNC_STATUS\t HEALTH_STATUS\t HEALTH_MESSAGE\t INSTALLATION_STATUS " )
435
468
if err != nil {
436
469
return err
437
470
}
@@ -444,6 +477,7 @@ func RunRuntimeList(ctx context.Context) error {
444
477
syncStatus := rt .SyncStatus
445
478
healthStatus := rt .HealthStatus
446
479
healthMessage := "N/A"
480
+ installationStatus := rt .InstallationStatus
447
481
448
482
if rt .Metadata .Namespace != nil {
449
483
namespace = * rt .Metadata .Namespace
@@ -461,14 +495,15 @@ func RunRuntimeList(ctx context.Context) error {
461
495
healthMessage = * rt .HealthMessage
462
496
}
463
497
464
- _ , err = fmt .Fprintf (tb , "%s\t %s\t %s\t %s\t %s\t %s\t %s\n " ,
498
+ _ , err = fmt .Fprintf (tb , "%s\t %s\t %s\t %s\t %s\t %s\t %s\t %s \ n " ,
465
499
name ,
466
500
namespace ,
467
501
cluster ,
468
502
version ,
469
503
syncStatus ,
470
504
healthStatus ,
471
505
healthMessage ,
506
+ installationStatus ,
472
507
)
473
508
if err != nil {
474
509
return err
0 commit comments