Skip to content

Commit 6080bc6

Browse files
Add job timeout CLI arg
1 parent f0cdacf commit 6080bc6

14 files changed

Lines changed: 254 additions & 55 deletions

File tree

cmd/clickhouse/check_and_finalize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func waitAndFinalize(appCtx *app.Context, chClient clickhouse.Interface, operati
117117
}
118118
}
119119

120-
if err := restore.WaitForAPIRestore(checkStatusFn, defaultPollInterval, defaultRestoreTimeout, appCtx.Logger); err != nil {
120+
if err := restore.WaitForAPIRestore(checkStatusFn, defaultPollInterval, appCtx.JobTimeout, appCtx.Logger); err != nil {
121121
return err
122122
}
123123

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func addBackupConfigFlags(cmd *cobra.Command) {
2727
cmd.PersistentFlags().StringVar(&flags.ConfigMapName, "configmap", "suse-observability-backup-config", "ConfigMap name containing backup configuration")
2828
cmd.PersistentFlags().StringVar(&flags.SecretName, "secret", "suse-observability-backup-config", "Secret name containing backup configuration")
2929
cmd.PersistentFlags().StringVarP(&flags.OutputFormat, "output", "o", "table", "Output format (table, json)")
30+
cmd.PersistentFlags().IntVar(&flags.JobTimeout, "job-timeout", 30, "Timeout in minutes for waiting on job/restore completion")
3031
_ = cmd.MarkPersistentFlagRequired("namespace")
3132
}
3233

cmd/settings/check_and_finalize.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ func runCheckAndFinalize(appCtx *app.Context) error {
5454
CleanupPVC: false,
5555
WaitForJob: waitForJob,
5656
Log: appCtx.Logger,
57+
Timeout: appCtx.JobTimeout,
5758
})
5859
}

cmd/settings/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func getBackupListFromPVC(appCtx *app.Context) ([]BackupFileInfo, error) {
185185
}
186186
}()
187187

188-
if err := restore.WaitForJobCompletion(appCtx.K8sClient, appCtx.Namespace, jobName, appCtx.Logger); err != nil {
188+
if err := restore.WaitForJobCompletion(appCtx.K8sClient, appCtx.Namespace, jobName, appCtx.Logger, appCtx.JobTimeout); err != nil {
189189
return nil, err
190190
}
191191

cmd/settings/restore.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ func runRestore(appCtx *app.Context) error {
126126
return nil
127127
}
128128

129-
return waitAndCleanupRestoreJob(appCtx.K8sClient, appCtx.Namespace, jobName, appCtx.Logger)
129+
return waitAndCleanupRestoreJob(appCtx.K8sClient, appCtx.Namespace, jobName, appCtx.Logger, appCtx.JobTimeout)
130130
}
131131

132132
// waitAndCleanupRestoreJob waits for job completion and cleans up resources
133-
func waitAndCleanupRestoreJob(k8sClient *k8s.Client, namespace, jobName string, log *logger.Logger) error {
133+
func waitAndCleanupRestoreJob(k8sClient *k8s.Client, namespace, jobName string, log *logger.Logger, jobTimeout time.Duration) error {
134134
restore.PrintWaitingMessage(log, "settings", jobName, namespace)
135-
return restore.WaitAndCleanup(k8sClient, namespace, jobName, log, false)
135+
return restore.WaitAndCleanup(k8sClient, namespace, jobName, log, false, jobTimeout)
136136
}
137137

138138
// getLatestBackup retrieves the most recent backup from all sources (S3 and PVC)

cmd/stackgraph/check_and_finalize.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ func runCheckAndFinalize(appCtx *app.Context) error {
5454
CleanupPVC: true,
5555
WaitForJob: waitForJob,
5656
Log: appCtx.Logger,
57+
Timeout: appCtx.JobTimeout,
5758
})
5859
}

cmd/stackgraph/restore.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ func runRestore(appCtx *app.Context) error {
133133
return nil
134134
}
135135

136-
return waitAndCleanupRestoreJob(appCtx.K8sClient, appCtx.Namespace, jobName, appCtx.Logger)
136+
return waitAndCleanupRestoreJob(appCtx.K8sClient, appCtx.Namespace, jobName, appCtx.Logger, appCtx.JobTimeout)
137137
}
138138

