diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-20 18:08:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-20 18:08:44 +0300 |
commit | b9bac6dbf78a5a7976fba14aaeef96bdeb0da612 (patch) | |
tree | ffe277b562256f718b0818e8fd3c8fd8766d0269 /app/models | |
parent | 8c4198cbe631278e87fee04157d23494fbb80cdb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/clusters/concerns/application_core.rb | 2 | ||||
-rw-r--r-- | app/models/clusters/concerns/application_data.rb | 8 | ||||
-rw-r--r-- | app/models/clusters/concerns/application_status.rb | 5 | ||||
-rw-r--r-- | app/models/environment.rb | 4 | ||||
-rw-r--r-- | app/models/serverless/domain.rb | 44 | ||||
-rw-r--r-- | app/models/serverless/domain_cluster.rb | 11 |
6 files changed, 69 insertions, 5 deletions
diff --git a/app/models/clusters/concerns/application_core.rb b/app/models/clusters/concerns/application_core.rb index b94f2b15846..297d00aa281 100644 --- a/app/models/clusters/concerns/application_core.rb +++ b/app/models/clusters/concerns/application_core.rb @@ -15,7 +15,7 @@ module Clusters def set_initial_status return unless not_installable? - self.status = status_states[:installable] if cluster&.application_helm_available? || Feature.enabled?(:managed_apps_local_tiller) + self.status = status_states[:installable] if cluster&.application_helm_available? || ::Gitlab::Kubernetes::Helm.local_tiller_enabled? end def can_uninstall? diff --git a/app/models/clusters/concerns/application_data.rb b/app/models/clusters/concerns/application_data.rb index 3479fea415e..77c606553d2 100644 --- a/app/models/clusters/concerns/application_data.rb +++ b/app/models/clusters/concerns/application_data.rb @@ -23,7 +23,7 @@ module Clusters @files ||= begin files = { 'values.yaml': values } - files.merge!(certificate_files) if cluster.application_helm.has_ssl? + files.merge!(certificate_files) if use_tiller_ssl? files end @@ -31,6 +31,12 @@ module Clusters private + def use_tiller_ssl? + return false if ::Gitlab::Kubernetes::Helm.local_tiller_enabled? + + cluster.application_helm.has_ssl? + end + def certificate_files { 'ca.pem': ca_cert, diff --git a/app/models/clusters/concerns/application_status.rb b/app/models/clusters/concerns/application_status.rb index b63a596dfee..14237439a8d 100644 --- a/app/models/clusters/concerns/application_status.rb +++ b/app/models/clusters/concerns/application_status.rb @@ -92,7 +92,10 @@ module Clusters # When installing any application we are also performing an update # of tiller (see Gitlab::Kubernetes::Helm::ClientCommand) so # therefore we need to reflect that in the database. - application.cluster.application_helm.update!(version: Gitlab::Kubernetes::Helm::HELM_VERSION) + + unless ::Gitlab::Kubernetes::Helm.local_tiller_enabled? + application.cluster.application_helm.update!(version: Gitlab::Kubernetes::Helm::HELM_VERSION) + end end after_transition any => [:uninstalling], :use_transactions => false do |application, _| diff --git a/app/models/environment.rb b/app/models/environment.rb index bb41c4a066e..4224a32a6d7 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -95,6 +95,10 @@ class Environment < ApplicationRecord end end + def self.for_id_and_slug(id, slug) + find_by(id: id, slug: slug) + end + def self.max_deployment_id_sql Deployment.select(Deployment.arel_table[:id].maximum) .where(Deployment.arel_table[:environment_id].eq(arel_table[:id])) diff --git a/app/models/serverless/domain.rb b/app/models/serverless/domain.rb new file mode 100644 index 00000000000..2fef3b66b08 --- /dev/null +++ b/app/models/serverless/domain.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module Serverless + class Domain + include ActiveModel::Model + + REGEXP = %r{^(?<scheme>https?://)?(?<function_name>[^.]+)-(?<cluster_left>\h{2})a1(?<cluster_middle>\h{10})f2(?<cluster_right>\h{2})(?<environment_id>\h+)-(?<environment_slug>[^.]+)\.(?<pages_domain_name>.+)}.freeze + UUID_LENGTH = 14 + + attr_accessor :function_name, :serverless_domain_cluster, :environment + + validates :function_name, presence: true, allow_blank: false + validates :serverless_domain_cluster, presence: true + validates :environment, presence: true + + def self.generate_uuid + SecureRandom.hex(UUID_LENGTH / 2) + end + + def uri + URI("https://#{function_name}-#{serverless_domain_cluster_uuid}#{"%x" % environment.id}-#{environment.slug}.#{serverless_domain_cluster.domain}") + end + + def knative_uri + URI("http://#{function_name}.#{namespace}.#{serverless_domain_cluster.knative.hostname}") + end + + private + + def namespace + serverless_domain_cluster.cluster.kubernetes_namespace_for(environment) + end + + def serverless_domain_cluster_uuid + [ + serverless_domain_cluster.uuid[0..1], + 'a1', + serverless_domain_cluster.uuid[2..-3], + 'f2', + serverless_domain_cluster.uuid[-2..-1] + ].join + end + end +end diff --git a/app/models/serverless/domain_cluster.rb b/app/models/serverless/domain_cluster.rb index 94d90d3e305..9f914d5c3f8 100644 --- a/app/models/serverless/domain_cluster.rb +++ b/app/models/serverless/domain_cluster.rb @@ -16,11 +16,18 @@ module Serverless algorithm: 'aes-256-gcm' validates :pages_domain, :knative, presence: true - validates :uuid, presence: true, uniqueness: true, length: { is: Gitlab::Serverless::Domain::UUID_LENGTH }, + validates :uuid, presence: true, uniqueness: true, length: { is: ::Serverless::Domain::UUID_LENGTH }, format: { with: HEX_REGEXP, message: 'only allows hex characters' } - default_value_for(:uuid, allows_nil: false) { Gitlab::Serverless::Domain.generate_uuid } + default_value_for(:uuid, allows_nil: false) { ::Serverless::Domain.generate_uuid } delegate :domain, to: :pages_domain + delegate :cluster, to: :knative + + def self.for_uuid(uuid) + joins(:pages_domain, :knative) + .includes(:pages_domain, :knative) + .find_by(uuid: uuid) + end end end |