Skip to content

Commit 21df015

Browse files
jkheliltekton-robot
authored andcommitted
make the maximum resolution timeout configurable through defaultconfigmap
1 parent 451ecf5 commit 21df015

File tree

16 files changed

+1541
-27
lines changed

16 files changed

+1541
-27
lines changed

config/config-defaults.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ data:
9292
# possible values could be 1m, 5m, 10s, 1h, etc
9393
# default-imagepullbackoff-timeout: "5m"
9494
95+
# default-maximum-resolution-timeout specifies the default duration used by the
96+
# resolution controller before timing out when exceeded.
97+
# Possible values include "1m", "5m", "10s", "1h", etc.
98+
# Example: default-maximum-resolution-timeout: "1m"
99+
95100
# default-container-resource-requirements allow users to update default resource requirements
96101
# to a init-containers and containers of a pods create by the controller
97102
# Onet: All the resource requirements are applied to init-containers and containers

pkg/apis/config/default.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const (
5151

5252
DefaultImagePullBackOffTimeout = 0 * time.Minute
5353

54+
// Default maximum resolution timeout used by the resolution controller before timing out when exceeded
55+
DefaultMaximumResolutionTimeout = 1 * time.Minute
56+
5457
defaultTimeoutMinutesKey = "default-timeout-minutes"
5558
defaultServiceAccountKey = "default-service-account"
5659
defaultManagedByLabelValueKey = "default-managed-by-label-value"
@@ -63,6 +66,7 @@ const (
6366
defaultResolverTypeKey = "default-resolver-type"
6467
defaultContainerResourceRequirementsKey = "default-container-resource-requirements"
6568
defaultImagePullBackOffTimeout = "default-imagepullbackoff-timeout"
69+
defaultMaximumResolutionTimeout = "default-maximum-resolution-timeout"
6670
)
6771

6872
// DefaultConfig holds all the default configurations for the config.
@@ -83,6 +87,7 @@ type Defaults struct {
8387
DefaultResolverType string
8488
DefaultContainerResourceRequirements map[string]corev1.ResourceRequirements
8589
DefaultImagePullBackOffTimeout time.Duration
90+
DefaultMaximumResolutionTimeout time.Duration
8691
}
8792

8893
// GetDefaultsConfigName returns the name of the configmap containing all
@@ -114,6 +119,7 @@ func (cfg *Defaults) Equals(other *Defaults) bool {
114119
other.DefaultMaxMatrixCombinationsCount == cfg.DefaultMaxMatrixCombinationsCount &&
115120
other.DefaultResolverType == cfg.DefaultResolverType &&
116121
other.DefaultImagePullBackOffTimeout == cfg.DefaultImagePullBackOffTimeout &&
122+
other.DefaultMaximumResolutionTimeout == cfg.DefaultMaximumResolutionTimeout &&
117123
reflect.DeepEqual(other.DefaultForbiddenEnv, cfg.DefaultForbiddenEnv)
118124
}
119125

@@ -127,12 +133,13 @@ func NewDefaultsFromMap(cfgMap map[string]string) (*Defaults, error) {
127133
DefaultMaxMatrixCombinationsCount: DefaultMaxMatrixCombinationsCount,
128134
DefaultResolverType: DefaultResolverTypeValue,
129135
DefaultImagePullBackOffTimeout: DefaultImagePullBackOffTimeout,
136+
DefaultMaximumResolutionTimeout: DefaultMaximumResolutionTimeout,
130137
}
131138

132139
if defaultTimeoutMin, ok := cfgMap[defaultTimeoutMinutesKey]; ok {
133140
timeout, err := strconv.ParseInt(defaultTimeoutMin, 10, 0)
134141
if err != nil {
135-
return nil, fmt.Errorf("failed parsing tracing config %q", defaultTimeoutMinutesKey)
142+
return nil, fmt.Errorf("failed parsing default config %q", defaultTimeoutMinutesKey)
136143
}
137144
tc.DefaultTimeoutMinutes = int(timeout)
138145
}
@@ -172,7 +179,7 @@ func NewDefaultsFromMap(cfgMap map[string]string) (*Defaults, error) {
172179
if defaultMaxMatrixCombinationsCount, ok := cfgMap[defaultMaxMatrixCombinationsCountKey]; ok {
173180
matrixCombinationsCount, err := strconv.ParseInt(defaultMaxMatrixCombinationsCount, 10, 0)
174181
if err != nil {
175-
return nil, fmt.Errorf("failed parsing tracing config %q", defaultMaxMatrixCombinationsCountKey)
182+
return nil, fmt.Errorf("failed parsing default config %q", defaultMaxMatrixCombinationsCountKey)
176183
}
177184
tc.DefaultMaxMatrixCombinationsCount = int(matrixCombinationsCount)
178185
}
@@ -200,11 +207,19 @@ func NewDefaultsFromMap(cfgMap map[string]string) (*Defaults, error) {
200207
if defaultImagePullBackOff, ok := cfgMap[defaultImagePullBackOffTimeout]; ok {
201208
timeout, err := time.ParseDuration(defaultImagePullBackOff)
202209
if err != nil {
203-
return nil, fmt.Errorf("failed parsing tracing config %q", defaultImagePullBackOffTimeout)
210+
return nil, fmt.Errorf("failed parsing default config %q", defaultImagePullBackOffTimeout)
204211
}
205212
tc.DefaultImagePullBackOffTimeout = timeout
206213
}
207214

215+
if defaultMaximumResolutionTimeout, ok := cfgMap[defaultMaximumResolutionTimeout]; ok {
216+
timeout, err := time.ParseDuration(defaultMaximumResolutionTimeout)
217+
if err != nil {
218+
return nil, fmt.Errorf("failed parsing default config %q", defaultMaximumResolutionTimeout)
219+
}
220+
tc.DefaultMaximumResolutionTimeout = timeout
221+
}
222+
208223
return &tc, nil
209224
}
210225

pkg/apis/config/default_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
4545
DefaultMaxMatrixCombinationsCount: 256,
4646
DefaultResolverType: "git",
4747
DefaultImagePullBackOffTimeout: time.Duration(5) * time.Second,
48+
DefaultMaximumResolutionTimeout: 1 * time.Minute,
4849
},
4950
fileName: config.GetDefaultsConfigName(),
5051
},
@@ -65,6 +66,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
6566
},
6667
DefaultMaxMatrixCombinationsCount: 256,
6768
DefaultImagePullBackOffTimeout: 0,
69+
DefaultMaximumResolutionTimeout: 1 * time.Minute,
6870
},
6971
fileName: "config-defaults-with-pod-template",
7072
},
@@ -88,6 +90,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
8890
DefaultPodTemplate: &pod.Template{},
8991
DefaultMaxMatrixCombinationsCount: 256,
9092
DefaultImagePullBackOffTimeout: 0,
93+
DefaultMaximumResolutionTimeout: 1 * time.Minute,
9194
},
9295
},
9396
{
@@ -100,6 +103,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
100103
DefaultAAPodTemplate: &pod.AffinityAssistantTemplate{},
101104
DefaultMaxMatrixCombinationsCount: 256,
102105
DefaultImagePullBackOffTimeout: 0,
106+
DefaultMaximumResolutionTimeout: 1 * time.Minute,
103107
},
104108
},
105109
{
@@ -115,6 +119,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
115119
DefaultServiceAccount: "default",
116120
DefaultManagedByLabelValue: config.DefaultManagedByLabelValue,
117121
DefaultImagePullBackOffTimeout: 0,
122+
DefaultMaximumResolutionTimeout: 1 * time.Minute,
118123
},
119124
},
120125
{
@@ -127,6 +132,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
127132
DefaultManagedByLabelValue: "tekton-pipelines",
128133
DefaultForbiddenEnv: []string{"TEKTON_POWER_MODE", "TEST_ENV", "TEST_TEKTON"},
129134
DefaultImagePullBackOffTimeout: time.Duration(15) * time.Second,
135+
DefaultMaximumResolutionTimeout: 1 * time.Minute,
130136
},
131137
},
132138
{
@@ -139,6 +145,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
139145
DefaultMaxMatrixCombinationsCount: 256,
140146
DefaultContainerResourceRequirements: map[string]corev1.ResourceRequirements{},
141147
DefaultImagePullBackOffTimeout: 0,
148+
DefaultMaximumResolutionTimeout: 1 * time.Minute,
142149
},
143150
},
144151
{
@@ -154,6 +161,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
154161
DefaultManagedByLabelValue: "tekton-pipelines",
155162
DefaultMaxMatrixCombinationsCount: 256,
156163
DefaultImagePullBackOffTimeout: 0,
164+
DefaultMaximumResolutionTimeout: 1 * time.Minute,
157165
DefaultContainerResourceRequirements: map[string]corev1.ResourceRequirements{
158166
config.ResourceRequirementDefaultContainerKey: {
159167
Requests: corev1.ResourceList{
@@ -210,6 +218,7 @@ func TestNewDefaultsFromEmptyConfigMap(t *testing.T) {
210218
DefaultServiceAccount: "default",
211219
DefaultMaxMatrixCombinationsCount: 256,
212220
DefaultImagePullBackOffTimeout: 0,
221+
DefaultMaximumResolutionTimeout: 1 * time.Minute,
213222
}
214223
verifyConfigFileWithExpectedConfig(t, DefaultsConfigEmptyName, expectedConfig)
215224
}
@@ -377,6 +386,25 @@ func TestEquals(t *testing.T) {
377386
},
378387
expected: true,
379388
},
389+
{
390+
name: "different default maximum resolution timeout",
391+
left: &config.Defaults{
392+
DefaultMaximumResolutionTimeout: 10 * time.Minute,
393+
},
394+
right: &config.Defaults{
395+
DefaultMaximumResolutionTimeout: 20 * time.Minute,
396+
},
397+
expected: false,
398+
}, {
399+
name: "same default maximum resolution timeout",
400+
left: &config.Defaults{
401+
DefaultMaximumResolutionTimeout: 10 * time.Minute,
402+
},
403+
right: &config.Defaults{
404+
DefaultMaximumResolutionTimeout: 10 * time.Minute,
405+
},
406+
expected: true,
407+
},
380408
}
381409

382410
for _, tc := range testCases {

pkg/reconciler/resolutionrequest/controller.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package resolutionrequest
1919
import (
2020
"context"
2121

22+
"github.com/tektoncd/pipeline/pkg/apis/config"
2223
resolutionrequestinformer "github.com/tektoncd/pipeline/pkg/client/resolution/injection/informers/resolution/v1beta1/resolutionrequest"
2324
resolutionrequestreconciler "github.com/tektoncd/pipeline/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest"
2425
"k8s.io/utils/clock"
@@ -31,10 +32,19 @@ import (
3132
// ResolutionRequest objects.
3233
func NewController(clock clock.PassiveClock) func(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
3334
return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
35+
logger := logging.FromContext(ctx)
36+
37+
configStore := config.NewStore(logger.Named("config-store"))
38+
configStore.WatchConfigs(cmw)
39+
3440
r := &Reconciler{
3541
clock: clock,
3642
}
37-
impl := resolutionrequestreconciler.NewImpl(ctx, r)
43+
impl := resolutionrequestreconciler.NewImpl(ctx, r, func(impl *controller.Impl) controller.Options {
44+
return controller.Options{
45+
ConfigStore: configStore,
46+
}
47+
})
3848

3949
reqinformer := resolutionrequestinformer.Get(ctx)
4050
if _, err := reqinformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)); err != nil {

pkg/reconciler/resolutionrequest/resolutionrequest.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"time"
2323

24+
"github.com/tektoncd/pipeline/pkg/apis/config"
2425
"github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1"
2526
rrreconciler "github.com/tektoncd/pipeline/pkg/client/resolution/injection/reconciler/resolution/v1beta1/resolutionrequest"
2627
resolutioncommon "github.com/tektoncd/pipeline/pkg/resolution/common"
@@ -38,10 +39,6 @@ type Reconciler struct {
3839

3940
var _ rrreconciler.Interface = (*Reconciler)(nil)
4041

41-
// TODO(sbwsg): This should be exposed via ConfigMap using a config
42-
// store similarly to Tekton Pipelines'.
43-
const defaultMaximumResolutionDuration = 1 * time.Minute
44-
4542
// ReconcileKind processes updates to ResolutionRequests, sets status
4643
// fields on it, and returns any errors experienced along the way.
4744
func (r *Reconciler) ReconcileKind(ctx context.Context, rr *v1beta1.ResolutionRequest) reconciler.Event {
@@ -57,14 +54,15 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, rr *v1beta1.ResolutionRe
5754
rr.Status.InitializeConditions()
5855
}
5956

57+
maximumResolutionDuration := config.FromContextOrDefaults(ctx).Defaults.DefaultMaximumResolutionTimeout
6058
switch {
6159
case rr.Status.Data != "":
6260
rr.Status.MarkSucceeded()
63-
case requestDuration(rr) > defaultMaximumResolutionDuration:
64-
rr.Status.MarkFailed(resolutioncommon.ReasonResolutionTimedOut, timeoutMessage())
61+
case requestDuration(rr) > maximumResolutionDuration:
62+
rr.Status.MarkFailed(resolutioncommon.ReasonResolutionTimedOut, timeoutMessage(maximumResolutionDuration))
6563
default:
6664
rr.Status.MarkInProgress(resolutioncommon.MessageWaitingForResolver)
67-
return controller.NewRequeueAfter(defaultMaximumResolutionDuration - requestDuration(rr))
65+
return controller.NewRequeueAfter(maximumResolutionDuration - requestDuration(rr))
6866
}
6967

7068
return nil
@@ -77,6 +75,6 @@ func requestDuration(rr *v1beta1.ResolutionRequest) time.Duration {
7775
return time.Now().UTC().Sub(creationTime)
7876
}
7977

80-
func timeoutMessage() string {
81-
return fmt.Sprintf("resolution took longer than global timeout of %s", defaultMaximumResolutionDuration)
78+
func timeoutMessage(timeout time.Duration) string {
79+
return fmt.Sprintf("resolution took longer than global timeout of %s", timeout)
8280
}

pkg/reconciler/resolutionrequest/resolutionrequest_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/google/go-cmp/cmp"
2626
"github.com/google/go-cmp/cmp/cmpopts"
27+
"github.com/tektoncd/pipeline/pkg/apis/config"
2728
"github.com/tektoncd/pipeline/pkg/apis/resolution/v1beta1"
2829
ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing"
2930
resolutioncommon "github.com/tektoncd/pipeline/pkg/resolution/common"
@@ -63,6 +64,7 @@ func initializeResolutionRequestControllerAssets(t *testing.T, d test.Data) (tes
6364
t.Helper()
6465
ctx, _ := ttesting.SetupFakeContext(t)
6566
ctx, cancel := context.WithCancel(ctx)
67+
test.EnsureConfigurationConfigMapsExist(&d)
6668
c, informers := test.SeedTestData(t, ctx, d)
6769
configMapWatcher := cminformer.NewInformedWatcher(c.Kube, system.Namespace())
6870
ctl := NewController(testClock)(ctx, configMapWatcher)
@@ -129,7 +131,7 @@ func TestReconcile(t *testing.T) {
129131
Type: apis.ConditionSucceeded,
130132
Status: corev1.ConditionFalse,
131133
Reason: resolutioncommon.ReasonResolutionTimedOut,
132-
Message: timeoutMessage(),
134+
Message: timeoutMessage(config.FromContextOrDefaults(context.TODO()).Defaults.DefaultMaximumResolutionTimeout),
133135
}},
134136
},
135137
ResolutionRequestStatusFields: v1beta1.ResolutionRequestStatusFields{},
@@ -167,6 +169,7 @@ func TestReconcile(t *testing.T) {
167169
t.Run(tc.name, func(t *testing.T) {
168170
d := test.Data{
169171
ResolutionRequests: []*v1beta1.ResolutionRequest{tc.input},
172+
ConfigMaps: []*corev1.ConfigMap{newDefaultsConfigMap()},
170173
}
171174

172175
testAssets, cancel := getResolutionRequestController(t, d)
@@ -192,3 +195,10 @@ func TestReconcile(t *testing.T) {
192195
func getRequestName(rr *v1beta1.ResolutionRequest) string {
193196
return strings.Join([]string{rr.Namespace, rr.Name}, "/")
194197
}
198+
199+
func newDefaultsConfigMap() *corev1.ConfigMap {
200+
return &corev1.ConfigMap{
201+
ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()},
202+
Data: make(map[string]string),
203+
}
204+
}

pkg/resolution/resolver/bundle/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ limitations under the License.
1414
package bundle
1515

1616
const (
17-
// ConfigMapName is the bundle resolver's config map
18-
ConfigMapName = "bundleresolver-config"
1917
// ConfigServiceAccount is the configuration field name for controlling
2018
// the Service Account name to use for bundle requests.
2119
ConfigServiceAccount = "default-service-account"
2220
// ConfigKind is the configuration field name for controlling
2321
// what the layer name in the bundle image is.
2422
ConfigKind = "default-kind"
23+
// DefaultTimeoutKey is the configuration field name for controlling
24+
// the maximum duration of a resolution request for a file from registry.
25+
ConfigTimeoutKey = "fetch-timeout"
2526
)

0 commit comments

Comments
 (0)