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: {}, command: nil, init_containers: [], security_context: nil, pod_security_context: nil, volume_mounts: {}, service_port: nil, stdin: false, tty: false, &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
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/kube/cluster/standard/deployment_with_service.rb', line 10

def initialize(
  name:,
  image:,
  port:,
  namespace: 'default',
  env: {},
  command: nil,
  init_containers: [],
  security_context: nil,
  pod_security_context: nil,
  volume_mounts: {},
  service_port: nil,
  stdin: false,
  tty: false,
  &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[:command] = command if command
    container[:securityContext] = security_context if security_context
    container[:volumeMounts] = processed_volumes[:volume_mounts] unless processed_volumes[:volume_mounts].empty?

    # Keep stdin/tty open so the pod can be `kubectl attach`-ed for
    # interactive flows (e.g. an OAuth proxy that prompts for a
    # redirect URL on first authorization).
    container[:stdin] = true if stdin
    container[:tty] = true if tty

    spec.template.spec.containers = [container]
    spec.template.spec.initContainers = init_containers unless init_containers.empty?
    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



80
81
82
# File 'lib/kube/cluster/standard/deployment_with_service.rb', line 80

def limits
  @_limits
end

#probesObject



84
85
86
# File 'lib/kube/cluster/standard/deployment_with_service.rb', line 84

def probes
  @_probes
end