From 21692e021d315a4a4d7045c663c322653526634e Mon Sep 17 00:00:00 2001 From: Gene Liverman Date: Thu, 12 Aug 2021 15:56:32 -0400 Subject: [PATCH] Allow loading pools from a directory of files This allows for specifying a directory containing yaml files with one or more array entries inside where each array entry is a pool definition. The reason for this addition is to facilitate having one ConfigMap per pool in Kubernetes. --- lib/vmpooler.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/vmpooler.rb b/lib/vmpooler.rb index 74bd697..73af16c 100644 --- a/lib/vmpooler.rb +++ b/lib/vmpooler.rb @@ -46,6 +46,15 @@ module Vmpooler parsed_config.merge!(extra_config) end end + parsed_config[:config]['pools_from_dir'] = ENV['POOLS_FROM_DIR'] if ENV['POOLS_FROM_DIR'] + if parsed_config[:config]['pools_from_dir'] && Dir.exist?(parsed_config[:config]['pools_from_dir']) + pools_from_dir = [] + Dir["#{parsed_config[:config]['pools_from_dir']}/*.yaml"].sort.each do |file_name| + parsed_pool = Yaml.load_file(file_name) + pools_from_dir += parsed_pool if parsed_pool + end + parsed_config[:pools] = pools_from_dir unless pools_from_dir.empty? + end end parsed_config ||= { config: {} }