139139
// waitAndCleanupRestoreJob waits for job completion and cleans up resources
140-
func waitAndCleanupRestoreJob(k8sClient *k8s.Client, namespace, jobName string, log *logger.Logger) error {
140+
func waitAndCleanupRestoreJob(k8sClient *k8s.Client, namespace, jobName string, log *logger.Logger, jobTimeout time.Duration) error {
141141
restore.PrintWaitingMessage(log, "stackgraph", jobName, namespace)
142-
return restore.WaitAndCleanup(k8sClient, namespace, jobName, log, true)
142+
return restore.WaitAndCleanup(k8sClient, namespace, jobName, log, true, jobTimeout)
143143
}
144144

145145
// getLatestBackup retrieves the most recent backup from S3

cmd/victoriametrics/check_and_finalize.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ func runCheckAndFinalize(appCtx *app.Context) error {
5454
CleanupPVC: false,
5555
WaitForJob: waitForJob,
5656
Log: appCtx.Logger,
57+
Timeout: appCtx.JobTimeout,
5758
})
5859
}

cmd/victoriametrics/restore.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ func runRestore(appCtx *app.Context) error {
130130
return nil
131131
}
132132

133-
return waitAndCleanupRestoreJob(appCtx.K8sClient, appCtx.Namespace, jobName, appCtx.Logger)
133+
return waitAndCleanupRestoreJob(appCtx.K8sClient, appCtx.Namespace, jobName, appCtx.Logger, appCtx.JobTimeout)
134134
}
135135

136136
// waitAndCleanupRestoreJob waits for job completion and cleans up resources
137-
func waitAndCleanupRestoreJob(k8sClient *k8s.Client, namespace, jobName string, log *logger.Logger) error {
137+
func waitAndCleanupRestoreJob(k8sClient *k8s.Client, namespace, jobName string, log *logger.Logger, jobTimeout time.Duration) error {
138138
restore.PrintWaitingMessage(log, "victoria-metrics", jobName, namespace)
139-
return restore.WaitAndCleanup(k8sClient, namespace, jobName, log, false)
139+
return restore.WaitAndCleanup(k8sClient, namespace, jobName, log, false, jobTimeout)
140140
}
141141

142142
// getLatestBackup retrieves the most recent backup from S3

internal/app/app.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"time"
78

89
"github.com/stackvista/stackstate-backup-cli/internal/clients/clickhouse"
910
"github.com/stackvista/stackstate-backup-cli/internal/clients/elasticsearch"
@@ -16,15 +17,16 @@ import (
1617

1718
// Context holds all dependencies for cli commands
1819
type Context struct {
19-
K8sClient *k8s.Client
20-
Namespace string
21-
S3Client s3.Interface
22-
ESClient elasticsearch.Interface
23-
CHClient clickhouse.Interface
24-
Config *config.Config
25-
Logger *logger.Logger
26-
Formatter *output.Formatter
27-
Context context.Context
20+
K8sClient *k8s.Client
21+
Namespace string
22+
S3Client s3.Interface
23+
ESClient elasticsearch.Interface
24+
CHClient clickhouse.Interface
25+
Config *config.Config
26+
Logger *logger.Logger
27+
Formatter *output.Formatter
28+
Context context.Context
29+
JobTimeout time.Duration
2830
}
2931

3032
// NewContext creates production dependencies
@@ -68,14 +70,15 @@ func NewContext(flags *config.CLIGlobalFlags) (*Context, error) {
6870
formatter := output.NewFormatter(os.Stdout, flags.OutputFormat)
6971

7072
return &Context{
71-
K8sClient: k8sClient,
72-
Namespace: flags.Namespace,
73-
Config: cfg,
74-
S3Client: s3Client,
75-
ESClient: esClient,
76-
CHClient: chClient,
77-
Logger: logger.New(flags.Quiet, flags.Debug),
78-
Formatter: formatter,
79-
Context: context.Background(),
73+
K8sClient: k8sClient,
74+
Namespace: flags.Namespace,
75+
Config: cfg,
76+
S3Client: s3Client,
77+
ESClient: esClient,
78+
CHClient: chClient,
79+
Logger: logger.New(flags.Quiet, flags.Debug),
80+
Formatter: formatter,
81+
Context: context.Background(),
82+
JobTimeout: time.Duration(flags.JobTimeout) * time.Minute,
8083
}, nil
8184
}

0 commit comments

Comments
 (0)