Class: Kube::Cluster::Standard::DeploymentWithService

Inherits:
Manifest
  • Object
show all
Defined in:
lib/kube/cluster/standard/deployment_with_service.rb

Instance Attribute Summary

Attributes inherited from Manifest

#resources

Instance Method Summary collapse

Methods inherited from Manifest

#<<

Constructor Details

#initialize(name:, image:, port:, namespace: 'default', env: {}, security_context: nil, pod_security_context: nil, volume_mounts: {}, service_port: nil, &block) ⇒ DeploymentWithService

Returns a new instance of DeploymentWithService.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/kube/cluster/standard/deployment_with_service.rb', line 10

def initialize(
  name:,
  image:,
  port:,
  namespace: 'default',
  env: {},
  security_context: nil,
  pod_security_context: nil,
  volume_mounts: {},
  service_port: nil,
  &block
)
  @_limits = {}
  @_probes = {}

  processed_env     = EnvProcessing.process(env)
  processed_volumes = VolumeProcessing.process(volume_mounts)

  service_ports = Array(service_port || port)

  service = Kube::Cluster::Standard::Service.new(
    name: name,
    namespace: namespace,
    ports: service_ports
  )

  deployment = Kube::Cluster['Deployment'].new do
    .name = name
    .namespace = namespace
    .labels = { 'app' => name }

    spec.replicas = 1
    spec.selector.matchLabels = { 'app' => name }

    spec.template..labels = { 'app' => name }
    spec.template.spec.securityContext = pod_security_context if pod_security_context

    container = {
      name: name,
      image: image,
      ports: [{ name: 'http', containerPort: port, protocol: 'TCP' }],
      env: processed_env
    }
    container[:securityContext] = security_context if security_context
    container[:volumeMounts] = processed_volumes[:volume_mounts] unless processed_volumes[:volume_mounts].empty?

    spec.template.spec.containers = [container]
    spec.template.spec.volumes = processed_volumes[:volumes] unless processed_volumes[:volumes].empty?
  end

  super(deployment, service)

  instance_exec(&block) if block

  _apply_limits(deployment)
  _apply_probes(deployment)
end

Instance Method Details

#limitsObject



68
69
70
# File 'lib/kube/cluster/standard/deployment_with_service.rb', line 68

def limits
  @_limits
end

#probesObject



72
73
74
# File 'lib/kube/cluster/standard/deployment_with_service.rb', line 72

def probes
  @_probes
end