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.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +13 -5
  3. data/.travis.yml +2 -10
  4. data/CHANGELOG.md +21 -2
  5. data/README.md +112 -46
  6. data/Rakefile +2 -5
  7. data/kubeclient.gemspec +9 -7
  8. data/lib/kubeclient.rb +8 -8
  9. data/lib/kubeclient/common.rb +88 -105
  10. data/lib/kubeclient/config.rb +10 -10
  11. data/lib/kubeclient/http_error.rb +25 -0
  12. data/lib/kubeclient/missing_kind_compatibility.rb +1 -1
  13. data/lib/kubeclient/resource.rb +11 -0
  14. data/lib/kubeclient/resource_not_found_error.rb +4 -0
  15. data/lib/kubeclient/version.rb +1 -1
  16. data/lib/kubeclient/watch_stream.rb +17 -10
  17. data/test/test_common.rb +3 -3
  18. data/test/test_component_status.rb +16 -14
  19. data/test/test_config.rb +11 -11
  20. data/test/test_endpoint.rb +16 -12
  21. data/test/test_guestbook_go.rb +64 -62
  22. data/test/test_helper.rb +2 -0
  23. data/test/test_kubeclient.rb +268 -282
  24. data/test/test_limit_range.rb +11 -11
  25. data/test/test_missing_methods.rb +3 -3
  26. data/test/test_namespace.rb +27 -27
  27. data/test/test_node.rb +17 -15
  28. data/test/test_persistent_volume.rb +16 -14
  29. data/test/test_persistent_volume_claim.rb +16 -14
  30. data/test/test_pod.rb +16 -14
  31. data/test/test_pod_log.rb +4 -4
  32. data/test/test_process_template.rb +7 -7
  33. data/test/test_replication_controller.rb +29 -4
  34. data/test/test_resource_list_without_kind.rb +7 -7
  35. data/test/test_resource_quota.rb +4 -4
  36. data/test/test_secret.rb +11 -10
  37. data/test/test_service.rb +36 -31
  38. data/test/test_service_account.rb +4 -4
  39. data/test/test_watch.rb +52 -29
  40. data/test/test_watch_notice.rb +1 -1
  41. metadata +35 -26
  42. data/Gemfile-rest-client-1.8.rb +0 -11
  43. data/lib/kubeclient/kube_exception.rb +0 -14
@@ -20,7 +20,7 @@ module Kubeclient
20
20
  def initialize(kcfg, kcfg_path)
21
21
  @kcfg = kcfg
22
22
  @kcfg_path = kcfg_path
23
- fail 'Unknown kubeconfig version' if @kcfg['apiVersion'] != 'v1'
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
- fail "Unknown context #{context_name}" unless context
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
- fail "Unknown cluster #{context['cluster']}" unless cluster
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
- return File.read(ext_file_path(cluster['certificate-authority']))
92
+ File.read(ext_file_path(cluster['certificate-authority']))
93
93
  elsif cluster.key?('certificate-authority-data')
94
- return Base64.decode64(cluster['certificate-authority-data'])
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
- return File.read(ext_file_path(user['client-certificate']))
100
+ File.read(ext_file_path(user['client-certificate']))
101
101
  elsif user.key?('client-certificate-data')
102
- return Base64.decode64(user['client-certificate-data'])
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
- return File.read(ext_file_path(user['client-key']))
108
+ File.read(ext_file_path(user['client-key']))
109
109
  elsif user.key?('client-key-data')
110
- return Base64.decode64(user['client-key-data'])
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(username password).each do |attr|
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
@@ -58,7 +58,7 @@ module Kubeclient
58
58
  'templates' => 'Template',
59
59
  'useridentitymappings' => 'UserIdentityMapping',
60
60
  'users' => 'User'
61
- }
61
+ }.freeze
62
62
 
63
63
  def self.resource_kind(name)
64
64
  MAPPING[name]
@@ -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
@@ -0,0 +1,4 @@
1
+ module Kubeclient
2
+ class ResourceNotFoundError < HttpError
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
1
  # Kubernetes REST-API Client
2
2
  module Kubeclient
3
- VERSION = '2.5.2'
3
+ VERSION = '3.0.0'.freeze
4
4
  end
@@ -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, format: :json)
7
+ def initialize(uri, http_options, as:)
8
8
  @uri = uri
9
9
  @http_client = nil
10
10
  @http_options = http_options
