lib/floe/workflow/runner.rb in floe-0.8.0 vs lib/floe/workflow/runner.rb in floe-0.9.0

- old
+ new

@@ -3,33 +3,46 @@ module Floe class Workflow class Runner include Logging - TYPES = %w[docker podman kubernetes].freeze OUTPUT_MARKER = "__FLOE_OUTPUT__\n" def initialize(_options = {}) end + @runners = {} class << self - attr_writer :docker_runner + # deprecated -- use Floe.set_runner instead + def docker_runner=(value) + set_runner("docker", value) + end - def docker_runner - @docker_runner ||= Floe::Workflow::Runner::Docker.new + # see Floe.set_runner + def set_runner(scheme, name_or_instance, options = {}) + @runners[scheme] = + case name_or_instance + when "docker", nil + Floe::Workflow::Runner::Docker.new(options) + when "podman" + Floe::Workflow::Runner::Podman.new(options) + when "kubernetes" + Floe::Workflow::Runner::Kubernetes.new(options) + when Floe::Workflow::Runner + name_or_instance + else + raise ArgumentError, "docker runner must be one of: docker, podman, kubernetes" + end end def for_resource(resource) raise ArgumentError, "resource cannot be nil" if resource.nil? + # if no runners are set, default docker:// to docker + set_runner("docker", "docker") if @runners.empty? scheme = resource.split("://").first - case scheme - when "docker" - docker_runner - else - raise "Invalid resource scheme [#{scheme}]" - end + @runners[scheme] || raise(ArgumentError, "Invalid resource scheme [#{scheme}]") end end def run!(resource, env = {}, secrets = {}) raise NotImplementedError, "Must be implemented in a subclass" @@ -51,9 +64,13 @@ def output(_runner_context) raise NotImplementedError, "Must be implemented in a subclass" end def cleanup(_runner_context) + raise NotImplementedError, "Must be implemented in a subclass" + end + + def wait(timeout: nil, events: %i[create update delete]) raise NotImplementedError, "Must be implemented in a subclass" end end end end