kubernetes-deploy 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29573aea8ad1792ad61ec614c01d86b8a1a4b42c
|
4
|
+
data.tar.gz: c626801864c77a1879d922c9140c16f1e8d203d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ba1893e0ff7cdf82eaffec1ded3cd3efe46409f0c05d8e9a2f67cca6f0777798f8184351c64bd922de651a2ef51b78d480edf677741a0b6cb392b1fee102156
|
7
|
+
data.tar.gz: 12761dfb12a052f1cc8971e10c881c36fcdfb4c69c7bb8aa492fa6b36b4b6e5f9a23cb47b53030097af21438fa2489ac04f7c0cb29e97fabde293ecc94ee9157
|
data/lib/kubernetes-deploy.rb
CHANGED
@@ -12,6 +12,7 @@ module KubernetesDeploy
|
|
12
12
|
|
13
13
|
def self.for_type(type, name, namespace, file)
|
14
14
|
case type
|
15
|
+
when 'cloudsql' then Cloudsql.new(name, namespace, file)
|
15
16
|
when 'configmap' then ConfigMap.new(name, namespace, file)
|
16
17
|
when 'deployment' then Deployment.new(name, namespace, file)
|
17
18
|
when 'pod' then Pod.new(name, namespace, file)
|
@@ -69,6 +70,10 @@ module KubernetesDeploy
|
|
69
70
|
!deploy_succeeded? && !deploy_failed? && (Time.now.utc - @deploy_started > self.class::TIMEOUT)
|
70
71
|
end
|
71
72
|
|
73
|
+
def tpr?
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
72
77
|
def status_data
|
73
78
|
{
|
74
79
|
group: group_name,
|
@@ -82,7 +87,7 @@ module KubernetesDeploy
|
|
82
87
|
end
|
83
88
|
|
84
89
|
def group_name
|
85
|
-
type
|
90
|
+
type.downcase.pluralize
|
86
91
|
end
|
87
92
|
|
88
93
|
def run_kubectl(*args)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module KubernetesDeploy
|
2
|
+
class Cloudsql < KubernetesResource
|
3
|
+
TIMEOUT = 5.minutes
|
4
|
+
|
5
|
+
def initialize(name, namespace, file)
|
6
|
+
@name, @namespace, @file = name, namespace, file
|
7
|
+
end
|
8
|
+
|
9
|
+
def sync
|
10
|
+
_, st = run_kubectl("get", type, @name)
|
11
|
+
@found = st.success?
|
12
|
+
@status = if cloudsql_proxy_deployment_exists? && mysql_service_exists?
|
13
|
+
"Provisioned"
|
14
|
+
else
|
15
|
+
"Unknown"
|
16
|
+
end
|
17
|
+
|
18
|
+
log_status
|
19
|
+
end
|
20
|
+
|
21
|
+
def deploy_succeeded?
|
22
|
+
cloudsql_proxy_deployment_exists? && mysql_service_exists?
|
23
|
+
end
|
24
|
+
|
25
|
+
def deploy_failed?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
def tpr?
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def exists?
|
34
|
+
@found
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def cloudsql_proxy_deployment_exists?
|
39
|
+
deployment, st = run_kubectl("get", "deployments", "cloudsql-proxy", "-o=json")
|
40
|
+
|
41
|
+
if st.success?
|
42
|
+
parsed = JSON.parse(deployment)
|
43
|
+
|
44
|
+
if parsed.fetch("status", {}).fetch("availableReplicas", -1) == parsed.fetch("status", {}).fetch("replicas", 0)
|
45
|
+
# all cloudsql-proxy pods are running
|
46
|
+
return true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def mysql_service_exists?
|
54
|
+
service, st = run_kubectl("get", "services", "mysql", "-o=json")
|
55
|
+
|
56
|
+
if st.success?
|
57
|
+
parsed = JSON.parse(service)
|
58
|
+
|
59
|
+
if parsed.fetch("spec", {}).fetch("clusterIP", "") != ""
|
60
|
+
# the service has an assigned cluster IP and is therefore functioning
|
61
|
+
return true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -7,6 +7,7 @@ require 'tempfile'
|
|
7
7
|
|
8
8
|
require 'kubernetes-deploy/kubernetes_resource'
|
9
9
|
%w(
|
10
|
+
cloudsql
|
10
11
|
config_map
|
11
12
|
deployment
|
12
13
|
ingress
|
@@ -20,6 +21,7 @@ end
|
|
20
21
|
module KubernetesDeploy
|
21
22
|
class Runner
|
22
23
|
PREDEPLOY_SEQUENCE = %w(
|
24
|
+
Cloudsql
|
23
25
|
ConfigMap
|
24
26
|
PersistentVolumeClaim
|
25
27
|
Pod
|
@@ -59,7 +61,6 @@ MSG
|
|
59
61
|
@namespace = namespace
|
60
62
|
@context = context
|
61
63
|
@current_sha = current_sha
|
62
|
-
|
63
64
|
@template_dir = File.expand_path(template_dir)
|
64
65
|
# Max length of podname is only 63chars so try to save some room by truncating sha to 8 chars
|
65
66
|
@id = current_sha[0...8] + "-#{SecureRandom.hex(4)}" if current_sha
|
@@ -134,7 +135,7 @@ MSG
|
|
134
135
|
end
|
135
136
|
|
136
137
|
def discover_resource_via_dry_run(tempfile)
|
137
|
-
resource_id, err, st = run_kubectl("
|
138
|
+
resource_id, err, st = run_kubectl("create", "-f", tempfile.path, "--dry-run", "--output=name")
|
138
139
|
raise FatalDeploymentError, "Dry run failed for template #{File.basename(tempfile.path)}." unless st.success?
|
139
140
|
resource_id
|
140
141
|
end
|
@@ -226,10 +227,27 @@ MSG
|
|
226
227
|
KubernetesDeploy.logger.info("All required parameters and files are present")
|
227
228
|
end
|
228
229
|
|
230
|
+
def update_tprs(resources)
|
231
|
+
resources.each do |r|
|
232
|
+
KubernetesDeploy.logger.info("- #{r.id}")
|
233
|
+
r.deploy_started = Time.now.utc
|
234
|
+
_, _, st = run_kubectl("replace", "-f", r.file.path)
|
235
|
+
|
236
|
+
unless st.success?
|
237
|
+
# it doesn't exist so we can't replace it
|
238
|
+
run_kubectl("create", "-f", r.file.path)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
229
243
|
def deploy_resources(resources, prune: false)
|
230
|
-
command = ["apply"
|
244
|
+
command = ["apply"]
|
231
245
|
KubernetesDeploy.logger.info("Deploying resources:")
|
232
246
|
|
247
|
+
# TPRs must use update for now: https://github.com/kubernetes/kubernetes/issues/39906
|
248
|
+
tprs, resources = resources.partition(&:tpr?)
|
249
|
+
update_tprs(tprs)
|
250
|
+
|
233
251
|
resources.each do |r|
|
234
252
|
KubernetesDeploy.logger.info("- #{r.id}")
|
235
253
|
command.push("-f", r.file.path)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubernetes-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kir Shatrov
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- kubernetes-deploy.gemspec
|
88
88
|
- lib/kubernetes-deploy.rb
|
89
89
|
- lib/kubernetes-deploy/kubernetes_resource.rb
|
90
|
+
- lib/kubernetes-deploy/kubernetes_resource/cloudsql.rb
|
90
91
|
- lib/kubernetes-deploy/kubernetes_resource/config_map.rb
|
91
92
|
- lib/kubernetes-deploy/kubernetes_resource/deployment.rb
|
92
93
|
- lib/kubernetes-deploy/kubernetes_resource/ingress.rb
|
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
116
|
version: '0'
|
116
117
|
requirements: []
|
117
118
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.5.
|
119
|
+
rubygems_version: 2.5.1
|
119
120
|
signing_key:
|
120
121
|
specification_version: 4
|
121
122
|
summary: Kubernetes deploy scripts
|