Class: Ci::GenerateKubeconfigService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ci/generate_kubeconfig_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(pipeline, token:, environment:) ⇒ GenerateKubeconfigService

Returns a new instance of GenerateKubeconfigService.



5
6
7
8
9
10
11
# File 'app/services/ci/generate_kubeconfig_service.rb', line 5

def initialize(pipeline, token:, environment:)
  @pipeline = pipeline
  @token = token
  @environment = environment

  @template = Gitlab::Kubernetes::Kubeconfig::Template.new
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/ci/generate_kubeconfig_service.rb', line 13

def execute
  template.add_cluster(
    name: cluster_name,
    url: Gitlab::Kas.tunnel_url
  )

  agent_authorizations.each do |authorization|
    agent = authorization.agent
    user = user_name(agent)

    template.add_user(
      name: user,
      token: agent_token(agent)
    )

    template.add_context(
      name: context_name(agent),
      namespace: context_namespace(authorization),
      cluster: cluster_name,
      user: user
    )
  end

  template
end