BigW Consortium Gitlab

Commit 6571efb6 by Shinya Maeda

Fix spec. Fix usage ping. Fix warnings by adding new models and attributes.

parent ef3ebed6
...@@ -30,10 +30,8 @@ module Clusters ...@@ -30,10 +30,8 @@ module Clusters
message: Gitlab::Regex.kubernetes_namespace_regex_message message: Gitlab::Regex.kubernetes_namespace_regex_message
} }
# TODO: when cluster.gcp? skip validation when create a record validates :api_url, url: true, presence: true
# TODO: when cluster.user? validates always validates :token, presence: true
# validates :api_url, url: true, presence: true
# validates :token, presence: true
after_save :clear_reactive_cache! after_save :clear_reactive_cache!
......
...@@ -2,6 +2,9 @@ module Clusters ...@@ -2,6 +2,9 @@ module Clusters
class CreateService < BaseService class CreateService < BaseService
attr_reader :access_token attr_reader :access_token
TEMPOLARY_API_URL = 'http://tempolary_api_url'.freeze
TEMPOLARY_TOKEN = 'tempolary_token'.freeze
def execute(access_token) def execute(access_token)
@access_token = access_token @access_token = access_token
...@@ -28,8 +31,13 @@ module Clusters ...@@ -28,8 +31,13 @@ module Clusters
def cluster_params def cluster_params
return @cluster_params if defined?(@cluster_params) return @cluster_params if defined?(@cluster_params)
params[:provider_gcp_attributes].try do |h| params[:provider_gcp_attributes].try do |provider|
h[:access_token] = access_token provider[:access_token] = access_token
params[:platform_kubernetes_attributes].try do |platform|
platform[:api_url] = TEMPOLARY_API_URL
platform[:token] = TEMPOLARY_TOKEN
end
end end
@cluster_params = params.merge(user: current_user) @cluster_params = params.merge(user: current_user)
......
...@@ -22,7 +22,7 @@ class CreateNewClustersArchitectures < ActiveRecord::Migration ...@@ -22,7 +22,7 @@ class CreateNewClustersArchitectures < ActiveRecord::Migration
t.datetime_with_timezone :created_at, null: false t.datetime_with_timezone :created_at, null: false
t.datetime_with_timezone :updated_at, null: false t.datetime_with_timezone :updated_at, null: false
end end
create_table :cluster_platforms_kubernetes do |t| create_table :cluster_platforms_kubernetes do |t|
t.references :cluster, null: false, index: { unique: true }, foreign_key: { on_delete: :cascade } t.references :cluster, null: false, index: { unique: true }, foreign_key: { on_delete: :cascade }
......
...@@ -8,8 +8,8 @@ module Gitlab ...@@ -8,8 +8,8 @@ module Gitlab
triggers: 'Ci::Trigger', triggers: 'Ci::Trigger',
pipeline_schedules: 'Ci::PipelineSchedule', pipeline_schedules: 'Ci::PipelineSchedule',
builds: 'Ci::Build', builds: 'Ci::Build',
cluster: 'Gcp::Cluster', cluster: 'Clusters::Cluster',
clusters: 'Gcp::Cluster', clusters: 'Clusters::Cluster',
hooks: 'ProjectHook', hooks: 'ProjectHook',
merge_access_levels: 'ProtectedBranch::MergeAccessLevel', merge_access_levels: 'ProtectedBranch::MergeAccessLevel',
push_access_levels: 'ProtectedBranch::PushAccessLevel', push_access_levels: 'ProtectedBranch::PushAccessLevel',
......
...@@ -48,9 +48,9 @@ module Gitlab ...@@ -48,9 +48,9 @@ module Gitlab
deploy_keys: DeployKey.count, deploy_keys: DeployKey.count,
deployments: Deployment.count, deployments: Deployment.count,
environments: ::Environment.count, environments: ::Environment.count,
gcp_clusters: ::Gcp::Cluster.count, clusters: ::Clusters::Cluster.count,
gcp_clusters_enabled: ::Gcp::Cluster.enabled.count, clusters_enabled: ::Clusters::Cluster.enabled.count,
gcp_clusters_disabled: ::Gcp::Cluster.disabled.count, clusters_disabled: ::Clusters::Cluster.disabled.count,
in_review_folder: ::Environment.in_review_folder.count, in_review_folder: ::Environment.in_review_folder.count,
groups: Group.count, groups: Group.count,
issues: Issue.count, issues: Issue.count,
......
...@@ -72,7 +72,7 @@ describe Projects::ClustersController do ...@@ -72,7 +72,7 @@ describe Projects::ClustersController do
go go
expect(assigns(:authorize_url)).to include(key) 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
end end
...@@ -175,7 +175,7 @@ describe Projects::ClustersController do ...@@ -175,7 +175,7 @@ describe Projects::ClustersController do
platform_type: :kubernetes, platform_type: :kubernetes,
provider_type: :gcp, provider_type: :gcp,
provider_gcp_attributes: { provider_gcp_attributes: {
gcp_project_id: '111', gcp_project_id: '111'
} }
} }
} }
......
...@@ -313,6 +313,49 @@ Ci::PipelineSchedule: ...@@ -313,6 +313,49 @@ Ci::PipelineSchedule:
- deleted_at - deleted_at
- created_at - created_at
- updated_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: Gcp::Cluster:
- id - id
- project_id - project_id
......
...@@ -60,9 +60,9 @@ describe Gitlab::UsageData do ...@@ -60,9 +60,9 @@ describe Gitlab::UsageData do
deploy_keys deploy_keys
deployments deployments
environments environments
gcp_clusters clusters
gcp_clusters_enabled clusters_enabled
gcp_clusters_disabled clusters_disabled
in_review_folder in_review_folder
groups groups
issues issues
......
...@@ -51,45 +51,45 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching ...@@ -51,45 +51,45 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
end end
end end
# context 'when validates api_url' do context 'when validates api_url' do
# let(:kubernetes) { build(:platform_kubernetes, :configured) } let(:kubernetes) { build(:platform_kubernetes, :configured) }
# before do before do
# kubernetes.api_url = api_url kubernetes.api_url = api_url
# end end
# context 'when api_url is invalid url' do context 'when api_url is invalid url' do
# let(:api_url) { '!!!!!!' } let(:api_url) { '!!!!!!' }
# it { expect(kubernetes.save).to be_falsey } it { expect(kubernetes.save).to be_falsey }
# end end
# context 'when api_url is nil' do context 'when api_url is nil' do
# let(:api_url) { nil } let(:api_url) { nil }
# it { expect(kubernetes.save).to be_falsey } it { expect(kubernetes.save).to be_falsey }
# end end
# context 'when api_url is valid url' do context 'when api_url is valid url' do
# let(:api_url) { 'https://111.111.111.111' } let(:api_url) { 'https://111.111.111.111' }
# it { expect(kubernetes.save).to be_truthy } it { expect(kubernetes.save).to be_truthy }
# end end
# end end
# context 'when validates token' do context 'when validates token' do
# let(:kubernetes) { build(:platform_kubernetes, :configured) } let(:kubernetes) { build(:platform_kubernetes, :configured) }
# before do before do
# kubernetes.token = token kubernetes.token = token
# end end
# context 'when token is nil' do context 'when token is nil' do
# let(:token) { nil } let(:token) { nil }
# it { expect(kubernetes.save).to be_falsey } it { expect(kubernetes.save).to be_falsey }
# end end
# end end
end end
describe '#actual_namespace' do describe '#actual_namespace' do
......
...@@ -42,7 +42,8 @@ describe Clusters::CreateService do ...@@ -42,7 +42,8 @@ describe Clusters::CreateService do
expect(result.provider.machine_type).to eq('machine_type-a') expect(result.provider.machine_type).to eq('machine_type-a')
expect(result.provider.access_token).to eq(access_token) expect(result.provider.access_token).to eq(access_token)
expect(result.platform.namespace).to eq('custom-namespace') 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
end end
...@@ -99,7 +100,6 @@ describe Clusters::CreateService do ...@@ -99,7 +100,6 @@ describe Clusters::CreateService do
expect(result.project).to eq(project) expect(result.project).to eq(project)
expect(result.provider).to be_nil expect(result.provider).to be_nil
expect(result.platform.namespace).to eq('custom-namespace') expect(result.platform.namespace).to eq('custom-namespace')
expect(result.platform.valid?).to be_truthy
end end
end end
......
...@@ -40,7 +40,7 @@ describe Clusters::Gcp::FinalizeCreationService do ...@@ -40,7 +40,7 @@ describe Clusters::Gcp::FinalizeCreationService do
{ {
endpoint: endpoint, endpoint: endpoint,
username: username, username: username,
password: password, password: password
} }
) )
......
...@@ -61,6 +61,11 @@ module GoogleApi ...@@ -61,6 +61,11 @@ module GoogleApi
Base64.encode64(File.read(pem_file)) Base64.encode64(File.read(pem_file))
end 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) def cloud_platform_cluster_body(**options)
{ {
"name": options[:name] || 'string', "name": options[:name] || 'string',
......
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