Welcome to mirror list, hosted at ThFree Co, Russian Federation.

service.rb « serverless « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c3ab2e9ddeb82dc0033e8238120d27b8aa741de0 (plain)
1
2
3
4
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# frozen_string_literal: true

class Gitlab::Serverless::Service
  include Gitlab::Utils::StrongMemoize

  def initialize(attributes)
    @attributes = attributes
  end

  def name
    @attributes.dig('metadata', 'name')
  end

  def namespace
    @attributes.dig('metadata', 'namespace')
  end

  def environment_scope
    @attributes.dig('environment_scope')
  end

  def environment
    @attributes.dig('environment')
  end

  def podcount
    @attributes.dig('podcount')
  end

  def created_at
    strong_memoize(:created_at) do
      timestamp = @attributes.dig('metadata', 'creationTimestamp')
      DateTime.parse(timestamp) if timestamp
    end
  end

  def image
    @attributes.dig(
      'spec',
      'runLatest',
      'configuration',
      'build',
      'template',
      'name')
  end

  def description
    knative_07_description || knative_05_06_description
  end

  def cluster
    @attributes.dig('cluster')
  end

  def url
    proxy_url || knative_06_07_url || knative_05_url
  end

  private

  def proxy_url
    if cluster&.serverless_domain
      ::Serverless::Domain.new(
        function_name: name,
        serverless_domain_cluster: cluster.serverless_domain,
        environment: environment
      ).uri.to_s
    end
  end

  def knative_07_description
    @attributes.dig(
      'spec',
      'template',
      'metadata',
      'annotations',
      'Description'
    )
  end

  def knative_05_06_description
    @attributes.dig(
      'spec',
      'runLatest',
      'configuration',
      'revisionTemplate',
      'metadata',
      'annotations',
      'Description')
  end

  def knative_05_url
    domain = @attributes.dig('status', 'domain')
    return unless domain

    "http://#{domain}"
  end

  def knative_06_07_url
    @attributes.dig('status', 'url')
  end
end