This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

finalize_cluster_creation_service.rb 1.15 KB
Newer Older
1
2
3
module Ci
  class FinalizeClusterCreationService
    def execute(cluster)
4
      api_client =
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
        GoogleApi::CloudPlatform::Client.new(cluster.gcp_token, nil)

      begin
        gke_cluster = api_client.projects_zones_clusters_get(
          cluster.gcp_project_id,
          cluster.gcp_cluster_zone,
          cluster.gcp_cluster_name)
      rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e
        return cluster.errored!("Failed to request to CloudPlatform; #{e.message}")
      end

      endpoint = gke_cluster.endpoint
      api_url = 'https://' + endpoint
      ca_cert = Base64.decode64(gke_cluster.master_auth.cluster_ca_certificate)
      username = gke_cluster.master_auth.username
      password = gke_cluster.master_auth.password

      kubernetes_token = Ci::FetchKubernetesTokenService.new(
        api_url, ca_cert, username, password).execute

      unless kubernetes_token
        return cluster.errored!('Failed to get a default token of kubernetes')
      end

      Ci::IntegrateClusterService.new.execute(
        cluster, endpoint, ca_cert, kubernetes_token, username, password)
    end
  end
end