fix: populate timeout context to node-collector (#3766)

This commit is contained in:
chenk
2023-03-13 13:10:37 +02:00
committed by GitHub
parent bd9c6e613e
commit cac5881bbb
3 changed files with 40 additions and 41 deletions

View File

@@ -32,6 +32,14 @@ func Run(ctx context.Context, args []string, opts flag.Options) error {
if err != nil {
return xerrors.Errorf("failed getting k8s cluster: %w", err)
}
ctx, cancel := context.WithTimeout(ctx, opts.Timeout)
defer cancel()
defer func() {
if xerrors.Is(err, context.DeadlineExceeded) {
log.Logger.Warn("Increase --timeout value")
}
}()
switch args[0] {
case clusterArtifact:
@@ -56,16 +64,6 @@ func newRunner(flagOpts flag.Options, cluster string) *runner {
}
func (r *runner) run(ctx context.Context, artifacts []*artifacts.Artifact) error {
ctx, cancel := context.WithTimeout(ctx, r.flagOpts.Timeout)
defer cancel()
var err error
defer func() {
if xerrors.Is(err, context.DeadlineExceeded) {
log.Logger.Warn("Increase --timeout value")
}
}()
runner, err := cmd.NewRunner(ctx, r.flagOpts)
if err != nil {
if errors.Is(err, cmd.SkipScan) {