@@ -26,6 +26,7 @@ import (
26
26
"github.com/codefresh-io/cli-v2/pkg/runtime"
27
27
"github.com/codefresh-io/cli-v2/pkg/store"
28
28
"github.com/codefresh-io/cli-v2/pkg/util"
29
+ apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
29
30
argodashboardutil "github.com/codefresh-io/cli-v2/pkg/util/argo-agent"
30
31
cdutil "github.com/codefresh-io/cli-v2/pkg/util/cd"
31
32
eventsutil "github.com/codefresh-io/cli-v2/pkg/util/events"
@@ -46,7 +47,6 @@ import (
46
47
47
48
"github.com/Masterminds/semver/v3"
48
49
"github.com/ghodss/yaml"
49
- "github.com/go-git/go-billy/v5/memfs"
50
50
billyUtils "github.com/go-git/go-billy/v5/util"
51
51
"github.com/juju/ansiterm"
52
52
"github.com/spf13/cobra"
@@ -191,15 +191,13 @@ func NewRuntimeInstallCommand() *cobra.Command {
191
191
cmd .Flags ().StringVar (& versionStr , "version" , "" , "The runtime version to install, defaults to latest" )
192
192
cmd .Flags ().DurationVar (& store .Get ().WaitTimeout , "wait-timeout" , store .Get ().WaitTimeout , "How long to wait for the runtime components to be ready" )
193
193
194
- insCloneOpts = git . AddFlags (cmd , & git. AddFlagsOptions {
194
+ insCloneOpts = apu . AddCloneFlags (cmd , & apu. CloneFlagsOptions {
195
195
CreateIfNotExist : true ,
196
- FS : memfs .New (),
197
196
})
198
- gsCloneOpts = git . AddFlags (cmd , & git. AddFlagsOptions {
197
+ gsCloneOpts = apu . AddCloneFlags (cmd , & apu. CloneFlagsOptions {
199
198
Prefix : "git-src" ,
200
199
Optional : true ,
201
200
CreateIfNotExist : true ,
202
- FS : memfs .New (),
203
201
})
204
202
f = kube .AddFlags (cmd .Flags ())
205
203
@@ -265,7 +263,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
265
263
rt .Spec .Cluster = server
266
264
rt .Spec .IngressHost = opts .IngressHost
267
265
268
- log .G (ctx ).WithField ("version" , rt .Spec .Version ).Infof ("installing runtime '%s'" , opts .RuntimeName )
266
+ log .G (ctx ).WithField ("version" , rt .Spec .Version ).Infof ("Installing runtime '%s'" , opts .RuntimeName )
269
267
err = apcmd .RunRepoBootstrap (ctx , & apcmd.RepoBootstrapOptions {
270
268
AppSpecifier : rt .Spec .FullSpecifier (),
271
269
Namespace : opts .RuntimeName ,
@@ -298,7 +296,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
298
296
}
299
297
300
298
for _ , component := range rt .Spec .Components {
301
- log .G (ctx ).Infof ("creating component '%s'" , component .Name )
299
+ log .G (ctx ).Infof ("Creating component '%s'" , component .Name )
302
300
if err = component .CreateApp (ctx , opts .KubeFactory , opts .insCloneOpts , opts .RuntimeName , store .Get ().CFComponentType ); err != nil {
303
301
return fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
304
302
}
@@ -338,13 +336,13 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
338
336
var wg sync.WaitGroup
339
337
340
338
wg .Add (1 )
341
- err = intervalCheckIsRuntimePersisted (15000 , ctx , opts .RuntimeName , & wg )
339
+ err = intervalCheckIsRuntimePersisted (ctx , opts .RuntimeName , & wg )
342
340
if err != nil {
343
- return fmt .Errorf ("failed to complete installation. Error : %w" , err )
341
+ return fmt .Errorf ("failed to complete installation: %w" , err )
344
342
}
345
343
wg .Wait ()
346
344
347
- log .G (ctx ).Infof ("done installing runtime '%s'" , opts .RuntimeName )
345
+ log .G (ctx ).Infof ("Done installing runtime '%s'" , opts .RuntimeName )
348
346
return nil
349
347
}
350
348
@@ -415,29 +413,37 @@ func checkExistingRuntimes(ctx context.Context, runtime string) error {
415
413
return fmt .Errorf ("runtime '%s' already exists" , runtime )
416
414
}
417
415
418
- func intervalCheckIsRuntimePersisted (milliseconds int , ctx context.Context , runtimeName string , wg * sync.WaitGroup ) error {
419
- interval := time .Duration (milliseconds ) * time .Millisecond
420
- ticker := time .NewTicker (interval )
421
- var err error
416
+ func intervalCheckIsRuntimePersisted (ctx context.Context , runtimeName string , wg * sync.WaitGroup ) error {
417
+ maxRetries := 60 // up to 10 min
418
+ longerThanUsualCount := 30 // after 5 min
419
+ waitMsg := "Waiting for the runtime installation to complete"
420
+ longetThanUsualMsg := waitMsg + " (this is taking longer than usual, you might need to check your cluster for errors)"
421
+ stop := util .WithSpinner (ctx , waitMsg )
422
+ ticker := time .NewTicker (time .Second * 10 )
422
423
423
- for retries := 20 ; retries > 0 ; <- ticker .C {
424
- retries --
425
- fmt .Println ("waiting for the runtime installation to complete..." )
424
+ for triesLeft := maxRetries ; triesLeft > 0 ; triesLeft , _ = triesLeft - 1 , <- ticker .C {
426
425
runtime , err := cfConfig .NewClient ().V2 ().Runtime ().Get (ctx , runtimeName )
427
426
if err != nil {
427
+ stop ()
428
428
return fmt .Errorf ("failed to complete the runtime installation. Error: %w" , err )
429
429
}
430
430
431
- if runtime .InstallationStatus != model .InstallationStatusCompleted {
432
- continue
431
+ if runtime .InstallationStatus == model .InstallationStatusCompleted {
432
+ stop ()
433
+ wg .Done ()
434
+ ticker .Stop ()
435
+ return nil
433
436
}
434
437
435
- wg .Done ()
436
- ticker .Stop ()
437
- return nil
438
+ if triesLeft == longerThanUsualCount {
439
+ stop ()
440
+ stop = util .WithSpinner (ctx , longetThanUsualMsg )
441
+ }
438
442
}
439
443
440
- return fmt .Errorf ("failed to complete the runtime installation due to timeout. Error: %w" , err )
444
+ stop ()
445
+
446
+ return fmt .Errorf ("timed out while waiting for runtime installation to complete" )
441
447
}
442
448
443
449
func NewRuntimeListCommand () * cobra.Command {
@@ -459,7 +465,7 @@ func RunRuntimeList(ctx context.Context) error {
459
465
}
460
466
461
467
if len (runtimes ) == 0 {
462
- log .G (ctx ).Info ("no runtimes were found" )
468
+ log .G (ctx ).Info ("No runtimes were found" )
463
469
return nil
464
470
}
465
471
@@ -559,9 +565,7 @@ func NewRuntimeUninstallCommand() *cobra.Command {
559
565
cmd .Flags ().BoolVar (& skipChecks , "skip-checks" , false , "If true, will not verify that runtime exists before uninstalling" )
560
566
cmd .Flags ().DurationVar (& store .Get ().WaitTimeout , "wait-timeout" , store .Get ().WaitTimeout , "How long to wait for the runtime components to be deleted" )
561
567
562
- cloneOpts = git .AddFlags (cmd , & git.AddFlagsOptions {
563
- FS : memfs .New (),
564
- })
568
+ cloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {})
565
569
f = kube .AddFlags (cmd .Flags ())
566
570
567
571
return cmd
@@ -577,7 +581,7 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
577
581
}
578
582
}
579
583
580
- log .G (ctx ).Infof ("uninstalling runtime '%s'" , opts .RuntimeName )
584
+ log .G (ctx ).Infof ("Uninstalling runtime '%s'" , opts .RuntimeName )
581
585
582
586
if err := apcmd .RunRepoUninstall (ctx , & apcmd.RepoUninstallOptions {
583
587
Namespace : opts .RuntimeName ,
@@ -588,13 +592,13 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
588
592
return fmt .Errorf ("failed uninstalling runtime: %w" , err )
589
593
}
590
594
591
- log .G (ctx ).Infof ("deleting runtime '%s' from the platform" , opts .RuntimeName )
595
+ log .G (ctx ).Infof ("Deleting runtime '%s' from the platform" , opts .RuntimeName )
592
596
593
597
if _ , err := cfConfig .NewClient ().V2 ().Runtime ().Delete (ctx , opts .RuntimeName ); err != nil {
594
598
return fmt .Errorf ("failed to delete runtime from the platform: %w" , err )
595
599
}
596
600
597
- log .G (ctx ).Infof ("done uninstalling runtime '%s'" , opts .RuntimeName )
601
+ log .G (ctx ).Infof ("Done uninstalling runtime '%s'" , opts .RuntimeName )
598
602
return nil
599
603
}
600
604
@@ -653,9 +657,7 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
653
657
}
654
658
655
659
cmd .Flags ().StringVar (& versionStr , "version" , "" , "The runtime version to upgrade to, defaults to latest" )
656
- cloneOpts = git .AddFlags (cmd , & git.AddFlagsOptions {
657
- FS : memfs .New (),
658
- })
660
+ cloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {})
659
661
660
662
return cmd
661
663
}
@@ -689,7 +691,8 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
689
691
return fmt .Errorf ("failed to upgrade runtime: %w" , err )
690
692
}
691
693
692
- if _ , err = r .Persist (ctx , & git.PushOptions {CommitMsg : fmt .Sprintf ("Upgraded to %s" , newRt .Spec .Version )}); err != nil {
694
+ log .G (ctx ).Info ("Pushing new runtime definition" )
695
+ if err := apu .PushWithMessage (ctx , r , fmt .Sprintf ("Upgraded to %s" , newRt .Spec .Version )); err != nil {
693
696
return err
694
697
}
695
698
@@ -717,10 +720,9 @@ func persistRuntime(ctx context.Context, cloneOpts *git.CloneOptions, rt *runtim
717
720
return err
718
721
}
719
722
720
- _ , err = r .Persist (ctx , & git.PushOptions {
721
- CommitMsg : "Persisted runtime data" ,
722
- })
723
- return err
723
+ log .G (ctx ).Info ("Pushing runtime definition to the installation repo" )
724
+
725
+ return apu .PushWithMessage (ctx , r , "Persisted runtime data" )
724
726
}
725
727
726
728
func createWorkflowsIngress (ctx context.Context , cloneOpts * git.CloneOptions , rt * runtime.Runtime ) error {
@@ -768,10 +770,9 @@ func createWorkflowsIngress(ctx context.Context, cloneOpts *git.CloneOptions, rt
768
770
return err
769
771
}
770
772
771
- _ , err = r .Persist (ctx , & git.PushOptions {
772
- CommitMsg : "Created Workflows Ingress" ,
773
- })
774
- return err
773
+ log .G (ctx ).Info ("Pushing Argo Workflows ingress manifests" )
774
+
775
+ return apu .PushWithMessage (ctx , r , "Created Workflows Ingress" )
775
776
}
776
777
777
778
func createEventsReporter (ctx context.Context , cloneOpts * git.CloneOptions , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
@@ -817,10 +818,9 @@ func createEventsReporter(ctx context.Context, cloneOpts *git.CloneOptions, opts
817
818
return err
818
819
}
819
820
820
- _ , err = r .Persist (ctx , & git.PushOptions {
821
- CommitMsg : "Created Codefresh Event Reporter" ,
822
- })
823
- return err
821
+ log .G (ctx ).Info ("Pushing Event Reporter manifests" )
822
+
823
+ return apu .PushWithMessage (ctx , r , "Created Codefresh Event Reporter" )
824
824
}
825
825
826
826
func createCodefreshArgoAgentReporter (ctx context.Context , cloneOpts * git.CloneOptions , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
@@ -844,10 +844,9 @@ func createCodefreshArgoAgentReporter(ctx context.Context, cloneOpts *git.CloneO
844
844
return err
845
845
}
846
846
847
- _ , err = r .Persist (ctx , & git.PushOptions {
848
- CommitMsg : "Created ArgoCD Agent Reporter" ,
849
- })
850
- return err
847
+ log .G (ctx ).Info ("Pushing ArgoCD Agent manifests" )
848
+
849
+ return apu .PushWithMessage (ctx , r , "Created ArgoCD Agent Reporter" )
851
850
}
852
851
853
852
func createWorkflowReporter (ctx context.Context , cloneOpts * git.CloneOptions , opts * RuntimeInstallOptions ) error {
@@ -878,10 +877,9 @@ func createWorkflowReporter(ctx context.Context, cloneOpts *git.CloneOptions, op
878
877
return err
879
878
}
880
879
881
- _ , err = r .Persist (ctx , & git.PushOptions {
882
- CommitMsg : "Created Codefresh Workflow Reporter" ,
883
- })
884
- return err
880
+ log .G (ctx ).Info ("Pushing Codefresh Workflow Reporter mainifests" )
881
+
882
+ return apu .PushWithMessage (ctx , r , "Created Codefresh Workflow Reporter" )
885
883
}
886
884
887
885
func updateProject (repofs fs.FS , rt * runtime.Runtime ) error {
0 commit comments