Class: Orchparty::Kubernetes::ChartBuilder

Inherits:
CommonBuilder show all
Defined in:
lib/orchparty/dsl_parser_kubernetes.rb

Instance Method Summary collapse

Methods inherited from CommonBuilder

#_build, #method_missing, #mix, #variables

Methods inherited from Builder

#assign_or_merge, build

Constructor Details

#initialize(name, application, type) ⇒ ChartBuilder

Returns a new instance of ChartBuilder.



357
358
359
360
# File 'lib/orchparty/dsl_parser_kubernetes.rb', line 357

def initialize(name, application, type)
  super AST.chart(name:, _type: type)
  @application = application
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Orchparty::Kubernetes::CommonBuilder

Instance Method Details

#secrets(name, deploy: :helm, &block) ⇒ Object

secrets can be aprt of the helm chart or we write them to a file and later apply it apiVersion: v1 kind: Secret metadata:

name: dotfile-secret

data:

key: base64_encoded_value


381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/orchparty/dsl_parser_kubernetes.rb', line 381

def secrets(name, deploy: :helm, &block)
  case deploy
  when :helm
    result = ServiceBuilder.build(name, 'chart-secret', block)
    @application.services[name] = result
    @application._service_order << name
    @node._services << name
    self
  when :apply
    result = ServiceBuilder.build(name, 'apply', block)
    file = Tempfile.create(name)
    result.tmp_file = file.path
    file.puts "apiVersion: v1\nkind: Secret\nmetadata:\n  name: #{@node.name}-#{name}\ntype: Opaque\ndata:"
    result._.each do |key, value|
      file.puts "  #{key}: #{Base64.strict_encode64(value.respond_to?(:call) ? value.call : value)}"
    end
    file.close
    @application.services[name] = result
    @application._service_order << name
  when :none

  else
    raise "unknown secret type: #{type}, known tpyes: [helm, apply]"
  end
end

#service(name, &block) ⇒ Object



362
363
364
365
366
367
368
369
370
# File 'lib/orchparty/dsl_parser_kubernetes.rb', line 362

def service(name, &block)
  result = ServiceBuilder.build(name, 'chart-service', block)

  name = "chart-#{@node.name}-#{name}"
  @application.services[name] = result
  @application._service_order << name
  @node._services << name
  self
end