class Reschedule::Reschedulers::All

Attributes

kubernetes_api[R]
replication_controller_name_regex[R]

Public Class Methods

new(options={}) click to toggle source
Calls superclass method
# File lib/reschedule/reschedulers/all.rb, line 10
def initialize(options={})
  super
  @kubernetes_api = Reschedule::Kubernetes::Api.new
  @replication_controller_name_regex = options['replication_controller_name_match'].present? ? Regexp.new(options['replication_controller_name_match']) : nil
end

Public Instance Methods

run() click to toggle source
Calls superclass method
# File lib/reschedule/reschedulers/all.rb, line 16
def run
  super
  replication_controllers = kubernetes_api.get_replication_controllers(namespace: options['namespace'])
  Reschedule.logger.debug "Found #{replication_controllers.length} replication controllers"

  replication_controllers.select! do |replication_controller|
    template = replication_controller.spec[:template] || replication_controller.spec['table'][:template]
    image = template['spec']['containers'][0]['image']
    next if image.include?('/reschedule')
    next if replication_controller.spec.replicas == 0
    next if replication_controller_name_regex && replication_controller.metadata.name !~ replication_controller_name_regex
    true
  end

  Reschedule.logger.debug "Found #{replication_controllers.length} replication controllers to reschedule"
  replication_controllers.each do |replication_controller|
    reschedule_replication_controller(replication_controller.metadata.name)
  end
end