kubeclient 2.5.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require_relative 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            # Core api resource list without kind tests
         
     | 
| 
       4 
4 
     | 
    
         
             
            class TestResourceListWithoutKind < MiniTest::Test
         
     | 
| 
         @@ -15,19 +15,19 @@ class TestResourceListWithoutKind < MiniTest::Test 
     | 
|
| 
       15 
15 
     | 
    
         
             
                    entity: 'pod',
         
     | 
| 
       16 
16 
     | 
    
         
             
                    type: 'Pod',
         
     | 
| 
       17 
17 
     | 
    
         
             
                    name: 'pods',
         
     | 
| 
       18 
     | 
    
         
            -
                    methods: %w 
     | 
| 
      
 18 
     | 
    
         
            +
                    methods: %w[pod pods]
         
     | 
| 
       19 
19 
     | 
    
         
             
                  },
         
     | 
| 
       20 
20 
     | 
    
         
             
                  {
         
     | 
| 
       21 
21 
     | 
    
         
             
                    entity: 'node',
         
     | 
| 
       22 
22 
     | 
    
         
             
                    type: 'Node',
         
     | 
| 
       23 
23 
     | 
    
         
             
                    name: 'nodes',
         
     | 
| 
       24 
     | 
    
         
            -
                    methods: %w 
     | 
| 
      
 24 
     | 
    
         
            +
                    methods: %w[node nodes]
         
     | 
| 
       25 
25 
     | 
    
         
             
                  },
         
     | 
| 
       26 
26 
     | 
    
         
             
                  {
         
     | 
| 
       27 
27 
     | 
    
         
             
                    entity: 'service',
         
     | 
| 
       28 
28 
     | 
    
         
             
                    type: 'Service',
         
     | 
| 
       29 
29 
     | 
    
         
             
                    name: 'services',
         
     | 
| 
       30 
     | 
    
         
            -
                    methods: %w 
     | 
| 
      
 30 
     | 
    
         
            +
                    methods: %w[service services]
         
     | 
| 
       31 
31 
     | 
    
         
             
                  }
         
     | 
| 
       32 
32 
     | 
    
         
             
                ].each { |h| assert_entities(client.instance_variable_get(:@entities)[h[:entity]], h) }
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
         @@ -49,19 +49,19 @@ class TestResourceListWithoutKind < MiniTest::Test 
     | 
|
| 
       49 
49 
     | 
    
         
             
                    entity: 'template',
         
     | 
| 
       50 
50 
     | 
    
         
             
                    type: 'Template',
         
     | 
| 
       51 
51 
     | 
    
         
             
                    name: 'templates',
         
     | 
| 
       52 
     | 
    
         
            -
                    methods: %w 
     | 
| 
      
 52 
     | 
    
         
            +
                    methods: %w[template templates]
         
     | 
| 
       53 
53 
     | 
    
         
             
                  },
         
     | 
| 
       54 
54 
     | 
    
         
             
                  {
         
     | 
| 
       55 
55 
     | 
    
         
             
                    entity: 'build',
         
     | 
| 
       56 
56 
     | 
    
         
             
                    type: 'Build',
         
     | 
| 
       57 
57 
     | 
    
         
             
                    name: 'builds',
         
     | 
| 
       58 
     | 
    
         
            -
                    methods: %w 
     | 
| 
      
 58 
     | 
    
         
            +
                    methods: %w[build builds]
         
     | 
| 
       59 
59 
     | 
    
         
             
                  },
         
     | 
| 
       60 
60 
     | 
    
         
             
                  {
         
     | 
| 
       61 
61 
     | 
    
         
             
                    entity: 'project',
         
     | 
| 
       62 
62 
     | 
    
         
             
                    type: 'Project',
         
     | 
| 
       63 
63 
     | 
    
         
             
                    name: 'projects',
         
     | 
| 
       64 
     | 
    
         
            -
                    methods: %w 
     | 
| 
      
 64 
     | 
    
         
            +
                    methods: %w[project projects]
         
     | 
| 
       65 
65 
     | 
    
         
             
                  }
         
     | 
| 
       66 
66 
     | 
    
         
             
                ].each { |h| assert_entities(client.instance_variable_get(:@entities)[h[:entity]], h) }
         
     | 
| 
       67 
67 
     | 
    
         | 
    
        data/test/test_resource_quota.rb
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require_relative 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            # ResourceQuota tests
         
     | 
