From 27e56be68b7fd082504974f824378870faab190a Mon Sep 17 00:00:00 2001 From: shverma Date: Fri, 12 Dec 2025 09:41:11 +0530 Subject: [PATCH 1/2] Remove default Artifacthub url override This patch includes the following changes: - Remove the default Hub catalog configuration from the PAC settings before PAC SyncConfig function call as this is already handled by the PAC SyncConfig function - Remove the default ArtifactHub URL override, which is managed by PAC. - Update the transform test to align with PAC changes, hub_url should not be fetchable, and PAC will now set the catalog type to tektonhub. Signed-off-by: Shiv Verma --- .../v1alpha1/openshiftpipelinesascode_defaults.go | 13 ++----------- .../openshiftpipelinesascode_defaults_test.go | 6 +++--- .../v1alpha1/openshiftpipelinesascode_validation.go | 2 +- .../testdata/test-expected-additional-pac-cm.yaml | 10 ++-------- .../openshift/openshiftpipelinesascode/transform.go | 2 +- .../openshiftpipelinesascode/transform_test.go | 2 +- 6 files changed, 10 insertions(+), 25 deletions(-) diff --git a/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_defaults.go b/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_defaults.go index baee7a20e5..d29f545d99 100644 --- a/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_defaults.go +++ b/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_defaults.go @@ -24,7 +24,6 @@ import ( "strings" "sync" - hubtypes "github.com/openshift-pipelines/pipelines-as-code/pkg/hub/vars" pacSettings "github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings" "go.uber.org/zap" "knative.dev/pkg/logging" @@ -46,7 +45,8 @@ func (set *PACSettings) setPACDefaults(logger *zap.SugaredLogger) { if set.Settings == nil { set.Settings = map[string]string{} } - defaultPacSettings := pacSettings.DefaultSettings() + defaultPacSettings := pacSettings.Settings{} + err := pacSettings.SyncConfig(logger, &defaultPacSettings, set.Settings, map[string]func(string) error{}) if err != nil { logger.Error("error on applying default PAC settings", err) @@ -55,15 +55,6 @@ func (set *PACSettings) setPACDefaults(logger *zap.SugaredLogger) { // Remove tektonhub catalog to only keep artifacthub defaultPacSettings.HubCatalogs.Delete("tektonhub") - // Override the default ArtifactHub URL to use https://artifacthub.io instead of https://artifacthub.io/api/v1 - if defaultCatalog, ok := defaultPacSettings.HubCatalogs.Load("default"); ok { - catalog := defaultCatalog.(pacSettings.HubCatalog) - if catalog.Type == hubtypes.ArtifactHubType { - catalog.URL = "https://artifacthub.io" - } - defaultPacSettings.HubCatalogs.Store("default", catalog) - } - set.Settings = ConvertPacStructToConfigMap(&defaultPacSettings) setAdditionalPACControllerDefault(set.AdditionalPACControllers) } diff --git a/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_defaults_test.go b/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_defaults_test.go index bfb0125879..59c8ae4f7b 100644 --- a/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_defaults_test.go +++ b/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_defaults_test.go @@ -61,7 +61,7 @@ func TestSetPACControllerDefaultSettings(t *testing.T) { "error-log-snippet": "true", "error-log-snippet-number-of-lines": "3", "hub-catalog-type": "artifacthub", - "hub-url": "https://artifacthub.io", + "hub-url": "https://artifacthub.io/api/v1", "max-keep-run-upper-limit": "0", "remember-ok-to-test": "false", "require-ok-to-test-sha": "false", @@ -120,7 +120,7 @@ func TestSetPACControllerLimitedSettings(t *testing.T) { "error-log-snippet": "true", "error-log-snippet-number-of-lines": "3", "hub-catalog-type": "artifacthub", - "hub-url": "https://artifacthub.io", + "hub-url": "https://artifacthub.io/api/v1", "max-keep-run-upper-limit": "0", "remember-ok-to-test": "false", "require-ok-to-test-sha": "false", @@ -186,7 +186,7 @@ func TestSetPACControllerDefaultSettingsWithMultipleCatalogs(t *testing.T) { "error-log-snippet": "true", "error-log-snippet-number-of-lines": "3", "hub-catalog-type": "artifacthub", - "hub-url": "https://artifacthub.io", + "hub-url": "https://artifacthub.io/api/v1", "max-keep-run-upper-limit": "0", "remember-ok-to-test": "false", "require-ok-to-test-sha": "false", diff --git a/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_validation.go b/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_validation.go index 6743223ebb..def4baecbd 100644 --- a/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_validation.go +++ b/pkg/apis/operator/v1alpha1/openshiftpipelinesascode_validation.go @@ -52,7 +52,7 @@ func (pac *OpenShiftPipelinesAsCode) Validate(ctx context.Context) *apis.FieldEr func (ps *PACSettings) validate(logger *zap.SugaredLogger, path string) *apis.FieldError { var errs *apis.FieldError - defaultPacSettings := pacSettings.DefaultSettings() + defaultPacSettings := pacSettings.Settings{} if err := pacSettings.SyncConfig(logger, &defaultPacSettings, ps.Settings, pacSettings.DefaultValidators()); err != nil { errs = errs.Also(apis.ErrInvalidValue(err, fmt.Sprintf("%s.settings", path))) } diff --git a/pkg/reconciler/openshift/openshiftpipelinesascode/testdata/test-expected-additional-pac-cm.yaml b/pkg/reconciler/openshift/openshiftpipelinesascode/testdata/test-expected-additional-pac-cm.yaml index dc5f685f51..6d18308064 100644 --- a/pkg/reconciler/openshift/openshiftpipelinesascode/testdata/test-expected-additional-pac-cm.yaml +++ b/pkg/reconciler/openshift/openshiftpipelinesascode/testdata/test-expected-additional-pac-cm.yaml @@ -27,10 +27,10 @@ data: secret-github-app-scope-extra-repos: "" # Tekton HUB API urls - hub-url: "https://custom-hub.com" + hub-url: "https://custom-hub-catalog.com" # Tekton HUB catalog type - hub-catalog-type: "artifacthub" + hub-catalog-type: "tektonhub" # Additional Hub Catalogs is supported, for example: # @@ -41,12 +41,6 @@ data: # this configuration will have a new catalog named anotherhub on https://api.other.com/v1 endpoint and catalog name tekton # to be used by a user in their templates like this: # pipelinesascode.tekton.dev/task: "anotherhub://task" - # - # Increase the number of the catalog to add more of them - catalog-tektonhub-id: "tektonhub" - catalog-tektonhub-name: "tekton" - catalog-tektonhub-type: "tektonhub" - catalog-tektonhub-url: "https://api.hub.tekton.dev/v1" # Allow fetching remote tasks remote-tasks: "true" diff --git a/pkg/reconciler/openshift/openshiftpipelinesascode/transform.go b/pkg/reconciler/openshift/openshiftpipelinesascode/transform.go index ac577ca36d..689003d16e 100644 --- a/pkg/reconciler/openshift/openshiftpipelinesascode/transform.go +++ b/pkg/reconciler/openshift/openshiftpipelinesascode/transform.go @@ -227,7 +227,7 @@ func updateAdditionControllerConfigMap(config v1alpha1.AdditionalPACControllerCo config.Settings = map[string]string{} } - defaultPacSettings := pacSettings.DefaultSettings() + defaultPacSettings := pacSettings.Settings{} err := pacSettings.SyncConfig(zap.NewNop().Sugar(), &defaultPacSettings, config.Settings, pacSettings.DefaultValidators()) if err != nil { return err diff --git a/pkg/reconciler/openshift/openshiftpipelinesascode/transform_test.go b/pkg/reconciler/openshift/openshiftpipelinesascode/transform_test.go index ec3b78c479..fc2cace06b 100644 --- a/pkg/reconciler/openshift/openshiftpipelinesascode/transform_test.go +++ b/pkg/reconciler/openshift/openshiftpipelinesascode/transform_test.go @@ -156,7 +156,7 @@ func TestUpdateAdditionControllerConfigMap(t *testing.T) { additionalPACConfig := v1alpha1.AdditionalPACControllerConfig{ ConfigMapName: "test-config", SecretName: "test-secret", - Settings: map[string]string{"application-name": "Test CI application", "hub-url": "https://custom-hub.com"}, + Settings: map[string]string{"application-name": "Test CI application", "hub-url": "https://custom-hub-catalog.com"}, } updatedManifest, err := manifest.Transform(updateAdditionControllerConfigMap(additionalPACConfig)) From 1a0443fe886b7ad4d6c826d3d1710649c16974b3 Mon Sep 17 00:00:00 2001 From: shverma Date: Tue, 16 Dec 2025 10:15:02 +0530 Subject: [PATCH 2/2] Bump openshift-pipelines/pipelines-as-code to v0.39.3 Signed-off-by: Shiv Verma --- go.mod | 2 +- go.sum | 4 +-- .../pkg/params/settings/default.go | 32 +++++++++++++++++++ vendor/modules.txt | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index cecda8b1dd..9d3255e459 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/manifestival/client-go-client v0.6.0 github.com/manifestival/manifestival v0.7.2 github.com/markbates/inflect v1.0.4 - github.com/openshift-pipelines/pipelines-as-code v0.39.2 + github.com/openshift-pipelines/pipelines-as-code v0.39.3 github.com/openshift/api v0.0.0-20240521185306-0314f31e7774 github.com/openshift/apiserver-library-go v0.0.0-20230816171015-6bfafa975bfb github.com/openshift/client-go v0.0.0-20240523113335-452272e0496d diff --git a/go.sum b/go.sum index f7ca8df17c..6316956199 100644 --- a/go.sum +++ b/go.sum @@ -2377,8 +2377,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8 github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= -github.com/openshift-pipelines/pipelines-as-code v0.39.2 h1:VvSzAaWlEcOnu6xRXWKEquYbdr6RYqTv6zQzIym+NK4= -github.com/openshift-pipelines/pipelines-as-code v0.39.2/go.mod h1:5KqGAgmiFldqi4KG4Vj/5juzbUbPucASmqKrWwePG9U= +github.com/openshift-pipelines/pipelines-as-code v0.39.3 h1:Er8vZZrbslGeaGG5tUlMbUlzTeMCyMRsWqSD5tIJUjo= +github.com/openshift-pipelines/pipelines-as-code v0.39.3/go.mod h1:5KqGAgmiFldqi4KG4Vj/5juzbUbPucASmqKrWwePG9U= github.com/openshift/api v0.0.0-20240521185306-0314f31e7774 h1:SsoLnIil/D0FcjUbQ9Z8h95B7rxFvrso2X6OQjR8jPw= github.com/openshift/api v0.0.0-20240521185306-0314f31e7774/go.mod h1:7Hm1kLJGxWT6eysOpD2zUztdn+w91eiERn6KtI5o9aw= github.com/openshift/apiserver-library-go v0.0.0-20230816171015-6bfafa975bfb h1:UMgJny13BBcHpY+JQ9Eg1Dm9+J7nWO3eqPvV1Zpd49A= diff --git a/vendor/github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings/default.go b/vendor/github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings/default.go index 85e196d071..f0ea70ec8d 100644 --- a/vendor/github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings/default.go +++ b/vendor/github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings/default.go @@ -1,9 +1,13 @@ package settings import ( + "context" "fmt" + "net/http" "net/url" + "strings" "sync" + "time" hubtypes "github.com/openshift-pipelines/pipelines-as-code/pkg/hub/vars" "go.uber.org/zap" @@ -20,6 +24,9 @@ func getHubCatalogs(logger *zap.SugaredLogger, catalogs *sync.Map, config map[st if hubType, ok := config[HubCatalogTypeKey]; !ok || hubType == "" { config[HubCatalogTypeKey] = hubtypes.ArtifactHubType + if config[HubURLKey] != "" { + config[HubCatalogTypeKey] = getHubCatalogTypeViaAPI(config[HubURLKey]) + } } else if hubType != hubtypes.ArtifactHubType && hubType != hubtypes.TektonHubType { logger.Warnf("CONFIG: invalid hub type %s, defaulting to %s", hubType, hubtypes.ArtifactHubType) config[HubCatalogTypeKey] = hubtypes.ArtifactHubType @@ -105,3 +112,28 @@ func getHubCatalogs(logger *zap.SugaredLogger, catalogs *sync.Map, config map[st } return catalogs } + +func getHubCatalogTypeViaAPI(hubURL string) string { + statsURL := fmt.Sprintf("%s/api/v1/stats", strings.TrimSuffix(hubURL, "/")) + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + req, err := http.NewRequestWithContext(ctx, http.MethodGet, statsURL, nil) + if err != nil { + return hubtypes.TektonHubType + } + + resp, err := http.DefaultClient.Do(req) + if err != nil { + return hubtypes.TektonHubType + } + defer resp.Body.Close() + + if resp.StatusCode == http.StatusOK { + return hubtypes.ArtifactHubType + } + + // if the API call fails, return Tekton Hub type + return hubtypes.TektonHubType +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 384bb1d0e6..776a17fed2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1001,7 +1001,7 @@ github.com/opencontainers/go-digest ## explicit; go 1.18 github.com/opencontainers/image-spec/specs-go github.com/opencontainers/image-spec/specs-go/v1 -# github.com/openshift-pipelines/pipelines-as-code v0.39.2 +# github.com/openshift-pipelines/pipelines-as-code v0.39.3 ## explicit; go 1.24.0 github.com/openshift-pipelines/pipelines-as-code/pkg/cli github.com/openshift-pipelines/pipelines-as-code/pkg/configutil