kubeclient 0.3.0 → 4.9.2

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 (63) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/actions.yml +35 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +29 -0
  5. data/CHANGELOG.md +208 -0
  6. data/Gemfile +3 -0
  7. data/README.md +706 -57
  8. data/RELEASING.md +69 -0
  9. data/Rakefile +3 -5
  10. data/kubeclient.gemspec +19 -11
  11. data/lib/kubeclient/aws_eks_credentials.rb +46 -0
  12. data/lib/kubeclient/common.rb +597 -161
  13. data/lib/kubeclient/config.rb +195 -0
  14. data/lib/kubeclient/entity_list.rb +7 -2
  15. data/lib/kubeclient/exec_credentials.rb +89 -0
  16. data/lib/kubeclient/gcp_auth_provider.rb +19 -0
  17. data/lib/kubeclient/gcp_command_credentials.rb +31 -0
  18. data/lib/kubeclient/google_application_default_credentials.rb +31 -0
  19. data/lib/kubeclient/http_error.rb +25 -0
  20. data/lib/kubeclient/missing_kind_compatibility.rb +68 -0
  21. data/lib/kubeclient/oidc_auth_provider.rb +52 -0
  22. data/lib/kubeclient/resource.rb +11 -0
  23. data/lib/kubeclient/resource_not_found_error.rb +4 -0
  24. data/lib/kubeclient/version.rb +1 -1
  25. data/lib/kubeclient/watch_stream.rb +71 -28
  26. data/lib/kubeclient.rb +25 -82
  27. metadata +140 -114
  28. data/.travis.yml +0 -6
  29. data/lib/kubeclient/kube_exception.rb +0 -13
  30. data/lib/kubeclient/watch_notice.rb +0 -7
  31. data/test/json/created_namespace_b3.json +0 -20
  32. data/test/json/created_secret.json +0 -16
  33. data/test/json/created_service_b3.json +0 -31
  34. data/test/json/empty_pod_list_b3.json +0 -9
  35. data/test/json/endpoint_list_b3.json +0 -48
  36. data/test/json/entity_list_b3.json +0 -56
  37. data/test/json/event_list_b3.json +0 -35
  38. data/test/json/namespace_b3.json +0 -13
  39. data/test/json/namespace_exception_b3.json +0 -8
  40. data/test/json/namespace_list_b3.json +0 -32
  41. data/test/json/node_b3.json +0 -29
  42. data/test/json/node_list_b3.json +0 -37
  43. data/test/json/pod_b3.json +0 -92
  44. data/test/json/pod_list_b3.json +0 -75
  45. data/test/json/replication_controller_b3.json +0 -57
  46. data/test/json/replication_controller_list_b3.json +0 -64
  47. data/test/json/secret_list_b3.json +0 -44
  48. data/test/json/service_b3.json +0 -33
  49. data/test/json/service_illegal_json_404.json +0 -1
  50. data/test/json/service_list_b3.json +0 -97
  51. data/test/json/service_update_b3.json +0 -22
  52. data/test/json/versions_list.json +0 -6
  53. data/test/json/watch_stream_b3.json +0 -3
  54. data/test/test_helper.rb +0 -4
  55. data/test/test_kubeclient.rb +0 -407
  56. data/test/test_namespace.rb +0 -53
  57. data/test/test_node.rb +0 -25
  58. data/test/test_pod.rb +0 -21
  59. data/test/test_replication_controller.rb +0 -24
  60. data/test/test_secret.rb +0 -58
  61. data/test/test_service.rb +0 -136
  62. data/test/test_watch.rb +0 -37
  63. data/test/valid_token_file +0 -1
