Commit b82d3355 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '35591-instance-and-project-level-ssl-and-custom-domain-support' into 'master'

Backend data model for serverless domains

See merge request gitlab-org/gitlab!19835
parents 9da101ef b470ed51
......@@ -11,6 +11,8 @@ module Clusters
self.table_name = 'clusters_applications_knative'
has_one :serverless_domain_cluster, class_name: 'Serverless::DomainCluster', foreign_key: 'clusters_applications_knative_id', inverse_of: :knative
include ::Clusters::Concerns::ApplicationCore
include ::Clusters::Concerns::ApplicationStatus
include ::Clusters::Concerns::ApplicationVersion
......
......@@ -6,6 +6,7 @@ class PagesDomain < ApplicationRecord
SSL_RENEWAL_THRESHOLD = 30.days.freeze
enum certificate_source: { user_provided: 0, gitlab_provided: 1 }, _prefix: :certificate
enum domain_type: { instance: 0, group: 1, project: 2 }, _prefix: :domain_type
belongs_to :project
has_many :acme_orders, class_name: "PagesDomainAcmeOrder"
......@@ -25,6 +26,8 @@ class PagesDomain < ApplicationRecord
validate :validate_intermediates, if: ->(domain) { domain.certificate.present? && domain.certificate_changed? }
default_value_for(:auto_ssl_enabled, allow_nil: false) { ::Gitlab::LetsEncrypt.enabled? }
default_value_for :domain_type, allow_nil: false, value: :project
default_value_for :wildcard, allow_nil: false, value: false
attr_encrypted :key,
mode: :per_attribute_iv_and_salt,
......@@ -217,6 +220,8 @@ class PagesDomain < ApplicationRecord
# rubocop: disable CodeReuse/ServiceClass
def update_daemon
return if domain_type_instance?
::Projects::UpdatePagesConfigurationService.new(project).execute
end
# rubocop: enable CodeReuse/ServiceClass
......
# frozen_string_literal: true
module Serverless
class DomainCluster < ApplicationRecord
self.table_name = 'serverless_domain_cluster'
belongs_to :pages_domain
belongs_to :knative, class_name: 'Clusters::Applications::Knative', foreign_key: 'clusters_applications_knative_id'
belongs_to :creator, class_name: 'User', optional: true
validates :pages_domain, :knative, :uuid, presence: true
validates :uuid, uniqueness: true, length: { is: 14 }
end
end
---
title: Create data model for serverless domains
merge_request: 19835
author:
type: added
# frozen_string_literal: true
class CreateServerlessDomainCluster < ActiveRecord::Migration[5.2]
DOWNTIME = false
def change
create_table :serverless_domain_cluster, id: false, primary_key: :uuid do |t|
t.references :pages_domain, null: false, foreign_key: { on_delete: :cascade }
t.references :clusters_applications_knative, null: false,
foreign_key: { to_table: :clusters_applications_knative, on_delete: :cascade },
index: { name: :idx_serverless_domain_cluster_on_clusters_applications_knative, unique: true }
t.references :creator, name: :created_by, foreign_key: { to_table: :users, on_delete: :nullify }
t.timestamps_with_timezone null: false
t.string :uuid, null: false, limit: 14, primary_key: true
end
end
end
# frozen_string_literal: true
class AddWildcardAndDomainTypeToPagesDomains < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
PROJECT_TYPE = 2
disable_ddl_transaction!
def up
add_column_with_default :pages_domains, :wildcard, :boolean, default: false
add_column_with_default :pages_domains, :domain_type, :integer, limit: 2, default: PROJECT_TYPE
end
def down
remove_column :pages_domains, :wildcard
remove_column :pages_domains, :domain_type
end
end
# frozen_string_literal: true
class AddIndexesToPagesDomainsOnWildcardAndDomainType < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :pages_domains, :wildcard
add_concurrent_index :pages_domains, :domain_type
end
def down
remove_concurrent_index :pages_domains, :wildcard
remove_concurrent_index :pages_domains, :domain_type
end
end
......@@ -2951,13 +2951,17 @@ ActiveRecord::Schema.define(version: 2019_12_08_071112) do
t.datetime_with_timezone "certificate_valid_not_before"
t.datetime_with_timezone "certificate_valid_not_after"
t.integer "certificate_source", limit: 2, default: 0, null: false
t.boolean "wildcard", default: false, null: false
t.integer "domain_type", limit: 2, default: 2, null: false
t.index ["certificate_source", "certificate_valid_not_after"], name: "index_pages_domains_need_auto_ssl_renewal", where: "(auto_ssl_enabled = true)"
t.index ["domain"], name: "index_pages_domains_on_domain", unique: true
t.index ["domain_type"], name: "index_pages_domains_on_domain_type"
t.index ["project_id", "enabled_until"], name: "index_pages_domains_on_project_id_and_enabled_until"
t.index ["project_id"], name: "index_pages_domains_on_project_id"
t.index ["remove_at"], name: "index_pages_domains_on_remove_at"
t.index ["verified_at", "enabled_until"], name: "index_pages_domains_on_verified_at_and_enabled_until"
t.index ["verified_at"], name: "index_pages_domains_on_verified_at"
t.index ["wildcard"], name: "index_pages_domains_on_wildcard"
end
create_table "path_locks", id: :serial, force: :cascade do |t|
......@@ -3654,6 +3658,17 @@ ActiveRecord::Schema.define(version: 2019_12_08_071112) do
t.index ["issue_id"], name: "index_sentry_issues_on_issue_id", unique: true
end
create_table "serverless_domain_cluster", primary_key: "uuid", id: :string, limit: 14, force: :cascade do |t|
t.bigint "pages_domain_id", null: false
t.bigint "clusters_applications_knative_id", null: false
t.bigint "creator_id"
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.index ["clusters_applications_knative_id"], name: "idx_serverless_domain_cluster_on_clusters_applications_knative", unique: true
t.index ["creator_id"], name: "index_serverless_domain_cluster_on_creator_id"
t.index ["pages_domain_id"], name: "index_serverless_domain_cluster_on_pages_domain_id"
end
create_table "service_desk_settings", primary_key: "project_id", id: :bigint, default: nil, force: :cascade do |t|
t.string "issue_template_key", limit: 255
end
......@@ -4714,6 +4729,9 @@ ActiveRecord::Schema.define(version: 2019_12_08_071112) do
add_foreign_key "self_managed_prometheus_alert_events", "environments", on_delete: :cascade
add_foreign_key "self_managed_prometheus_alert_events", "projects", on_delete: :cascade
add_foreign_key "sentry_issues", "issues", on_delete: :cascade
add_foreign_key "serverless_domain_cluster", "clusters_applications_knative", on_delete: :cascade
add_foreign_key "serverless_domain_cluster", "pages_domains", on_delete: :cascade
add_foreign_key "serverless_domain_cluster", "users", column: "creator_id", on_delete: :nullify
add_foreign_key "service_desk_settings", "projects", on_delete: :cascade
add_foreign_key "services", "projects", name: "fk_71cce407f9", on_delete: :cascade
add_foreign_key "slack_integrations", "services", on_delete: :cascade
......
# frozen_string_literal: true
FactoryBot.define do
factory :serverless_domain_cluster, class: Serverless::DomainCluster do
pages_domain { create(:pages_domain) }
knative { create(:clusters_applications_knative) }
creator { create(:user) }
uuid { SecureRandom.hex(7) }
end
end
......@@ -16,6 +16,10 @@ describe Clusters::Applications::Knative do
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async)
end
describe 'associations' do
it { is_expected.to have_one(:serverless_domain_cluster).class_name('Serverless::DomainCluster').with_foreign_key('clusters_applications_knative_id').inverse_of(:knative) }
end
describe 'when cloud run is enabled' do
let(:cluster) { create(:cluster, :provided_by_gcp, :cloud_run_enabled) }
let(:knative_cloud_run) { create(:clusters_applications_knative, cluster: cluster) }
......
......@@ -175,6 +175,16 @@ describe PagesDomain do
it { is_expected.to validate_presence_of(:verification_code) }
end
describe 'default values' do
it 'defaults wildcard to false' do
expect(subject.wildcard).to eq(false)
end
it 'defaults domain_type to project' do
expect(subject.domain_type).to eq('project')
end
end
describe '#verification_code' do
subject { pages_domain.verification_code }
......@@ -305,6 +315,14 @@ describe PagesDomain do
end
describe '#update_daemon' do
context 'when domain_type is instance' do
it 'does nothing' do
expect(Projects::UpdatePagesConfigurationService).not_to receive(:new)
create(:pages_domain, domain_type: :instance)
end
end
it 'runs when the domain is created' do
domain = build(:pages_domain)
......
# frozen_string_literal: true
require 'spec_helper'
describe Serverless::DomainCluster do
subject { create(:serverless_domain_cluster) }
describe 'validations' do
it { is_expected.to validate_presence_of(:pages_domain) }
it { is_expected.to validate_presence_of(:knative) }
it { is_expected.to validate_presence_of(:uuid) }
it { is_expected.to validate_uniqueness_of(:uuid) }
it { is_expected.to validate_length_of(:uuid).is_equal_to(14) }
end
describe 'associations' do
it { is_expected.to belong_to(:pages_domain) }
it { is_expected.to belong_to(:knative) }
it { is_expected.to belong_to(:creator).optional }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment