Commit b39028fb authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '52363-add-domain-to-cluster-model' into 'master'

Add domain field into Clusters::Cluster

See merge request gitlab-org/gitlab-ce!24368
parents ae216618 cfe65a0d
...@@ -49,8 +49,9 @@ module Clusters ...@@ -49,8 +49,9 @@ module Clusters
validates :name, cluster_name: true validates :name, cluster_name: true
validates :cluster_type, presence: true validates :cluster_type, presence: true
validate :restrict_modification, on: :update validates :domain, allow_nil: true, hostname: { allow_numeric_hostname: true, require_valid_tld: true }
validate :restrict_modification, on: :update
validate :no_groups, unless: :group_type? validate :no_groups, unless: :group_type?
validate :no_projects, unless: :project_type? validate :no_projects, unless: :project_type?
......
# frozen_string_literal: true
class AddDomainToCluster < ActiveRecord::Migration[5.0]
DOWNTIME = false
def change
add_column :clusters, :domain, :string
end
end
...@@ -647,6 +647,7 @@ ActiveRecord::Schema.define(version: 20190115054216) do ...@@ -647,6 +647,7 @@ ActiveRecord::Schema.define(version: 20190115054216) do
t.string "name", null: false t.string "name", null: false
t.string "environment_scope", default: "*", null: false t.string "environment_scope", default: "*", null: false
t.integer "cluster_type", limit: 2, default: 3, null: false t.integer "cluster_type", limit: 2, default: 3, null: false
t.string "domain"
t.index ["enabled"], name: "index_clusters_on_enabled", using: :btree t.index ["enabled"], name: "index_clusters_on_enabled", using: :btree
t.index ["user_id"], name: "index_clusters_on_user_id", using: :btree t.index ["user_id"], name: "index_clusters_on_user_id", using: :btree
end end
......
...@@ -59,5 +59,9 @@ FactoryBot.define do ...@@ -59,5 +59,9 @@ FactoryBot.define do
trait :with_installed_helm do trait :with_installed_helm do
application_helm factory: %i(clusters_applications_helm installed) application_helm factory: %i(clusters_applications_helm installed)
end end
trait :with_domain do
domain 'example.com'
end
end end
end end
...@@ -113,7 +113,7 @@ describe Clusters::Cluster do ...@@ -113,7 +113,7 @@ describe Clusters::Cluster do
end end
end end
describe 'validation' do describe 'validations' do
subject { cluster.valid? } subject { cluster.valid? }
context 'when validates name' do context 'when validates name' do
...@@ -252,6 +252,31 @@ describe Clusters::Cluster do ...@@ -252,6 +252,31 @@ describe Clusters::Cluster do
end end
end end
end end
describe 'domain validation' do
let(:cluster) { build(:cluster) }
subject { cluster }
context 'when cluster has domain' do
let(:cluster) { build(:cluster, :with_domain) }
it { is_expected.to be_valid }
end
context 'when cluster has an invalid domain' do
let(:cluster) { build(:cluster, domain: 'not-valid-domain') }
it 'should add an error on domain' do
expect(subject).not_to be_valid
expect(subject.errors[:domain].first).to eq('is not a fully qualified domain name')
end
end
context 'when cluster does not have a domain' do
it { is_expected.to be_valid }
end
end
end end
describe '.ancestor_clusters_for_clusterable' do describe '.ancestor_clusters_for_clusterable' do
......
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