Skip to content

Commit

Permalink
fix: add delay when creating pod/deployments (#478)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly authored Nov 24, 2023
1 parent 079c74b commit 38edcf2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/runner/processors/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"path/filepath"
"time"

"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
"github.com/kyverno/chainsaw/pkg/client"
Expand Down Expand Up @@ -240,12 +241,29 @@ func (p *stepProcessor) applyOperation(ctx context.Context, op v1alpha1.Apply, t
}
var ops []operation
dryRun := op.DryRun != nil && *op.DryRun
addDelay := false
for i := range resources {
resource := resources[i]
ops = append(ops, operation{
timeout: timeout.Get(timeout.DefaultApplyTimeout, p.config.Timeouts.Apply, p.test.Spec.Timeouts.Apply, p.step.Spec.Timeouts.Apply, to),
operation: opapply.New(p.getClient(dryRun), &resource, p.namespacer, p.getCleaner(ctx, dryRun), op.Check),
})
if resource.GetKind() == "Pod" || resource.GetKind() == "Deployment" {
addDelay = true
}
}
if addDelay {
ops = append(ops, operation{
timeout: timeout.Get(2*time.Minute, nil, nil, nil, nil),
operation: opcommand.New(
v1alpha1.Command{
Entrypoint: "sleep",
Args: []string{"5s"},
},
p.test.BasePath,
p.namespacer.GetNamespace(),
),
})
}
return ops, nil
}
Expand Down Expand Up @@ -280,12 +298,29 @@ func (p *stepProcessor) createOperation(ctx context.Context, op v1alpha1.Create,
}
var ops []operation
dryRun := op.DryRun != nil && *op.DryRun
addDelay := false
for i := range resources {
resource := resources[i]
ops = append(ops, operation{
timeout: timeout.Get(timeout.DefaultApplyTimeout, p.config.Timeouts.Apply, p.test.Spec.Timeouts.Apply, p.step.Spec.Timeouts.Apply, to),
operation: opcreate.New(p.getClient(dryRun), &resource, p.namespacer, p.getCleaner(ctx, dryRun), op.Check),
})
if resource.GetKind() == "Pod" || resource.GetKind() == "Deployment" {
addDelay = true
}
}
if addDelay {
ops = append(ops, operation{
timeout: timeout.Get(2*time.Minute, nil, nil, nil, nil),
operation: opcommand.New(
v1alpha1.Command{
Entrypoint: "sleep",
Args: []string{"5s"},
},
p.test.BasePath,
p.namespacer.GetNamespace(),
),
})
}
return ops, nil
}
Expand Down

0 comments on commit 38edcf2

Please sign in to comment.