Skip to content

Commit

Permalink
Add a simple HTTP resolver
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
chmouel committed Oct 20, 2023
1 parent c52f937 commit ba9d269
Show file tree
Hide file tree
Showing 10 changed files with 596 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/resolvers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/tektoncd/pipeline/pkg/resolution/resolver/cluster"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/framework"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/git"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/http"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/hub"
filteredinformerfactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered"
"knative.dev/pkg/injection/sharedmain"
Expand All @@ -40,7 +41,8 @@ func main() {
framework.NewController(ctx, &git.Resolver{}),
framework.NewController(ctx, &hub.Resolver{TektonHubURL: tektonHubURL, ArtifactHubURL: artifactHubURL}),
framework.NewController(ctx, &bundle.Resolver{}),
framework.NewController(ctx, &cluster.Resolver{}))
framework.NewController(ctx, &cluster.Resolver{}),
framework.NewController(ctx, &http.Resolver{}))
}

func buildHubURL(configAPI, defaultURL, yamlEndpoint string) string {
Expand Down
26 changes: 26 additions & 0 deletions config/resolvers/http-resolver-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 The Tekton Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
name: http-resolver-config
namespace: tekton-pipelines-resolvers
labels:
app.kubernetes.io/component: resolvers
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
data:
# The maximum amount of time the http resolver will wait for a response from the server.
fetch-timeout: "1m"
77 changes: 77 additions & 0 deletions docs/http-resolver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!--
---
linkTitle: "HTTP Resolver"
weight: 311
---
-->

# HTTP Resolver

This resolver responds to type `http`.

## Parameters

| Param Name | Description | Example Value |
|------------------|-------------------------------------------------------------------------------|------------------------------------------------------------|
| `url` | The URL to fetch from | https://raw.githubusercontent.com/tektoncd-catalog/git-clone/main/task/git-clone/git-clone.yaml |

A valid URL must be provided. Only HTTP or HTTPS URLs are supported.

## Requirements

- A cluster running Tekton Pipeline v0.41.0 or later.
- The [built-in remote resolvers installed](./install.md#installing-and-configuring-remote-task-and-pipeline-resolution).
- The `enable-http-resolver` feature flag in the `resolvers-feature-flags` ConfigMap in the
`tekton-pipelines-resolvers` namespace set to `true`.
- [Beta features](./additional-configs.md#beta-features) enabled.

## Configuration

This resolver uses a `ConfigMap` for its settings. See
[`../config/resolvers/http-resolver-config.yaml`](../config/resolvers/http-resolver-config.yaml)
for the name, namespace and defaults that the resolver ships with.

### Options

| Option Name | Description | Example Values |
|-----------------------------|------------------------------------------------------|------------------------|
| `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` |

## Usage

### Task Resolution

```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: remote-task-reference
spec:
taskRef:
resolver: http
params:
- name: url
value: https://raw.githubusercontent.com/tektoncd-catalog/git-clone/main/task/git-clone/git-clone.yaml
```
### Pipeline Resolution
```yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: http-demo
spec:
pipelineRef:
resolver: http
params:
- name: url # optional
value: https://raw.githubusercontent.com/tektoncd/catalog/main/pipeline/build-push-gke-deploy/0.1/build-push-gke-deploy.yaml
```
---
Except as otherwise noted, the content of this page is licensed under the
[Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/),
and code samples are licensed under the
[Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
8 changes: 8 additions & 0 deletions pkg/apis/config/resolver/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const (
DefaultEnableBundlesResolver = true
// DefaultEnableClusterResolver is the default value for "enable-cluster-resolver".
DefaultEnableClusterResolver = true
// DefaultEnableHttpResolver is the default value for "enable-http-resolver".
DefaultEnableHttpResolver = true

// EnableGitResolver is the flag used to enable the git remote resolver
EnableGitResolver = "enable-git-resolver"
Expand All @@ -42,6 +44,8 @@ const (
EnableBundlesResolver = "enable-bundles-resolver"
// EnableClusterResolver is the flag used to enable the cluster remote resolver
EnableClusterResolver = "enable-cluster-resolver"
// EnableHttpResolver is the flag used to enable the http remote resolver
EnableHttpResolver = "enable-http-resolver"
)

// FeatureFlags holds the features configurations
Expand All @@ -51,6 +55,7 @@ type FeatureFlags struct {
EnableHubResolver bool
EnableBundleResolver bool
EnableClusterResolver bool
EnableHttpResolver bool
}

// GetFeatureFlagsConfigName returns the name of the configmap containing all
Expand Down Expand Up @@ -90,6 +95,9 @@ func NewFeatureFlagsFromMap(cfgMap map[string]string) (*FeatureFlags, error) {
if err := setFeature(EnableClusterResolver, DefaultEnableClusterResolver, &tc.EnableClusterResolver); err != nil {
return nil, err
}
if err := setFeature(EnableHttpResolver, DefaultEnableHttpResolver, &tc.EnableHttpResolver); err != nil {
return nil, err
}
return &tc, nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/config/resolver/feature_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) {
EnableHubResolver: true,
EnableBundleResolver: true,
EnableClusterResolver: true,
EnableHttpResolver: true,
},
fileName: "feature-flags-empty",
},
Expand All @@ -47,6 +48,7 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) {
EnableHubResolver: false,
EnableBundleResolver: false,
EnableClusterResolver: false,
EnableHttpResolver: false,
},
fileName: "feature-flags-all-flags-set",
},
Expand All @@ -68,6 +70,7 @@ func TestNewFeatureFlagsFromEmptyConfigMap(t *testing.T) {
EnableHubResolver: resolver.DefaultEnableHubResolver,
EnableBundleResolver: resolver.DefaultEnableBundlesResolver,
EnableClusterResolver: resolver.DefaultEnableClusterResolver,
EnableHttpResolver: resolver.DefaultEnableHttpResolver,
}
verifyConfigFileWithExpectedFeatureFlagsConfig(t, FeatureFlagsConfigEmptyName, expectedConfig)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ data:
enable-hub-resolver: "false"
enable-bundles-resolver: "false"
enable-cluster-resolver: "false"
enable-http-resolver: "false"
23 changes: 23 additions & 0 deletions pkg/resolution/resolver/http/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2023 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package http

const (
// timeoutKey is the configuration field name for controlling
// the maximum duration of a resolution request for a file from http.
timeoutKey = "fetch-timeout"
)
19 changes: 19 additions & 0 deletions pkg/resolution/resolver/http/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright 2023 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package http

const (
// urlParam is the url to fetch the task from
urlParam string = "url"
)
Loading

0 comments on commit ba9d269

Please sign in to comment.