seira 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/lib/helpers.rb +5 -0
- data/lib/seira/pods.rb +74 -55
- data/lib/seira/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 48543d46e562c460bb07cd4e5264b381a9f8f290416fc9b49ed72f857c0082d9
|
4
|
+
data.tar.gz: 14866aed401685a325be5f8687ac799be8028a2607537ea7c0634331af7f9ad6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 867599d8ef0343d263432f3c0faac188864eb0df28bacbb381238669df373c9d9d5c5a9d2ec7dd02a633bbae40b7ba2559db8ee41a094f71c8ceb541d7a8b2d0
|
7
|
+
data.tar.gz: 2a8e70e9c427e1f718d85f538b1df7c0909e942e87cec9c575e9ee64a9560b2b7cd3a2bc2b801e5ab47d3a6d18f2245afdd6d0943ea9f2a4a3ac180853b043cf
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.1
|
data/.travis.yml
CHANGED
data/lib/helpers.rb
CHANGED
@@ -17,6 +17,11 @@ module Seira
|
|
17
17
|
JSON.parse(output)['items']
|
18
18
|
end
|
19
19
|
|
20
|
+
def fetch_pod(name, context:)
|
21
|
+
output = Seira::Commands.kubectl("get pod #{name} -o json", context: context, return_output: true)
|
22
|
+
JSON.parse(output) unless output.empty?
|
23
|
+
end
|
24
|
+
|
20
25
|
def log_link(context:, query:)
|
21
26
|
link = context[:settings].log_link_format
|
22
27
|
return nil if link.nil?
|
data/lib/seira/pods.rb
CHANGED
@@ -82,69 +82,88 @@ module Seira
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
# If a pod name is specified,
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
if
|
90
|
-
|
91
|
-
|
92
|
-
|
85
|
+
# If a pod name is specified, find the pod with that name
|
86
|
+
existing_pod = Helpers.fetch_pod(pod_name, context: context) unless pod_name.to_s.empty?
|
87
|
+
|
88
|
+
# Use existing pod if found and not --dedicated
|
89
|
+
# Otherwise, connect to a random pod from the specified tier or the 'terminal' tier if unspecified
|
90
|
+
target_pod = if existing_pod && dedicated
|
91
|
+
puts "Cannot create new dedicated pod with name: #{pod_name}"
|
92
|
+
puts "A pod with this name already exists"
|
93
|
+
exit(1)
|
94
|
+
elsif existing_pod
|
95
|
+
existing_pod
|
96
|
+
elsif dedicated || pod_name.to_s.empty?
|
97
|
+
Helpers.fetch_pods(context: context, filters: { tier: tier || 'terminal' }).sample
|
98
|
+
else
|
99
|
+
puts 'Could not find pod to connect to'
|
100
|
+
exit(1)
|
101
|
+
end
|
93
102
|
|
94
103
|
if dedicated
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
104
|
+
new_pod = if pod_name.nil?
|
105
|
+
create_dedicated_pod(target_pod)
|
106
|
+
else
|
107
|
+
create_dedicated_pod(target_pod, pod_name)
|
108
|
+
end
|
109
|
+
|
110
|
+
connect_to_pod(new_pod, command)
|
111
|
+
clean_up_pod(new_pod)
|
112
|
+
else
|
113
|
+
# If we don't need a dedicated pod, it's way easier - just connect to the already running one
|
114
|
+
connect_to_pod(target_pod.dig('metadata', 'name'), command)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Create a dedicated temp pod to run in
|
119
|
+
# This is useful if you would like to have a persistent connection that doesn't get killed
|
120
|
+
# when someone updates the terminal deployment, or if you want to avoid noisy neighbors
|
121
|
+
# connected to the same pod.
|
122
|
+
def create_dedicated_pod(target_pod, pod_name = "temp-#{Random.unique_name}")
|
123
|
+
spec = target_pod['spec']
|
124
|
+
temp_pod = {
|
125
|
+
apiVersion: target_pod['apiVersion'],
|
126
|
+
kind: 'Pod',
|
127
|
+
spec: spec,
|
128
|
+
metadata: {
|
129
|
+
name: pod_name,
|
130
|
+
annotations: {
|
131
|
+
owner: Helpers.shell_username
|
112
132
|
}
|
113
133
|
}
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
134
|
+
}
|
135
|
+
# Don't restart the pod when it dies
|
136
|
+
spec['restartPolicy'] = 'Never'
|
137
|
+
# Overwrite container commands with something that times out, so if the client disconnects
|
138
|
+
# there's a limited amount of time that the temp pod is still taking up resources
|
139
|
+
# Note that this will break a pods which depends on containers running real commands, but
|
140
|
+
# for a simple terminal pod it's fine
|
141
|
+
spec['containers'].each do |container|
|
142
|
+
container['command'] = %w[sleep 86400] # 86400 seconds = 24 hours
|
143
|
+
end
|
123
144
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
145
|
+
puts 'Creating dedicated pod...'
|
146
|
+
unless system("kubectl --namespace=#{app} create -f - <<JSON\n#{temp_pod.to_json}\nJSON")
|
147
|
+
puts 'Failed to create dedicated pod'
|
148
|
+
exit(1)
|
149
|
+
end
|
129
150
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
151
|
+
print 'Waiting for dedicated pod to start...'
|
152
|
+
loop do
|
153
|
+
pod = JSON.parse(kubectl("get pods/#{pod_name} -o json", context: context, return_output: true))
|
154
|
+
break if pod['status']['phase'] == 'Running'
|
155
|
+
print '.'
|
156
|
+
sleep 1
|
157
|
+
end
|
158
|
+
print "\n"
|
138
159
|
|
139
|
-
|
160
|
+
pod_name
|
161
|
+
end
|
140
162
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
else
|
146
|
-
# If we don't need a dedicated pod, it's way easier - just connect to the already running one
|
147
|
-
connect_to_pod(target_pod.dig('metadata', 'name'), command)
|
163
|
+
# Clean up pod so it isn't taking up resources. Usually only for dedicated pods
|
164
|
+
def clean_up_pod(pod_name)
|
165
|
+
unless kubectl("delete pods/#{pod_name}", context: context)
|
166
|
+
puts 'Failed to delete temp pod'
|
148
167
|
end
|
149
168
|
end
|
150
169
|
|
data/lib/seira/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seira
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Ringwelski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
requirements: []
|
160
160
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.6
|
161
|
+
rubygems_version: 2.7.6
|
162
162
|
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: An opinionated library for building applications on Kubernetes.
|