11
- @format = format
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
- fail KubeException.new(response.code, response.reason, response)
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
- yield @format == :json ? WatchNotice.new(JSON.parse(line)) : line.chomp
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(user: @http_options[:basic_auth_user],
44
- pass: @http_options[:basic_auth_password])
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
- client_options[:ssl_socket_class] =
70
- @http_options[:ssl_socket_class] if @http_options[:ssl_socket_class]
77
+ socket_option = :ssl_socket_class
71
78
  else
72
- client_options[:socket_class] =
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
@@ -1,9 +1,9 @@
1
- require 'test_helper'
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
- ).each_slice(2) do |singular, plural|
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
- require 'test_helper'
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 'http://localhost:8080/api/', 'v1'
14
- component_status = client.get_component_status 'etcd-0', 'default'
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::ComponentStatus, component_status)
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(:get,
22
- 'http://localhost:8080/api/v1',
23
- times: 1)
24
- assert_requested(:get,
25
- 'http://localhost:8080/api/v1/namespaces/default/componentstatuses/etcd-0',
26
- times: 1)
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
@@ -1,31 +1,27 @@
1
- require 'test_helper'
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 KubeClientConfigTest < MiniTest::Test
4
+ class KubeclientConfigTest < MiniTest::Test
9
5
  def test_allinone
10
- config = Kubeclient::Config.read(test_config_file('allinone.kubeconfig'))
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(test_config_file('external.kubeconfig'))
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(test_config_file('nouser.kubeconfig'))
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(test_config_file('userauth.kubeconfig'))
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(test_config_file('userauth.kubeconfig'))
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
@@ -1,31 +1,35 @@
1
- require 'test_helper'
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(body: open_test_file('core_api_resource_list.json'),
8
- status: 200)
7
+ .to_return(
8
+ body: open_test_file('core_api_resource_list.json'),
9
+ status: 200
10
+ )
9
11
 
10
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
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 = [{ 'addresses' => [{ 'ip' => '172.17.0.25' }], 'ports' =>
16
- [{ 'name' => 'https',
17
- 'port' => 6443,
18
- 'protocol' => 'TCP' }] }]
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 = "{\"metadata\":{\"name\":\"myendpoint\",\"namespace\":\"default\"}," \
21
- "\"subsets\":[{\"addresses\":[{\"ip\":\"172.17.0.25\"}],\"ports\":[{\"name\":\"https\"," \
22
- "\"port\":6443,\"protocol\":\"TCP\"}]}],\"kind\":\"Endpoints\",\"apiVersion\":\"v1\"}"
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 testing_ep
32
+ created_ep = client.create_endpoint(testing_ep)
29
33
  assert_equal('Endpoints', created_ep.kind)
30
34
  end
31
35
  end
@@ -1,4 +1,4 @@
1
- require 'test_helper'
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 :webmock
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 'http://10.35.0.23:8080/api/', 'v1'
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(client, testing_ns.metadata.name,
23
- ['guestbook', 'redis-master', 'redis-slave'])
24
- delete_replication_controllers(client, testing_ns.metadata.name,
25
- ['guestbook', 'redis-master', 'redis-slave'])
26
-
27
- client.create_namespace testing_ns
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 testing_ns.metadata.name
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 namespace_name
44
- rescue KubeException => exception
45
- assert_instance_of(KubeException, exception)
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 guestbook_service(ns)
66
- redis_service = client.create_service redis_service(ns)
67
- redis_slave_service = client.create_service redis_slave_service(ns)
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 guestbook_rc(namespace)
73
- rc2 = client.create_replication_controller redis_master_rc(namespace)
74
- rc3 = client.create_replication_controller redis_slave_rc(namespace)
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::Service)
83
- client.delete_service service.metadata.name, namespace
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 service, namespace
89
+ client.delete_service(service, namespace)
87
90
  end
88
- rescue KubeException => exception
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::ReplicationController)
100
- client.delete_replication_controller rc.metadata.name, namespace
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 rc, namespace
105
+ client.delete_replication_controller(rc, namespace)
104
106
  end
105
- rescue KubeException => exception
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::ReplicationController.new
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 = [{ 'name' => 'redis-master',
139
- 'image' => 'redis',
140
- 'ports' => [{ 'name' => 'redis-server',
141
- 'containerPort' => 6379 }] }]
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 = [{ 'name' => 'redis-slave',
156
- 'image' => 'kubernetes/redis-slave:v2',
157
- 'ports' => [{ 'name' => 'redis-server',
158
- 'containerPort' => 6379 }
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 = [{ 'name' => 'guestbook',
172
- 'image' => 'kubernetes/guestbook:v2',
173
- 'ports' => [{ 'name' => 'http-server',
174
- 'containerPort' => 3000 }]
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::Service.new
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