Commit 6571efb6 authored by Shinya Maeda's avatar Shinya Maeda

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

parent ef3ebed6
......@@ -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!
......
......@@ -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)
......
......@@ -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',
......
......@@ -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,
......
......@@ -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'
}
}
}
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -40,7 +40,7 @@ describe Clusters::Gcp::FinalizeCreationService do
{
endpoint: endpoint,
username: username,
password: password,
password: password
}
)
......
......@@ -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',
......
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