diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-14 15:06:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-14 15:06:14 +0300 |
commit | e464f195ff5debc3e9aad0f8c4537404b92019c6 (patch) | |
tree | 9efe381ffb9d8c9bceb3cced1e27b6b59dc6298b /app | |
parent | 5ff1b520badaa2da217416964709f49f3ede350a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/lib/utils/common_utils.js | 10 | ||||
-rw-r--r-- | app/models/clusters/cluster.rb | 14 | ||||
-rw-r--r-- | app/models/clusters/clusters_hierarchy.rb | 18 | ||||
-rw-r--r-- | app/models/clusters/platforms/kubernetes.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/deployment_platform.rb | 6 | ||||
-rw-r--r-- | app/models/project.rb | 5 | ||||
-rw-r--r-- | app/models/storage/hashed_project.rb | 8 | ||||
-rw-r--r-- | app/models/storage/legacy_project.rb | 10 | ||||
-rw-r--r-- | app/services/projects/hashed_storage/migrate_repository_service.rb | 1 | ||||
-rw-r--r-- | app/services/projects/hashed_storage/rollback_repository_service.rb | 1 | ||||
-rw-r--r-- | app/views/search/_form.html.haml | 1 | ||||
-rw-r--r-- | app/views/search/show.html.haml | 3 |
12 files changed, 50 insertions, 29 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index 7c4373ba517..177ae4f9838 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -177,6 +177,15 @@ export const urlParamsToArray = (path = '') => export const getUrlParamsArray = () => urlParamsToArray(window.location.search); +/** + * Accepts encoding string which includes query params being + * sent to URL. + * + * @param {string} path Query param string + * + * @returns {object} Query params object containing key-value pairs + * with both key and values decoded into plain string. + */ export const urlParamsToObject = (path = '') => splitPath(path).reduce((dataParam, filterParam) => { if (filterParam === '') { @@ -185,6 +194,7 @@ export const urlParamsToObject = (path = '') => const data = dataParam; let [key, value] = filterParam.split('='); + key = /%\w+/g.test(key) ? decodeURIComponent(key) : key; const isArray = key.includes('[]'); key = key.replace('[]', ''); value = decodeURIComponent(value.replace(/\+/g, ' ')); diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index 72f6acc0aa4..c49d5063f8b 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -24,6 +24,7 @@ module Clusters KUBE_INGRESS_BASE_DOMAIN = 'KUBE_INGRESS_BASE_DOMAIN' belongs_to :user + belongs_to :management_project, class_name: '::Project', optional: true has_many :cluster_projects, class_name: 'Clusters::Project' has_many :projects, through: :cluster_projects, class_name: '::Project' @@ -63,6 +64,7 @@ module Clusters validate :restrict_modification, on: :update validate :no_groups, unless: :group_type? validate :no_projects, unless: :project_type? + validate :unique_management_project_environment_scope after_save :clear_reactive_cache! @@ -200,6 +202,18 @@ module Clusters private + def unique_management_project_environment_scope + return unless management_project + + duplicate_management_clusters = management_project.management_clusters + .where(environment_scope: environment_scope) + .where.not(id: id) + + if duplicate_management_clusters.any? + errors.add(:environment_scope, "cannot add duplicated environment scope") + end + end + def instance_domain @instance_domain ||= Gitlab::CurrentSettings.auto_devops_domain end diff --git a/app/models/clusters/clusters_hierarchy.rb b/app/models/clusters/clusters_hierarchy.rb index 5556fc8d3f0..a906eb2888b 100644 --- a/app/models/clusters/clusters_hierarchy.rb +++ b/app/models/clusters/clusters_hierarchy.rb @@ -4,8 +4,9 @@ module Clusters class ClustersHierarchy DEPTH_COLUMN = :depth - def initialize(clusterable) + def initialize(clusterable, include_management_project: true) @clusterable = clusterable + @include_management_project = include_management_project end # Returns clusters in order from deepest to highest group @@ -24,7 +25,7 @@ module Clusters private - attr_reader :clusterable + attr_reader :clusterable, :include_management_project def recursive_cte cte = Gitlab::SQL::RecursiveCTE.new(:clusters_cte) @@ -38,12 +39,25 @@ module Clusters raise ArgumentError, "unknown type for #{clusterable}" end + if clusterable.is_a?(::Project) && include_management_project + cte << management_clusters_query + end + cte << base_query cte << parent_query(cte) cte end + # Management clusters should be first in the hierarchy so we use 0 for the + # depth column. + # + # group_parent_id is un-used but we still need to match the same number of + # columns as other queries in the CTE. + def management_clusters_query + clusterable.management_clusters.select([clusters_star, 'NULL AS group_parent_id', "0 AS #{DEPTH_COLUMN}"]) + end + def group_clusters_base_query group_parent_id_alias = alias_as_column(groups[:parent_id], 'group_parent_id') join_sources = ::Group.left_joins(:clusters).arel.join_sources diff --git a/app/models/clusters/platforms/kubernetes.rb b/app/models/clusters/platforms/kubernetes.rb index 943f36299d4..314ef78757d 100644 --- a/app/models/clusters/platforms/kubernetes.rb +++ b/app/models/clusters/platforms/kubernetes.rb @@ -73,7 +73,7 @@ module Clusters .append(key: 'KUBE_CA_PEM_FILE', value: ca_pem, file: true) end - if !cluster.managed? + if !cluster.managed? || cluster.management_project == project namespace = Gitlab::Kubernetes::DefaultNamespace.new(cluster, project: project).from_environment_name(environment_name) variables diff --git a/app/models/concerns/deployment_platform.rb b/app/models/concerns/deployment_platform.rb index e1a8725e728..fe8e9609820 100644 --- a/app/models/concerns/deployment_platform.rb +++ b/app/models/concerns/deployment_platform.rb @@ -11,6 +11,10 @@ module DeploymentPlatform private + def cluster_management_project_enabled? + Feature.enabled?(:cluster_management_project, default_enabled: true) + end + def find_deployment_platform(environment) find_platform_kubernetes_with_cte(environment) || find_instance_cluster_platform_kubernetes(environment: environment) @@ -18,7 +22,7 @@ module DeploymentPlatform # EE would override this and utilize environment argument def find_platform_kubernetes_with_cte(_environment) - Clusters::ClustersHierarchy.new(self).base_and_ancestors + Clusters::ClustersHierarchy.new(self, include_management_project: cluster_management_project_enabled?).base_and_ancestors .enabled.default_environment .first&.platform_kubernetes end diff --git a/app/models/project.rb b/app/models/project.rb index 26ed9b0cd1e..d7e3dc676ca 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -68,7 +68,7 @@ class Project < ApplicationRecord :snippets_access_level, :builds_access_level, :repository_access_level, to: :project_feature, allow_nil: true - delegate :base_dir, :disk_path, :ensure_storage_path_exists, to: :storage + delegate :base_dir, :disk_path, to: :storage delegate :scheduled?, :started?, :in_progress?, :failed?, :finished?, @@ -122,8 +122,6 @@ class Project < ApplicationRecord # Storage specific hooks after_initialize :use_hashed_storage after_create :check_repository_absence! - after_create :ensure_storage_path_exists - after_save :ensure_storage_path_exists, if: :saved_change_to_namespace_id? acts_as_ordered_taggable @@ -247,6 +245,7 @@ class Project < ApplicationRecord has_one :cluster_project, class_name: 'Clusters::Project' has_many :clusters, through: :cluster_project, class_name: 'Clusters::Cluster' has_many :kubernetes_namespaces, class_name: 'Clusters::KubernetesNamespace' + has_many :management_clusters, class_name: 'Clusters::Cluster', foreign_key: :management_project_id, inverse_of: :management_project has_many :prometheus_metrics diff --git a/app/models/storage/hashed_project.rb b/app/models/storage/hashed_project.rb index 519d91434ad..9a38b06b2f9 100644 --- a/app/models/storage/hashed_project.rb +++ b/app/models/storage/hashed_project.rb @@ -27,14 +27,6 @@ module Storage "#{base_dir}/#{disk_hash}" if disk_hash end - # TODO: remove this method entirely after 12.4 https://gitlab.com/gitlab-org/gitlab/issues/33244 - # we no longer need ensure_storage_path_exists to call add_namespace since both creating and moving - # repositories will be preceded by a mkdir -p in gitaly to ensure the parent of the destination directory - # exists. - def ensure_storage_path_exists - true - end - def rename_repo(old_full_path: nil, new_full_path: nil) true end diff --git a/app/models/storage/legacy_project.rb b/app/models/storage/legacy_project.rb index 1d0124e8321..345172cca76 100644 --- a/app/models/storage/legacy_project.rb +++ b/app/models/storage/legacy_project.rb @@ -23,16 +23,6 @@ module Storage project.full_path end - # TODO: remove this method entirely after 12.4 https://gitlab.com/gitlab-org/gitlab/issues/33244 - # we no longer need ensure_storage_path_exists to call add_namespace since both creating and moving - # repositories will be preceded by a mkdir -p in gitaly to ensure the parent of the destination directory - # exists. - def ensure_storage_path_exists - return unless namespace - - true - end - def rename_repo(old_full_path: nil, new_full_path: nil) old_full_path ||= project.full_path_before_last_save new_full_path ||= project.build_full_path diff --git a/app/services/projects/hashed_storage/migrate_repository_service.rb b/app/services/projects/hashed_storage/migrate_repository_service.rb index e248a13c702..0a0bd90cd20 100644 --- a/app/services/projects/hashed_storage/migrate_repository_service.rb +++ b/app/services/projects/hashed_storage/migrate_repository_service.rb @@ -8,7 +8,6 @@ module Projects @old_storage_version = project.storage_version project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:repository] - project.ensure_storage_path_exists @new_disk_path = project.disk_path diff --git a/app/services/projects/hashed_storage/rollback_repository_service.rb b/app/services/projects/hashed_storage/rollback_repository_service.rb index 67733f4770b..a705112ebe3 100644 --- a/app/services/projects/hashed_storage/rollback_repository_service.rb +++ b/app/services/projects/hashed_storage/rollback_repository_service.rb @@ -8,7 +8,6 @@ module Projects @old_storage_version = project.storage_version project.storage_version = nil - project.ensure_storage_path_exists @new_disk_path = project.disk_path diff --git a/app/views/search/_form.html.haml b/app/views/search/_form.html.haml index 464db94b7f4..dc75918eb93 100644 --- a/app/views/search/_form.html.haml +++ b/app/views/search/_form.html.haml @@ -18,4 +18,3 @@ = render 'filter' .d-flex-center.flex-column.flex-lg-row = button_tag _("Search"), class: "btn btn-success btn-search form-control mt-lg-0 ml-lg-1 align-self-end" - = render_if_exists 'search/form_elasticsearch' diff --git a/app/views/search/show.html.haml b/app/views/search/show.html.haml index 9235678bc1d..f300e1d4841 100644 --- a/app/views/search/show.html.haml +++ b/app/views/search/show.html.haml @@ -2,9 +2,10 @@ - page_title @search_term - @hide_breadcrumbs = true -.page-title-holder.d-flex.align-items-center +.page-title-holder.d-sm-flex.align-items-sm-center %h1.page-title< = _('Search') + = render_if_exists 'search/form_elasticsearch', attrs: { class: 'ml-sm-auto' } .prepend-top-default = render 'search/form' |