Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJames Fargher <proglottis@gmail.com>2019-04-18 05:45:31 +0300
committerJames Fargher <proglottis@gmail.com>2019-05-06 23:37:03 +0300
commit8db382b05545fdef0a60bcff65f8c23e8b1ed282 (patch)
tree48c45052013b98a571ce73a6b2239a9ea050e414 /app
parent733da6d6a015e8c951dcc02250cfe1fab87789c0 (diff)
Allow projects to use instance level clusters
There are two cluster hierarchies one for the deployment platform and one for controllers. The main difference is that deployment platforms do not check user permissions and only return the first match.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/clusters_controller.rb12
-rw-r--r--app/models/clusters/cluster.rb4
-rw-r--r--app/models/clusters/instance.rb4
-rw-r--r--app/models/concerns/deployment_platform.rb17
4 files changed, 34 insertions, 3 deletions
diff --git a/app/controllers/admin/clusters_controller.rb b/app/controllers/admin/clusters_controller.rb
index 777bdf5c981..f2b54125d48 100644
--- a/app/controllers/admin/clusters_controller.rb
+++ b/app/controllers/admin/clusters_controller.rb
@@ -8,10 +8,18 @@ class Admin::ClustersController < Clusters::ClustersController
private
def clusterable
- @clusterable ||= InstanceClusterablePresenter.fabricate(Clusters::Instance.new, current_user: current_user)
+ @clusterable ||= InstanceClusterablePresenter.fabricate(cluster_instance, current_user: current_user)
+ end
+
+ def cluster_instance
+ @cluster_instance ||= Clusters::Instance.new
end
def check_instance_clusters_feature_flag!
- render_404 unless Feature.enabled?(:instance_clusters, default_enabled: true)
+ render_404 unless instance_clusters_enabled?
+ end
+
+ def instance_clusters_enabled?
+ cluster_instance.instance_clusters_enabled?
end
end
diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb
index 7220159ac95..9299e61dad3 100644
--- a/app/models/clusters/cluster.rb
+++ b/app/models/clusters/cluster.rb
@@ -115,10 +115,12 @@ module Clusters
}
def self.ancestor_clusters_for_clusterable(clusterable, hierarchy_order: :asc)
+ return [] if clusterable.is_a?(Instance)
+
hierarchy_groups = clusterable.ancestors_upto(hierarchy_order: hierarchy_order).eager_load(:clusters)
hierarchy_groups = hierarchy_groups.merge(current_scope) if current_scope
- hierarchy_groups.flat_map(&:clusters)
+ hierarchy_groups.flat_map(&:clusters) + Instance.new.clusters
end
def status_name
diff --git a/app/models/clusters/instance.rb b/app/models/clusters/instance.rb
index fde83c5a8ad..bbbf6da16fb 100644
--- a/app/models/clusters/instance.rb
+++ b/app/models/clusters/instance.rb
@@ -8,4 +8,8 @@ class Clusters::Instance
def feature_available?(feature)
::Feature.enabled?(feature, default_enabled: true)
end
+
+ def instance_clusters_enabled?
+ ::Feature.enabled?(:instance_clusters, default_enabled: true)
+ end
end
diff --git a/app/models/concerns/deployment_platform.rb b/app/models/concerns/deployment_platform.rb
index 0107af5f8ec..c2dafec1a54 100644
--- a/app/models/concerns/deployment_platform.rb
+++ b/app/models/concerns/deployment_platform.rb
@@ -14,6 +14,7 @@ module DeploymentPlatform
def find_deployment_platform(environment)
find_cluster_platform_kubernetes(environment: environment) ||
find_group_cluster_platform_kubernetes_with_feature_guard(environment: environment) ||
+ find_instance_cluster_platform_kubernetes_with_feature_guard(environment: environment) ||
find_kubernetes_service_integration ||
build_cluster_and_deployment_platform
end
@@ -36,6 +37,22 @@ module DeploymentPlatform
.first&.platform_kubernetes
end
+ def find_instance_cluster_platform_kubernetes_with_feature_guard(environment: nil)
+ return unless instance_clusters_enabled?
+
+ find_instance_cluster_platform_kubernetes(environment: environment)
+ end
+
+ # EE would override this and utilize environment argument
+ def find_instance_cluster_platform_kubernetes(environment: nil)
+ Clusters::Instance.new.clusters.enabled.default_environment
+ .first&.platform_kubernetes
+ end
+
+ def instance_clusters_enabled?
+ Feature.enabled?(:instance_clusters, default_enabled: true)
+ end
+
def find_kubernetes_service_integration
services.deployment.reorder(nil).find_by(active: true)
end