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

ingress.rb « kubernetes « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c5643dd670aee0ae30556f78bd0cc14fb1fb4da6 (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
# frozen_string_literal: true

module Gitlab
  module Kubernetes
    class Ingress
      include Gitlab::Utils::StrongMemoize

      # Canary Ingress Annotations https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#canary
      ANNOTATION_KEY_CANARY = 'nginx.ingress.kubernetes.io/canary'
      ANNOTATION_KEY_CANARY_WEIGHT = 'nginx.ingress.kubernetes.io/canary-weight'

      def initialize(attributes = {})
        @attributes = attributes
      end

      def canary?
        strong_memoize(:is_canary) do
          annotations.any? do |key, value|
            key == ANNOTATION_KEY_CANARY && value == 'true'
          end
        end
      end

      def canary_weight
        return unless canary?
        return unless annotations.key?(ANNOTATION_KEY_CANARY_WEIGHT)

        annotations[ANNOTATION_KEY_CANARY_WEIGHT].to_i
      end

      def name
        metadata['name']
      end

      private

      def metadata
        @attributes.fetch('metadata', {})
      end

      def annotations
        metadata.fetch('annotations', {})
      end
    end
  end
end