debian-mirror-gitlab/lib/gitlab/kubernetes/ingress.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.1 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# 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