Class: OodCore::Job::Adapters::Kubernetes::Resources::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/job/adapters/kubernetes/resources.rb

Overview

Utility class for kuberenetes container object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, image, command: [], port: nil, env: {}, memory_limit: nil, memory_request: nil, cpu_limit: nil, cpu_request: nil, working_dir: "", restart_policy: "Never", image_pull_policy: nil, image_pull_secret: nil, supplemental_groups: [], startup_probe: {}, labels: {}) ⇒ Container

Returns a new instance of Container.

Raises:

  • (ArgumentError)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 66

def initialize(
    name, image, command: [], port: nil, env: {},
    memory_limit: nil, memory_request: nil, cpu_limit: nil, cpu_request: nil,
    working_dir: "", restart_policy: "Never", image_pull_policy: nil, image_pull_secret: nil, supplemental_groups: [],
    startup_probe: {}, labels: {}
  )
  raise ArgumentError, "containers need valid names and images" unless name && image

  @name = name
  @image = image
  @command = command.nil? ? [] : command
  @port = port&.to_i
  @env = env.nil? ? {} : env
  @memory_limit = memory_limit.nil? ? "4Gi" : memory_limit
  @memory_request = memory_request.nil? ? "4Gi" : memory_request
  @cpu_limit = cpu_limit.nil? ? "1" : cpu_limit
  @cpu_request = cpu_request.nil? ? "1" : cpu_request
  @working_dir = working_dir.nil? ? "" : working_dir
  @restart_policy = restart_policy.nil? ? "Never" : restart_policy
  @image_pull_policy = image_pull_policy.nil? ? "IfNotPresent" : image_pull_policy
  @image_pull_secret = image_pull_secret
  @supplemental_groups = supplemental_groups.nil? ? [] : supplemental_groups
  @startup_probe = TCPProbe.new(@port, startup_probe)
  @labels = labels.nil? ? {} : labels
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def command
  @command
end

#cpu_limitObject

Returns the value of attribute cpu_limit.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def cpu_limit
  @cpu_limit
end

#cpu_requestObject

Returns the value of attribute cpu_request.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def cpu_request
  @cpu_request
end

#envObject

Returns the value of attribute env.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def env
  @env
end

#imageObject

Returns the value of attribute image.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def image
  @image
end

#image_pull_policyObject

Returns the value of attribute image_pull_policy.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def image_pull_policy
  @image_pull_policy
end

#image_pull_secretObject

Returns the value of attribute image_pull_secret.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def image_pull_secret
  @image_pull_secret
end

#labelsObject

Returns the value of attribute labels.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def labels
  @labels
end

#memory_limitObject

Returns the value of attribute memory_limit.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def memory_limit
  @memory_limit
end

#memory_requestObject

Returns the value of attribute memory_request.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def memory_request
  @memory_request
end

#nameObject

Returns the value of attribute name.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def name
  @name
end

#portObject

Returns the value of attribute port.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def port
  @port
end

#restart_policyObject

Returns the value of attribute restart_policy.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def restart_policy
  @restart_policy
end

#startup_probeObject

Returns the value of attribute startup_probe.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def startup_probe
  @startup_probe
end

#supplemental_groupsObject

Returns the value of attribute supplemental_groups.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def supplemental_groups
  @supplemental_groups
end

#working_dirObject

Returns the value of attribute working_dir.



61
62
63
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 61

def working_dir
  @working_dir
end

Instance Method Details

#==(other) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ood_core/job/adapters/kubernetes/resources.rb', line 92

def ==(other)
  name == other.name &&
    image == other.image &&
    command == other.command &&
    port == other.port &&
    env == other.env &&
    memory_limit == other.memory_limit &&
    memory_request == other.memory_request &&
    cpu_limit == other.cpu_limit &&
    cpu_request == other.cpu_request &&
    working_dir == other.working_dir &&
    restart_policy == other.restart_policy &&
    image_pull_policy == other.image_pull_policy &&
    image_pull_secret == other.image_pull_secret &&
    supplemental_groups == other.supplemental_groups &&
    startup_probe.to_h == other.startup_probe.to_h &&
    labels.to_h == other.labels.to_h
end