| 
       4 
4 
     | 
    
         
             
            class TestResourceQuota < MiniTest::Test
         
     | 
| 
         @@ -10,10 +10,10 @@ class TestResourceQuota < MiniTest::Test 
     | 
|
| 
       10 
10 
     | 
    
         
             
                  .to_return(body: open_test_file('resource_quota.json'),
         
     | 
| 
       11 
11 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       14 
     | 
    
         
            -
                quota = client.get_resource_quota 
     | 
| 
      
 13 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
      
 14 
     | 
    
         
            +
                quota = client.get_resource_quota('quota', 'quota-example')
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                assert_instance_of(Kubeclient:: 
     | 
| 
      
 16 
     | 
    
         
            +
                assert_instance_of(Kubeclient::Resource, quota)
         
     | 
| 
       17 
17 
     | 
    
         
             
                assert_equal('quota', quota.metadata.name)
         
     | 
| 
       18 
18 
     | 
    
         
             
                assert_equal('20', quota.spec.hard.cpu)
         
     | 
| 
       19 
19 
     | 
    
         
             
                assert_equal('10', quota.spec.hard.secrets)
         
     | 
    
        data/test/test_secret.rb
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require_relative 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            # Namespace entity tests
         
     | 
| 
       4 
4 
     | 
    
         
             
            class TestSecret < MiniTest::Test
         
     | 
| 
         @@ -11,10 +11,10 @@ class TestSecret < MiniTest::Test 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  .to_return(body: open_test_file('created_secret.json'),
         
     | 
| 
       12 
12 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       15 
     | 
    
         
            -
                secret = client.get_secret 
     | 
| 
      
 14 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
      
 15 
     | 
    
         
            +
                secret = client.get_secret('test-secret', 'dev')
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                assert_instance_of(Kubeclient:: 
     | 
| 
      
 17 
     | 
    
         
            +
                assert_instance_of(Kubeclient::Resource, secret)
         
     | 
| 
       18 
18 
     | 
    
         
             
                assert_equal('4e38a198-2bcb-11e5-a483-0e840567604d', secret.metadata.uid)
         
     | 
| 
       19 
19 
     | 
    
         
             
                assert_equal('test-secret', secret.metadata.name)
         
     | 
| 
       20 
20 
     | 
    
         
             
                assert_equal('v1', secret.apiVersion)
         
     | 
| 
         @@ -31,10 +31,11 @@ class TestSecret < MiniTest::Test 
     | 
|
| 
       31 
31 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
33 
     | 
    
         
             
                stub_request(:delete, %r{/secrets})
         
     | 
| 
       34 
     | 
    
         
            -
                  .to_return(status: 200)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  .to_return(status: 200, body: open_test_file('created_secret.json'))
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       37 
     | 
    
         
            -
                client.delete_secret 
     | 
| 
      
 36 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
      
 37 
     | 
    
         
            +
                secret = client.delete_secret('test-secret', 'dev')
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_kind_of(RecursiveOpenStruct, secret)
         
     | 
| 
       38 
39 
     | 
    
         | 
| 
       39 
40 
     | 
    
         
             
                assert_requested(:delete,
         
     | 
| 
       40 
41 
     | 
    
         
             
                                 'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
         
     | 
| 
         @@ -57,9 +58,9 @@ class TestSecret < MiniTest::Test 
     | 
|
| 
       57 
58 
     | 
    
         
             
                secret.data = {}
         
     | 
| 
       58 
59 
     | 
    
         
             
                secret.data['super-secret'] = 'Y2F0J3MgYXJlIGF3ZXNvbWUK'
         
     | 
| 
       59 
60 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       61 
     | 
    
         
            -
                created_secret = client.create_secret 
     | 
| 
       62 
     | 
    
         
            -
                assert_instance_of(Kubeclient:: 
     | 
| 
      
 61 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/')
         
     | 
| 
      
 62 
     | 
    
         
            +
                created_secret = client.create_secret(secret)
         
     | 
| 
      
 63 
     | 
    
         
            +
                assert_instance_of(Kubeclient::Resource, created_secret)
         
     | 
| 
       63 
64 
     | 
    
         
             
                assert_equal(secret.metadata.name, created_secret.metadata.name)
         
     | 
| 
       64 
65 
     | 
    
         
             
                assert_equal(secret.metadata.namespace, created_secret.metadata.namespace)
         
     | 
| 
       65 
66 
     | 
    
         
             
                assert_equal(
         
     | 
    
        data/test/test_service.rb
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require_relative 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            # Service entity tests
         
     | 
| 
       4 
4 
     | 
    
         
             
            class TestService < MiniTest::Test
         
     | 
| 
         @@ -11,17 +11,18 @@ class TestService < MiniTest::Test 
     | 
|
| 
       11 
11 
     | 
    
         
             
                our_service.metadata.labels.name = 'guestbook'
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                our_service.spec = {}
         
     | 
| 
       14 
     | 
    
         
            -
                our_service.spec.ports = [{ 
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                our_service.spec.ports = [{
         
     | 
| 
      
 15 
     | 
    
         
            +
                  'port' => 3000,
         
     | 
| 
      
 16 
     | 
    
         
            +
                  'targetPort' => 'http-server',
         
     | 
| 
      
 17 
     | 
    
         
            +
                  'protocol' => 'TCP'
         
     | 
| 
       17 
18 
     | 
    
         
             
                }]
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
       19 
20 
     | 
    
         
             
                assert_equal('guestbook', our_service.metadata.labels.name)
         
     | 
| 
       20 
21 
     | 
    
         | 
| 
       21 
22 
     | 
    
         
             
                hash = our_service.to_h
         
     | 
| 
       22 
23 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                assert_equal 
     | 
| 
       24 
     | 
    
         
            -
                             hash[:metadata][:labels][:name]
         
     | 
| 
      
 24 
     | 
    
         
            +
                assert_equal(our_service.metadata.labels.name,
         
     | 
| 
      
 25 
     | 
    
         
            +
                             hash[:metadata][:labels][:name])
         
     | 
| 
       25 
26 
     | 
    
         | 
| 
       26 
27 
     | 
    
         
             
                expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
         
     | 
| 
       27 
28 
     | 
    
         
             
                stub_request(:get, %r{/api/v1$})
         
     | 
| 
         @@ -31,15 +32,15 @@ class TestService < MiniTest::Test 
     | 
|
| 
       31 
32 
     | 
    
         
             
                stub_request(:post, expected_url)
         
     | 
| 
       32 
33 
     | 
    
         
             
                  .to_return(body: open_test_file('created_service.json'), status: 201)
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       35 
     | 
    
         
            -
                created = client.create_service 
     | 
| 
      
 35 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/')
         
     | 
| 
      
 36 
     | 
    
         
            +
                created = client.create_service(our_service)
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
                assert_instance_of(Kubeclient:: 
     | 
| 
      
 38 
     | 
    
         
            +
                assert_instance_of(Kubeclient::Resource, created)
         
     | 
| 
       38 
39 
     | 
    
         
             
                assert_equal(created.metadata.name, our_service.metadata.name)
         
     | 
| 
       39 
40 
     | 
    
         
             
                assert_equal(created.spec.ports.size, our_service.spec.ports.size)
         
     | 
| 
       40 
41 
     | 
    
         | 
| 
       41 
42 
     | 
    
         
             
                # Check that original entity_config is not modified by kind/apiVersion patches:
         
     | 
| 
       42 
     | 
    
         
            -
                 
     | 
| 
      
 43 
     | 
    
         
            +
                assert_nil(our_service.kind)
         
     | 
| 
       43 
44 
     | 
    
         | 
| 
       44 
45 
     | 
    
         
             
                assert_requested(:post, expected_url, times: 1) do |req|
         
     | 
| 
       45 
46 
     | 
    
         
             
                  data = JSON.parse(req.body)
         
     | 
| 
         @@ -72,8 +73,8 @@ class TestService < MiniTest::Test 
     | 
|
| 
       72 
73 
     | 
    
         
             
                stub_request(:post, expected_url)
         
     | 
| 
       73 
74 
     | 
    
         
             
                  .to_return(body: open_test_file('created_service.json'), status: 201)
         
     | 
| 
       74 
75 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       76 
     | 
    
         
            -
                client.create_service 
     | 
| 
      
 76 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/')
         
     | 
| 
      
 77 
     | 
    
         
            +
                client.create_service(service)
         
     | 
| 
       77 
78 
     | 
    
         | 
| 
       78 
79 
     | 
    
         
             
                assert_requested(:post, expected_url, times: 1) do |req|
         
     | 
| 
       79 
80 
     | 
    
         
             
                  data = JSON.parse(req.body)
         
     | 
| 
         @@ -107,8 +108,8 @@ class TestService < MiniTest::Test 
     | 
|
| 
       107 
108 
     | 
    
         
             
                stub_request(:post, %r{namespaces/staging/services})
         
     | 
| 
       108 
109 
     | 
    
         
             
                  .to_return(body: open_test_file('created_service.json'), status: 201)
         
     | 
| 
       109 
110 
     | 
    
         | 
| 
       110 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       111 
     | 
    
         
            -
                client.create_service 
     | 
| 
      
 111 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/')
         
     | 
| 
      
 112 
     | 
    
         
            +
                client.create_service(service)
         
     | 
| 
       112 
113 
     | 
    
         | 
| 
       113 
114 
     | 
    
         
             
                assert_requested(:post, expected_url, times: 1) do |req|
         
     | 
| 
       114 
115 
     | 
    
         
             
                  data = JSON.parse(req.body)
         
     | 
| 
         @@ -128,10 +129,10 @@ class TestService < MiniTest::Test 
     | 
|
| 
       128 
129 
     | 
    
         
             
                  .to_return(body: open_test_file('service.json'),
         
     | 
| 
       129 
130 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       130 
131 
     | 
    
         | 
| 
       131 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       132 
     | 
    
         
            -
                service = client.get_service 
     | 
| 
      
 132 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/')
         
     | 
| 
      
 133 
     | 
    
         
            +
                service = client.get_service('redis-slave', 'development')
         
     | 
| 
       133 
134 
     | 
    
         | 
| 
       134 
     | 
    
         
            -
                assert_instance_of(Kubeclient:: 
     | 
| 
      
 135 
     | 
    
         
            +
                assert_instance_of(Kubeclient::Resource, service)
         
     | 
| 
       135 
136 
     | 
    
         
             
                assert_equal('2015-04-05T13:00:31Z',
         
     | 
| 
       136 
137 
     | 
    
         
             
                             service.metadata.creationTimestamp)
         
     | 
| 
       137 
138 
     | 
    
         
             
                assert_equal('bdb80a8f-db93-11e4-b293-f8b156af4ae1', service.metadata.uid)
         
     | 
| 
         @@ -163,10 +164,11 @@ class TestService < MiniTest::Test 
     | 
|
| 
       163 
164 
     | 
    
         
             
                  .to_return(body: open_test_file('core_api_resource_list.json'),
         
     | 
| 
       164 
165 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       165 
166 
     | 
    
         
             
                stub_request(:delete, %r{/namespaces/default/services})
         
     | 
| 
       166 
     | 
    
         
            -
                  .to_return(status: 200)
         
     | 
| 
      
 167 
     | 
    
         
            +
                  .to_return(body: open_test_file('service.json'), status: 200)
         
     | 
| 
       167 
168 
     | 
    
         | 
| 
       168 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       169 
     | 
    
         
            -
                client.delete_service 
     | 
| 
      
 169 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
      
 170 
     | 
    
         
            +
                our_service = client.delete_service(our_service.name, 'default')
         
     | 
| 
      
 171 
     | 
    
         
            +
                assert_kind_of(RecursiveOpenStruct, our_service)
         
     | 
| 
       170 
172 
     | 
    
         | 
| 
       171 
173 
     | 
    
         
             
                assert_requested(:delete,
         
     | 
| 
       172 
174 
     | 
    
         
             
                                 'http://localhost:8080/api/v1/namespaces/default/services/redis-service',
         
     | 
| 
         @@ -182,10 +184,10 @@ class TestService < MiniTest::Test 
     | 
|
| 
       182 
184 
     | 
    
         
             
                stub_request(:get, %r{/services/redis-slave})
         
     | 
| 
       183 
185 
     | 
    
         
             
                  .to_return(status: 404)
         
     | 
| 
       184 
186 
     | 
    
         | 
| 
       185 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
      
 187 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/')
         
     | 
| 
       186 
188 
     | 
    
         | 
| 
       187 
     | 
    
         
            -
                exception = assert_raises( 
     | 
| 
       188 
     | 
    
         
            -
                  client.get_service 
     | 
| 
      
 189 
     | 
    
         
            +
                exception = assert_raises(Kubeclient::HttpError) do
         
     | 
| 
      
 190 
     | 
    
         
            +
                  client.get_service('redis-slave')
         
     | 
| 
       189 
191 
     | 
    
         
             
                end
         
     | 
| 
       190 
192 
     | 
    
         
             
                assert_equal(404, exception.error_code)
         
     | 
| 
       191 
193 
     | 
    
         
             
              end
         
     | 
| 
         @@ -198,8 +200,8 @@ class TestService < MiniTest::Test 
     | 
|
| 
       198 
200 
     | 
    
         
             
                  .to_return(body: open_test_file('service.json'),
         
     | 
| 
       199 
201 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       200 
202 
     | 
    
         | 
| 
       201 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       202 
     | 
    
         
            -
                service = client.get_service 
     | 
| 
      
 203 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/')
         
     | 
| 
      
 204 
     | 
    
         
            +
                service = client.get_service('redis-slave', 'development')
         
     | 
| 
       203 
205 
     | 
    
         
             
                assert_equal('redis-slave', service.metadata.name)
         
     | 
| 
       204 
206 
     | 
    
         | 
| 
       205 
207 
     | 
    
         
             
                assert_requested(:get,
         
     | 
| 
         @@ -222,8 +224,9 @@ class TestService < MiniTest::Test 
     | 
|
| 
       222 
224 
     | 
    
         
             
                stub_request(:put, expected_url)
         
     | 
| 
       223 
225 
     | 
    
         
             
                  .to_return(body: open_test_file('service_update.json'), status: 201)
         
     | 
| 
       224 
226 
     | 
    
         | 
| 
       225 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       226 
     | 
    
         
            -
                client.update_service 
     | 
| 
      
 227 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
      
 228 
     | 
    
         
            +
                service = client.update_service(service)
         
     | 
| 
      
 229 
     | 
    
         
            +
                assert_kind_of(RecursiveOpenStruct, service)
         
     | 
| 
       227 
230 
     | 
    
         | 
| 
       228 
231 
     | 
    
         
             
                assert_requested(:put, expected_url, times: 1) do |req|
         
     | 
| 
       229 
232 
     | 
    
         
             
                  data = JSON.parse(req.body)
         
     | 
| 
         @@ -248,8 +251,9 @@ class TestService < MiniTest::Test 
     | 
|
| 
       248 
251 
     | 
    
         
             
                stub_request(:put, expected_url)
         
     | 
| 
       249 
252 
     | 
    
         
             
                  .to_return(body: open_test_file('service_update.json'), status: 201)
         
     | 
| 
       250 
253 
     | 
    
         | 
| 
       251 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       252 
     | 
    
         
            -
                client.update_service 
     | 
| 
      
 254 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
      
 255 
     | 
    
         
            +
                service = client.update_service(service)
         
     | 
| 
      
 256 
     | 
    
         
            +
                assert_kind_of(RecursiveOpenStruct, service)
         
     | 
| 
       253 
257 
     | 
    
         | 
| 
       254 
258 
     | 
    
         
             
                assert_requested(:put, expected_url, times: 1) do |req|
         
     | 
| 
       255 
259 
     | 
    
         
             
                  data = JSON.parse(req.body)
         
     | 
| 
         @@ -281,8 +285,9 @@ class TestService < MiniTest::Test 
     | 
|
| 
       281 
285 
     | 
    
         
             
                  }
         
     | 
| 
       282 
286 
     | 
    
         
             
                }
         
     | 
| 
       283 
287 
     | 
    
         | 
| 
       284 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       285 
     | 
    
         
            -
                client.patch_service 
     | 
| 
      
 288 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
      
 289 
     | 
    
         
            +
                service = client.patch_service(name, patch, 'development')
         
     | 
| 
      
 290 
     | 
    
         
            +
                assert_kind_of(RecursiveOpenStruct, service)
         
     | 
| 
       286 
291 
     | 
    
         | 
| 
       287 
292 
     | 
    
         
             
                assert_requested(:patch, expected_url, times: 1) do |req|
         
     | 
| 
       288 
293 
     | 
    
         
             
                  data = JSON.parse(req.body)
         
     | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require_relative 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            # ServiceAccount tests
         
     | 
| 
       4 
4 
     | 
    
         
             
            class TestServiceAccount < MiniTest::Test
         
     | 
| 
         @@ -10,10 +10,10 @@ class TestServiceAccount < MiniTest::Test 
     | 
|
| 
       10 
10 
     | 
    
         
             
                  .to_return(body: open_test_file('core_api_resource_list.json'),
         
     | 
| 
       11 
11 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       14 
     | 
    
         
            -
                account = client.get_service_account 
     | 
| 
      
 13 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
      
 14 
     | 
    
         
            +
                account = client.get_service_account('default')
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                assert_instance_of(Kubeclient:: 
     | 
| 
      
 16 
     | 
    
         
            +
                assert_instance_of(Kubeclient::Resource, account)
         
     | 
| 
       17 
17 
     | 
    
         
             
                assert_equal('default', account.metadata.name)
         
     | 
| 
       18 
18 
     | 
    
         
             
                assert_equal('default-token-6s23q', account.secrets[0].name)
         
     | 
| 
       19 
19 
     | 
    
         
             
                assert_equal('default-dockercfg-62tf3', account.secrets[1].name)
         
     | 
    
        data/test/test_watch.rb
    CHANGED
    
    | 
         @@ -1,23 +1,21 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require_relative 'test_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            # Watch entity tests
         
     | 
| 
       4 
4 
     | 
    
         
             
            class TestWatch < MiniTest::Test
         
     | 
| 
       5 
5 
     | 
    
         
             
              def test_watch_pod_success
         
     | 
| 
      
 6 
     | 
    
         
            +
                stub_resource_list
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       6 
8 
     | 
    
         
             
                expected = [
         
     | 
| 
       7 
9 
     | 
    
         
             
                  { 'type' => 'ADDED', 'resourceVersion' => '1389' },
         
     | 
| 
       8 
10 
     | 
    
         
             
                  { 'type' => 'MODIFIED', 'resourceVersion' => '1390' },
         
     | 
| 
       9 
11 
     | 
    
         
             
                  { 'type' => 'DELETED', 'resourceVersion' => '1398' }
         
     | 
| 
       10 
12 
     | 
    
         
             
                ]
         
     | 
| 
       11 
13 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                stub_request(:get, %r{/ 
     | 
| 
       13 
     | 
    
         
            -
                  .to_return(body: open_test_file('core_api_resource_list.json'),
         
     | 
| 
       14 
     | 
    
         
            -
                             status: 200)
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                stub_request(:get, %r{.*\/watch/pods})
         
     | 
| 
      
 14 
     | 
    
         
            +
                stub_request(:get, %r{/watch/pods})
         
     | 
| 
       17 
15 
     | 
    
         
             
                  .to_return(body: open_test_file('watch_stream.json'),
         
     | 
| 
       18 
16 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       19 
17 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
      
 18 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
       21 
19 
     | 
    
         | 
| 
       22 
20 
     | 
    
         
             
                client.watch_pods.to_enum.with_index do |notice, index|
         
     | 
| 
       23 
21 
     | 
    
         
             
                  assert_instance_of(Kubeclient::Common::WatchNotice, notice)
         
     | 
| 
         @@ -29,14 +27,27 @@ class TestWatch < MiniTest::Test 
     | 
|
| 
       29 
27 
     | 
    
         
             
                end
         
     | 
| 
       30 
28 
     | 
    
         
             
              end
         
     | 
| 
       31 
29 
     | 
    
         | 
| 
      
 30 
     | 
    
         
            +
              def test_watch_pod_raw
         
     | 
| 
      
 31 
     | 
    
         
            +
                stub_resource_list
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                stub_request(:get, %r{/watch/pods}).to_return(
         
     | 
| 
      
 34 
     | 
    
         
            +
                  body: open_test_file('watch_stream.json'),
         
     | 
| 
      
 35 
     | 
    
         
            +
                  status: 200
         
     | 
| 
      
 36 
     | 
    
         
            +
                )
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                got = nil
         
     | 
| 
      
 41 
     | 
    
         
            +
                client.watch_pods(as: :raw).each { |notice| got = notice }
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert_match(/\A{"type":"DELETED"/, got)
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       32 
45 
     | 
    
         
             
              def test_watch_pod_failure
         
     | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                             status: 200)
         
     | 
| 
       36 
     | 
    
         
            -
                stub_request(:get, %r{.*\/watch/pods}).to_return(status: 404)
         
     | 
| 
      
 46 
     | 
    
         
            +
                stub_resource_list
         
     | 
| 
      
 47 
     | 
    
         
            +
                stub_request(:get, %r{/watch/pods}).to_return(status: 404)
         
     | 
| 
       37 
48 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
       39 
     | 
    
         
            -
                assert_raises  
     | 
| 
      
 49 
     | 
    
         
            +
                client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
         
     | 
| 
      
 50 
     | 
    
         
            +
                assert_raises(Kubeclient::HttpError) do
         
     | 
| 
       40 
51 
     | 
    
         
             
                  client.watch_pods.each do
         
     | 
| 
       41 
52 
     | 
    
         
             
                  end
         
     | 
| 
       42 
53 
     | 
    
         
             
                end
         
     | 
| 
         @@ -51,24 +62,33 @@ class TestWatch < MiniTest::Test 
     | 
|
| 
       51 
62 
     | 
    
         
             
                  .to_return(body: open_test_file('pod_log.txt'),
         
     | 
| 
       52 
63 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       53 
64 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
                stream = Kubeclient::Common::WatchStream.new(URI.parse(url), {},  
     | 
| 
      
 65 
     | 
    
         
            +
                stream = Kubeclient::Common::WatchStream.new(URI.parse(url), {}, as: :raw)
         
     | 
| 
       55 
66 
     | 
    
         
             
                stream.to_enum.with_index do |line, index|
         
     | 
| 
       56 
67 
     | 
    
         
             
                  assert_instance_of(String, line)
         
     | 
| 
       57 
68 
     | 
    
         
             
                  assert_equal(expected_lines[index], line)
         
     | 
| 
       58 
69 
     | 
    
         
             
                end
         
     | 
| 
       59 
70 
     | 
    
         
             
              end
         
     | 
| 
       60 
71 
     | 
    
         | 
| 
      
 72 
     | 
    
         
            +
              # Ensure that WatchStream respects a format that's not JSON
         
     | 
| 
      
 73 
     | 
    
         
            +
              def test_watch_stream_unknown
         
     | 
| 
      
 74 
     | 
    
         
            +
                url = 'http://www.example.com/foobar'
         
     | 
| 
      
 75 
     | 
    
         
            +
                stub_request(:get, url)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  .to_return(body: open_test_file('pod_log.txt'),
         
     | 
| 
      
 77 
     | 
    
         
            +
                             status: 200)
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                stream = Kubeclient::Common::WatchStream.new(URI.parse(url), {}, as: :foo)
         
     | 
| 
      
 80 
     | 
    
         
            +
                assert_raises(NotImplementedError) { stream.each {} }
         
     | 
| 
      
 81 
     | 
    
         
            +
              end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
       61 
83 
     | 
    
         
             
              def test_watch_with_resource_version
         
     | 
| 
       62 
84 
     | 
    
         
             
                api_host = 'http://localhost:8080/api'
         
     | 
| 
       63 
85 
     | 
    
         
             
                version = '1995'
         
     | 
| 
       64 
     | 
    
         
            -
                 
     | 
| 
       65 
     | 
    
         
            -
                  .to_return(body: open_test_file('core_api_resource_list.json'),
         
     | 
| 
       66 
     | 
    
         
            -
                             status: 200)
         
     | 
| 
      
 86 
     | 
    
         
            +
                stub_resource_list
         
     | 
| 
       67 
87 
     | 
    
         
             
                stub_request(:get, %r{.*\/watch/events})
         
     | 
| 
       68 
88 
     | 
    
         
             
                  .to_return(body: open_test_file('watch_stream.json'),
         
     | 
| 
       69 
89 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       70 
90 
     | 
    
         | 
| 
       71 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
      
 91 
     | 
    
         
            +
                client = Kubeclient::Client.new(api_host, 'v1')
         
     | 
| 
       72 
92 
     | 
    
         
             
                results = client.watch_events(version).to_enum
         
     | 
| 
       73 
93 
     | 
    
         | 
| 
       74 
94 
     | 
    
         
             
                assert_equal(3, results.count)
         
     | 
| 
         @@ -81,14 +101,12 @@ class TestWatch < MiniTest::Test 
     | 
|
| 
       81 
101 
     | 
    
         
             
                api_host = 'http://localhost:8080/api'
         
     | 
| 
       82 
102 
     | 
    
         
             
                selector = 'name=redis-master'
         
     | 
| 
       83 
103 
     | 
    
         | 
| 
       84 
     | 
    
         
            -
                 
     | 
| 
       85 
     | 
    
         
            -
                  .to_return(body: open_test_file('core_api_resource_list.json'),
         
     | 
| 
       86 
     | 
    
         
            -
                             status: 200)
         
     | 
| 
      
 104 
     | 
    
         
            +
                stub_resource_list
         
     | 
| 
       87 
105 
     | 
    
         
             
                stub_request(:get, %r{.*\/watch/events})
         
     | 
| 
       88 
106 
     | 
    
         
             
                  .to_return(body: open_test_file('watch_stream.json'),
         
     | 
| 
       89 
107 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       90 
108 
     | 
    
         | 
| 
       91 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
      
 109 
     | 
    
         
            +
                client = Kubeclient::Client.new(api_host, 'v1')
         
     | 
| 
       92 
110 
     | 
    
         
             
                results = client.watch_events(label_selector: selector).to_enum
         
     | 
| 
       93 
111 
     | 
    
         | 
| 
       94 
112 
     | 
    
         
             
                assert_equal(3, results.count)
         
     | 
| 
         @@ -101,14 +119,12 @@ class TestWatch < MiniTest::Test 
     | 
|
| 
       101 
119 
     | 
    
         
             
                api_host = 'http://localhost:8080/api'
         
     | 
| 
       102 
120 
     | 
    
         
             
                selector = 'involvedObject.kind=Pod'
         
     | 
| 
       103 
121 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
                 
     | 
| 
       105 
     | 
    
         
            -
                  .to_return(body: open_test_file('core_api_resource_list.json'),
         
     | 
| 
       106 
     | 
    
         
            -
                             status: 200)
         
     | 
| 
      
 122 
     | 
    
         
            +
                stub_resource_list
         
     | 
| 
       107 
123 
     | 
    
         
             
                stub_request(:get, %r{.*\/watch/events})
         
     | 
| 
       108 
124 
     | 
    
         
             
                  .to_return(body: open_test_file('watch_stream.json'),
         
     | 
| 
       109 
125 
     | 
    
         
             
                             status: 200)
         
     | 
| 
       110 
126 
     | 
    
         | 
| 
       111 
     | 
    
         
            -
                client = Kubeclient::Client.new 
     | 
| 
      
 127 
     | 
    
         
            +
                client = Kubeclient::Client.new(api_host, 'v1')
         
     | 
| 
       112 
128 
     | 
    
         
             
                results = client.watch_events(field_selector: selector).to_enum
         
     | 
| 
       113 
129 
     | 
    
         | 
| 
       114 
130 
     | 
    
         
             
                assert_equal(3, results.count)
         
     | 
| 
         @@ -120,9 +136,7 @@ class TestWatch < MiniTest::Test 
     | 
|
| 
       120 
136 
     | 
    
         
             
              def test_watch_with_finish_and_ebadf
         
     | 
| 
       121 
137 
     | 
    
         
             
                api_host = 'http://localhost:8080/api'
         
     | 
| 
       122 
138 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
                 
     | 
| 
       124 
     | 
    
         
            -
                  .to_return(body: open_test_file('core_api_resource_list.json'),
         
     | 
| 
       125 
     | 
    
         
            -
                             status: 200)
         
     | 
| 
      
 139 
     | 
    
         
            +
                stub_resource_list
         
     | 
| 
       126 
140 
     | 
    
         
             
                stub_request(:get, %r{.*\/watch/events})
         
     | 
| 
       127 
141 
     | 
    
         
             
                  .to_return(body: open_test_file('watch_stream.json'), status: 200)
         
     | 
| 
       128 
142 
     | 
    
         | 
| 
         @@ -137,4 +151,13 @@ class TestWatch < MiniTest::Test 
     | 
|
| 
       137 
151 
     | 
    
         | 
| 
       138 
152 
     | 
    
         
             
                assert_requested(:get, "#{api_host}/v1/watch/events", times: 1)
         
     | 
| 
       139 
153 
     | 
    
         
             
              end
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
              private
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
              def stub_resource_list
         
     | 
| 
      
 158 
     | 
    
         
            +
                stub_request(:get, %r{/api/v1$}).to_return(
         
     | 
| 
      
 159 
     | 
    
         
            +
                  body: open_test_file('core_api_resource_list.json'),
         
     | 
| 
      
 160 
     | 
    
         
            +
                  status: 200
         
     | 
| 
      
 161 
     | 
    
         
            +
                )
         
     | 
| 
      
 162 
     | 
    
         
            +
              end
         
     | 
| 
       140 
163 
     | 
    
         
             
            end
         
     |