@@ -123,15 +123,15 @@ func NewRuntimeInstallCommand() *cobra.Command {
123123# To run this command you need to create a personal access token for your git provider
124124# and provide it using:
125125
126- export INSTALL_GIT_TOKEN =<token>
126+ export GIT_TOKEN =<token>
127127
128128# or with the flag:
129129
130- --install- git-token <token>
130+ --git-token <token>
131131
132132# Adds a new runtime
133133
134- <BIN> runtime install runtime-name --install- repo gitops_repo
134+ <BIN> runtime install runtime-name --repo gitops_repo
135135` ),
136136 PreRun : func (_ * cobra.Command , _ []string ) {
137137 if gsCloneOpts .Auth .Password == "" {
@@ -206,6 +206,32 @@ func NewRuntimeInstallCommand() *cobra.Command {
206206 return cmd
207207}
208208
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+
209235func RunRuntimeInstall (ctx context.Context , opts * RuntimeInstallOptions ) error {
210236 if err := preInstallationChecks (ctx , opts ); err != nil {
211237 return fmt .Errorf ("pre installation checks failed: %w" , err )
@@ -216,17 +242,26 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
216242 return fmt .Errorf ("failed to download runtime definition: %w" , err )
217243 }
218244
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 ( )
222248 }
223249
224- opts .RuntimeToken = runtimeCreationResponse .NewAccessToken
225250 server , err := util .CurrentServer ()
226251 if err != nil {
227252 return fmt .Errorf ("failed to get current server address: %w" , err )
228253 }
229254
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+
230265 rt .Spec .Cluster = server
231266 rt .Spec .IngressHost = opts .IngressHost
232267
@@ -388,20 +423,18 @@ func intervalCheckIsRuntimePersisted(milliseconds int, ctx context.Context, runt
388423 for retries := 20 ; retries > 0 ; <- ticker .C {
389424 retries --
390425 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 )
393427 if err != nil {
394- continue
428+ return fmt . Errorf ( "failed to complete the runtime installation. Error: %w" , err )
395429 }
396430
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
403433 }
404434
435+ wg .Done ()
436+ ticker .Stop ()
437+ return nil
405438 }
406439
407440 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 {
431464 }
432465
433466 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 " )
435468 if err != nil {
436469 return err
437470 }
@@ -444,6 +477,7 @@ func RunRuntimeList(ctx context.Context) error {
444477 syncStatus := rt .SyncStatus
445478 healthStatus := rt .HealthStatus
446479 healthMessage := "N/A"
480+ installationStatus := rt .InstallationStatus
447481
448482 if rt .Metadata .Namespace != nil {
449483 namespace = * rt .Metadata .Namespace
@@ -461,14 +495,15 @@ func RunRuntimeList(ctx context.Context) error {
461495 healthMessage = * rt .HealthMessage
462496 }
463497
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 " ,
465499 name ,
466500 namespace ,
467501 cluster ,
468502 version ,
469503 syncStatus ,
470504 healthStatus ,
471505 healthMessage ,
506+ installationStatus ,
472507 )
473508 if err != nil {
474509 return err
0 commit comments