Skip to content

Commit 47754c2

Browse files
committed
Add a simple HTTP resolver
This adds a simple HTTP resolver that can fetch a file from a remote HTTP(S) URL. Only fetch timeout configuration for now is supported. This is kept simple for now, and does not support any kind of HTTP authentication, custom TLS or any other features. Something we can improve on later. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent f78bcff commit 47754c2

File tree

12 files changed

+666
-1
lines changed

12 files changed

+666
-1
lines changed

cmd/resolvers/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/tektoncd/pipeline/pkg/resolution/resolver/cluster"
2626
"github.com/tektoncd/pipeline/pkg/resolution/resolver/framework"
2727
"github.com/tektoncd/pipeline/pkg/resolution/resolver/git"
28+
"github.com/tektoncd/pipeline/pkg/resolution/resolver/http"
2829
"github.com/tektoncd/pipeline/pkg/resolution/resolver/hub"
2930
filteredinformerfactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered"
3031
"knative.dev/pkg/injection/sharedmain"
@@ -40,7 +41,8 @@ func main() {
4041
framework.NewController(ctx, &git.Resolver{}),
4142
framework.NewController(ctx, &hub.Resolver{TektonHubURL: tektonHubURL, ArtifactHubURL: artifactHubURL}),
4243
framework.NewController(ctx, &bundle.Resolver{}),
43-
framework.NewController(ctx, &cluster.Resolver{}))
44+
framework.NewController(ctx, &cluster.Resolver{}),
45+
framework.NewController(ctx, &http.Resolver{}))
4446
}
4547

