kubeclient 2.5.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kubeclient might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -5
- data/.travis.yml +2 -10
- data/CHANGELOG.md +21 -2
- data/README.md +112 -46
- data/Rakefile +2 -5
- data/kubeclient.gemspec +9 -7
- data/lib/kubeclient.rb +8 -8
- data/lib/kubeclient/common.rb +88 -105
- data/lib/kubeclient/config.rb +10 -10
- data/lib/kubeclient/http_error.rb +25 -0
- data/lib/kubeclient/missing_kind_compatibility.rb +1 -1
- data/lib/kubeclient/resource.rb +11 -0
- data/lib/kubeclient/resource_not_found_error.rb +4 -0
- data/lib/kubeclient/version.rb +1 -1
- data/lib/kubeclient/watch_stream.rb +17 -10
- data/test/test_common.rb +3 -3
- data/test/test_component_status.rb +16 -14
- data/test/test_config.rb +11 -11
- data/test/test_endpoint.rb +16 -12
- data/test/test_guestbook_go.rb +64 -62
- data/test/test_helper.rb +2 -0
- data/test/test_kubeclient.rb +268 -282
- data/test/test_limit_range.rb +11 -11
- data/test/test_missing_methods.rb +3 -3
- data/test/test_namespace.rb +27 -27
- data/test/test_node.rb +17 -15
- data/test/test_persistent_volume.rb +16 -14
- data/test/test_persistent_volume_claim.rb +16 -14
- data/test/test_pod.rb +16 -14
- data/test/test_pod_log.rb +4 -4
- data/test/test_process_template.rb +7 -7
- data/test/test_replication_controller.rb +29 -4
- data/test/test_resource_list_without_kind.rb +7 -7
- data/test/test_resource_quota.rb +4 -4
- data/test/test_secret.rb +11 -10
- data/test/test_service.rb +36 -31
- data/test/test_service_account.rb +4 -4
- data/test/test_watch.rb +52 -29
- data/test/test_watch_notice.rb +1 -1
- metadata +35 -26
- data/Gemfile-rest-client-1.8.rb +0 -11
- data/lib/kubeclient/kube_exception.rb +0 -14
data/lib/kubeclient/config.rb
CHANGED
@@ -20,7 +20,7 @@ module Kubeclient
|
|
20
20
|
def initialize(kcfg, kcfg_path)
|
21
21
|
@kcfg = kcfg
|
22
22
|
@kcfg_path = kcfg_path
|
23
|
-
|
23
|
+
raise 'Unknown kubeconfig version' if @kcfg['apiVersion'] != 'v1'
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.read(filename)
|
@@ -72,13 +72,13 @@ module Kubeclient
|
|
72
72
|
break x['context'] if x['name'] == context_name
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
raise KeyError, "Unknown context #{context_name}" unless context
|
76
76
|
|
77
77
|
cluster = @kcfg['clusters'].detect do |x|
|
78
78
|
break x['cluster'] if x['name'] == context['cluster']
|
79
79
|
end
|
80
80
|
|
81
|
-
|
81
|
+
raise KeyError, "Unknown cluster #{context['cluster']}" unless cluster
|
82
82
|
|
83
83
|
user = @kcfg['users'].detect do |x|
|
84
84
|
break x['user'] if x['name'] == context['user']
|
@@ -89,25 +89,25 @@ module Kubeclient
|
|
89
89
|
|
90
90
|
def fetch_cluster_ca_data(cluster)
|
91
91
|
if cluster.key?('certificate-authority')
|
92
|
-
|
92
|
+
File.read(ext_file_path(cluster['certificate-authority']))
|
93
93
|
elsif cluster.key?('certificate-authority-data')
|
94
|
-
|
94
|
+
Base64.decode64(cluster['certificate-authority-data'])
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
def fetch_user_cert_data(user)
|
99
99
|
if user.key?('client-certificate')
|
100
|
-
|
100
|
+
File.read(ext_file_path(user['client-certificate']))
|
101
101
|
elsif user.key?('client-certificate-data')
|
102
|
-
|
102
|
+
Base64.decode64(user['client-certificate-data'])
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
106
|
def fetch_user_key_data(user)
|
107
107
|
if user.key?('client-key')
|
108
|
-
|
108
|
+
File.read(ext_file_path(user['client-key']))
|
109
109
|
elsif user.key?('client-key-data')
|
110
|
-
|
110
|
+
Base64.decode64(user['client-key-data'])
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -116,7 +116,7 @@ module Kubeclient
|
|
116
116
|
if user.key?('token')
|
117
117
|
options[:bearer_token] = user['token']
|
118
118
|
else
|
119
|
-
%w
|
119
|
+
%w[username password].each do |attr|
|
120
120
|
options[attr.to_sym] = user[attr] if user.key?(attr)
|
121
121
|
end
|
122
122
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# TODO: remove this on next major version bump
|
2
|
+
# Deprected http exception
|
3
|
+
class KubeException < StandardError
|
4
|
+
attr_reader :error_code, :message, :response
|
5
|
+
|
6
|
+
def initialize(error_code, message, response)
|
7
|
+
@error_code = error_code
|
8
|
+
@message = message
|
9
|
+
@response = response
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
string = "HTTP status code #{@error_code}, #{@message}"
|
14
|
+
if @response.is_a?(RestClient::Response) && @response.request
|
15
|
+
string << " for #{@response.request.method.upcase} #{@response.request.url}"
|
16
|
+
end
|
17
|
+
string
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Kubeclient
|
22
|
+
# Exception that is raised when a http request fails
|
23
|
+
class HttpError < KubeException
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'recursive_open_struct'
|
2
|
+
|
3
|
+
module Kubeclient
|
4
|
+
# Represents all the objects returned by Kubeclient
|
5
|
+
class Resource < RecursiveOpenStruct
|
6
|
+
def initialize(hash = nil, args = {})
|
7
|
+
args[:recurse_over_arrays] = true
|
8
|
+
super(hash, args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/kubeclient/version.rb
CHANGED
@@ -4,11 +4,11 @@ module Kubeclient
|
|
4
4
|
module Common
|
5
5
|
# HTTP Stream used to watch changes on entities
|
6
6
|
class WatchStream
|
7
|
-
def initialize(uri, http_options,
|
7
|
+
def initialize(uri, http_options, as:)
|
8
8
|
@uri = uri
|
9
9
|
@http_client = nil
|
10
10
|
@http_options = http_options
|
11
|
-
@
|
11
|
+
@as = as
|
12
12
|
end
|
13
13
|
|
14
14
|
def each
|
@@ -17,14 +17,20 @@ module Kubeclient
|
|
17
17
|
@http_client = build_client
|
18
18
|
response = @http_client.request(:get, @uri, build_client_options)
|
19
19
|
unless response.code < 300
|
20
|
-
|
20
|
+
raise Kubeclient::HttpError.new(response.code, response.reason, response)
|
21
21
|
end
|
22
22
|
|
23
23
|
buffer = ''
|
24
24
|
response.body.each do |chunk|
|
25
25
|
buffer << chunk
|
26
26
|
while (line = buffer.slice!(/.+\n/))
|
27
|
-
|
27
|
+
result =
|
28
|
+
case @as
|
29
|
+
when :ros then WatchNotice.new(JSON.parse(line))
|
30
|
+
when :raw then line.chomp
|
31
|
+
else raise NotImplementedError, "Unsupported as #{@as.inspect}"
|
32
|
+
end
|
33
|
+
yield(result)
|
28
34
|
end
|
29
35
|
end
|
30
36
|
rescue IOError, Errno::EBADF
|
@@ -40,8 +46,10 @@ module Kubeclient
|
|
40
46
|
|
41
47
|
def build_client
|
42
48
|
if @http_options[:basic_auth_user] && @http_options[:basic_auth_password]
|
43
|
-
HTTP.basic_auth(
|
44
|
-
|
49
|
+
HTTP.basic_auth(
|
50
|
+
user: @http_options[:basic_auth_user],
|
51
|
+
pass: @http_options[:basic_auth_password]
|
52
|
+
)
|
45
53
|
else
|
46
54
|
HTTP::Client.new
|
47
55
|
end
|
@@ -66,12 +74,11 @@ module Kubeclient
|
|
66
74
|
}
|
67
75
|
if @http_options[:ssl]
|
68
76
|
client_options[:ssl] = @http_options[:ssl]
|
69
|
-
|
70
|
-
@http_options[:ssl_socket_class] if @http_options[:ssl_socket_class]
|
77
|
+
socket_option = :ssl_socket_class
|
71
78
|
else
|
72
|
-
|
73
|
-
@http_options[:socket_class] if @http_options[:socket_class]
|
79
|
+
socket_option = :socket_class
|
74
80
|
end
|
81
|
+
client_options[socket_option] = @http_options[socket_option] if @http_options[socket_option]
|
75
82
|
client_options
|
76
83
|
end
|
77
84
|
end
|
data/test/test_common.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
3
|
# Unit tests for the common module
|
4
4
|
class CommonTest < MiniTest::Test
|
5
5
|
def test_underscore_entity
|
6
|
-
%w
|
6
|
+
%w[
|
7
7
|
Pod pod
|
8
8
|
Service service
|
9
9
|
ReplicationController replication_controller
|
@@ -25,7 +25,7 @@ class CommonTest < MiniTest::Test
|
|
25
25
|
BuildConfig build_config
|
26
26
|
Image image
|
27
27
|
ImageStream image_stream
|
28
|
-
|
28
|
+
].each_slice(2) do |singular, plural|
|
29
29
|
assert_equal(Kubeclient::ClientMixin.underscore_entity(singular), plural)
|
30
30
|
end
|
31
31
|
end
|
@@ -1,28 +1,30 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
3
|
# ComponentStatus tests
|
4
4
|
class TestComponentStatus < MiniTest::Test
|
5
5
|
def test_get_from_json_v3
|
6
6
|
stub_request(:get, %r{/componentstatuses})
|
7
|
-
.to_return(body: open_test_file('component_status.json'),
|
8
|
-
status: 200)
|
7
|
+
.to_return(body: open_test_file('component_status.json'), status: 200)
|
9
8
|
stub_request(:get, %r{/api/v1$})
|
10
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
11
|
-
status: 200)
|
9
|
+
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
12
10
|
|
13
|
-
client = Kubeclient::Client.new
|
14
|
-
component_status = client.get_component_status
|
11
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
12
|
+
component_status = client.get_component_status('etcd-0', 'default')
|
15
13
|
|
16
|
-
assert_instance_of(Kubeclient::
|
14
|
+
assert_instance_of(Kubeclient::Resource, component_status)
|
17
15
|
assert_equal('etcd-0', component_status.metadata.name)
|
18
16
|
assert_equal('Healthy', component_status.conditions[0].type)
|
19
17
|
assert_equal('True', component_status.conditions[0].status)
|
20
18
|
|
21
|
-
assert_requested(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
assert_requested(
|
20
|
+
:get,
|
21
|
+
'http://localhost:8080/api/v1',
|
22
|
+
times: 1
|
23
|
+
)
|
24
|
+
assert_requested(
|
25
|
+
:get,
|
26
|
+
'http://localhost:8080/api/v1/namespaces/default/componentstatuses/etcd-0',
|
27
|
+
times: 1
|
28
|
+
)
|
27
29
|
end
|
28
30
|
end
|
data/test/test_config.rb
CHANGED
@@ -1,31 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
def test_config_file(name)
|
4
|
-
File.new(File.join(File.dirname(__FILE__), 'config', name))
|
5
|
-
end
|
1
|
+
require_relative 'test_helper'
|
6
2
|
|
7
3
|
# Testing Kubernetes client configuration
|
8
|
-
class
|
4
|
+
class KubeclientConfigTest < MiniTest::Test
|
9
5
|
def test_allinone
|
10
|
-
config = Kubeclient::Config.read(
|
6
|
+
config = Kubeclient::Config.read(config_file('allinone.kubeconfig'))
|
11
7
|
assert_equal(['default/localhost:8443/system:admin'], config.contexts)
|
12
8
|
check_context(config.context, ssl: true)
|
13
9
|
end
|
14
10
|
|
15
11
|
def test_external
|
16
|
-
config = Kubeclient::Config.read(
|
12
|
+
config = Kubeclient::Config.read(config_file('external.kubeconfig'))
|
17
13
|
assert_equal(['default/localhost:8443/system:admin'], config.contexts)
|
18
14
|
check_context(config.context, ssl: true)
|
19
15
|
end
|
20
16
|
|
21
17
|
def test_nouser
|
22
|
-
config = Kubeclient::Config.read(
|
18
|
+
config = Kubeclient::Config.read(config_file('nouser.kubeconfig'))
|
23
19
|
assert_equal(['default/localhost:8443/nouser'], config.contexts)
|
24
20
|
check_context(config.context, ssl: false)
|
25
21
|
end
|
26
22
|
|
27
23
|
def test_user_token
|
28
|
-
config = Kubeclient::Config.read(
|
24
|
+
config = Kubeclient::Config.read(config_file('userauth.kubeconfig'))
|
29
25
|
assert_equal(['localhost/system:admin:token', 'localhost/system:admin:userpass'],
|
30
26
|
config.contexts)
|
31
27
|
context = config.context('localhost/system:admin:token')
|
@@ -34,7 +30,7 @@ class KubeClientConfigTest < MiniTest::Test
|
|
34
30
|
end
|
35
31
|
|
36
32
|
def test_user_password
|
37
|
-
config = Kubeclient::Config.read(
|
33
|
+
config = Kubeclient::Config.read(config_file('userauth.kubeconfig'))
|
38
34
|
assert_equal(['localhost/system:admin:token', 'localhost/system:admin:userpass'],
|
39
35
|
config.contexts)
|
40
36
|
context = config.context('localhost/system:admin:userpass')
|
@@ -69,4 +65,8 @@ class KubeClientConfigTest < MiniTest::Test
|
|
69
65
|
assert_equal(OpenSSL::SSL::VERIFY_NONE, context.ssl_options[:verify_ssl])
|
70
66
|
end
|
71
67
|
end
|
68
|
+
|
69
|
+
def config_file(name)
|
70
|
+
File.new(File.join(File.dirname(__FILE__), 'config', name))
|
71
|
+
end
|
72
72
|
end
|
data/test/test_endpoint.rb
CHANGED
@@ -1,31 +1,35 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
3
|
# Endpoint entity tests
|
4
4
|
class TestEndpoint < MiniTest::Test
|
5
5
|
def test_create_endpoint
|
6
6
|
stub_request(:get, %r{/api/v1$})
|
7
|
-
.to_return(
|
8
|
-
|
7
|
+
.to_return(
|
8
|
+
body: open_test_file('core_api_resource_list.json'),
|
9
|
+
status: 200
|
10
|
+
)
|
9
11
|
|
10
|
-
client = Kubeclient::Client.new
|
12
|
+
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
11
13
|
testing_ep = Kubeclient::Resource.new
|
12
14
|
testing_ep.metadata = {}
|
13
15
|
testing_ep.metadata.name = 'myendpoint'
|
14
16
|
testing_ep.metadata.namespace = 'default'
|
15
|
-
testing_ep.subsets = [
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
testing_ep.subsets = [
|
18
|
+
{
|
19
|
+
'addresses' => [{ 'ip' => '172.17.0.25' }],
|
20
|
+
'ports' => [{ 'name' => 'https', 'port' => 6443, 'protocol' => 'TCP' }]
|
21
|
+
}
|
22
|
+
]
|
19
23
|
|
20
|
-
req_body =
|
21
|
-
|
22
|
-
|
24
|
+
req_body = '{"metadata":{"name":"myendpoint","namespace":"default"},' \
|
25
|
+
'"subsets":[{"addresses":[{"ip":"172.17.0.25"}],"ports":[{"name":"https",' \
|
26
|
+
'"port":6443,"protocol":"TCP"}]}],"kind":"Endpoints","apiVersion":"v1"}'
|
23
27
|
|
24
28
|
stub_request(:post, 'http://localhost:8080/api/v1/namespaces/default/endpoints')
|
25
29
|
.with(body: req_body)
|
26
30
|
.to_return(body: open_test_file('created_endpoint.json'), status: 201)
|
27
31
|
|
28
|
-
created_ep = client.create_endpoint
|
32
|
+
created_ep = client.create_endpoint(testing_ep)
|
29
33
|
assert_equal('Endpoints', created_ep.kind)
|
30
34
|
end
|
31
35
|
end
|
data/test/test_guestbook_go.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
require 'vcr'
|
3
3
|
|
4
4
|
# creation of google's example of guest book
|
@@ -6,12 +6,12 @@ class CreateGuestbookGo < MiniTest::Test
|
|
6
6
|
def test_create_guestbook_entities
|
7
7
|
VCR.configure do |c|
|
8
8
|
c.cassette_library_dir = 'test/cassettes'
|
9
|
-
c.hook_into
|
9
|
+
c.hook_into(:webmock)
|
10
10
|
end
|
11
11
|
|
12
12
|
# WebMock.allow_net_connect!
|
13
13
|
VCR.use_cassette('kubernetes_guestbook') do # , record: :new_episodes) do
|
14
|
-
client = Kubeclient::Client.new
|
14
|
+
client = Kubeclient::Client.new('http://10.35.0.23:8080/api/', 'v1')
|
15
15
|
|
16
16
|
testing_ns = Kubeclient::Resource.new
|
17
17
|
testing_ns.metadata = {}
|
@@ -19,12 +19,16 @@ class CreateGuestbookGo < MiniTest::Test
|
|
19
19
|
|
20
20
|
# delete in case they existed before so creation can be tested
|
21
21
|
delete_namespace(client, testing_ns.metadata.name)
|
22
|
-
delete_services(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
delete_services(
|
23
|
+
client, testing_ns.metadata.name,
|
24
|
+
['guestbook', 'redis-master', 'redis-slave']
|
25
|
+
)
|
26
|
+
delete_replication_controllers(
|
27
|
+
client, testing_ns.metadata.name,
|
28
|
+
['guestbook', 'redis-master', 'redis-slave']
|
29
|
+
)
|
30
|
+
|
31
|
+
client.create_namespace(testing_ns)
|
28
32
|
services = create_services(client, testing_ns.metadata.name)
|
29
33
|
replicators = create_replication_controllers(client, testing_ns.metadata.name)
|
30
34
|
|
@@ -35,15 +39,14 @@ class CreateGuestbookGo < MiniTest::Test
|
|
35
39
|
delete_services(client, testing_ns.metadata.name, services)
|
36
40
|
delete_replication_controllers(client, testing_ns.metadata.name, replicators)
|
37
41
|
|
38
|
-
client.delete_namespace
|
42
|
+
client.delete_namespace(testing_ns.metadata.name)
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
42
46
|
def delete_namespace(client, namespace_name)
|
43
|
-
client.delete_namespace
|
44
|
-
|
45
|
-
|
46
|
-
assert_equal(404, exception.error_code)
|
47
|
+
client.delete_namespace(namespace_name)
|
48
|
+
rescue Kubeclient::ResourceNotFoundError => exception
|
49
|
+
assert_equal(404, exception.error_code)
|
47
50
|
end
|
48
51
|
|
49
52
|
def get_namespaces(client)
|
@@ -62,16 +65,16 @@ class CreateGuestbookGo < MiniTest::Test
|
|
62
65
|
end
|
63
66
|
|
64
67
|
def create_services(client, ns)
|
65
|
-
guestbook_service = client.create_service
|
66
|
-
redis_service = client.create_service
|
67
|
-
redis_slave_service = client.create_service
|
68
|
+
guestbook_service = client.create_service(guestbook_service(ns))
|
69
|
+
redis_service = client.create_service(redis_service(ns))
|
70
|
+
redis_slave_service = client.create_service(redis_slave_service(ns))
|
68
71
|
[guestbook_service, redis_service, redis_slave_service]
|
69
72
|
end
|
70
73
|
|
71
74
|
def create_replication_controllers(client, namespace)
|
72
|
-
rc = client.create_replication_controller
|
73
|
-
rc2 = client.create_replication_controller
|
74
|
-
rc3 = client.create_replication_controller
|
75
|
+
rc = client.create_replication_controller(guestbook_rc(namespace))
|
76
|
+
rc2 = client.create_replication_controller(redis_master_rc(namespace))
|
77
|
+
rc3 = client.create_replication_controller(redis_slave_rc(namespace))
|
75
78
|
[rc, rc2, rc3]
|
76
79
|
end
|
77
80
|
|
@@ -79,14 +82,13 @@ class CreateGuestbookGo < MiniTest::Test
|
|
79
82
|
# if the entity is not found, no need to fail the test
|
80
83
|
services.each do |service|
|
81
84
|
begin
|
82
|
-
if service.instance_of?(Kubeclient::
|
83
|
-
client.delete_service
|
85
|
+
if service.instance_of?(Kubeclient::Resource)
|
86
|
+
client.delete_service(service.metadata.name, namespace)
|
84
87
|
else
|
85
88
|
# it's just a string - service name
|
86
|
-
client.delete_service
|
89
|
+
client.delete_service(service, namespace)
|
87
90
|
end
|
88
|
-
rescue
|
89
|
-
assert_instance_of(KubeException, exception)
|
91
|
+
rescue Kubeclient::ResourceNotFoundError => exception
|
90
92
|
assert_equal(404, exception.error_code)
|
91
93
|
end
|
92
94
|
end
|
@@ -96,14 +98,13 @@ class CreateGuestbookGo < MiniTest::Test
|
|
96
98
|
# if the entity is not found, no need to fail the test
|
97
99
|
replication_controllers.each do |rc|
|
98
100
|
begin
|
99
|
-
if rc.instance_of?(Kubeclient::
|
100
|
-
client.delete_replication_controller
|
101
|
+
if rc.instance_of?(Kubeclient::Resource)
|
102
|
+
client.delete_replication_controller(rc.metadata.name, namespace)
|
101
103
|
else
|
102
104
|
# it's just a string - rc name
|
103
|
-
client.delete_replication_controller
|
105
|
+
client.delete_replication_controller(rc, namespace)
|
104
106
|
end
|
105
|
-
rescue
|
106
|
-
assert_instance_of(KubeException, exception)
|
107
|
+
rescue Kubeclient::ResourceNotFoundError => exception
|
107
108
|
assert_equal(404, exception.error_code)
|
108
109
|
end
|
109
110
|
end
|
@@ -112,7 +113,7 @@ class CreateGuestbookGo < MiniTest::Test
|
|
112
113
|
private
|
113
114
|
|
114
115
|
def construct_base_rc(namespace)
|
115
|
-
rc = Kubeclient::
|
116
|
+
rc = Kubeclient::Resource.new
|
116
117
|
rc.metadata = {}
|
117
118
|
rc.metadata.namespace = namespace
|
118
119
|
rc.metadata.labels = {}
|
@@ -135,10 +136,14 @@ class CreateGuestbookGo < MiniTest::Test
|
|
135
136
|
rc.spec.selector.role = 'master'
|
136
137
|
rc.spec.template.metadata.labels.app = 'redis'
|
137
138
|
rc.spec.template.metadata.labels.role = 'master'
|
138
|
-
rc.spec.template.spec.containers = [{
|
139
|
-
|
140
|
-
|
141
|
-
|
139
|
+
rc.spec.template.spec.containers = [{
|
140
|
+
'name' => 'redis-master',
|
141
|
+
'image' => 'redis',
|
142
|
+
'ports' => [{
|
143
|
+
'name' => 'redis-server',
|
144
|
+
'containerPort' => 6379
|
145
|
+
}]
|
146
|
+
}]
|
142
147
|
rc
|
143
148
|
end
|
144
149
|
|
@@ -152,11 +157,14 @@ class CreateGuestbookGo < MiniTest::Test
|
|
152
157
|
rc.spec.selector.role = 'slave'
|
153
158
|
rc.spec.template.metadata.labels.app = 'redis'
|
154
159
|
rc.spec.template.metadata.labels.role = 'slave'
|
155
|
-
rc.spec.template.spec.containers = [{
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
+
rc.spec.template.spec.containers = [{
|
161
|
+
'name' => 'redis-slave',
|
162
|
+
'image' => 'kubernetes/redis-slave:v2',
|
163
|
+
'ports' => [{
|
164
|
+
'name' => 'redis-server',
|
165
|
+
'containerPort' => 6379
|
166
|
+
}]
|
167
|
+
}]
|
160
168
|
rc
|
161
169
|
end
|
162
170
|
|
@@ -168,17 +176,23 @@ class CreateGuestbookGo < MiniTest::Test
|
|
168
176
|
rc.spec.replicas = 3
|
169
177
|
rc.spec.selector.app = 'guestbook'
|
170
178
|
rc.spec.template.metadata.labels.app = 'guestbook'
|
171
|
-
rc.spec.template.spec.containers = [
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
179
|
+
rc.spec.template.spec.containers = [
|
180
|
+
{
|
181
|
+
'name' => 'guestbook',
|
182
|
+
'image' => 'kubernetes/guestbook:v2',
|
183
|
+
'ports' => [
|
184
|
+
{
|
185
|
+
'name' => 'http-server',
|
186
|
+
'containerPort' => 3000
|
187
|
+
}
|
188
|
+
]
|
189
|
+
}
|
190
|
+
]
|
177
191
|
rc
|
178
192
|
end
|
179
193
|
|
180
194
|
def base_service(namespace)
|
181
|
-
our_service = Kubeclient::
|
195
|
+
our_service = Kubeclient::Resource.new
|
182
196
|
our_service.metadata = {}
|
183
197
|
our_service.metadata.namespace = namespace
|
184
198
|
our_service.metadata.labels = {}
|
@@ -192,11 +206,7 @@ class CreateGuestbookGo < MiniTest::Test
|
|
192
206
|
our_service.metadata.name = 'redis-slave'
|
193
207
|
our_service.metadata.labels.app = 'redis'
|
194
208
|
our_service.metadata.labels.role = 'slave'
|
195
|
-
|
196
|
-
our_service.spec.ports = [{ 'port' => 6379,
|
197
|
-
'targetPort' => 'redis-server'
|
198
|
-
}]
|
199
|
-
|
209
|
+
our_service.spec.ports = [{ 'port' => 6379, 'targetPort' => 'redis-server' }]
|
200
210
|
our_service.spec.selector.app = 'redis'
|
201
211
|
our_service.spec.selector.role = 'slave'
|
202
212
|
our_service
|
@@ -207,11 +217,7 @@ class CreateGuestbookGo < MiniTest::Test
|
|
207
217
|
our_service.metadata.name = 'redis-master'
|
208
218
|
our_service.metadata.labels.app = 'redis'
|
209
219
|
our_service.metadata.labels.role = 'master'
|
210
|
-
|
211
|
-
our_service.spec.ports = [{ 'port' => 6379,
|
212
|
-
'targetPort' => 'redis-server'
|
213
|
-
}]
|
214
|
-
|
220
|
+
our_service.spec.ports = [{ 'port' => 6379, 'targetPort' => 'redis-server' }]
|
215
221
|
our_service.spec.selector.app = 'redis'
|
216
222
|
our_service.spec.selector.role = 'master'
|
217
223
|
our_service
|
@@ -221,11 +227,7 @@ class CreateGuestbookGo < MiniTest::Test
|
|
221
227
|
our_service = base_service(namespace)
|
222
228
|
our_service.metadata.name = 'guestbook'
|
223
229
|
our_service.metadata.labels.name = 'guestbook'
|
224
|
-
|
225
|
-
our_service.spec.ports = [{ 'port' => 3000,
|
226
|
-
'targetPort' => 'http-server'
|
227
|
-
}]
|
228
|
-
|
230
|
+
our_service.spec.ports = [{ 'port' => 3000, 'targetPort' => 'http-server' }]
|
229
231
|
our_service.spec.selector.app = 'guestbook'
|
230
232
|
our_service.type = 'LoadBalancer'
|
231
233
|
our_service
|