summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-11-01 16:12:44 +0900
committerShinya Maeda <shinya@gitlab.com>2017-11-01 16:12:44 +0900
commit6571efb6c3afd568c019e7bb46aba84328a4e821 (patch)
tree24d455c614cf37dac75c6e83d4d58555247bc7b0
parentef3ebed6d3d3910bdf6080d6304ee7c5d5b0cc87 (diff)
downloadgitlab-ce-6571efb6c3afd568c019e7bb46aba84328a4e821.tar.gz
Fix spec. Fix usage ping. Fix warnings by adding new models and attributes.
-rw-r--r--app/models/clusters/platforms/kubernetes.rb6
-rw-r--r--app/services/clusters/create_service.rb12
-rw-r--r--db/migrate/20171013094327_create_new_clusters_architectures.rb2
-rw-r--r--lib/gitlab/import_export/relation_factory.rb4
-rw-r--r--lib/gitlab/usage_data.rb6
-rw-r--r--spec/controllers/projects/clusters_controller_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/safe_model_attributes.yml43
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb6
-rw-r--r--spec/models/clusters/platforms/kubernetes_spec.rb56
-rw-r--r--spec/services/clusters/create_service_spec.rb4
-rw-r--r--spec/services/clusters/gcp/finalize_creation_service_spec.rb2
-rw-r--r--spec/support/google_api/cloud_platform_helpers.rb5
12 files changed, 102 insertions, 48 deletions
diff --git a/app/models/clusters/platforms/kubernetes.rb b/app/models/clusters/platforms/kubernetes.rb
index e30ab805f1e..52022509d49 100644
--- a/app/models/clusters/platforms/kubernetes.rb
+++ b/app/models/clusters/platforms/kubernetes.rb
@@ -30,10 +30,8 @@ module Clusters
message: Gitlab::Regex.kubernetes_namespace_regex_message
}
- # TODO: when cluster.gcp? skip validation when create a record
- # TODO: when cluster.user? validates always
- # validates :api_url, url: true, presence: true
- # validates :token, presence: true
+ validates :api_url, url: true, presence: true
+ validates :token, presence: true
after_save :clear_reactive_cache!
diff --git a/app/services/clusters/create_service.rb b/app/services/clusters/create_service.rb
index 8c30e247fdc..503118fa6b6 100644
--- a/app/services/clusters/create_service.rb
+++ b/app/services/clusters/create_service.rb
@@ -2,6 +2,9 @@ module Clusters
class CreateService < BaseService
attr_reader :access_token
+ TEMPOLARY_API_URL = 'http://tempolary_api_url'.freeze
+ TEMPOLARY_TOKEN = 'tempolary_token'.freeze
+
def execute(access_token)
@access_token = access_token
@@ -28,8 +31,13 @@ module Clusters
def cluster_params
return @cluster_params if defined?(@cluster_params)
- params[:provider_gcp_attributes].try do |h|
- h[:access_token] = access_token
+ params[:provider_gcp_attributes].try do |provider|
+ provider[:access_token] = access_token
+
+ params[:platform_kubernetes_attributes].try do |platform|
+ platform[:api_url] = TEMPOLARY_API_URL
+ platform[:token] = TEMPOLARY_TOKEN
+ end
end
@cluster_params = params.merge(user: current_user)
diff --git a/db/migrate/20171013094327_create_new_clusters_architectures.rb b/db/migrate/20171013094327_create_new_clusters_architectures.rb
index 35df8cb4a60..2eae72595c6 100644
--- a/db/migrate/20171013094327_create_new_clusters_architectures.rb
+++ b/db/migrate/20171013094327_create_new_clusters_architectures.rb
@@ -22,7 +22,7 @@ class CreateNewClustersArchitectures < ActiveRecord::Migration
t.datetime_with_timezone :created_at, null: false
t.datetime_with_timezone :updated_at, null: false
end
-
+
create_table :cluster_platforms_kubernetes do |t|
t.references :cluster, null: false, index: { unique: true }, foreign_key: { on_delete: :cascade }
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb
index 469b230377d..a790dcfe8a6 100644
--- a/lib/gitlab/import_export/relation_factory.rb
+++ b/lib/gitlab/import_export/relation_factory.rb
@@ -8,8 +8,8 @@ module Gitlab
triggers: 'Ci::Trigger',
pipeline_schedules: 'Ci::PipelineSchedule',
builds: 'Ci::Build',
- cluster: 'Gcp::Cluster',
- clusters: 'Gcp::Cluster',
+ cluster: 'Clusters::Cluster',
+ clusters: 'Clusters::Cluster',
hooks: 'ProjectHook',
merge_access_levels: 'ProtectedBranch::MergeAccessLevel',
push_access_levels: 'ProtectedBranch::PushAccessLevel',
diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb
index 70a403652e7..112d4939582 100644
--- a/lib/gitlab/usage_data.rb
+++ b/lib/gitlab/usage_data.rb
@@ -48,9 +48,9 @@ module Gitlab
deploy_keys: DeployKey.count,
deployments: Deployment.count,
environments: ::Environment.count,
- gcp_clusters: ::Gcp::Cluster.count,
- gcp_clusters_enabled: ::Gcp::Cluster.enabled.count,
- gcp_clusters_disabled: ::Gcp::Cluster.disabled.count,
+ clusters: ::Clusters::Cluster.count,
+ clusters_enabled: ::Clusters::Cluster.enabled.count,
+ clusters_disabled: ::Clusters::Cluster.disabled.count,
in_review_folder: ::Environment.in_review_folder.count,
groups: Group.count,
issues: Issue.count,
diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb
index 4661f959693..c7d3c945430 100644
--- a/spec/controllers/projects/clusters_controller_spec.rb
+++ b/spec/controllers/projects/clusters_controller_spec.rb
@@ -72,7 +72,7 @@ describe Projects::ClustersController do
go
expect(assigns(:authorize_url)).to include(key)
- expect(session[session_key_for_redirect_uri]).to eq(namespace_project_clusters_url(project.namespace, project))
+ expect(session[session_key_for_redirect_uri]).to eq(project_clusters_url(project))
end
end
@@ -175,7 +175,7 @@ describe Projects::ClustersController do
platform_type: :kubernetes,
provider_type: :gcp,
provider_gcp_attributes: {
- gcp_project_id: '111',
+ gcp_project_id: '111'
}
}
}
diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml
index 89d30407077..d8dc3672d40 100644
--- a/spec/lib/gitlab/import_export/safe_model_attributes.yml
+++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml
@@ -313,6 +313,49 @@ Ci::PipelineSchedule:
- deleted_at
- created_at
- updated_at
+Clusters::Cluster:
+- id
+- user_id
+- enabled
+- name
+- provider_type
+- platform_type
+- created_at
+- updated_at
+Clusters::Project:
+- id
+- project_id
+- cluster_id
+- created_at
+- updated_at
+Clusters::Providers::Gcp:
+- id
+- cluster_id
+- status
+- status_reason
+- gcp_project_id
+- zone
+- num_nodes
+- machine_type
+- operation_id
+- endpoint
+- encrypted_access_token
+- encrypted_access_token_iv
+- created_at
+- updated_at
+Clusters::Platforms::Kubernetes:
+- id
+- cluster_id
+- api_url
+- ca_cert
+- namespace
+- username
+- encrypted_password
+- encrypted_password_iv
+- encrypted_token
+- encrypted_token_iv
+- created_at
+- updated_at
Gcp::Cluster:
- id
- project_id
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index a7b65e94706..a4c1113ae37 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -60,9 +60,9 @@ describe Gitlab::UsageData do
deploy_keys
deployments
environments
- gcp_clusters
- gcp_clusters_enabled
- gcp_clusters_disabled
+ clusters
+ clusters_enabled
+ clusters_disabled
in_review_folder
groups
issues
diff --git a/spec/models/clusters/platforms/kubernetes_spec.rb b/spec/models/clusters/platforms/kubernetes_spec.rb
index df68720ffd8..d11ce690601 100644
--- a/spec/models/clusters/platforms/kubernetes_spec.rb
+++ b/spec/models/clusters/platforms/kubernetes_spec.rb
@@ -51,45 +51,45 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
end
end
- # context 'when validates api_url' do
- # let(:kubernetes) { build(:platform_kubernetes, :configured) }
+ context 'when validates api_url' do
+ let(:kubernetes) { build(:platform_kubernetes, :configured) }
- # before do
- # kubernetes.api_url = api_url
- # end
+ before do
+ kubernetes.api_url = api_url
+ end
- # context 'when api_url is invalid url' do
- # let(:api_url) { '!!!!!!' }
+ context 'when api_url is invalid url' do
+ let(:api_url) { '!!!!!!' }
- # it { expect(kubernetes.save).to be_falsey }
- # end
+ it { expect(kubernetes.save).to be_falsey }
+ end
- # context 'when api_url is nil' do
- # let(:api_url) { nil }
+ context 'when api_url is nil' do
+ let(:api_url) { nil }
- # it { expect(kubernetes.save).to be_falsey }
- # end
+ it { expect(kubernetes.save).to be_falsey }
+ end
- # context 'when api_url is valid url' do
- # let(:api_url) { 'https://111.111.111.111' }
+ context 'when api_url is valid url' do
+ let(:api_url) { 'https://111.111.111.111' }
- # it { expect(kubernetes.save).to be_truthy }
- # end
- # end
+ it { expect(kubernetes.save).to be_truthy }
+ end
+ end
- # context 'when validates token' do
- # let(:kubernetes) { build(:platform_kubernetes, :configured) }
+ context 'when validates token' do
+ let(:kubernetes) { build(:platform_kubernetes, :configured) }
- # before do
- # kubernetes.token = token
- # end
+ before do
+ kubernetes.token = token
+ end
- # context 'when token is nil' do
- # let(:token) { nil }
+ context 'when token is nil' do
+ let(:token) { nil }
- # it { expect(kubernetes.save).to be_falsey }
- # end
- # end
+ it { expect(kubernetes.save).to be_falsey }
+ end
+ end
end
describe '#actual_namespace' do
diff --git a/spec/services/clusters/create_service_spec.rb b/spec/services/clusters/create_service_spec.rb
index b33578d6acd..9ed6ae8c2fc 100644
--- a/spec/services/clusters/create_service_spec.rb
+++ b/spec/services/clusters/create_service_spec.rb
@@ -42,7 +42,8 @@ describe Clusters::CreateService do
expect(result.provider.machine_type).to eq('machine_type-a')
expect(result.provider.access_token).to eq(access_token)
expect(result.platform.namespace).to eq('custom-namespace')
- expect(result.platform.valid?).to be_falsey
+ expect(result.platform.api_url).to eq(Clusters::CreateService::TEMPOLARY_API_URL)
+ expect(result.platform.token).to eq(Clusters::CreateService::TEMPOLARY_TOKEN)
end
end
@@ -99,7 +100,6 @@ describe Clusters::CreateService do
expect(result.project).to eq(project)
expect(result.provider).to be_nil
expect(result.platform.namespace).to eq('custom-namespace')
- expect(result.platform.valid?).to be_truthy
end
end
diff --git a/spec/services/clusters/gcp/finalize_creation_service_spec.rb b/spec/services/clusters/gcp/finalize_creation_service_spec.rb
index 70ea1cbca46..ca7741f641b 100644
--- a/spec/services/clusters/gcp/finalize_creation_service_spec.rb
+++ b/spec/services/clusters/gcp/finalize_creation_service_spec.rb
@@ -40,7 +40,7 @@ describe Clusters::Gcp::FinalizeCreationService do
{
endpoint: endpoint,
username: username,
- password: password,
+ password: password
}
)
diff --git a/spec/support/google_api/cloud_platform_helpers.rb b/spec/support/google_api/cloud_platform_helpers.rb
index ef73add3991..4b785611ab5 100644
--- a/spec/support/google_api/cloud_platform_helpers.rb
+++ b/spec/support/google_api/cloud_platform_helpers.rb
@@ -61,6 +61,11 @@ module GoogleApi
Base64.encode64(File.read(pem_file))
end
+ ##
+ # gcloud container clusters create
+ # https://cloud.google.com/container-engine/reference/rest/v1/projects.zones.clusters/create
+ # rubocop:disable Metrics/CyclomaticComplexity
+ # rubocop:disable Metrics/PerceivedComplexity
def cloud_platform_cluster_body(**options)
{
"name": options[:name] || 'string',