Class: Kdep::Renderer
- Inherits:
-
Object
- Object
- Kdep::Renderer
- Defined in:
- lib/kdep/renderer.rb
Instance Method Summary collapse
-
#initialize(config, deploy_dir) ⇒ Renderer
constructor
A new instance of Renderer.
-
#render_helm_ingresses ⇒ Object
Feature B: render N Ingress resources from config.
- #render_resource(resource_name) ⇒ Object
Constructor Details
#initialize(config, deploy_dir) ⇒ Renderer
Returns a new instance of Renderer.
6 7 8 9 |
# File 'lib/kdep/renderer.rb', line 6 def initialize(config, deploy_dir) @config = config @deploy_dir = deploy_dir end |
Instance Method Details
#render_helm_ingresses ⇒ Object
Feature B: render N Ingress resources from config. Returns [[suffix, yaml], …] so the caller can emit multiple files.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/kdep/renderer.rb', line 33 def render_helm_ingresses entries = @config["ingresses"] || [] return [] if entries.empty? template_path = File.join(Kdep.templates_dir, "resources", "helm_ingress.yml.erb") raise "helm_ingress template not found at #{template_path}" unless File.exist?(template_path) template_content = File.read(template_path) erb = if RUBY_VERSION >= "2.6" ERB.new(template_content, trim_mode: "-") else ERB.new(template_content, nil, "-") end entries.map do |ingress| context = TemplateContext.new(@config) context.instance_variable_set(:@ingress, ingress) [ingress["name"], erb.result(context.get_binding)] end end |
#render_resource(resource_name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kdep/renderer.rb', line 11 def render_resource(resource_name) template_path = resolve_template(resource_name) raise "Template not found: #{resource_name}.yml.erb" unless template_path template_content = File.read(template_path) erb = if RUBY_VERSION >= "2.6" ERB.new(template_content, trim_mode: "-") else ERB.new(template_content, nil, "-") end secrets = {} if resource_name == "secret" secrets = load_secrets end context = TemplateContext.new(@config, secrets) erb.result(context.get_binding) end |