Skip to content
Open
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
2 changes: 2 additions & 0 deletions config/resolvers/hubresolver-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ data:
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 Artifact Hub StepAction catalog from where to pull the resource.
default-artifact-hub-stepaction-catalog: "git-clone-stepaction"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be this one, but most likely tekton-catalog-stepactions isn't it ? But it was never created..

# the default layer kind in the hub image.
default-kind: "task"
# the default hub source to pull the resource from.
Expand Down
11 changes: 5 additions & 6 deletions docs/hub-resolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Use resolver type `hub`.

| Param Name | Description | Example Value |
|------------------|-------------------------------------------------------------------------------|------------------------------------------------------------|
| `catalog` | The catalog from where to pull the resource (Optional) | Default: `tekton-catalog-tasks` (for `task` kind); `tekton-catalog-pipelines` (for `pipeline` kind); no default for `stepaction` kind, so `catalog` must be set explicitly |
| `catalog` | The catalog from where to pull the resource (Optional) | Default: `tekton-catalog-tasks` (for `task` kind); `tekton-catalog-pipelines` (for `pipeline` kind); `git-clone-stepaction` (for `stepaction` kind) |
| `type` | The type of Hub from where to pull the resource (Optional). Either `artifact` or `tekton` | Default: `artifact` (recommended). Note: `tekton` type is deprecated. |
| `kind` | `task`, `pipeline` or `stepaction` (Optional) | Default: `task` |
| `name` | The name of the task or pipeline to fetch from the hub | `golang-build` |
| `version` | Version or a Constraint (see [below](#version-constraint) of a task or a pipeline to pull in from. Wrap the number in quotes! | `"0.5.0"`, `">= 0.5.0"` |
| `name` | The name of the task, pipeline, or StepAction to fetch from the hub | `golang-build` |
| `version` | Version or a Constraint (see [below](#version-constraint)) of a task, pipeline, or StepAction to pull in. Wrap the number in quotes! | `"0.5.0"`, `">= 0.5.0"` |
| `url` | Custom hub API endpoint to query instead of the cluster-configured default (Optional). Must be an absolute HTTP or HTTPS URL. Overrides all other URL configuration (ConfigMap URL lists, environment variables, and defaults). | `https://internal-hub.example.com` |

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`.
Expand All @@ -43,7 +43,8 @@ for the name, namespace and defaults that the resolver ships with.
| `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-artifact-hub-stepaction-catalog`| The default artifact hub catalog from where to pull the resource for StepAction kind. | `git-clone-stepaction` |
| `default-kind` | The default object kind for references. | `task`, `pipeline`, `stepaction` |
| `default-type` | The default hub from where to pull the resource. | `artifact`, `tekton` |
| `artifact-hub-urls` | Ordered YAML list of Artifact Hub API URLs to try. First successful response wins. If not set, the `ARTIFACT_HUB_API` env var or default is used. URLs must use `http` or `https` scheme. | See [below](#configuring-multiple-hub-urls) |
| `tekton-hub-urls` | Ordered YAML list of Tekton Hub API URLs to try. First successful response wins. If not set, the `TEKTON_HUB_API` env var is used. URLs must use `http` or `https` scheme. | See [below](#configuring-multiple-hub-urls) |
Expand Down Expand Up @@ -145,8 +146,6 @@ spec:
ref:
resolver: hub
params:
- name: catalog
value: git-clone-stepaction
- name: type # optional
value: artifact
- name: kind
Expand Down
6 changes: 6 additions & 0 deletions pkg/remoteresolution/resolver/hub/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ func resolveCatalogName(paramsMap, conf map[string]string) (string, error) {
return configAHTaskCatalog, nil
case "pipeline":
return configAHPipelineCatalog, nil
case hub.StepActionKind:
configAHStepActionCatalog, ok := conf[hub.ConfigArtifactHubStepActionCatalog]
if !ok {
return "", errors.New("default Artifact Hub StepAction catalog was not set during installation of the hub resolver")
}
return configAHStepActionCatalog, nil
default:
return "", fmt.Errorf("failed to resolve catalog name with kind: %s", paramsMap[hub.ParamKind])
}
Expand Down
67 changes: 63 additions & 4 deletions pkg/remoteresolution/resolver/hub/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,64 @@ func TestValidateMissing(t *testing.T) {
}
}

func TestResolveCatalogNameStepAction(t *testing.T) {
params := map[string]string{
hubresolver.ParamKind: hubresolver.StepActionKind,
hubresolver.ParamType: ArtifactHubType,
}
conf := resolutionframework.GetResolverConfigFromContext(contextWithConfig())

got, err := resolveCatalogName(params, conf)
if err != nil {
t.Fatalf("unexpected error resolving catalog: %v", err)
}
if want := "git-clone-stepaction"; got != want {
t.Errorf("expected catalog %q but got %q", want, got)
}
}

func TestResolveCatalogNameWithoutStepActionCatalog(t *testing.T) {
conf := resolutionframework.GetResolverConfigFromContext(contextWithConfig())
delete(conf, hubresolver.ConfigArtifactHubStepActionCatalog)

t.Run("stepaction requires its default", func(t *testing.T) {
params := map[string]string{hubresolver.ParamKind: hubresolver.StepActionKind, hubresolver.ParamType: ArtifactHubType}
_, err := resolveCatalogName(params, conf)
if err == nil {
t.Fatal("expected an error when the default StepAction catalog is not configured")
}
if want := "default Artifact Hub StepAction catalog was not set during installation of the hub resolver"; err.Error() != want {
t.Errorf("expected error %q but got %q", want, err)
}
})

t.Run("explicit stepaction catalog remains compatible", func(t *testing.T) {
params := map[string]string{
hubresolver.ParamCatalog: "custom-stepactions",
hubresolver.ParamKind: hubresolver.StepActionKind,
hubresolver.ParamType: ArtifactHubType,
}
got, err := resolveCatalogName(params, conf)
if err != nil {
t.Fatalf("unexpected error resolving explicit StepAction catalog: %v", err)
}
if want := "custom-stepactions"; got != want {
t.Errorf("expected catalog %q but got %q", want, got)
}
})

t.Run("task remains compatible", func(t *testing.T) {
params := map[string]string{hubresolver.ParamKind: "task", hubresolver.ParamType: ArtifactHubType}
got, err := resolveCatalogName(params, conf)
if err != nil {
t.Fatalf("unexpected error resolving task catalog: %v", err)
}
if want := "tekton-catalog-tasks"; got != want {
t.Errorf("expected catalog %q but got %q", want, got)
}
})
}

func TestValidateConflictingKindName(t *testing.T) {
testCases := []struct {
kind string
Expand Down Expand Up @@ -304,10 +362,11 @@ func toParams(m map[string]string) []pipelinev1.Param {

func contextWithConfig() context.Context {
config := map[string]string{
"default-tekton-hub-catalog": "Tekton",
"default-artifact-hub-task-catalog": "tekton-catalog-tasks",
"default-artifact-hub-pipeline-catalog": "tekton-catalog-pipelines",
"default-type": "artifact",
"default-tekton-hub-catalog": "Tekton",
"default-artifact-hub-task-catalog": "tekton-catalog-tasks",
"default-artifact-hub-pipeline-catalog": "tekton-catalog-pipelines",
"default-artifact-hub-stepaction-catalog": "git-clone-stepaction",
"default-type": "artifact",
}

return resolutionframework.InjectResolverConfigToContext(context.Background(), config)
Expand Down
4 changes: 4 additions & 0 deletions pkg/resolution/resolver/hub/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const ConfigArtifactHubTaskCatalog = "default-artifact-hub-task-catalog"
// the Artifact Hub Pipeline catalog to fetch the remote resource from.
const ConfigArtifactHubPipelineCatalog = "default-artifact-hub-pipeline-catalog"

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

// ConfigKind is the configuration field name for controlling
// what the layer name in the hub image is.
const ConfigKind = "default-kind"
Expand Down
9 changes: 9 additions & 0 deletions pkg/resolution/resolver/hub/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const (
// TektonHubType is the value to use setting the type field to tekton
TektonHubType string = "tekton"

// StepActionKind is the value to use setting the kind field to stepaction
StepActionKind = "stepaction"

disabledError = "cannot handle resolution request, enable-hub-resolver feature flag not true"
)

Expand Down Expand Up @@ -267,6 +270,12 @@ func resolveCatalogName(paramsMap, conf map[string]string) (string, error) {
return configAHTaskCatalog, nil
case "pipeline":
return configAHPipelineCatalog, nil
case StepActionKind:
configAHStepActionCatalog, ok := conf[ConfigArtifactHubStepActionCatalog]
if !ok {
return "", errors.New("default Artifact Hub StepAction catalog was not set during installation of the hub resolver")
}
return configAHStepActionCatalog, nil
default:
return "", fmt.Errorf("failed to resolve catalog name with kind: %s", paramsMap[ParamKind])
}
Expand Down
57 changes: 53 additions & 4 deletions pkg/resolution/resolver/hub/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ func TestResolveCatalogName(t *testing.T) {
hubType: "artifact",
expectedCat: "tekton-catalog-pipelines",
},
{
name: "artifact type default stepaction catalog",
kind: StepActionKind,
hubType: "artifact",
expectedCat: "git-clone-stepaction",
},
{
name: "custom catalog",
inputCat: "custom-catalog",
Expand Down Expand Up @@ -495,6 +501,48 @@ func TestResolveCatalogName(t *testing.T) {
}
}

func TestResolveCatalogNameWithoutStepActionCatalog(t *testing.T) {
conf := framework.GetResolverConfigFromContext(contextWithConfig())
delete(conf, ConfigArtifactHubStepActionCatalog)

t.Run("stepaction requires its default", func(t *testing.T) {
params := map[string]string{ParamKind: StepActionKind, ParamType: ArtifactHubType}
_, err := resolveCatalogName(params, conf)
if err == nil {
t.Fatal("expected an error when the default StepAction catalog is not configured")
}
if want := "default Artifact Hub StepAction catalog was not set during installation of the hub resolver"; err.Error() != want {
t.Errorf("expected error %q but got %q", want, err)
}
})

t.Run("explicit stepaction catalog remains compatible", func(t *testing.T) {
params := map[string]string{
ParamCatalog: "custom-stepactions",
ParamKind: StepActionKind,
ParamType: ArtifactHubType,
}
got, err := resolveCatalogName(params, conf)
if err != nil {
t.Fatalf("unexpected error resolving explicit StepAction catalog: %v", err)
}
if want := "custom-stepactions"; got != want {
t.Errorf("expected catalog %q but got %q", want, got)
}
})

t.Run("task remains compatible", func(t *testing.T) {
params := map[string]string{ParamKind: "task", ParamType: ArtifactHubType}
got, err := resolveCatalogName(params, conf)
if err != nil {
t.Fatalf("unexpected error resolving task catalog: %v", err)
}
if want := "tekton-catalog-tasks"; got != want {
t.Errorf("expected catalog %q but got %q", want, got)
}
})
}

func TestResolveDisabled(t *testing.T) {
resolver := Resolver{}

Expand Down Expand Up @@ -641,10 +689,11 @@ func toParams(m map[string]string) []pipelinev1.Param {

func contextWithConfig() context.Context {
config := map[string]string{
"default-tekton-hub-catalog": "Tekton",
"default-artifact-hub-task-catalog": "tekton-catalog-tasks",
"default-artifact-hub-pipeline-catalog": "tekton-catalog-pipelines",
"default-type": "artifact",
"default-tekton-hub-catalog": "Tekton",
"default-artifact-hub-task-catalog": "tekton-catalog-tasks",
"default-artifact-hub-pipeline-catalog": "tekton-catalog-pipelines",
"default-artifact-hub-stepaction-catalog": "git-clone-stepaction",
"default-type": "artifact",
}

return framework.InjectResolverConfigToContext(context.Background(), config)
Expand Down
Loading