Merge pull request #124494 from brianpursley/FixSlowUnitTest-TestForceApply

Improve performance of TestForceApply unit test (k8s.io/kubectl/pkg/cmd/apply)
This commit is contained in:
Kubernetes Prow Robot 2024-04-26 10:50:38 -07:00 committed by GitHub
commit 8718b33366
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -2087,6 +2087,9 @@ func TestForceApply(t *testing.T) {
"post": 1,
}
// Set the patch retry back off period to something low, so the test can run more quickly
patchRetryBackOffPeriod = 1 * time.Millisecond
for _, testingOpenAPISchema := range testingOpenAPISchemas {
for _, openAPIFeatureToggle := range applyFeatureToggles {

View File

@ -49,8 +49,6 @@ import (
const (
// maxPatchRetry is the maximum number of conflicts retry for during a patch operation before returning failure
maxPatchRetry = 5
// backOffPeriod is the period to back off when apply patch results in error.
backOffPeriod = 1 * time.Second
// how many times we can retry before back off
triesBeforeBackOff = 1
// groupVersionKindExtensionKey is the key used to lookup the
@ -59,6 +57,9 @@ const (
groupVersionKindExtensionKey = "x-kubernetes-group-version-kind"
)
// patchRetryBackOffPeriod is the period to back off when apply patch results in error.
var patchRetryBackOffPeriod = 1 * time.Second
var createPatchErrFormat = "creating patch with:\noriginal:\n%s\nmodified:\n%s\ncurrent:\n%s\nfor:"
// Patcher defines options to patch OpenAPI objects.
@ -363,7 +364,7 @@ func (p *Patcher) Patch(current runtime.Object, modified []byte, source, namespa
}
for i := 1; i <= p.Retries && apierrors.IsConflict(err); i++ {
if i > triesBeforeBackOff {
p.BackOff.Sleep(backOffPeriod)
p.BackOff.Sleep(patchRetryBackOffPeriod)
}
current, getErr = p.Helper.Get(namespace, name)
if getErr != nil {