Multiple UI errors when a kubernetes deployment in a linked environment has 0 replicas
Summary
Multiple UI errors when a kubernetes deployment in a linked cluster/environment has 0 replicas.
The /jobs/ID page shows "An error occurred while fetching the job." and has an exception 'NoMethodErrorProjects::JobsController#show'
The /environments page shows "An error occurred while fetching the environments." and has an exception 'NoMethodError (private method `select' called for nil:NilClass):'
Steps to reproduce
Link a kubernetes cluster to an environment scope such as "prod", do a kubernetes deployment to that environment and the job logs work. Manually scale the linked kubernetes deployment outside gitlab to have 0 replicas and visit the job log again to observe the error.
The same procedure will lead to an error on the Environment page.
Example Project
n/a
What is the current bug behavior?
The /jobs/ID page shows a red error banner "An error occurred while fetching the job." The /environments page shows a red error banner "An error occurred while fetching the environments."
What is the expected correct behavior?
I realize that manually scaling a deployment to 0 replicas might not be a common use-case but I would expect the jobs log page to be able to display the logs and the environment page to show 0 pods for that environment.
Relevant logs and/or screenshots
When a deployment is scaled to 0 replicas in a kubernetes cluster/namespace linked to the environment.
A visit to https://gitlab.mydomain.net/mygroup/myapplication/-/jobs/21112 causes this exception:
NoMethodError (private method `select' called for nil:NilClass):
ee/lib/gitlab/kubernetes/deployment.rb:64:in `block in filtered_pods_by_track'
lib/gitlab/utils/strong_memoize.rb:28:in `strong_memoize'
ee/lib/gitlab/kubernetes/deployment.rb:63:in `filtered_pods_by_track'
ee/lib/gitlab/kubernetes/deployment.rb:42:in `created_instances'
ee/lib/gitlab/kubernetes/deployment.rb:69:in `instances'
ee/lib/gitlab/kubernetes/rollout_status.rb:50:in `each'
ee/lib/gitlab/kubernetes/rollout_status.rb:50:in `flat_map'
ee/lib/gitlab/kubernetes/rollout_status.rb:50:in `initialize'
ee/lib/gitlab/kubernetes/rollout_status.rb:40:in `new'
ee/lib/gitlab/kubernetes/rollout_status.rb:40:in `from_deployments'
ee/app/models/concerns/ee/kubernetes_service.rb:14:in `block in rollout_status'
app/models/concerns/reactive_caching.rb:79:in `with_reactive_cache'
lib/gitlab/metrics/instrumentation.rb:161:in `block in with_reactive_cache'
lib/gitlab/metrics/method_call.rb:36:in `measure'
lib/gitlab/metrics/instrumentation.rb:161:in `with_reactive_cache'
ee/app/models/concerns/ee/kubernetes_service.rb:10:in `rollout_status'
ee/app/models/ee/environment.rb:50:in `rollout_status'
app/serializers/base_serializer.rb:16:in `represent'
app/controllers/projects/jobs_controller.rb:66:in `block (2 levels) in show'
app/controllers/projects/jobs_controller.rb:59:in `show'
lib/gitlab/i18n.rb:55:in `with_locale'
lib/gitlab/i18n.rb:61:in `with_user_locale'
app/controllers/application_controller.rb:417:in `set_locale'
lib/gitlab/middleware/rails_queue_duration.rb:24:in `call'
lib/gitlab/metrics/rack_middleware.rb:17:in `block in call'
lib/gitlab/metrics/transaction.rb:55:in `run'
lib/gitlab/metrics/rack_middleware.rb:17:in `call'
lib/gitlab/middleware/multipart.rb:103:in `call'
lib/gitlab/request_profiler/middleware.rb:16:in `call'
ee/lib/gitlab/jira/middleware.rb:15:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:13:in `call'
lib/gitlab/middleware/correlation_id.rb:16:in `block in call'
lib/gitlab/correlation_id.rb:15:in `use_id'
lib/gitlab/middleware/correlation_id.rb:15:in `call'
lib/gitlab/middleware/read_only/controller.rb:42:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/request_context.rb:20:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:29:in `call'
lib/gitlab/middleware/release_env.rb:13:in `call'
Started GET "/mygroup/myapplication/-/jobs/21112" for my.ip.my.ip at 2019-02-14 16:37:41 +0000
A visit to https://gitlab.mydomain.net/mygroup/myapplication/environments causes this exception:
NoMethodError (private method `select' called for nil:NilClass):
ee/lib/gitlab/kubernetes/deployment.rb:64:in `block in filtered_pods_by_track'
lib/gitlab/utils/strong_memoize.rb:28:in `strong_memoize'
ee/lib/gitlab/kubernetes/deployment.rb:63:in `filtered_pods_by_track'
ee/lib/gitlab/kubernetes/deployment.rb:42:in `created_instances'
ee/lib/gitlab/kubernetes/deployment.rb:69:in `instances'
ee/lib/gitlab/kubernetes/rollout_status.rb:50:in `each'
ee/lib/gitlab/kubernetes/rollout_status.rb:50:in `flat_map'
ee/lib/gitlab/kubernetes/rollout_status.rb:50:in `initialize'
ee/lib/gitlab/kubernetes/rollout_status.rb:40:in `new'
ee/lib/gitlab/kubernetes/rollout_status.rb:40:in `from_deployments'
ee/app/models/concerns/ee/kubernetes_service.rb:14:in `block in rollout_status'
app/models/concerns/reactive_caching.rb:79:in `with_reactive_cache'
lib/gitlab/metrics/instrumentation.rb:161:in `block in with_reactive_cache'
lib/gitlab/metrics/method_call.rb:36:in `measure'
lib/gitlab/metrics/instrumentation.rb:161:in `with_reactive_cache'
ee/app/models/concerns/ee/kubernetes_service.rb:10:in `rollout_status'
ee/app/models/ee/environment.rb:50:in `rollout_status'
app/serializers/base_serializer.rb:16:in `represent'
app/serializers/concerns/with_pagination.rb:21:in `represent'
app/serializers/environment_serializer.rb:23:in `block in represent'
app/serializers/environment_serializer.rb:20:in `map'
app/serializers/environment_serializer.rb:20:in `represent'
app/controllers/projects/environments_controller.rb:34:in `block (2 levels) in index'
app/controllers/projects/environments_controller.rb:24:in `index'
lib/gitlab/i18n.rb:55:in `with_locale'
lib/gitlab/i18n.rb:61:in `with_user_locale'
app/controllers/application_controller.rb:417:in `set_locale'
lib/gitlab/middleware/rails_queue_duration.rb:24:in `call'
lib/gitlab/metrics/rack_middleware.rb:17:in `block in call'
lib/gitlab/metrics/transaction.rb:55:in `run'
lib/gitlab/metrics/rack_middleware.rb:17:in `call'
lib/gitlab/middleware/multipart.rb:103:in `call'
lib/gitlab/request_profiler/middleware.rb:16:in `call'
ee/lib/gitlab/jira/middleware.rb:15:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:25:in `call'
lib/gitlab/middleware/correlation_id.rb:16:in `block in call'
lib/gitlab/correlation_id.rb:15:in `use_id'
lib/gitlab/middleware/correlation_id.rb:15:in `call'
lib/gitlab/middleware/read_only/controller.rb:42:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/request_context.rb:20:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:29:in `call'
lib/gitlab/middleware/release_env.rb:13:in `call'
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
System information System: Ubuntu 16.04 Proxy: no Current User: git Using RVM: no Ruby Version: 2.5.3p105 Gem Version: 2.7.6 Bundler Version:1.16.6 Rake Version: 12.3.2 Redis Version: 3.2.12 Git Version: 2.18.1 Sidekiq Version:5.2.3 Go Version: unknown
GitLab information Version: 11.7.5-ee Revision: ed04633 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql DB Version: 9.6.6 URL: https://gitlab.mydomain.net HTTP Clone URL: https://gitlab.mydomain.net/some-group/some-project.git SSH Clone URL: git@gitlab.mydomain.net:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: yes Using Omniauth: yes Omniauth Providers: github
GitLab Shell Version: 8.4.4 Repository storage paths: default: /gitlab-efs/gitlab-data/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
Checking GitLab subtasks ...Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 8.4.4 ? ... OK (8.4.4) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Redis available via internal API: OK
Access to /gitlab-efs/gitlab-data/home/.ssh/authorized_keys: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking Incoming Email ...
Incoming Email: ... Reply by email is disabled in config/gitlab.yml
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... Server: ldapmain LDAP authentication... Success LDAP users with access to your GitLab server (only showing the first 100 results) ..All My LDAP users...
Checking LDAP ... Finished
Checking GitLab App ...
Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 3/4 ... yes 5/5 ... yes 3/6 ... yes 9/7 ... yes 9/8 ... yes 5/9 ... yes 16/10 ... yes 9/11 ... yes 5/12 ... yes 9/13 ... yes 9/14 ... yes 9/15 ... yes 9/16 ... yes 9/17 ... yes 9/18 ... yes 9/19 ... yes 9/20 ... yes 9/21 ... yes 5/22 ... yes 9/23 ... yes 9/24 ... yes 9/25 ... yes 9/27 ... yes 5/28 ... yes 9/29 ... yes 5/30 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.3.5 ? ... yes (2.5.3) Git version >= 2.18.0 ? ... yes (2.18.1) Git user has default SSH configuration? ... yes Active users: ... 16 Elasticsearch version 5.6 - 6.x? ... skipped (elasticsearch is disabled)
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished
Possible fixes
Ignore kubernetes deployments with 0 pods.