diff --git a/config/resolvers/hubresolver-config.yaml b/config/resolvers/hubresolver-config.yaml index 47570cc764d..fc0fd4d27d0 100644 --- a/config/resolvers/hubresolver-config.yaml +++ b/config/resolvers/hubresolver-config.yaml @@ -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" # the default layer kind in the hub image. default-kind: "task" # the default hub source to pull the resource from. diff --git a/docs/hub-resolver.md b/docs/hub-resolver.md index aca05ef40ae..168ec165ca4 100644 --- a/docs/hub-resolver.md +++ b/docs/hub-resolver.md @@ -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.` ..0`) and the Catalogs in the Tekton Hub follows the simplified semVer (i.e. `.`). 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`. @@ -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) | @@ -145,8 +146,6 @@ spec: ref: resolver: hub params: - - name: catalog - value: git-clone-stepaction - name: type # optional value: artifact - name: kind diff --git a/pkg/remoteresolution/resolver/hub/resolver.go b/pkg/remoteresolution/resolver/hub/resolver.go index e5322c50c37..4aa5903ca98 100644 --- a/pkg/remoteresolution/resolver/hub/resolver.go +++ b/pkg/remoteresolution/resolver/hub/resolver.go @@ -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]) } diff --git a/pkg/remoteresolution/resolver/hub/resolver_test.go b/pkg/remoteresolution/resolver/hub/resolver_test.go index 103e170f907..442ece4ae90 100644 --- a/pkg/remoteresolution/resolver/hub/resolver_test.go +++ b/pkg/remoteresolution/resolver/hub/resolver_test.go @@ -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 @@ -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) diff --git a/pkg/resolution/resolver/hub/config.go b/pkg/resolution/resolver/hub/config.go index 747b9c4e1ec..bda602c54f8 100644 --- a/pkg/resolution/resolver/hub/config.go +++ b/pkg/resolution/resolver/hub/config.go @@ -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" diff --git a/pkg/resolution/resolver/hub/resolver.go b/pkg/resolution/resolver/hub/resolver.go index d4dc8179f00..265fe0027c2 100644 --- a/pkg/resolution/resolver/hub/resolver.go +++ b/pkg/resolution/resolver/hub/resolver.go @@ -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" ) @@ -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]) } diff --git a/pkg/resolution/resolver/hub/resolver_test.go b/pkg/resolution/resolver/hub/resolver_test.go index abc2e04ece7..9b018f39417 100644 --- a/pkg/resolution/resolver/hub/resolver_test.go +++ b/pkg/resolution/resolver/hub/resolver_test.go @@ -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", @@ -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{} @@ -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)