kubeclient 4.9.1 → 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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/actions.yml +35 -0
  3. data/CHANGELOG.md +8 -0
  4. data/kubeclient.gemspec +3 -2
  5. data/lib/kubeclient/common.rb +2 -2
  6. data/lib/kubeclient/config.rb +6 -1
  7. data/lib/kubeclient/version.rb +1 -1
  8. metadata +8 -214
  9. data/.travis.yml +0 -29
  10. data/test/cassettes/kubernetes_guestbook.yml +0 -879
  11. data/test/config/allinone.kubeconfig +0 -20
  12. data/test/config/execauth.kubeconfig +0 -62
  13. data/test/config/external-ca.pem +0 -18
  14. data/test/config/external-cert.pem +0 -19
  15. data/test/config/external-key.rsa +0 -27
  16. data/test/config/external.kubeconfig +0 -20
  17. data/test/config/gcpauth.kubeconfig +0 -22
  18. data/test/config/gcpcmdauth.kubeconfig +0 -26
  19. data/test/config/nouser.kubeconfig +0 -16
  20. data/test/config/oidcauth.kubeconfig +0 -25
  21. data/test/config/timestamps.kubeconfig +0 -25
  22. data/test/config/userauth.kubeconfig +0 -28
  23. data/test/json/bindings_list.json +0 -10
  24. data/test/json/component_status.json +0 -17
  25. data/test/json/component_status_list.json +0 -52
  26. data/test/json/config.istio.io_api_resource_list.json +0 -679
  27. data/test/json/config_map_list.json +0 -9
  28. data/test/json/core_api_resource_list.json +0 -181
  29. data/test/json/core_api_resource_list_without_kind.json +0 -129
  30. data/test/json/core_oapi_resource_list_without_kind.json +0 -197
  31. data/test/json/created_endpoint.json +0 -28
  32. data/test/json/created_namespace.json +0 -20
  33. data/test/json/created_secret.json +0 -16
  34. data/test/json/created_security_context_constraint.json +0 -65
  35. data/test/json/created_service.json +0 -31
  36. data/test/json/empty_pod_list.json +0 -9
  37. data/test/json/endpoint_list.json +0 -48
  38. data/test/json/entity_list.json +0 -56
  39. data/test/json/event_list.json +0 -35
  40. data/test/json/extensions_v1beta1_api_resource_list.json +0 -217
  41. data/test/json/limit_range.json +0 -23
  42. data/test/json/limit_range_list.json +0 -31
  43. data/test/json/namespace.json +0 -13
  44. data/test/json/namespace_exception.json +0 -8
  45. data/test/json/namespace_list.json +0 -32
  46. data/test/json/node.json +0 -29
  47. data/test/json/node_list.json +0 -37
  48. data/test/json/node_notice.json +0 -160
  49. data/test/json/persistent_volume.json +0 -37
  50. data/test/json/persistent_volume_claim.json +0 -32
  51. data/test/json/persistent_volume_claim_list.json +0 -40
  52. data/test/json/persistent_volume_claims_nil_items.json +0 -8
  53. data/test/json/persistent_volume_list.json +0 -45
  54. data/test/json/pod.json +0 -92
  55. data/test/json/pod_list.json +0 -79
  56. data/test/json/pod_template_list.json +0 -9
  57. data/test/json/pods_1.json +0 -265
  58. data/test/json/pods_2.json +0 -102
  59. data/test/json/pods_410.json +0 -9
  60. data/test/json/processed_template.json +0 -27
  61. data/test/json/replication_controller.json +0 -57
  62. data/test/json/replication_controller_list.json +0 -66
  63. data/test/json/resource_quota.json +0 -46
  64. data/test/json/resource_quota_list.json +0 -54
  65. data/test/json/secret_list.json +0 -44
  66. data/test/json/security.openshift.io_api_resource_list.json +0 -69
  67. data/test/json/security_context_constraint_list.json +0 -375
  68. data/test/json/service.json +0 -33
  69. data/test/json/service_account.json +0 -25
  70. data/test/json/service_account_list.json +0 -82
  71. data/test/json/service_illegal_json_404.json +0 -1
  72. data/test/json/service_json_patch.json +0 -26
  73. data/test/json/service_list.json +0 -97
  74. data/test/json/service_merge_patch.json +0 -26
  75. data/test/json/service_patch.json +0 -25
  76. data/test/json/service_update.json +0 -22
  77. data/test/json/template.json +0 -27
  78. data/test/json/template.openshift.io_api_resource_list.json +0 -75
  79. data/test/json/template_list.json +0 -35
  80. data/test/json/versions_list.json +0 -6
  81. data/test/json/watch_stream.json +0 -3
  82. data/test/test_common.rb +0 -95
  83. data/test/test_common_url_handling.rb +0 -160
  84. data/test/test_component_status.rb +0 -29
  85. data/test/test_config.rb +0 -222
  86. data/test/test_endpoint.rb +0 -54
  87. data/test/test_exec_credentials.rb +0 -225
  88. data/test/test_gcp_command_credentials.rb +0 -27
  89. data/test/test_google_application_default_credentials.rb +0 -15
  90. data/test/test_guestbook_go.rb +0 -235
  91. data/test/test_helper.rb +0 -18
  92. data/test/test_kubeclient.rb +0 -881
  93. data/test/test_limit_range.rb +0 -25
  94. data/test/test_missing_methods.rb +0 -80
  95. data/test/test_namespace.rb +0 -59
  96. data/test/test_node.rb +0 -70
  97. data/test/test_oidc_auth_provider.rb +0 -103
  98. data/test/test_persistent_volume.rb +0 -29
  99. data/test/test_persistent_volume_claim.rb +0 -28
  100. data/test/test_pod.rb +0 -81
  101. data/test/test_pod_log.rb +0 -157
  102. data/test/test_process_template.rb +0 -80
  103. data/test/test_replication_controller.rb +0 -47
  104. data/test/test_resource_list_without_kind.rb +0 -78
  105. data/test/test_resource_quota.rb +0 -23
  106. data/test/test_secret.rb +0 -62
  107. data/test/test_security_context_constraint.rb +0 -62
  108. data/test/test_service.rb +0 -357
  109. data/test/test_service_account.rb +0 -26
  110. data/test/test_watch.rb +0 -195
  111. data/test/txt/pod_log.txt +0 -6
  112. data/test/valid_token_file +0 -1
