Class: K8sInternalLb::Service
- Inherits:
-
Object
- Object
- K8sInternalLb::Service
- Defined in:
- lib/k8s_internal_lb/service.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#endpoints ⇒ Object
Returns the value of attribute endpoints.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#last_update ⇒ Object
Returns the value of attribute last_update.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#ports ⇒ Object
Returns the value of attribute ports.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#endpoints ⇒ Object
Returns the value of attribute endpoints.
6 7 8 |
# File 'lib/k8s_internal_lb/service.rb', line 6 def endpoints @endpoints end |
#interval ⇒ Object
Returns the value of attribute interval.
6 7 8 |
# File 'lib/k8s_internal_lb/service.rb', line 6 def interval @interval end |
#last_update ⇒ Object
Returns the value of attribute last_update.
6 7 8 |
# File 'lib/k8s_internal_lb/service.rb', line 6 def last_update @last_update end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/k8s_internal_lb/service.rb', line 5 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
6 7 8 |
# File 'lib/k8s_internal_lb/service.rb', line 6 def namespace @namespace end |
#ports ⇒ Object
Returns the value of attribute ports.
6 7 8 |
# File 'lib/k8s_internal_lb/service.rb', line 6 def ports @ports end |
Class Method Details
.create(type: :TCP, **params) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/k8s_internal_lb/service.rb', line 8 def self.create(type: :TCP, **params) raise ArgumentError, 'Must specify service type' if type.nil? klass = Services.const_get type raise ArgumentError, 'Unknown service type' if klass.nil? klass.new(**params) end |
Instance Method Details
#logger ⇒ Object
17 18 19 |
# File 'lib/k8s_internal_lb/service.rb', line 17 def logger @logger ||= Logging::Logger[self] end |
#to_subsets ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/k8s_internal_lb/service.rb', line 25 def to_subsets grouped = endpoints.group_by(&:port) # TODO: Find all port combinations that result in the same list of ready # and not-ready addresses, and combine them into a single pair of # multiple ports. # # { # 1 => { active: [A, B], inactive: [C] }, # 2 => { active: [A, B], inactive: [C] } # } # => # { # [1,2] => { active: [A, B], inactive: [C] } # } grouped = grouped.map do |p, g| { addresses: g.select(&:ready?).map(&:address), notReadyAddresses: g.select(&:not_ready?).map(&:address), ports: [p] } end # grouped = grouped.group_by { |s| s[:addresses] + s[:notReadyAddresses] } # .map do |_, s| # v = s.first # # v[:ports] = s.reduce([]) { |sum, e| sum << e[:ports] } # # v # end grouped end |
#update ⇒ Object
21 22 23 |
# File 'lib/k8s_internal_lb/service.rb', line 21 def update raise NotImplementedError end |