@@ -26,6 +26,7 @@ import (
2626 "github.com/codefresh-io/cli-v2/pkg/runtime"
2727 "github.com/codefresh-io/cli-v2/pkg/store"
2828 "github.com/codefresh-io/cli-v2/pkg/util"
29+ apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
2930 argodashboardutil "github.com/codefresh-io/cli-v2/pkg/util/argo-agent"
3031 cdutil "github.com/codefresh-io/cli-v2/pkg/util/cd"
3132 eventsutil "github.com/codefresh-io/cli-v2/pkg/util/events"
@@ -46,7 +47,6 @@ import (
4647
4748 "github.com/Masterminds/semver/v3"
4849 "github.com/ghodss/yaml"
49- "github.com/go-git/go-billy/v5/memfs"
5050 billyUtils "github.com/go-git/go-billy/v5/util"
5151 "github.com/juju/ansiterm"
5252 "github.com/spf13/cobra"
@@ -191,15 +191,13 @@ func NewRuntimeInstallCommand() *cobra.Command {
191191 cmd .Flags ().StringVar (& versionStr , "version" , "" , "The runtime version to install, defaults to latest" )
192192 cmd .Flags ().DurationVar (& store .Get ().WaitTimeout , "wait-timeout" , store .Get ().WaitTimeout , "How long to wait for the runtime components to be ready" )
193193
194- insCloneOpts = git . AddFlags (cmd , & git. AddFlagsOptions {
194+ insCloneOpts = apu . AddCloneFlags (cmd , & apu. CloneFlagsOptions {
195195 CreateIfNotExist : true ,
196- FS : memfs .New (),
197196 })
198- gsCloneOpts = git . AddFlags (cmd , & git. AddFlagsOptions {
197+ gsCloneOpts = apu . AddCloneFlags (cmd , & apu. CloneFlagsOptions {
199198 Prefix : "git-src" ,
200199 Optional : true ,
201200 CreateIfNotExist : true ,
202- FS : memfs .New (),
203201 })
204202 f = kube .AddFlags (cmd .Flags ())
205203
@@ -265,7 +263,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
265263 rt .Spec .Cluster = server
266264 rt .Spec .IngressHost = opts .IngressHost
267265
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 )
269267 err = apcmd .RunRepoBootstrap (ctx , & apcmd.RepoBootstrapOptions {
270268 AppSpecifier : rt .Spec .FullSpecifier (),
271269 Namespace : opts .RuntimeName ,
@@ -298,7 +296,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
298296 }
299297
300298 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 )
302300 if err = component .CreateApp (ctx , opts .KubeFactory , opts .insCloneOpts , opts .RuntimeName , store .Get ().CFComponentType ); err != nil {
303301 return fmt .Errorf ("failed to create '%s' application: %w" , component .Name , err )
304302 }
@@ -338,13 +336,13 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
338336 var wg sync.WaitGroup
339337
340338 wg .Add (1 )
341- err = intervalCheckIsRuntimePersisted (15000 , ctx , opts .RuntimeName , & wg )
339+ err = intervalCheckIsRuntimePersisted (ctx , opts .RuntimeName , & wg )
342340 if err != nil {
343- return fmt .Errorf ("failed to complete installation. Error : %w" , err )
341+ return fmt .Errorf ("failed to complete installation: %w" , err )
344342 }
345343 wg .Wait ()
346344
347- log .G (ctx ).Infof ("done installing runtime '%s'" , opts .RuntimeName )
345+ log .G (ctx ).Infof ("Done installing runtime '%s'" , opts .RuntimeName )
348346 return nil
349347}
350348
@@ -415,29 +413,37 @@ func checkExistingRuntimes(ctx context.Context, runtime string) error {
415413 return fmt .Errorf ("runtime '%s' already exists" , runtime )
416414}
417415
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 )
422423
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 {
426425 runtime , err := cfConfig .NewClient ().V2 ().Runtime ().Get (ctx , runtimeName )
427426 if err != nil {
427+ stop ()
428428 return fmt .Errorf ("failed to complete the runtime installation. Error: %w" , err )
429429 }
430430
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
433436 }
434437
435- wg .Done ()
436- ticker .Stop ()
437- return nil
438+ if triesLeft == longerThanUsualCount {
439+ stop ()
440+ stop = util .WithSpinner (ctx , longetThanUsualMsg )
441+ }
438442 }
439443
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" )
441447}
442448
443449func NewRuntimeListCommand () * cobra.Command {
@@ -459,7 +465,7 @@ func RunRuntimeList(ctx context.Context) error {
459465 }
460466
461467 if len (runtimes ) == 0 {
462- log .G (ctx ).Info ("no runtimes were found" )
468+ log .G (ctx ).Info ("No runtimes were found" )
463469 return nil
464470 }
465471
@@ -559,9 +565,7 @@ func NewRuntimeUninstallCommand() *cobra.Command {
559565 cmd .Flags ().BoolVar (& skipChecks , "skip-checks" , false , "If true, will not verify that runtime exists before uninstalling" )
560566 cmd .Flags ().DurationVar (& store .Get ().WaitTimeout , "wait-timeout" , store .Get ().WaitTimeout , "How long to wait for the runtime components to be deleted" )
561567
562- cloneOpts = git .AddFlags (cmd , & git.AddFlagsOptions {
563- FS : memfs .New (),
564- })
568+ cloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {})
565569 f = kube .AddFlags (cmd .Flags ())
566570
567571 return cmd
@@ -577,7 +581,7 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
577581 }
578582 }
579583
580- log .G (ctx ).Infof ("uninstalling runtime '%s'" , opts .RuntimeName )
584+ log .G (ctx ).Infof ("Uninstalling runtime '%s'" , opts .RuntimeName )
581585
582586 if err := apcmd .RunRepoUninstall (ctx , & apcmd.RepoUninstallOptions {
583587 Namespace : opts .RuntimeName ,
@@ -588,13 +592,13 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
588592 return fmt .Errorf ("failed uninstalling runtime: %w" , err )
589593 }
590594
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 )
592596
593597 if _ , err := cfConfig .NewClient ().V2 ().Runtime ().Delete (ctx , opts .RuntimeName ); err != nil {
594598 return fmt .Errorf ("failed to delete runtime from the platform: %w" , err )
595599 }
596600
597- log .G (ctx ).Infof ("done uninstalling runtime '%s'" , opts .RuntimeName )
601+ log .G (ctx ).Infof ("Done uninstalling runtime '%s'" , opts .RuntimeName )
598602 return nil
599603}
600604
@@ -653,9 +657,7 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
653657 }
654658
655659 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 {})
659661
660662 return cmd
661663}
@@ -689,7 +691,8 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
689691 return fmt .Errorf ("failed to upgrade runtime: %w" , err )
690692 }
691693
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 {
693696 return err
694697 }
695698
@@ -717,10 +720,9 @@ func persistRuntime(ctx context.Context, cloneOpts *git.CloneOptions, rt *runtim
717720 return err
718721 }
719722
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" )
724726}
725727
726728func createWorkflowsIngress (ctx context.Context , cloneOpts * git.CloneOptions , rt * runtime.Runtime ) error {
@@ -768,10 +770,9 @@ func createWorkflowsIngress(ctx context.Context, cloneOpts *git.CloneOptions, rt
768770 return err
769771 }
770772
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" )
775776}
776777
777778func 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
817818 return err
818819 }
819820
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" )
824824}
825825
826826func 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
844844 return err
845845 }
846846
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" )
851850}
852851
853852func createWorkflowReporter (ctx context.Context , cloneOpts * git.CloneOptions , opts * RuntimeInstallOptions ) error {
@@ -878,10 +877,9 @@ func createWorkflowReporter(ctx context.Context, cloneOpts *git.CloneOptions, op
878877 return err
879878 }
880879
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" )
885883}
886884
887885func updateProject (repofs fs.FS , rt * runtime.Runtime ) error {
0 commit comments