Helm chart version validation error is not clear to users when trying to add helm chart to the Package Registry
Summary
Helm chart with incorrectly formatted version does not appear in the Package Registry due to validation error, and there is no clear indication of an error when uploading such chart.
Steps to reproduce
- create a helm chart with the version that is not following semver 2 convention in
Chart.yaml
, for example:v2021.08.0-build
- publish this chart in your Helm Package registry
What is the current bug behavior?
The chart will be successfully uploaded, and the API call will return 201 Created
, but the process will actually fail at later step during the version validation when running the background job. As a result, the chart will not be visible in the Package Registry in GitLab UI.
What is the expected correct behavior?
We should fail earlier: probably validate the chart version at the beginning & explain to users that the validation fails.
Relevant logs and/or screenshots
The reason why the helm chart is not visible in UI becomes clear only after checking the log /var/log/gitlab/sidekiq/current
:
{
"severity": "WARN",
"time": "2021-08-13T08:41:33.311Z",
"class": "Packages::Helm::ExtractionWorker",
"args": [
"[FILTERED]",
"29"
],
"retry": 25,
"queue": "package_repositories:packages_helm_extraction",
"version": 0,
"queue_namespace": "package_repositories",
"jid": "1eeb223c5eaf2ce6ffb57e58",
"created_at": "2021-08-13T08:38:20.699Z",
"meta.user": "root",
"meta.caller_id": "POST /api/:version/projects/:id/packages/helm/api/:channel/charts",
...
"meta.feature_category": "package_registry",
"meta.client_id": "user/1",
"correlation_id": "98b7e06d1be95723832d11e6404efd7f",
"idempotency_key": "resque:gitlab:duplicate:package_repositories:packages_helm_extraction:1bbff2b75a4610220822895a7aa8723833b840d0c50bf07cad09802317a9626b",
...
"error_message": "Validation failed: Version is invalid",
"error_class": "ActiveRecord::RecordInvalid",
"error_backtrace": [
"app/services/packages/helm/process_file_service.rb:39:in `rename_package_and_set_version'",
"app/services/packages/helm/process_file_service.rb:23:in `block (2 levels) in execute'",
"lib/gitlab/database.rb:405:in `block in transaction'",
"lib/gitlab/database.rb:404:in `transaction'",
"app/services/packages/helm/process_file_service.rb:22:in `block in execute'",
"app/services/concerns/exclusive_lease_guard.rb:29:in `try_obtain_lease'",
"app/services/packages/helm/process_file_service.rb:21:in `execute'",
"app/workers/packages/helm/extraction_worker.rb:19:in `perform'",
"lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/until_executing.rb:16:in `perform'",
"lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb:41:in `perform'",
"lib/gitlab/sidekiq_middleware/duplicate_jobs/server.rb:8:in `call'",
"lib/gitlab/sidekiq_middleware/worker_context.rb:9:in `wrap_in_optional_context'",
"lib/gitlab/sidekiq_middleware/worker_context/server.rb:17:in `block in call'",
"lib/gitlab/application_context.rb:74:in `block in use'",
"lib/gitlab/application_context.rb:74:in `use'",
"lib/gitlab/application_context.rb:27:in `with_context'",
"lib/gitlab/sidekiq_middleware/worker_context/server.rb:15:in `call'",
"lib/gitlab/sidekiq_status/server_middleware.rb:7:in `call'",
"lib/gitlab/sidekiq_versioning/middleware.rb:9:in `call'",
"lib/gitlab/sidekiq_middleware/admin_mode/server.rb:14:in `call'",
"lib/gitlab/sidekiq_middleware/instrumentation_logger.rb:9:in `call'",
"lib/gitlab/sidekiq_middleware/batch_loader.rb:7:in `call'",
"lib/gitlab/sidekiq_middleware/extra_done_log_metadata.rb:7:in `call'",
"lib/gitlab/sidekiq_middleware/request_store_middleware.rb:10:in `block in call'",
"lib/gitlab/with_request_store.rb:17:in `enabling_request_store'",
"lib/gitlab/with_request_store.rb:10:in `with_request_store'",
"lib/gitlab/sidekiq_middleware/request_store_middleware.rb:9:in `call'",
"lib/gitlab/sidekiq_middleware/server_metrics.rb:69:in `block in call'",
"lib/gitlab/sidekiq_middleware/server_metrics.rb:92:in `block in instrument'",
"lib/gitlab/metrics/background_transaction.rb:30:in `run'",
"lib/gitlab/sidekiq_middleware/server_metrics.rb:92:in `instrument'",
"lib/gitlab/sidekiq_middleware/server_metrics.rb:68:in `call'",
"lib/gitlab/sidekiq_middleware/monitor.rb:8:in `block in call'",
"lib/gitlab/sidekiq_daemon/monitor.rb:49:in `within_job'",
"lib/gitlab/sidekiq_middleware/monitor.rb:7:in `call'",
"lib/gitlab/sidekiq_middleware/size_limiter/server.rb:13:in `call'",
"lib/gitlab/sidekiq_logging/structured_logger.rb:19:in `call'"
],
"db_duration_s": 0.003753
}
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
System information System: Ubuntu 18.04 Proxy: no Current User: git Using RVM: no Ruby Version: 2.7.2p137 Gem Version: 3.1.4 Bundler Version:2.1.4 Rake Version: 13.0.3 Redis Version: 6.0.14 Git Version: 2.32.0 Sidekiq Version:5.2.9 Go Version: unknown GitLab information Version: 14.1.0-ee Revision: e4567ef4362 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 12.6 URL: https://gitlabhost.tld HTTP Clone URL: https://gitlabhost.tld/some-group/some-project.git SSH Clone URL: git@gitlabhost.tld:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers: google_oauth2 GitLab Shell Version: 13.19.0 Repository storage paths: - default: /var/opt/gitlab/git-data/repositories GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Git: /opt/gitlab/embedded/bin/git
Possible fixes
We are trying to rename the package in https://gitlab.com/gitlab-org/gitlab/-/blob/v14.1.2-ee/app/services/packages/helm/process_file_service.rb#L33, and we validate the version in https://gitlab.com/gitlab-org/gitlab/blob/v14.1.2-ee/lib/gitlab/regex.rb#L140 using the regex similar to semver.