@@ -1,225 +0,0 @@
1
- require_relative 'test_helper'
2
- require 'open3'
3
-
4
- # Unit tests for the ExecCredentials provider
5
- class ExecCredentialsTest < MiniTest::Test
6
- def test_exec_opts_missing
7
- expected_msg =
8
- 'exec options are required'
9
- exception = assert_raises(ArgumentError) do
10
- Kubeclient::ExecCredentials.run(nil)
11
- end
12
- assert_equal(expected_msg, exception.message)
13
- end
14
-
15
- def test_exec_command_missing
16
- expected_msg =
17
- 'exec command is required'
18
- exception = assert_raises(KeyError) do
19
- Kubeclient::ExecCredentials.run({})
20
- end
21
- assert_equal(expected_msg, exception.message)
22
- end
23
-
24
- def test_exec_command_failure
25
- err = 'Error'
26
- expected_msg =
27
- "exec command failed: #{err}"
28
-
29
- st = Minitest::Mock.new
30
- st.expect(:success?, false)
31
-
32
- opts = { 'command' => 'dummy' }
33
-
34
- Open3.stub(:capture3, [nil, err, st]) do
35
- exception = assert_raises(RuntimeError) do
36
- Kubeclient::ExecCredentials.run(opts)
37
- end
38
- assert_equal(expected_msg, exception.message)
39
- end
40
- end
41
-
42
- def test_run_with_token_credentials
43
- opts = { 'command' => 'dummy' }
44
-
45
- credentials = {
46
- 'token' => '0123456789ABCDEF0123456789ABCDEF'
47
- }
48
-
49
- creds = JSON.dump(
50
- 'apiVersion' => 'client.authentication.k8s.io/v1alpha1',
51
- 'status' => credentials
52
- )
53
-
54
- st = Minitest::Mock.new
55
- st.expect(:success?, true)
56
-
57
- Open3.stub(:capture3, [creds, nil, st]) do
58
- assert_equal(credentials, Kubeclient::ExecCredentials.run(opts))
59
- end
60
- end
61
-
62
- def test_run_with_client_credentials
63
- opts = { 'command' => 'dummy' }
64
-
65
- credentials = {
66
- 'clientCertificateData' => '0123456789ABCDEF0123456789ABCDEF',
67
- 'clientKeyData' => '0123456789ABCDEF0123456789ABCDEF'
68
- }
69
-
70
- creds = JSON.dump(
71
- 'apiVersion' => 'client.authentication.k8s.io/v1alpha1',
72
- 'status' => credentials
73
- )
74
-
75
- st = Minitest::Mock.new
76
- st.expect(:success?, true)
77
-
78
- Open3.stub(:capture3, [creds, nil, st]) do
79
- assert_equal(credentials, Kubeclient::ExecCredentials.run(opts))
80
- end
81
- end
82
-
83
- def test_run_with_missing_client_certificate_data
84
- opts = { 'command' => 'dummy' }
85
-
86
- credentials = {
87
- 'clientKeyData' => '0123456789ABCDEF0123456789ABCDEF'
88
- }
89
-
90
- creds = JSON.dump(
91
- 'apiVersion' => 'client.authentication.k8s.io/v1alpha1',
92
- 'status' => credentials
93
- )
94
-
95
- st = Minitest::Mock.new
96
- st.expect(:success?, true)
97
-
98
- expected_msg = 'exec plugin didn\'t return client certificate data'
99
-
100
- Open3.stub(:capture3, [creds, nil, st]) do
101
- exception = assert_raises(RuntimeError) do
102
- Kubeclient::ExecCredentials.run(opts)
103
- end
104
- assert_equal(expected_msg, exception.message)
105
- end
106
- end
107
-
108
- def test_run_with_missing_client_key_data
109
- opts = { 'command' => 'dummy' }
110
-
111
- credentials = {
112
- 'clientCertificateData' => '0123456789ABCDEF0123456789ABCDEF'
113
- }
114
-
115
- creds = JSON.dump(
116
- 'apiVersion' => 'client.authentication.k8s.io/v1alpha1',
117
- 'status' => credentials
118
- )
119
-
120
- st = Minitest::Mock.new
121
- st.expect(:success?, true)
122
-
123
- expected_msg = 'exec plugin didn\'t return client key data'
124
-
125
- Open3.stub(:capture3, [creds, nil, st]) do
126
- exception = assert_raises(RuntimeError) do
127
- Kubeclient::ExecCredentials.run(opts)
128
- end
129
- assert_equal(expected_msg, exception.message)
130
- end
131
- end
132
-
133
- def test_run_with_client_data_and_token
134
- opts = { 'command' => 'dummy' }
135
-
136
- credentials = {
137
- 'clientCertificateData' => '0123456789ABCDEF0123456789ABCDEF',
138
- 'clientKeyData' => '0123456789ABCDEF0123456789ABCDEF',
139
- 'token' => '0123456789ABCDEF0123456789ABCDEF'
140
- }
141
-
142
- creds = JSON.dump(
143
- 'apiVersion' => 'client.authentication.k8s.io/v1alpha1',
144
- 'status' => credentials
145
- )
146
-
147
- st = Minitest::Mock.new
148
- st.expect(:success?, true)
149
-
150
- expected_msg = 'exec plugin returned both token and client data'
151
-
152
- Open3.stub(:capture3, [creds, nil, st]) do
153
- exception = assert_raises(RuntimeError) do
154
- Kubeclient::ExecCredentials.run(opts)
155
- end
156
- assert_equal(expected_msg, exception.message)
157
- end
158
- end
159
-
160
- def test_status_missing
161
- opts = { 'command' => 'dummy' }
162
-
163
- creds = JSON.dump('apiVersion' => 'client.authentication.k8s.io/v1alpha1')
164
-
165
- st = Minitest::Mock.new
166
- st.expect(:success?, true)
167
-
168
- expected_msg = 'exec plugin didn\'t return a status field'
169
-
170
- Open3.stub(:capture3, [creds, nil, st]) do
171
- exception = assert_raises(RuntimeError) do
172
- Kubeclient::ExecCredentials.run(opts)
173
- end
174
- assert_equal(expected_msg, exception.message)
175
- end
176
- end
177
-
178
- def test_credentials_missing
179
- opts = { 'command' => 'dummy' }
180
-
181
- creds = JSON.dump(
182
- 'apiVersion' => 'client.authentication.k8s.io/v1alpha1',
183
- 'status' => {}
184
- )
185
-
186
- st = Minitest::Mock.new
187
- st.expect(:success?, true)
188
-
189
- expected_msg = 'exec plugin didn\'t return a token or client data'
190
-
191
- Open3.stub(:capture3, [creds, nil, st]) do
192
- exception = assert_raises(RuntimeError) do
193
- Kubeclient::ExecCredentials.run(opts)
194
- end
195
- assert_equal(expected_msg, exception.message)
196
- end
197
- end
198
-
199
- def test_api_version_mismatch
200
- api_version = 'client.authentication.k8s.io/v1alpha1'
201
- expected_version = 'client.authentication.k8s.io/v1beta1'
202
-
203
- opts = {
204
- 'command' => 'dummy',
205
- 'apiVersion' => expected_version
206
- }
207
-
208
- creds = JSON.dump(
209
- 'apiVersion' => api_version
210
- )
211
-
212
- st = Minitest::Mock.new
213
- st.expect(:success?, true)
214
-
215
- expected_msg = "exec plugin is configured to use API version #{expected_version}," \
216
- " plugin returned version #{api_version}"
217
-
218
- Open3.stub(:capture3, [creds, nil, st]) do
219
- exception = assert_raises(RuntimeError) do
220
- Kubeclient::ExecCredentials.run(opts)
221
- end
222
- assert_equal(expected_msg, exception.message)
223
- end
224
- end
225
- end
@@ -1,27 +0,0 @@
1
- require_relative 'test_helper'
2
- require 'open3'
3
-
4
- # Unit tests for the GCPCommandCredentials token provider
5
- class GCPCommandCredentialsTest < MiniTest::Test
6
- def test_token
7
- opts = { 'cmd-args' => 'config config-helper --format=json',
8
- 'cmd-path' => '/path/to/gcloud',
9
- 'expiry-key' => '{.credential.token_expiry}',
10
- 'token-key' => '{.credential.access_token}' }
11
-
12
- creds = JSON.dump(
13
- 'credential' => {
14
- 'access_token' => '9A3A941836F2458175BE18AA1971EBBF47949B07',
15
- 'token_expiry' => '2019-04-12T15:02:51Z'
16
- }
17
- )
18
-
19
- st = Minitest::Mock.new
20
- st.expect(:success?, true)
21
-
22
- Open3.stub(:capture3, [creds, nil, st]) do
23
- assert_equal('9A3A941836F2458175BE18AA1971EBBF47949B07',
24
- Kubeclient::GCPCommandCredentials.token(opts))
25
- end
26
- end
27
- end
@@ -1,15 +0,0 @@
1
- require_relative 'test_helper'
2
- require 'googleauth'
3
-
4
- # Unit tests for the ApplicationDefaultCredentials token provider
5
- class GoogleApplicationDefaultCredentialsTest < MiniTest::Test
6
- def test_token
7
- auth = Minitest::Mock.new
8
- auth.expect(:apply, nil, [{}])
9
- auth.expect(:access_token, 'valid_token')
10
-
11
- Google::Auth.stub(:get_application_default, auth) do
12
- assert_equal('valid_token', Kubeclient::GoogleApplicationDefaultCredentials.token)
13
- end
14
- end
15
- end
@@ -1,235 +0,0 @@
1
- require_relative 'test_helper'
2
- require 'vcr'
3
-
4
- # creation of google's example of guest book
5
- class CreateGuestbookGo < MiniTest::Test
6
- def test_create_guestbook_entities
7
- VCR.configure do |c|
8
- c.cassette_library_dir = 'test/cassettes'
9
- c.hook_into(:webmock)
10
- end
11
-
12
- # WebMock.allow_net_connect!
13
- VCR.use_cassette('kubernetes_guestbook') do # , record: :new_episodes) do
14
- client = Kubeclient::Client.new('http://10.35.0.23:8080/api/', 'v1')
15
-
16
- testing_ns = Kubeclient::Resource.new
17
- testing_ns.metadata = {}
18
- testing_ns.metadata.name = 'kubeclient-ns'
19
-
20
- # delete in case they existed before so creation can be tested
21
- delete_namespace(client, testing_ns.metadata.name)
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)
32
- services = create_services(client, testing_ns.metadata.name)
33
- replicators = create_replication_controllers(client, testing_ns.metadata.name)
34
-
35
- get_namespaces(client)
36
- get_services(client, testing_ns.metadata.name)
37
- get_replication_controllers(client, testing_ns.metadata.name)
38
-
39
- delete_services(client, testing_ns.metadata.name, services)
40
- delete_replication_controllers(client, testing_ns.metadata.name, replicators)
41
-
42
- client.delete_namespace(testing_ns.metadata.name)
43
- end
44
- end
45
-
46
- def delete_namespace(client, namespace_name)
47
- client.delete_namespace(namespace_name)
48
- rescue Kubeclient::ResourceNotFoundError => exception
49
- assert_equal(404, exception.error_code)
50
- end
51
-
52
- def get_namespaces(client)
53
- namespaces = client.get_namespaces
54
- assert(true, namespaces.size > 2)
55
- end
56
-
57
- def get_services(client, ns)
58
- retrieved_services = client.get_services(namespace: ns)
59
- assert_equal(3, retrieved_services.size)
60
- end
61
-
62
- def get_replication_controllers(client, ns)
63
- retrieved_replicators = client.get_replication_controllers(namespace: ns)
64
- assert_equal(3, retrieved_replicators.size)
65
- end
66
-
67
- def create_services(client, 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))
71
- [guestbook_service, redis_service, redis_slave_service]
72
- end
73
-
74
- def create_replication_controllers(client, 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))
78
- [rc, rc2, rc3]
79
- end
80
-
81
- def delete_services(client, namespace, services)
82
- # if the entity is not found, no need to fail the test
83
- services.each do |service|
84
- begin
85
- if service.instance_of?(Kubeclient::Resource)
86
- client.delete_service(service.metadata.name, namespace)
87
- else
88
- # it's just a string - service name
89
- client.delete_service(service, namespace)
90
- end
91
- rescue Kubeclient::ResourceNotFoundError => exception
92
- assert_equal(404, exception.error_code)
93
- end
94
- end
95
- end
96
-
97
- def delete_replication_controllers(client, namespace, replication_controllers)
98
- # if the entity is not found, no need to fail the test
99
- replication_controllers.each do |rc|
100
- begin
101
- if rc.instance_of?(Kubeclient::Resource)
102
- client.delete_replication_controller(rc.metadata.name, namespace)
103
- else
104
- # it's just a string - rc name
105
- client.delete_replication_controller(rc, namespace)
106
- end
107
- rescue Kubeclient::ResourceNotFoundError => exception
108
- assert_equal(404, exception.error_code)
109
- end
110
- end
111
- end
112
-
113
- private
114
-
115
- def construct_base_rc(namespace)
116
- rc = Kubeclient::Resource.new
117
- rc.metadata = {}
118
- rc.metadata.namespace = namespace
119
- rc.metadata.labels = {}
120
- rc.spec = {}
121
- rc.spec.selector = {}
122
- rc.spec.template = {}
123
- rc.spec.template.metadata = {}
124
- rc.spec.template.spec = {}
125
- rc.spec.template.metadata.labels = {}
126
- rc
127
- end
128
-
129
- def redis_master_rc(namespace)
130
- rc = construct_base_rc(namespace)
131
- rc.metadata.name = 'redis-master'
132
- rc.metadata.labels.app = 'redis'
133
- rc.metadata.labels.role = 'master'
134
- rc.spec.replicas = 1
135
- rc.spec.selector.app = 'redis'
136
- rc.spec.selector.role = 'master'
137
- rc.spec.template.metadata.labels.app = 'redis'
138
- rc.spec.template.metadata.labels.role = 'master'
139
- rc.spec.template.spec.containers = [{
140
- 'name' => 'redis-master',
141
- 'image' => 'redis',
142
- 'ports' => [{
143
- 'name' => 'redis-server',
144
- 'containerPort' => 6379
145
- }]
146
- }]
147
- rc
148
- end
149
-
150
- def redis_slave_rc(namespace)
151
- rc = construct_base_rc(namespace)
152
- rc.metadata.name = 'redis-slave'
153
- rc.metadata.labels.app = 'redis'
154
- rc.metadata.labels.role = 'slave'
155
- rc.spec.replicas = 2
156
- rc.spec.selector.app = 'redis'
157
- rc.spec.selector.role = 'slave'
158
- rc.spec.template.metadata.labels.app = 'redis'
159
- rc.spec.template.metadata.labels.role = 'slave'
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
- }]
168
- rc
169
- end
170
-
171
- def guestbook_rc(namespace)
172
- rc = construct_base_rc(namespace)
173
- rc.metadata.name = 'guestbook'
174
- rc.metadata.labels.app = 'guestbook'
175
- rc.metadata.labels.role = 'slave'
176
- rc.spec.replicas = 3
177
- rc.spec.selector.app = 'guestbook'
178
- rc.spec.template.metadata.labels.app = 'guestbook'
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
- ]
191
- rc
192
- end
193
-
194
- def base_service(namespace)
195
- our_service = Kubeclient::Resource.new
196
- our_service.metadata = {}
197
- our_service.metadata.namespace = namespace
198
- our_service.metadata.labels = {}
199
- our_service.spec = {}
200
- our_service.spec.selector = {}
201
- our_service
202
- end
203
-
204
- def redis_slave_service(namespace)
205
- our_service = base_service(namespace)
206
- our_service.metadata.name = 'redis-slave'
207
- our_service.metadata.labels.app = 'redis'
208
- our_service.metadata.labels.role = 'slave'
209
- our_service.spec.ports = [{ 'port' => 6379, 'targetPort' => 'redis-server' }]
210
- our_service.spec.selector.app = 'redis'
211
- our_service.spec.selector.role = 'slave'
212
- our_service
213
- end
214
-
215
- def redis_service(namespace)
216
- our_service = base_service(namespace)
217
- our_service.metadata.name = 'redis-master'
218
- our_service.metadata.labels.app = 'redis'
219
- our_service.metadata.labels.role = 'master'
220
- our_service.spec.ports = [{ 'port' => 6379, 'targetPort' => 'redis-server' }]
221
- our_service.spec.selector.app = 'redis'
222
- our_service.spec.selector.role = 'master'
223
- our_service
224
- end
225
-
226
- def guestbook_service(namespace)
227
- our_service = base_service(namespace)
228
- our_service.metadata.name = 'guestbook'
229
- our_service.metadata.labels.name = 'guestbook'
230
- our_service.spec.ports = [{ 'port' => 3000, 'targetPort' => 'http-server' }]
231
- our_service.spec.selector.app = 'guestbook'
232
- our_service.type = 'LoadBalancer'
233
- our_service
234
- end
235
- end