Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEP-0115] Support Artifact Hub in Hub Resolver #5666

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions cmd/resolvers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,26 @@ import (

func main() {
ctx := filteredinformerfactory.WithSelectors(signals.NewContext(), v1alpha1.ManagedByLabelKey)

apiURL := os.Getenv("HUB_API")
hubURL := hub.DefaultHubURL
if apiURL == "" {
hubURL = hub.DefaultHubURL
} else {
if !strings.HasSuffix(apiURL, "/") {
apiURL += "/"
}
hubURL = apiURL + hub.YamlEndpoint
}
tektonHubURL := buildHubURL(os.Getenv("TEKTON_HUB_API"), "", hub.TektonHubYamlEndpoint)
artifactHubURL := buildHubURL(os.Getenv("ARTIFACT_HUB_API"), hub.DefaultArtifactHubURL, hub.ArtifactHubYamlEndpoint)

sharedmain.MainWithContext(ctx, "controller",
framework.NewController(ctx, &git.Resolver{}),
framework.NewController(ctx, &hub.Resolver{HubURL: hubURL}),
framework.NewController(ctx, &hub.Resolver{TektonHubURL: tektonHubURL, ArtifactHubURL: artifactHubURL}),
framework.NewController(ctx, &bundle.Resolver{}),
framework.NewController(ctx, &cluster.Resolver{}))
}

func buildHubURL(configAPI, defaultURL, yamlEndpoint string) string {
var hubURL string
if configAPI == "" {
hubURL = defaultURL
} else {
if !strings.HasSuffix(configAPI, "/") {
configAPI += "/"
}
hubURL = configAPI + yamlEndpoint
QuanZhang-William marked this conversation as resolved.
Show resolved Hide resolved
}

return hubURL
}
12 changes: 9 additions & 3 deletions config/resolvers/hubresolver-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ metadata:
app.kubernetes.io/instance: default
app.kubernetes.io/part-of: tekton-pipelines
data:
# the default catalog from where to pull the resource.
default-catalog: "Tekton"
# The default layer kind in the hub image.
# the default Tekton Hub catalog from where to pull the resource.
default-tekton-hub-catalog: "Tekton"
# the default Artifact Hub Task catalog from where to pull the resource.
default-artifact-hub-task-catalog: "tekton-catalog-tasks"
# the default Artifact Hub Pipeline catalog from where to pull the resource.
default-artifact-hub-pipeline-catalog: "tekton-catalog-pipelines"
# the default layer kind in the hub image.
default-kind: "task"
# the default hub source to pull the resource from.
default-type: "artifact"
4 changes: 2 additions & 2 deletions config/resolvers/resolvers-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ spec:
- name: METRICS_DOMAIN
value: tekton.dev/resolution
# Override this env var to set a private hub api endpoint
- name: HUB_API
value: "https://api.hub.tekton.dev/"
- name: ARTIFACT_HUB_API
value: "https://artifacthub.io/"
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
Expand Down
52 changes: 39 additions & 13 deletions docs/hub-resolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ Use resolver type `hub`.

| Param Name | Description | Example Value |
|------------------|-------------------------------------------------------------------------------|------------------------------------------------------------|
| `catalog` | The catalog from where to pull the resource (Optional) | Default: `Tekton` |
| `kind` | Either `task` or `pipeline` | `task` |
| `catalog` | The catalog from where to pull the resource (Optional) | Default: `tekton-catalog-tasks` (for `task` kind); `tekton-catalog-pipelines` (for `pipeline` kind) |
| `type` | The type of Hub from where to pull the resource (Optional). Either `artifact` or `tekton` | Default: `artifact` |
| `kind` | Either `task` or `pipeline` (Optional) | Default: `task` |
| `name` | The name of the task or pipeline to fetch from the hub | `golang-build` |
| `version` | Version of task or pipeline to pull in from hub. Wrap the number in quotes! | `"0.5"` |
| `version` | Version of task or pipeline to pull in from hub. Wrap the number in quotes! | `"0.5.0"` |

The Catalogs in the Artifact Hub follows the semVer (i.e.` <major-version>.<minor-version>.0`) and the Catalogs in the Tekton Hub follows the simplified semVer (i.e. `<major-version>.<minor-version>`). Both full and simplified semantic versioning will be accepted by the `version` parameter. The Hub Resolver will map the version to the format expected by the target Hub `type`.

## Requirements

Expand All @@ -26,25 +29,44 @@ for the name, namespace and defaults that the resolver ships with.

### Options

| Option Name | Description | Example Values |
|-------------------|------------------------------------------------------|--------------------|
| `default-catalog` | The default catalog from where to pull the resource. | `tekton` |
| `default-kind` | The default object kind for references. | `task`, `pipeline` |
| Option Name | Description | Example Values |
|-----------------------------|------------------------------------------------------|------------------------|
| `default-tekton-hub-catalog`| The default tekton hub catalog from where to pull the resource.| `Tekton` |
| `default-artifact-hub-task-catalog`| The default artifact hub catalog from where to pull the resource for task kind.| `tekton-catalog-tasks` |
| `default-artifact-hub-pipeline-catalog`| The default artifact hub catalog from where to pull the resource for pipeline kind. | `tekton-catalog-pipelines` |
| `default-kind` | The default object kind for references. | `task`, `pipeline` |
| `default-type` | The default hub from where to pull the resource. | `artifact`, `tekton` |


### Configuring the Hub API endpoint

By default this resolver will hit the public hub api at https://hub.tekton.dev/
The Hub Resolver supports to resolve resources from the [Artifact Hub](https://artifacthub.io/) and the [Tekton Hub](https://hub.tekton.dev/),
which can be configured by setting the `type` field of the resolver.

*(Please note that the [Tekton Hub](https://hub.tekton.dev/) will be deprecated after [migration to the Artifact Hub](https://github.com/tektoncd/hub/issues/667) is done.)*

When setting the `type` field to `artifact`, the resolver will hit the public hub api at https://artifacthub.io/ by default
but you can configure your own (for example to use a private hub
instance) by setting the `HUB_API` environment variable in
instance) by setting the `ARTIFACT_HUB_API` environment variable in
[`../config/resolvers/resolvers-deployment.yaml`](../config/resolvers/resolvers-deployment.yaml). Example:

```yaml
env
- name: ARTIFACT_HUB_API
value: "https://artifacthub.io/"
```

When setting the `type` field to `tekton`, you **must** configure your own instance of the Tekton Hub by setting the `TEKTON_HUB_API` environment variable in
[`../config/resolvers/resolvers-deployment.yaml`](../config/resolvers/resolvers-deployment.yaml). Example:

```yaml
env
- name: HUB_API
value: "https://api.hub.tekton.dev/"
- name: TEKTON_HUB_API
value: "https://api.private.hub.instance.dev"
```

The Tekton Hub deployment guide can be found [here](https://github.com/tektoncd/hub/blob/main/docs/DEPLOYMENT.md).

## Usage

### Task Resolution
Expand All @@ -59,7 +81,9 @@ spec:
resolver: hub
params:
- name: catalog # optional
value: Tekton
value: tekton-catalog-tasks
- name: type # optional
value: artifact
- name: kind
value: task
- name: name
Expand All @@ -80,7 +104,9 @@ spec:
resolver: hub
params:
- name: catalog # optional
value: Tekton
value: tekton-catalog-pipelines
- name: type # optional
value: artifact
- name: kind
value: pipeline
- name: name
Expand Down
32 changes: 28 additions & 4 deletions examples/v1beta1/taskruns/hub-resolver.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
generateName: hub-resolver
generateName: hub-resolver-simple-semver-
spec:
workspaces:
- name: output
Expand All @@ -17,11 +17,35 @@ spec:
taskRef:
resolver: hub
params:
- name: catalog # optional
value: Tekton
- name: kind
- name: type #optional
value: artifact
- name: kind #optional
value: task
- name: name
value: git-clone
- name: version
value: "0.6"
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
generateName: hub-resolver-semver-required-fields-only-
spec:
workspaces:
- name: output
emptyDir: {}
podTemplate:
securityContext:
fsGroup: 65532
params:
- name: url
value: https://github.com/tektoncd/pipeline.git
- name: revision
value: main
taskRef:
resolver: hub
params:
- name: name
value: git-clone
- name: version
value: "0.6.0"
18 changes: 15 additions & 3 deletions pkg/resolution/resolver/hub/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ limitations under the License.

package hub

// ConfigCatalog is the configuration field name for controlling
// the catalog to fetch the remote resource from.
const ConfigCatalog = "default-catalog"
// ConfigTektonHubCatalog is the configuration field name for controlling
// the Tekton Hub catalog to fetch the remote resource from.
const ConfigTektonHubCatalog = "default-tekton-hub-catalog"

// ConfigArtifactHubTaskCatalog is the configuration field name for controlling
// the Artifact Hub Task catalog to fetch the remote resource from.
const ConfigArtifactHubTaskCatalog = "default-artifact-hub-task-catalog"

// ConfigArtifactHubPipelineCatalog is the configuration field name for controlling
// the Artifact Hub Pipeline catalog to fetch the remote resource from.
const ConfigArtifactHubPipelineCatalog = "default-artifact-hub-pipeline-catalog"

// ConfigKind is the configuration field name for controlling
// what the layer name in the hub image is.
const ConfigKind = "default-kind"

// ConfigType is the configuration field name for controlling
// the hub type to pull the resource from.
const ConfigType = "default-type"
14 changes: 10 additions & 4 deletions pkg/resolution/resolver/hub/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ limitations under the License.

package hub

// DefaultHubURL is de default url for the Tekton hub api
const DefaultHubURL = "https://api.hub.tekton.dev/v1/resource/%s/%s/%s/%s/yaml"
// DefaultArtifactHubURL is the default url for the Artifact hub api
const DefaultArtifactHubURL = "https://artifacthub.io/api/v1/packages/tekton-%s/%s/%s/%s"

// YamlEndpoint is the suffix for a private custom hub instance
const YamlEndpoint = "v1/resource/%s/%s/%s/%s/yaml"
// TektonHubYamlEndpoint is the suffix for a private custom Tekton hub instance
const TektonHubYamlEndpoint = "v1/resource/%s/%s/%s/%s/yaml"

// ArtifactHubYamlEndpoint is the suffix for a private custom Artifact hub instance
const ArtifactHubYamlEndpoint = "api/v1/packages/tekton-%s/%s/%s/%s"

// ParamName is the parameter defining what the layer name in the bundle
// image is.
Expand All @@ -34,3 +37,6 @@ const ParamVersion = "version"
// ParamCatalog is the parameter defining what the catalog in the bundle
// image is.
const ParamCatalog = "catalog"

// ParamType is the parameter defining what the hub type to pull the resource from.
const ParamType = "type"
Loading