data/test/test_pod.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Pod entity tests
4
- class TestPod < MiniTest::Test
5
- def test_get_from_json_v3
6
- stub_request(:get, %r{/pods})
7
- .to_return(body: open_test_json_file('pod_b3.json'),
8
- status: 200)
9
-
10
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
11
- pod = client.get_pod 'redis-master-pod', 'default'
12
-
13
- assert_instance_of(Kubeclient::Pod, pod)
14
- assert_equal('redis-master3', pod.metadata.name)
15
- assert_equal('dockerfile/redis', pod.spec.containers[0]['image'])
16
-
17
- assert_requested(:get,
18
- 'http://localhost:8080/api/v1beta3/namespaces/default/pods/redis-master-pod',
19
- times: 1)
20
- end
21
- end
@@ -1,24 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Replication Controller entity tests
4
- class TestReplicationController < MiniTest::Test
5
- def test_get_from_json_v3
6
- stub_request(:get, %r{/replicationcontrollers})
7
- .to_return(body: open_test_json_file('replication_controller_b3.json'),
8
- status: 200)
9
-
10
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
11
- rc = client.get_replication_controller 'frontendController', 'default'
12
-
13
- assert_instance_of(Kubeclient::ReplicationController, rc)
14
- assert_equal('guestbook-controller', rc.metadata.name)
15
- assert_equal('c71aa4c0-a240-11e4-a265-3c970e4a436a', rc.metadata.uid)
16
- assert_equal('default', rc.metadata.namespace)
17
- assert_equal(3, rc.spec.replicas)
18
- assert_equal('guestbook', rc.spec.selector.name)
19
-
20
- assert_requested(:get,
21
- 'http://localhost:8080/api/v1beta3/namespaces/default/replicationcontrollers/frontendController',
22
- times: 1)
23
- end
24
- end
data/test/test_secret.rb DELETED
@@ -1,58 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Namespace entity tests
4
- class TestSecret < MiniTest::Test
5
- def test_get_secret_v1
6
- stub_request(:get, %r{/secrets})
7
- .to_return(body: open_test_json_file('created_secret.json'),
8
- status: 200)
9
-
10
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
11
- secret = client.get_secret 'test-secret', 'dev'
12
-
13
- assert_instance_of(Kubeclient::Secret, secret)
14
- assert_equal('4e38a198-2bcb-11e5-a483-0e840567604d', secret.metadata.uid)
15
- assert_equal('test-secret', secret.metadata.name)
16
- assert_equal('v1', secret.apiVersion)
17
- assert_equal('Y2F0J3MgYXJlIGF3ZXNvbWUK', secret.data['super-secret'])
18
-
19
- assert_requested(:get,
20
- 'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
21
- times: 1)
22
- end
23
-
24
- def test_delete_secret_v1
25
- stub_request(:delete, %r{/secrets})
26
- .to_return(status: 200)
27
-
28
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
29
- client.delete_secret 'test-secret', 'dev'
30
-
31
- assert_requested(:delete,
32
- 'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
33
- times: 1)
34
- end
35
-
36
- def test_create_secret_v1
37
- stub_request(:post, %r{/secrets})
38
- .to_return(body: open_test_json_file('created_secret.json'),
39
- status: 201)
40
-
41
- secret = Kubeclient::Secret.new
42
- secret.metadata = {}
43
- secret.metadata.name = 'test-secret'
44
- secret.metadata.namespace = 'dev'
45
- secret.data = {}
46
- secret.data['super-secret'] = 'Y2F0J3MgYXJlIGF3ZXNvbWUK'
47
-
48
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
49
- created_secret = client.create_secret secret
50
- assert_instance_of(Kubeclient::Secret, created_secret)
51
- assert_equal(secret.metadata.name, created_secret.metadata.name)
52
- assert_equal(secret.metadata.namespace, created_secret.metadata.namespace)
53
- assert_equal(
54
- secret.data['super-secret'],
55
- created_secret.data['super-secret']
56
- )
57
- end
58
- end
data/test/test_service.rb DELETED
@@ -1,136 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Service entity tests
4
- class TestService < MiniTest::Test
5
- def test_construct_our_own_service
6
- our_service = Kubeclient::Service.new
7
- our_service.metadata = {}
8
- our_service.metadata.name = 'guestbook'
9
- our_service.metadata.namespace = 'staging'
10
- our_service.metadata.labels = {}
11
- our_service.metadata.labels.name = 'guestbook'
12
-
13
- our_service.spec = {}
14
- our_service.spec.ports = [{ 'port' => 3000,
15
- 'targetPort' => 'http-server',
16
- 'protocol' => 'TCP'
17
- }]
18
-
19
- assert_equal('guestbook', our_service.metadata.labels.name)
20
-
21
- hash = our_service.to_h
22
-
23
- assert_equal our_service.metadata.labels.name,
24
- hash[:metadata][:labels][:name]
25
-
26
- stub_request(:post, %r{namespaces/staging/services})
27
- .to_return(body: open_test_json_file('created_service_b3.json'),
28
- status: 201)
29
-
30
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
31
- created = client.create_service our_service
32
-
33
- assert_instance_of(Kubeclient::Service, created)
34
- assert_equal(created.metadata.name, our_service.metadata.name)
35
- assert_equal(created.spec.ports.size, our_service.spec.ports.size)
36
- end
37
-
38
- def test_conversion_from_json_v3
39
- stub_request(:get, %r{/services})
40
- .to_return(body: open_test_json_file('service_b3.json'),
41
- status: 200)
42
-
43
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
44
- service = client.get_service 'redis-slave', 'development'
45
-
46
- assert_instance_of(Kubeclient::Service, service)
47
- assert_equal('2015-04-05T13:00:31Z',
48
- service.metadata.creationTimestamp)
49
- assert_equal('bdb80a8f-db93-11e4-b293-f8b156af4ae1', service.metadata.uid)
50
- assert_equal('redis-slave', service.metadata.name)
51
- assert_equal('2815', service.metadata.resourceVersion)
52
- assert_equal('v1beta3', service.apiVersion)
53
- assert_equal('10.0.0.140', service.spec.portalIP)
54
- assert_equal('development', service.metadata.namespace)
55
-
56
- assert_equal('TCP', service.spec.ports[0].protocol)
57
- assert_equal(6379, service.spec.ports[0].port)
58
- assert_equal('', service.spec.ports[0].name)
59
- assert_equal('redis-server', service.spec.ports[0].targetPort)
60
-
61
- assert_requested(:get,
62
- 'http://localhost:8080/api/v1beta3/namespaces/development/services/redis-slave',
63
- times: 1)
64
- end
65
-
66
- def test_delete_service
67
- our_service = Kubeclient::Service.new
68
- our_service.name = 'redis-service'
69
- # TODO, new ports assignment to be added
70
- our_service.labels = {}
71
- our_service.labels.component = 'apiserver'
72
- our_service.labels.provider = 'kubernetes'
73
-
74
- stub_request(:delete, %r{/namespaces/default/services})
75
- .to_return(status: 200)
76
-
77
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
78
- client.delete_service our_service.name, 'default'
79
-
80
- assert_requested(:delete,
81
- 'http://localhost:8080/api/v1beta3/namespaces/default/services/redis-service',
82
- times: 1)
83
- end
84
-
85
- def test_get_service_no_ns
86
- # when not specifying namespace for entities which
87
- # are not node or namespace, the request will fail
88
- stub_request(:get, %r{/services/redis-slave})
89
- .to_return(status: 404)
90
-
91
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
92
-
93
- exception = assert_raises(KubeException) do
94
- client.get_service 'redis-slave'
95
- end
96
- assert_equal(404, exception.error_code)
97
- end
98
-
99
- def test_get_service
100
- stub_request(:get, %r{/namespaces/development/services/redis-slave})
101
- .to_return(body: open_test_json_file('service_b3.json'),
102
- status: 200)
103
-
104
- client = Kubeclient::Client.new 'http://localhost:8080/api/'
105
- service = client.get_service 'redis-slave', 'development'
106
- assert_equal('redis-slave', service.metadata.name)
107
-
108
- assert_requested(:get,
109
- 'http://localhost:8080/api/v1beta3/namespaces/development/services/redis-slave',
110
- times: 1)
111
- end
112
-
113
- def test_update_service
114
- entity = 'service'
115
- object = Kubeclient::Service.new
116
- name = 'my_service'
117
- object.metadata = {
118
- 'name' => name
119
- }
120
-
121
- stub_request(:put, %r{/services/#{name}})\
122
- .to_return(
123
- body: open_test_json_file('service_update_b3.json'),
124
- status: 200
125
- )
126
-
127
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
128
- client.update_entity entity, object
129
-
130
- assert_requested(
131
- :put,
132
- "http://localhost:8080/api/v1beta3/services/#{name}",
133
- times: 1
134
- )
135
- end
136
- end
data/test/test_watch.rb DELETED
@@ -1,37 +0,0 @@
1
- require 'test_helper'
2
-
3
- # Watch entity tests
4
- class TestWatch < MiniTest::Test
5
- def test_watch_pod_success
6
- expected = [
7
- { 'type' => 'ADDED', 'resourceVersion' => '1389' },
8
- { 'type' => 'MODIFIED', 'resourceVersion' => '1390' },
9
- { 'type' => 'DELETED', 'resourceVersion' => '1398' }
10
- ]
11
-
12
- stub_request(:get, %r{.*\/watch/pods})
13
- .to_return(body: open_test_json_file('watch_stream_b3.json'),
14
- status: 200)
15
-
16
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
17
-
18
- client.watch_pods.to_enum.with_index do |notice, index|
19
- assert_instance_of(Kubeclient::Common::WatchNotice, notice)
20
- assert_equal(expected[index]['type'], notice.type)
21
- assert_equal('Pod', notice.object.kind)
22
- assert_equal('php', notice.object.metadata.name)
23
- assert_equal(expected[index]['resourceVersion'],
24
- notice.object.metadata.resourceVersion)
25
- end
26
- end
27
-
28
- def test_watch_pod_failure
29
- stub_request(:get, %r{.*\/watch/pods}).to_return(status: 404)
30
-
31
- client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1beta3'
32
- assert_raises KubeException do
33
- client.watch_pods.each do
34
- end
35
- end
36
- end
37
- end
@@ -1 +0,0 @@
1
- valid_token