4648
func buildHubURL(configAPI, defaultURL string) string {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2023 The Tekton Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: ConfigMap
17+
metadata:
18+
name: http-resolver-config
19+
namespace: tekton-pipelines-resolvers
20+
labels:
21+
app.kubernetes.io/component: resolvers
22+
app.kubernetes.io/instance: default
23+
app.kubernetes.io/part-of: tekton-pipelines
24+
data:
25+
# The maximum amount of time the http resolver will wait for a response from the server.
26+
fetch-timeout: "1m"

docs/http-resolver.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<!--
2+
---
3+
linkTitle: "HTTP Resolver"
4+
weight: 311
5+
---
6+
-->
7+
8+
# HTTP Resolver
9+
10+
This resolver responds to type `http`.
11+
12+
## Parameters
13+
14+
| Param Name | Description | Example Value |
15+
|------------------|-------------------------------------------------------------------------------|------------------------------------------------------------|
16+
| `url` | The URL to fetch from | https://raw.githubusercontent.com/tektoncd-catalog/git-clone/main/task/git-clone/git-clone.yaml |
17+
18+
A valid URL must be provided. Only HTTP or HTTPS URLs are supported.
19+
20+
## Requirements
21+
22+
- A cluster running Tekton Pipeline v0.41.0 or later.
23+
- The [built-in remote resolvers installed](./install.md#installing-and-configuring-remote-task-and-pipeline-resolution).
24+
- The `enable-http-resolver` feature flag in the `resolvers-feature-flags` ConfigMap in the
25+
`tekton-pipelines-resolvers` namespace set to `true`.
26+
- [Beta features](./additional-configs.md#beta-features) enabled.
27+
28+
## Configuration
29+
30+
This resolver uses a `ConfigMap` for its settings. See
31+
[`../config/resolvers/http-resolver-config.yaml`](../config/resolvers/http-resolver-config.yaml)
32+
for the name, namespace and defaults that the resolver ships with.
33+
34+
### Options
35+
36+
| Option Name | Description | Example Values |
37+
|-----------------------------|------------------------------------------------------|------------------------|
38+
| `fetch-timeout` | The maximum time any fetching of URL resolution may take. **Note**: a global maximum timeout of 1 minute is currently enforced on _all_ resolution requests. | `1m`, `2s`, `700ms` |
39+
40+
## Usage
41+
42+
### Task Resolution
43+
44+
```yaml
45+
apiVersion: tekton.dev/v1beta1
46+
kind: TaskRun
47+
metadata:
48+
name: remote-task-reference
49+
spec:
50+
taskRef:
51+
resolver: http
52+
params:
53+
- name: url
54+
value: https://raw.githubusercontent.com/tektoncd-catalog/git-clone/main/task/git-clone/git-clone.yaml
55+
```
56+
57+
### Pipeline Resolution
58+
59+
```yaml
60+
apiVersion: tekton.dev/v1beta1
61+
kind: PipelineRun
62+
metadata:
63+
name: http-demo
64+
spec:
65+
pipelineRef:
66+
resolver: http
67+
params:
68+
- name: url
69+
value: https://raw.githubusercontent.com/tektoncd/catalog/main/pipeline/build-push-gke-deploy/0.1/build-push-gke-deploy.yaml
70+
```
71+
72+
---
73+
74+
Except as otherwise noted, the content of this page is licensed under the
75+
[Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/),
76+
and code samples are licensed under the
77+
[Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: tekton.dev/v1
3+
kind: PipelineRun
4+
metadata:
5+
generateName: http-resolver-
6+
spec:
7+
pipelineSpec:
8+
tasks:
9+
- name: http-resolver
10+
taskRef:
11+
resolver: http
12+
params:
13+
- name: url
14+
value: https://api.hub.tekton.dev/v1/resource/tekton/task/tkn/0.4/raw
15+
params:
16+
- name: ARGS
17+
value: ["version"]

pkg/apis/config/resolver/feature_flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const (
3333
DefaultEnableBundlesResolver = true
3434
// DefaultEnableClusterResolver is the default value for "enable-cluster-resolver".
3535
DefaultEnableClusterResolver = true
36+
// DefaultEnableHttpResolver is the default value for "enable-http-resolver".
37+
DefaultEnableHttpResolver = true
3638

3739
// EnableGitResolver is the flag used to enable the git remote resolver
3840
EnableGitResolver = "enable-git-resolver"
@@ -42,6 +44,8 @@ const (
4244
EnableBundlesResolver = "enable-bundles-resolver"
4345
// EnableClusterResolver is the flag used to enable the cluster remote resolver
4446
EnableClusterResolver = "enable-cluster-resolver"
47+
// EnableHttpResolver is the flag used to enable the http remote resolver
48+
EnableHttpResolver = "enable-http-resolver"
4549
)
4650

4751
// FeatureFlags holds the features configurations
@@ -51,6 +55,7 @@ type FeatureFlags struct {
5155
EnableHubResolver bool
5256
EnableBundleResolver bool
5357
EnableClusterResolver bool
58+
EnableHttpResolver bool
5459
}
5560

5661
// GetFeatureFlagsConfigName returns the name of the configmap containing all
@@ -90,6 +95,9 @@ func NewFeatureFlagsFromMap(cfgMap map[string]string) (*FeatureFlags, error) {
9095
if err := setFeature(EnableClusterResolver, DefaultEnableClusterResolver, &tc.EnableClusterResolver); err != nil {
9196
return nil, err
9297
}
98+
if err := setFeature(EnableHttpResolver, DefaultEnableHttpResolver, &tc.EnableHttpResolver); err != nil {
99+
return nil, err
100+
}
93101
return &tc, nil
94102
}
95103

pkg/apis/config/resolver/feature_flags_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) {
3838
EnableHubResolver: true,
3939
EnableBundleResolver: true,
4040
EnableClusterResolver: true,
41+
EnableHttpResolver: true,
4142
},
4243
fileName: "feature-flags-empty",
4344
},
@@ -47,6 +48,7 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) {
4748
EnableHubResolver: false,
4849
EnableBundleResolver: false,
4950
EnableClusterResolver: false,
51+
EnableHttpResolver: false,
5052
},
5153
fileName: "feature-flags-all-flags-set",
5254
},
@@ -68,6 +70,7 @@ func TestNewFeatureFlagsFromEmptyConfigMap(t *testing.T) {
6870
EnableHubResolver: resolver.DefaultEnableHubResolver,
6971
EnableBundleResolver: resolver.DefaultEnableBundlesResolver,
7072
EnableClusterResolver: resolver.DefaultEnableClusterResolver,
73+
EnableHttpResolver: resolver.DefaultEnableHttpResolver,
7174
}
7275
verifyConfigFileWithExpectedFeatureFlagsConfig(t, FeatureFlagsConfigEmptyName, expectedConfig)
7376
}

pkg/apis/config/resolver/testdata/feature-flags-all-flags-set.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ data:
2222
enable-hub-resolver: "false"
2323
enable-bundles-resolver: "false"
2424
enable-cluster-resolver: "false"
25+
enable-http-resolver: "false"

pkg/resolution/resolver/framework/testing/featureflag.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func ContextWithClusterResolverDisabled(ctx context.Context) context.Context {
4343
return contextWithResolverDisabled(ctx, "enable-cluster-resolver")
4444
}
4545

46+
// ContextWithHttpResolverDisabled returns a context containing a Config with the enable-http-resolver feature flag disabled.
47+
func ContextWithHttpResolverDisabled(ctx context.Context) context.Context {
48+
return contextWithResolverDisabled(ctx, "enable-http-resolver")
49+
}
50+
4651
func contextWithResolverDisabled(ctx context.Context, resolverFlag string) context.Context {
4752
featureFlags, _ := resolverconfig.NewFeatureFlagsFromMap(map[string]string{
4853
resolverFlag: "false",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2023 The Tekton Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package http
18+
19+
const (
20+
// timeoutKey is the configuration field name for controlling
21+
// the maximum duration of a resolution request for a file from http.
22+
timeoutKey = "fetch-timeout"
23+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright 2023 The Tekton Authors
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package http
15+
16+
const (
17+
// urlParam is the url to fetch the task from
18+
urlParam string = "url"
19+
)

0 commit comments

Comments
 (0)