Class: Kubec::Kubernetes::Container

Inherits:
Hash
  • Object
show all
Includes:
HasAttribute
Defined in:
lib/kubec/kubernetes/container.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from HasAttribute

included

Constructor Details

#initialize(name, &block) ⇒ Container

Returns a new instance of Container.



12
13
14
15
# File 'lib/kubec/kubernetes/container.rb', line 12

def initialize(name, &block)
  self[:name] = name
  instance_eval(&block)
end

Instance Method Details

#args(*args) ⇒ Object



62
63
64
# File 'lib/kubec/kubernetes/container.rb', line 62

def args(*args)
  self[:args] = args.flatten
end

#command(*args) ⇒ Object



56
57
58
59
60
# File 'lib/kubec/kubernetes/container.rb', line 56

def command(*args)
  args = args.flatten
  self[:command] = args.take(1)
  self[:args] = args.drop(1)
end

#config_file(name, path:, from:) ⇒ Object

TODO: Auto setup config map volume



35
36
37
38
39
40
# File 'lib/kubec/kubernetes/container.rb', line 35

def config_file(name, path:, from:)
  self[:volumeMounts] ||= []
  self[:volumeMounts].push name: from,
                           mountPath: [path, name].join('/'),
                           subPath: name
end

#env(key, value) ⇒ Object



22
23
24
25
26
# File 'lib/kubec/kubernetes/container.rb', line 22

def env(key, value)
  self[:env] ||= []
  self[:env].push name: key,
                  value: value.to_s
end

#fetch(*args) ⇒ Object

TODO: Refactor this feature



18
19
20
# File 'lib/kubec/kubernetes/container.rb', line 18

def fetch(*args)
  Environment.instance.fetch(*args)
end

#mount(name, at:) ⇒ Object



28
29
30
31
32
# File 'lib/kubec/kubernetes/container.rb', line 28

def mount(name, at:)
  self[:volumeMounts] ||= []
  self[:volumeMounts].push name: name,
                           mountPath: at
end

#port(container_port, host_port = nil, ip: nil, name: nil, protocol: nil) ⇒ Object

TODO: Add object to check fields



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kubec/kubernetes/container.rb', line 43

def port(container_port, host_port = nil,
         ip: nil, name: nil, protocol: nil)
  self[:ports] ||= []
  port = {
    containerPort: container_port,
    hostPort: host_port,
    hostIP: ip,
    name: name,
    protocol: protocol
  }.reject { |_, v| v.nil? }
  self[:ports].push port
end