Class: Metatron::Templates::Service
- Inherits:
-
Metatron::Template
- Object
- Metatron::Template
- Metatron::Templates::Service
- Includes:
- Concerns::Annotated, Concerns::Namespaced
- Defined in:
- lib/metatron/templates/service.rb
Overview
The Service Kubernetes resource
Instance Attribute Summary collapse
-
#additional_labels ⇒ Object
Returns the value of attribute additional_labels.
-
#additional_selector_labels ⇒ Object
Returns the value of attribute additional_selector_labels.
-
#cluster_ip ⇒ Object
Returns the value of attribute cluster_ip.
-
#ports ⇒ Object
Returns the value of attribute ports.
-
#publish_not_ready_addresses ⇒ Object
Returns the value of attribute publish_not_ready_addresses.
-
#selector ⇒ Object
Returns the value of attribute selector.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Metatron::Template
#api_version, #base_labels, #kind, #name
Instance Method Summary collapse
- #clusterIP ⇒ Object
-
#formatted_ports ⇒ Object
rubocop:enable Naming/MethodName.
- #formatted_publish_not_ready_addresses ⇒ Object
-
#initialize(name, port = nil) ⇒ Service
constructor
A new instance of Service.
-
#publishNotReadyAddresses ⇒ Object
rubocop:disable Naming/MethodName.
- #render ⇒ Object
Methods included from Concerns::Namespaced
#formatted_namespace, included, #namespaced_initialize
Methods included from Concerns::Annotated
#annotated_initialize, #formatted_annotations, included
Methods inherited from Metatron::Template
initializer, initializers, metatron_template_class?, nearest_metatron_ancestor
Constructor Details
#initialize(name, port = nil) ⇒ Service
Returns a new instance of Service.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/metatron/templates/service.rb', line 14 def initialize(name, port = nil) super(name) @type = "ClusterIP" @cluster_ip = nil @selector = base_labels @additional_labels = {} @additional_selector_labels = {} @publish_not_ready_addresses = false return unless port @ports = [ { port: port.to_i, targetPort: port.to_i, protocol: "TCP", name: } ] end |
Instance Attribute Details
#additional_labels ⇒ Object
Returns the value of attribute additional_labels.
10 11 12 |
# File 'lib/metatron/templates/service.rb', line 10 def additional_labels @additional_labels end |
#additional_selector_labels ⇒ Object
Returns the value of attribute additional_selector_labels.
10 11 12 |
# File 'lib/metatron/templates/service.rb', line 10 def additional_selector_labels @additional_selector_labels end |
#cluster_ip ⇒ Object
Returns the value of attribute cluster_ip.
10 11 12 |
# File 'lib/metatron/templates/service.rb', line 10 def cluster_ip @cluster_ip end |
#ports ⇒ Object
Returns the value of attribute ports.
10 11 12 |
# File 'lib/metatron/templates/service.rb', line 10 def ports @ports end |
#publish_not_ready_addresses ⇒ Object
Returns the value of attribute publish_not_ready_addresses.
10 11 12 |
# File 'lib/metatron/templates/service.rb', line 10 def publish_not_ready_addresses @publish_not_ready_addresses end |
#selector ⇒ Object
Returns the value of attribute selector.
10 11 12 |
# File 'lib/metatron/templates/service.rb', line 10 def selector @selector end |
#type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'lib/metatron/templates/service.rb', line 10 def type @type end |
Instance Method Details
#clusterIP ⇒ Object
36 37 |
# File 'lib/metatron/templates/service.rb', line 36 def clusterIP = cluster_ip # rubocop:enable Naming/MethodName |
#formatted_ports ⇒ Object
rubocop:enable Naming/MethodName
39 40 41 |
# File 'lib/metatron/templates/service.rb', line 39 def formatted_ports ports&.any? ? { ports: } : {} end |
#formatted_publish_not_ready_addresses ⇒ Object
43 44 45 |
# File 'lib/metatron/templates/service.rb', line 43 def formatted_publish_not_ready_addresses publish_not_ready_addresses ? { publishNotReadyAddresses: } : {} end |
#publishNotReadyAddresses ⇒ Object
rubocop:disable Naming/MethodName
35 |
# File 'lib/metatron/templates/service.rb', line 35 def publishNotReadyAddresses = publish_not_ready_addresses |
#render ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/metatron/templates/service.rb', line 47 def render { apiVersion:, kind:, metadata: { name:, labels: base_labels.merge(additional_labels) }.merge(formatted_annotations).merge(formatted_namespace), spec: { type:, selector: selector.merge(additional_selector_labels), clusterIP: }.compact.merge(formatted_ports).merge(formatted_publish_not_ready_addresses) } end |