Class: Metatron::Templates::Ingress
- Inherits:
-
Metatron::Template
- Object
- Metatron::Template
- Metatron::Templates::Ingress
- Includes:
- Concerns::Namespaced
- Defined in:
- lib/metatron/templates/ingress.rb
Overview
Template for basic Ingress k8s resource
Instance Attribute Summary collapse
-
#additional_annotations ⇒ Object
Returns the value of attribute additional_annotations.
-
#additional_labels ⇒ Object
Returns the value of attribute additional_labels.
-
#cert_manager_challenge_type ⇒ Object
Returns the value of attribute cert_manager_challenge_type.
-
#cert_manager_cluster_issuer ⇒ Object
Returns the value of attribute cert_manager_cluster_issuer.
-
#cert_manager_issuer ⇒ Object
Returns the value of attribute cert_manager_issuer.
-
#ingress_class ⇒ Object
Returns the value of attribute ingress_class.
-
#rules ⇒ Object
Returns the value of attribute rules.
-
#tls ⇒ Object
Returns the value of attribute tls.
Attributes inherited from Metatron::Template
#api_version, #base_labels, #kind, #name
Instance Method Summary collapse
-
#add_rule(rule) ⇒ Object
Supports one of (they are all equivalent): { host: “foo.bar”, service: { name: “some_service”, port: “some_port” } } { “foo.bar” => { “some_service” => “some_port” } } { host: “foo.bar”, paths: [{ path: “/”, service: { name: “some_service”, port: “some_port” } }] }.
-
#add_tls(*tls, secret: nil) ⇒ Object
Supports an array of hostnames to provide TLS for via some secret If the secret name isn’t provide, its name will be derived from the first hostname.
- #cert_manager_annotations ⇒ Object
- #formatted_annotations ⇒ Object
- #formatted_rules ⇒ Object
- #formatted_tls ⇒ Object
-
#initialize(name, ingress_class = "nginx") ⇒ Ingress
constructor
A new instance of Ingress.
- #render ⇒ Object
- #secret_name_from_hostname(hostname) ⇒ Object
Methods included from Concerns::Namespaced
#formatted_namespace, included, #namespaced_initialize
Methods inherited from Metatron::Template
initializer, initializers, metatron_template_class?, nearest_metatron_ancestor
Constructor Details
#initialize(name, ingress_class = "nginx") ⇒ Ingress
Returns a new instance of Ingress.
12 13 14 15 16 17 18 |
# File 'lib/metatron/templates/ingress.rb', line 12 def initialize(name, ingress_class = "nginx") super(name) @ingress_class = ingress_class @api_version = "networking.k8s.io/v1" @additional_labels = {} @additional_annotations = {} end |
Instance Attribute Details
#additional_annotations ⇒ Object
Returns the value of attribute additional_annotations.
9 10 11 |
# File 'lib/metatron/templates/ingress.rb', line 9 def additional_annotations @additional_annotations end |
#additional_labels ⇒ Object
Returns the value of attribute additional_labels.
9 10 11 |
# File 'lib/metatron/templates/ingress.rb', line 9 def additional_labels @additional_labels end |
#cert_manager_challenge_type ⇒ Object
Returns the value of attribute cert_manager_challenge_type.
9 10 11 |
# File 'lib/metatron/templates/ingress.rb', line 9 def cert_manager_challenge_type @cert_manager_challenge_type end |
#cert_manager_cluster_issuer ⇒ Object
Returns the value of attribute cert_manager_cluster_issuer.
9 10 11 |
# File 'lib/metatron/templates/ingress.rb', line 9 def cert_manager_cluster_issuer @cert_manager_cluster_issuer end |
#cert_manager_issuer ⇒ Object
Returns the value of attribute cert_manager_issuer.
9 10 11 |
# File 'lib/metatron/templates/ingress.rb', line 9 def cert_manager_issuer @cert_manager_issuer end |
#ingress_class ⇒ Object
Returns the value of attribute ingress_class.
9 10 11 |
# File 'lib/metatron/templates/ingress.rb', line 9 def ingress_class @ingress_class end |
#rules ⇒ Object
Returns the value of attribute rules.
9 10 11 |
# File 'lib/metatron/templates/ingress.rb', line 9 def rules @rules end |
#tls ⇒ Object
Returns the value of attribute tls.
9 10 11 |
# File 'lib/metatron/templates/ingress.rb', line 9 def tls @tls end |
Instance Method Details
#add_rule(rule) ⇒ Object
Supports one of (they are all equivalent):
{ host: "foo.bar", service: { name: "some_service", port: "some_port" } }
{ "foo.bar" => { "some_service" => "some_port" } }
{
host: "foo.bar",
paths: [{ path: "/", service: { name: "some_service", port: "some_port" } }]
}
27 28 29 30 |
# File 'lib/metatron/templates/ingress.rb', line 27 def add_rule(rule) @rules ||= [] @rules << (rule.key?(:host) ? complex_rule(rule) : simple_rule(rule)) end |
#add_tls(*tls, secret: nil) ⇒ Object
Supports an array of hostnames to provide TLS for via some secret If the secret name isn’t provide, its name will be derived from the first hostname
34 35 36 37 38 39 40 |
# File 'lib/metatron/templates/ingress.rb', line 34 def add_tls(*tls, secret: nil) @tls ||= [] @tls << { hosts: tls.map(&:downcase), secretName: secret || secret_name_from_hostname(tls.first) } end |
#cert_manager_annotations ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/metatron/templates/ingress.rb', line 42 def cert_manager_annotations cert_manager = {} if cert_manager_issuer cert_manager[:"cert-manager.io/issuer"] = cert_manager_issuer elsif cert_manager_cluster_issuer cert_manager[:"cert-manager.io/cluster-issuer"] = cert_manager_cluster_issuer end unless cert_manager.empty? cert_manager[:"cert-manager.io/acme-challenge-type"] = cert_manager_challenge_type || "http01" end {}.merge(cert_manager) end |
#formatted_annotations ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/metatron/templates/ingress.rb', line 57 def formatted_annotations ingress_annotations = { "kubernetes.io/ingress.class": ingress_class } { annotations: ingress_annotations .merge(additional_annotations) .merge(cert_manager_annotations) } end |
#formatted_rules ⇒ Object
66 67 68 |
# File 'lib/metatron/templates/ingress.rb', line 66 def formatted_rules (rules || []).empty? ? {} : { rules: } end |
#formatted_tls ⇒ Object
70 71 72 |
# File 'lib/metatron/templates/ingress.rb', line 70 def formatted_tls (tls || []).empty? ? {} : { tls: } end |
#render ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/metatron/templates/ingress.rb', line 74 def render { apiVersion:, kind:, metadata: { name:, labels: base_labels.merge(additional_labels) }.merge(formatted_annotations).merge(formatted_namespace), spec: formatted_rules.merge(formatted_tls) } end |
#secret_name_from_hostname(hostname) ⇒ Object
86 87 88 |
# File 'lib/metatron/templates/ingress.rb', line 86 def secret_name_from_hostname(hostname) "#{hostname.downcase.gsub(".", "-")}-tls" end |