Class: KuberKit::Core::ServiceFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/kuber_kit/core/service_factory.rb

Constant Summary collapse

AttributeNotSetError =
Class.new(KuberKit::Error)

Instance Method Summary collapse

Instance Method Details

#create(definition) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/kuber_kit/core/service_factory.rb', line 4

def create(definition)
  service_attrs = definition.to_service_attrs

  if service_attrs.template_name.nil?
    raise AttributeNotSetError, "Please set template for service using #template method"
  end

  configuration_attributes = KuberKit.current_configuration.service_attributes(service_attrs.name)
  attributes = (service_attrs.attributes || {}).merge(configuration_attributes)

  KuberKit::Core::Service.new(
    name:               service_attrs.name,
    template_name:      service_attrs.template_name,
    tags:               service_attrs.tags,
    images:             service_attrs.images,
    attributes:         attributes,
    deployer_strategy:  service_attrs.deployer_strategy,
  )
end