2017-09-30 15:54:22 +00:00
|
|
|
module Ci
|
|
|
|
class IntegrateClusterService
|
|
|
|
def execute(cluster, endpoint, ca_cert, token, username, password)
|
2017-10-02 12:58:50 +00:00
|
|
|
Gcp::Cluster.transaction do
|
2017-10-03 21:26:26 +00:00
|
|
|
cluster.update!(
|
|
|
|
enabled: true,
|
|
|
|
endpoint: endpoint,
|
|
|
|
ca_cert: ca_cert,
|
|
|
|
kubernetes_token: token,
|
|
|
|
username: username,
|
|
|
|
password: password,
|
2017-10-03 22:20:47 +00:00
|
|
|
service: cluster.project.find_or_initialize_service('kubernetes'),
|
2017-10-04 13:14:01 +00:00
|
|
|
status_event: :make_created)
|
2017-09-30 15:54:22 +00:00
|
|
|
|
2017-10-02 12:58:50 +00:00
|
|
|
cluster.service.update!(
|
2017-10-01 08:48:21 +00:00
|
|
|
active: true,
|
|
|
|
api_url: cluster.api_url,
|
|
|
|
ca_pem: ca_cert,
|
|
|
|
namespace: cluster.project_namespace,
|
|
|
|
token: token)
|
|
|
|
end
|
2017-09-30 15:54:22 +00:00
|
|
|
rescue ActiveRecord::RecordInvalid => e
|
2017-10-05 07:34:24 +00:00
|
|
|
cluster.make_errored!("Failed to integrate cluster into kubernetes_service: #{e.message}")
|
2017-09-30 15:54:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|