Class: Clusters::Kubernetes::FetchKubernetesTokenService

Inherits:
Object
  • Object
show all
Defined in:
app/services/clusters/kubernetes/fetch_kubernetes_token_service.rb

Constant Summary collapse

DEFAULT_TOKEN_RETRY_DELAY =
5.seconds
TOKEN_RETRY_LIMIT =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kubeclient, service_account_token_name, namespace, token_retry_delay: DEFAULT_TOKEN_RETRY_DELAY) ⇒ FetchKubernetesTokenService

Returns a new instance of FetchKubernetesTokenService.


11
12
13
14
15
16
# File 'app/services/clusters/kubernetes/fetch_kubernetes_token_service.rb', line 11

def initialize(kubeclient, , namespace, token_retry_delay: DEFAULT_TOKEN_RETRY_DELAY)
  @kubeclient = kubeclient
  @service_account_token_name = 
  @namespace = namespace
  @token_retry_delay = token_retry_delay
end

Instance Attribute Details

#kubeclientObject (readonly)

Returns the value of attribute kubeclient


9
10
11
# File 'app/services/clusters/kubernetes/fetch_kubernetes_token_service.rb', line 9

def kubeclient
  @kubeclient
end

#namespaceObject (readonly)

Returns the value of attribute namespace


9
10
11
# File 'app/services/clusters/kubernetes/fetch_kubernetes_token_service.rb', line 9

def namespace
  @namespace
end

#service_account_token_nameObject (readonly)

Returns the value of attribute service_account_token_name


9
10
11
# File 'app/services/clusters/kubernetes/fetch_kubernetes_token_service.rb', line 9

def 
  @service_account_token_name
end

Instance Method Details

#executeObject


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/clusters/kubernetes/fetch_kubernetes_token_service.rb', line 18

def execute
  # Kubernetes will create the Secret and set the token asynchronously
  # so it is necessary to retry
  # https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/#token-controller
  TOKEN_RETRY_LIMIT.times do
    token_base64 = get_secret&.dig('data', 'token')
    return Base64.decode64(token_base64) if token_base64

    sleep @token_retry_delay
  end

  nil
end