Class: Ruboty::K8s::Deployment

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/k8s/deployment.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, client) ⇒ Deployment

Returns a new instance of Deployment.



2
3
4
5
# File 'lib/ruboty/k8s/deployment.rb', line 2

def initialize(config, client)
  @config = config
  @client = client
end

Instance Method Details

#has_deployment?(deployment) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/ruboty/k8s/deployment.rb', line 7

def has_deployment?(deployment)
  @config.keys.include?(deployment)
end

#patch_deployment(deployment, image) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruboty/k8s/deployment.rb', line 21

def patch_deployment(deployment, image)
  raise "Unknown deployment name: `#{deployment}`" unless has_deployment?(deployment)

  response = @client.v1beta1.patch_deployment(
    @config[deployment]['deployment_name'],
    patch_deployment_params(deployment, image),
    @config[deployment]['namespace']
  )

  response.code == 200
end

#patch_deployment_params(deployment, image) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruboty/k8s/deployment.rb', line 33

def patch_deployment_params(deployment, image)
  {
    spec: {
      template: {
        spec: {
          containers: [
            {
              name: @config[deployment]['container_name'],
              image: image,
            }
          ]
        }
      }
    }
  }
end

#rollback_deployment(deployment) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/ruboty/k8s/deployment.rb', line 11

def rollback_deployment(deployment)
  raise "Unknown deployment name: `#{deployment}`" unless has_deployment?(deployment)

  response = @client.v1beta1.rollback_deployment(
    @config[deployment]['deployment_name'], {}, @config[deployment]['namespace']
  )

  response.code == 201
end