Class: Krane::MutatingWebhookConfiguration::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/krane/kubernetes_resource/mutating_webhook_configuration.rb

Defined Under Namespace

Classes: Rule

Constant Summary collapse

EQUIVALENT =
'Equivalent'
EXACT =
'Exact'

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ Webhook

Returns a new instance of Webhook.



42
43
44
# File 'lib/krane/kubernetes_resource/mutating_webhook_configuration.rb', line 42

def initialize(definition)
  @definition = definition
end

Instance Method Details

#has_side_effects?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/krane/kubernetes_resource/mutating_webhook_configuration.rb', line 50

def has_side_effects?
  !%w(None NoneOnDryRun).include?(side_effects)
end

#match_policyObject



54
55
56
# File 'lib/krane/kubernetes_resource/mutating_webhook_configuration.rb', line 54

def match_policy
  @definition.dig('matchPolicy')
end

#matches_resource?(resource, skip_rule_if_side_effect_none: true) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
# File 'lib/krane/kubernetes_resource/mutating_webhook_configuration.rb', line 58

def matches_resource?(resource, skip_rule_if_side_effect_none: true)
  return false if skip_rule_if_side_effect_none && !has_side_effects?
  rules.any? do |rule|
    rule.matches_resource?(resource, accept_equivalent: match_policy == EQUIVALENT)
  end
end

#rulesObject



65
66
67
# File 'lib/krane/kubernetes_resource/mutating_webhook_configuration.rb', line 65

def rules
  @definition.fetch('rules', []).map { |rule| Rule.new(rule) }
end

#side_effectsObject



46
47
48
# File 'lib/krane/kubernetes_resource/mutating_webhook_configuration.rb', line 46

def side_effects
  @definition.dig('sideEffects')
end