Skip to content

Commit 62b907d

Browse files
Fix logs (#109)
* wip * wip * changed timeout * bump autopilot * fixed some info messages * bump * codegen * added debug level
1 parent 6d49f15 commit 62b907d

16 files changed

+198
-109
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.103
1+
VERSION=v0.0.104
22
OUT_DIR=dist
33
YEAR?=$(shell date +"%Y")
44

cmd/commands/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func RunConfigCreateContext(ctx context.Context, context, apiKey, url string) er
8888
if err := cfConfig.CreateContext(ctx, context, apiKey, url); err != nil {
8989
return err
9090
}
91-
log.G().Infof("create new context: %s", context)
91+
log.G().Infof("New context created: '%s'", context)
9292
return RunConfigUseContext(ctx, context)
9393
}
9494

@@ -162,7 +162,7 @@ func RunConfigUseContext(ctx context.Context, context string) error {
162162
if err := cfConfig.UseContext(ctx, context); err != nil {
163163
return err
164164
}
165-
log.G().Infof("switched to context: %s", context)
165+
log.G().Infof("Switched to context: %s", context)
166166
return nil
167167
}
168168

@@ -190,6 +190,6 @@ func RunConfigDeleteContext(ctx context.Context, context string) error {
190190
return err
191191
}
192192

193-
log.G(ctx).Infof("delete context: %s", context)
193+
log.G(ctx).Infof("Deleted context: %s", context)
194194
return nil
195195
}

cmd/commands/git-source.go

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package commands
1616

1717
import (
1818
"context"
19-
"errors"
2019
"fmt"
2120
"os"
2221
"time"
@@ -35,8 +34,7 @@ import (
3534
aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
3635
wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
3736
wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
38-
"github.com/go-git/go-billy/v5/memfs"
39-
"github.com/go-git/go-git/v5/plumbing/transport"
37+
apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
4038
"github.com/spf13/cobra"
4139
v1 "k8s.io/api/core/v1"
4240
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -141,15 +139,13 @@ func NewGitSourceCreateCommand() *cobra.Command {
141139
},
142140
}
143141

144-
insCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
142+
insCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
145143
CreateIfNotExist: true,
146-
FS: memfs.New(),
147144
})
148-
gsCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
145+
gsCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
149146
Prefix: "git-src",
150147
Optional: true,
151148
CreateIfNotExist: true,
152-
FS: memfs.New(),
153149
})
154150

155151
return cmd
@@ -171,23 +167,11 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
171167
return fmt.Errorf("failed to create demo workflowTemplate: %w", err)
172168
}
173169

174-
pOpts := &git.PushOptions{
175-
CommitMsg: fmt.Sprintf("Created demo workflow template in %s Directory", opts.gsCloneOpts.Path()),
176-
}
170+
commitMsg := fmt.Sprintf("Created demo workflow template in %s Directory", opts.gsCloneOpts.Path())
177171

178-
_, err = gsRepo.Persist(ctx, pOpts)
179-
if err != nil {
180-
if errors.Is(err, transport.ErrRepositoryNotFound) {
181-
log.G(ctx).Warn("failed to persist git-source repo, trying again in 3 seconds...")
182-
time.Sleep(time.Second * 3)
183-
184-
_, err = gsRepo.Persist(ctx, pOpts)
185-
if err != nil {
186-
return fmt.Errorf("failed to push changes. Err: %w", err)
187-
}
188-
} else {
189-
return fmt.Errorf("failed to push changes. Err: %w", err)
190-
}
172+
log.G(ctx).Info("Pushing a demo workflow-template to the new git-source repo")
173+
if err := apu.PushWithMessage(ctx, gsRepo, commitMsg); err != nil {
174+
return fmt.Errorf("failed to push demo workflow-template to git-source repo: %w", err)
191175
}
192176
}
193177

@@ -307,9 +291,7 @@ func NewGitSourceDeleteCommand() *cobra.Command {
307291
},
308292
}
309293

310-
insCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
311-
FS: memfs.New(),
312-
})
294+
insCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{})
313295

314296
return cmd
315297
}
@@ -373,16 +355,14 @@ func NewGitSourceEditCommand() *cobra.Command {
373355
},
374356
}
375357

376-
insCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
358+
insCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
377359
CreateIfNotExist: true,
378-
FS: memfs.New(),
379360
})
380361

381-
gsCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
362+
gsCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
382363
Prefix: "git-src",
383364
Optional: true,
384365
CreateIfNotExist: true,
385-
FS: memfs.New(),
386366
})
387367

388368
return cmd
@@ -409,11 +389,8 @@ func RunGitSourceEdit(ctx context.Context, opts *GitSourceEditOptions) error {
409389
return fmt.Errorf("failed to write the updated config.json of git-source: %s. Err: %w", opts.GsName, err)
410390
}
411391

412-
_, err = repo.Persist(ctx, &git.PushOptions{
413-
CommitMsg: "Persisted an updated git-source",
414-
})
415-
416-
if err != nil {
392+
log.G(ctx).Info("Pushing updated GitSource to the installation repo")
393+
if err := apu.PushWithMessage(ctx, repo, fmt.Sprintf("Persisted an updated git-source '%s'", opts.GsName)); err != nil {
417394
return fmt.Errorf("failed to persist the updated git-source: %s. Err: %w", opts.GsName, err)
418395
}
419396

cmd/commands/runtime.go

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -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

443449
func 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

726728
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
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

777778
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
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

826826
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
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

853852
func 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

887885
func updateProject(repofs fs.FS, rt *runtime.Runtime) error {

0 commit comments

Comments
 (0)