Skip to content

Commit 90b84fa

Browse files
committed
Add configuration for custom bundle resolver backoff
A bundle resolver is susceptible to flakes in network communication. In order to increase reliability, we can add backoff retries to mitigate transient issues. While it may be possible to add a generic retry functionality around resolvers, implementation will likely be simpler if the retry functionality is isolated to the individual resolvers. Future work is needed to add retries to git resolver requests. Partially addresses #8571 Signed-off-by: arewm <[email protected]>
1 parent 00ed658 commit 90b84fa

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

pkg/resolution/resolver/bundle/bundle.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ func retrieveImage(ctx context.Context, keychain authn.Keychain, ref string) (st
142142
if err != nil {
143143
return "", nil, fmt.Errorf("%s is an unparseable image reference: %w", ref, err)
144144
}
145+
customRetryBackoff := remote.Backoff{GetBundleResolverBackoff(ctx)}
145146

146-
img, err := remote.Image(imgRef, remote.WithAuthFromKeychain(keychain), remote.WithContext(ctx))
147+
img, err := remote.Image(imgRef, remote.WithAuthFromKeychain(keychain), remote.WithContext(ctx),
148+
remote.WithRetryBackoff(customRetryBackoff))
147149
return imgRef.Context().Name(), img, err
148150
}
149151

pkg/resolution/resolver/bundle/config.go

+74-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,80 @@ const (
2020
// ConfigKind is the configuration field name for controlling
2121
// what the layer name in the bundle image is.
2222
ConfigKind = "default-kind"
23-
// DefaultTimeoutKey is the configuration field name for controlling
23+
// ConfigTimeoutKey is the configuration field name for controlling
2424
// the maximum duration of a resolution request for a file from registry.
2525
ConfigTimeoutKey = "fetch-timeout"
26+
// ConfigBackoffDuration is the configuration field name for controlling
27+
// the initial duration of a backoff when a bundle resolution fails
28+
ConfigBackoffDuration = "backoff-duration"
29+
DefaultBackoffDuration = 1.0 * time.Second
30+
// ConfigBackoffFactor is the configuration field name for controlling
31+
// the factor by which successive backoffs will increase when a bundle
32+
// resolution fails
33+
ConfigBackoffFactor = "backoff-factor"
34+
DefaultBackoffFactor = 3.0
35+
// ConfigBackoffJitter is the configuration field name for controlling
36+
// the randomness applied to backoff durations when a bundle resolution fails
37+
ConfigBackoffJitter = "backoff-jitter"
38+
DefaultBackoffJitter = 0.1
39+
// ConfigBackoffSteps is the configuration field name for controlling
40+
// the number of attempted backoffs to retry when a bundle resolution fails
41+
ConfigBackoffSteps = "backoff-steps"
42+
DefaultBackoffSteps = 3
2643
)
44+
45+
type BundleResolverBackoffConfig struct {
46+
Duration: time.Duration
47+
Factor: float64
48+
Jitter: float64
49+
Steps: int
50+
51+
}
52+
53+
func {
54+
conf := framework.GetResolverConfigFromContext(ctx)
55+
}
56+
57+
// GetResolutionTimeout returns a time.Duration for the amount of time a
58+
// single bundle fetch may take. This can be configured with the
59+
// fetch-timeout field in the bundle-resolver-config ConfigMap.
60+
func GetBundleResolverBackoff(ctx context.Context) (BundleResolverBackoffConfig, error) {
61+
conf := framework.GetResolverConfigFromContext(ctx)
62+
63+
customRetryBackoff := BundleResolverBackoffConfig{
64+
Duration: DefaultBackoffDuration,
65+
Factor: DefaultBackoffFactor,
66+
Jitter: DefaultBackoffJitter,
67+
Steps: DefaultBackoffSteps,
68+
}
69+
if v, ok := conf[ConfigBackoffDuration]; ok {
70+
var err error
71+
duration, err = time.ParseDuration(v)
72+
if err != nil {
73+
return customRetryBackoff, fmt.Errorf("error parsing backoff duration value %s: %w", v, err)
74+
}
75+
}
76+
if v, ok := conf[ConfigBackoffFactor]; ok {
77+
var err error
78+
factor, err = strconv.ParseFloat(string(v, 64)
79+
if err != nil {
80+
return customRetryBackoff, fmt.Errorf("error parsing backoff factor value %s: %w", v, err)
81+
}
82+
}
83+
if v, ok := conf[ConfigBackoffJitter]; ok {
84+
var err error
85+
factor, err = strconv.ParseFloat(string(v, 64)
86+
if err != nil {
87+
return customRetryBackoff, fmt.Errorf("error parsing backoff jitter value %s: %w", v, err)
88+
}
89+
}
90+
if v, ok := conf[ConfigBackoffSteps]; ok {
91+
var err error
92+
factor, err = strconv.ParseInt(string(v)
93+
if err != nil {
94+
return customRetryBackoff, fmt.Errorf("error parsing backoff steps value %s: %w", v, err)
95+
}
96+
}
97+
98+
return customRetryBackoff, nil
99+
}

0 commit comments

Comments
 (0)