Class: Dapp::Deployment::KubeApp
Defined Under Namespace
Modules: Error
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from KubeBase
#delete_pod!, #merge_kube_controller_spec, #pod_exist?, #pod_succeeded?, #run_job!
Constructor Details
#initialize(app) ⇒ KubeApp
Returns a new instance of KubeApp.
14
15
16
|
# File 'lib/dapp/deployment/kube_app.rb', line 14
def initialize(app)
@app = app
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
12
13
14
|
# File 'lib/dapp/deployment/kube_app.rb', line 12
def app
@app
end
|
Instance Method Details
#_dump_service_info(srv) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/dapp/deployment/kube_app.rb', line 77
def _dump_service_info(srv)
app.deployment.dapp.log_info("type: #{srv['spec']['type']}")
app.deployment.dapp.log_info("clusterIP: #{srv['spec']['clusterIP']}")
srv['spec'].fetch('ports', []).each do |port|
app.deployment.dapp.log_info("Port #{port['port']}:")
app.deployment.dapp.with_log_indent do
%w(protocol targetPort nodePort).each do |field_name|
app.deployment.dapp.log_info("#{field_name}: #{_field_value_for_log(port[field_name])}")
end
end
end
end
|
#_field_value_for_log(value) ⇒ Object
112
113
114
|
# File 'lib/dapp/deployment/kube_app.rb', line 112
def _field_value_for_log(value)
value ? value : '-'
end
|
#create_deployment!(conf_spec) ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/dapp/deployment/kube_app.rb', line 91
def create_deployment!(conf_spec)
d = nil
app.deployment.dapp.log_process("Creating kubernetes Deployment #{conf_spec['metadata']['name']}") do
d = app.deployment.kubernetes.create_deployment!(conf_spec)
end
_wait_for_deployment(d)
end
|
#create_service!(conf_spec) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/dapp/deployment/kube_app.rb', line 59
def create_service!(conf_spec)
srv = nil
app.deployment.dapp.log_process("Creating kubernetes Service #{conf_spec['metadata']['name']}") do
srv = app.deployment.kubernetes.create_service!(conf_spec)
end
_dump_service_info srv
end
|
#deployment ⇒ Object
18
19
20
|
# File 'lib/dapp/deployment/kube_app.rb', line 18
def deployment
app.deployment
end
|
#labels ⇒ Object
22
23
24
|
# File 'lib/dapp/deployment/kube_app.rb', line 22
def labels
deployment.kube.labels.merge('dapp-app' => app.name)
end
|
#merge_kube_deployment_spec(spec1, spec2) ⇒ Object
116
117
118
|
# File 'lib/dapp/deployment/kube_app.rb', line 116
def merge_kube_deployment_spec(spec1, spec2)
merge_kube_controller_spec(spec1, spec2)
end
|
#merge_kube_service_spec(spec1, spec2) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/dapp/deployment/kube_app.rb', line 120
def merge_kube_service_spec(spec1, spec2)
spec1.kube_in_depth_merge(spec2).tap do |spec|
spec['metadata'] ||= {}
metadata_labels = spec2.fetch('metadata', {}).fetch('labels', nil)
spec['metadata']['labels'] = metadata_labels if metadata_labels
spec['spec'] ||= {}
spec_selector = spec2.fetch('spec', {}).fetch('selector', nil)
spec['spec']['selector'] = spec_selector if spec_selector
spec['spec']['ports'] = begin
ports1 = spec1.fetch('spec', {}).fetch('ports', [])
ports2 = spec2.fetch('spec', {}).fetch('ports', [])
ports2.map do |port2|
if (port1 = ports1.find { |p| p['name'] == port2['name'] }).nil?
port2
else
port = port1.merge(port2)
port.delete('nodePort') if spec['spec']['type'] == 'ClusterIP'
port
end
end
end
end
end
|
#replace_deployment!(name, conf_spec) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/dapp/deployment/kube_app.rb', line 99
def replace_deployment!(name, conf_spec)
d = nil
old_d_revision = nil
app.deployment.dapp.log_process("Replacing kubernetes Deployment #{name}") do
old_spec = deployment.kubernetes.deployment(name)
old_d_revision = old_spec.fetch('metadata', {}).fetch('annotations', {}).fetch('deployment.kubernetes.io/revision', nil)
new_spec = merge_kube_deployment_spec(old_spec, conf_spec)
new_spec.fetch('metadata', {}).fetch('annotations', {}).delete('deployment.kubernetes.io/revision')
d = app.deployment.kubernetes.replace_deployment!(name, new_spec)
end
_wait_for_deployment(d, old_d_revision: old_d_revision)
end
|
#replace_service!(name, conf_spec) ⇒ Object
67
68
69
70
71
72
73
74
75
|
# File 'lib/dapp/deployment/kube_app.rb', line 67
def replace_service!(name, conf_spec)
srv = nil
app.deployment.dapp.log_process("Replacing kubernetes Service #{name}") do
old_spec = deployment.kubernetes.service(name)
new_spec = merge_kube_service_spec(old_spec, conf_spec)
srv = app.deployment.kubernetes.replace_service!(name, new_spec)
end
_dump_service_info srv
end
|