kubeclient 4.9.1 → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/actions.yml +43 -0
  3. data/CHANGELOG.md +65 -0
  4. data/README.md +6 -0
  5. data/kubeclient.gemspec +7 -3
  6. data/lib/kubeclient/common.rb +31 -19
  7. data/lib/kubeclient/config.rb +22 -10
  8. data/lib/kubeclient/version.rb +1 -1
  9. data/lib/kubeclient/watch_stream.rb +1 -0
  10. metadata +40 -218
  11. data/.travis.yml +0 -29
  12. data/test/cassettes/kubernetes_guestbook.yml +0 -879
  13. data/test/config/allinone.kubeconfig +0 -20
  14. data/test/config/execauth.kubeconfig +0 -62
  15. data/test/config/external-ca.pem +0 -18
  16. data/test/config/external-cert.pem +0 -19
  17. data/test/config/external-key.rsa +0 -27
  18. data/test/config/external.kubeconfig +0 -20
  19. data/test/config/gcpauth.kubeconfig +0 -22
  20. data/test/config/gcpcmdauth.kubeconfig +0 -26
  21. data/test/config/nouser.kubeconfig +0 -16
  22. data/test/config/oidcauth.kubeconfig +0 -25
  23. data/test/config/timestamps.kubeconfig +0 -25
  24. data/test/config/userauth.kubeconfig +0 -28
  25. data/test/json/bindings_list.json +0 -10
  26. data/test/json/component_status.json +0 -17
  27. data/test/json/component_status_list.json +0 -52
  28. data/test/json/config.istio.io_api_resource_list.json +0 -679
  29. data/test/json/config_map_list.json +0 -9
  30. data/test/json/core_api_resource_list.json +0 -181
  31. data/test/json/core_api_resource_list_without_kind.json +0 -129
  32. data/test/json/core_oapi_resource_list_without_kind.json +0 -197
  33. data/test/json/created_endpoint.json +0 -28
  34. data/test/json/created_namespace.json +0 -20
  35. data/test/json/created_secret.json +0 -16
  36. data/test/json/created_security_context_constraint.json +0 -65
  37. data/test/json/created_service.json +0 -31
  38. data/test/json/empty_pod_list.json +0 -9
  39. data/test/json/endpoint_list.json +0 -48
  40. data/test/json/entity_list.json +0 -56
  41. data/test/json/event_list.json +0 -35
  42. data/test/json/extensions_v1beta1_api_resource_list.json +0 -217
  43. data/test/json/limit_range.json +0 -23
  44. data/test/json/limit_range_list.json +0 -31
  45. data/test/json/namespace.json +0 -13
  46. data/test/json/namespace_exception.json +0 -8
  47. data/test/json/namespace_list.json +0 -32
  48. data/test/json/node.json +0 -29
  49. data/test/json/node_list.json +0 -37
  50. data/test/json/node_notice.json +0 -160
  51. data/test/json/persistent_volume.json +0 -37
  52. data/test/json/persistent_volume_claim.json +0 -32
  53. data/test/json/persistent_volume_claim_list.json +0 -40
  54. data/test/json/persistent_volume_claims_nil_items.json +0 -8
  55. data/test/json/persistent_volume_list.json +0 -45
  56. data/test/json/pod.json +0 -92
  57. data/test/json/pod_list.json +0 -79
  58. data/test/json/pod_template_list.json +0 -9
  59. data/test/json/pods_1.json +0 -265
  60. data/test/json/pods_2.json +0 -102
  61. data/test/json/pods_410.json +0 -9
  62. data/test/json/processed_template.json +0 -27
  63. data/test/json/replication_controller.json +0 -57
  64. data/test/json/replication_controller_list.json +0 -66
  65. data/test/json/resource_quota.json +0 -46
  66. data/test/json/resource_quota_list.json +0 -54
  67. data/test/json/secret_list.json +0 -44
  68. data/test/json/security.openshift.io_api_resource_list.json +0 -69
  69. data/test/json/security_context_constraint_list.json +0 -375
  70. data/test/json/service.json +0 -33
  71. data/test/json/service_account.json +0 -25
  72. data/test/json/service_account_list.json +0 -82
  73. data/test/json/service_illegal_json_404.json +0 -1
  74. data/test/json/service_json_patch.json +0 -26
  75. data/test/json/service_list.json +0 -97
  76. data/test/json/service_merge_patch.json +0 -26
  77. data/test/json/service_patch.json +0 -25
  78. data/test/json/service_update.json +0 -22
  79. data/test/json/template.json +0 -27
  80. data/test/json/template.openshift.io_api_resource_list.json +0 -75
  81. data/test/json/template_list.json +0 -35
  82. data/test/json/versions_list.json +0 -6
  83. data/test/json/watch_stream.json +0 -3
  84. data/test/test_common.rb +0 -95
  85. data/test/test_common_url_handling.rb +0 -160
  86. data/test/test_component_status.rb +0 -29
  87. data/test/test_config.rb +0 -222
  88. data/test/test_endpoint.rb +0 -54
  89. data/test/test_exec_credentials.rb +0 -225
  90. data/test/test_gcp_command_credentials.rb +0 -27
  91. data/test/test_google_application_default_credentials.rb +0 -15
  92. data/test/test_guestbook_go.rb +0 -235
  93. data/test/test_helper.rb +0 -18
  94. data/test/test_kubeclient.rb +0 -881
  95. data/test/test_limit_range.rb +0 -25
  96. data/test/test_missing_methods.rb +0 -80
  97. data/test/test_namespace.rb +0 -59
  98. data/test/test_node.rb +0 -70
  99. data/test/test_oidc_auth_provider.rb +0 -103
  100. data/test/test_persistent_volume.rb +0 -29
  101. data/test/test_persistent_volume_claim.rb +0 -28
  102. data/test/test_pod.rb +0 -81
  103. data/test/test_pod_log.rb +0 -157
  104. data/test/test_process_template.rb +0 -80
  105. data/test/test_replication_controller.rb +0 -47
  106. data/test/test_resource_list_without_kind.rb +0 -78
  107. data/test/test_resource_quota.rb +0 -23
  108. data/test/test_secret.rb +0 -62
  109. data/test/test_security_context_constraint.rb +0 -62
  110. data/test/test_service.rb +0 -357
  111. data/test/test_service_account.rb +0 -26
  112. data/test/test_watch.rb +0 -195
  113. data/test/txt/pod_log.txt +0 -6
  114. data/test/valid_token_file +0 -1
@@ -1,80 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- # Process Template tests
4
- class TestProcessTemplate < MiniTest::Test
5
- def test_process_template
6
- client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
7
- template = {}
8
- template[:metadata] = {}
9
- template[:metadata][:name] = 'my-template'
10
- template[:metadata][:namespace] = 'default'
11
- template[:kind] = 'Template'
12
- template[:apiVersion] = 'v1'
13
- service = {}
14
- service[:metadata] = {}
15
- service[:metadata][:name] = '${NAME_PREFIX}my-service'
16
- service[:kind] = 'Service'
17
- service[:apiVersion] = 'v1'
18
- template[:objects] = [service]
19
- param = { name: 'NAME_PREFIX', value: 'test/' }
20
- template[:parameters] = [param]
21
-
22
- req_body = '{"metadata":{"name":"my-template","namespace":"default"},' \
23
- '"kind":"Template","apiVersion":"v1","objects":[{"metadata":' \
24
- '{"name":"${NAME_PREFIX}my-service"},"kind":"Service","apiVersion":"v1"}],' \
25
- '"parameters":[{"name":"NAME_PREFIX","value":"test/"}]}'
26
-
27
- expected_url = 'http://localhost:8080/api/v1/namespaces/default/processedtemplates'
28
- stub_request(:post, expected_url)
29
- .with(body: req_body, headers: { 'Content-Type' => 'application/json' })
30
- .to_return(body: open_test_file('processed_template.json'), status: 200)
31
-
32
- processed_template = client.process_template(template)
33
-
34
- assert_equal('test/my-service', processed_template['objects'].first['metadata']['name'])
35
-
36
- assert_requested(:post, expected_url, times: 1) do |req|
37
- data = JSON.parse(req.body)
38
- data['kind'] == 'Template' &&
39
- data['apiVersion'] == 'v1' &&
40
- data['metadata']['name'] == 'my-template' &&
41
- data['metadata']['namespace'] == 'default'
42
- end
43
- end
44
-
45
- # Ensure _template and _templates methods hit `/templates` rather than
46
- # `/processedtemplates` URL.
47
- def test_templates_methods
48
- stub_request(:get, %r{/apis/template\.openshift\.io/v1$}).to_return(
49
- body: open_test_file('template.openshift.io_api_resource_list.json'),
50
- status: 200
51
- )
52
- client = Kubeclient::Client.new('http://localhost:8080/apis/template.openshift.io', 'v1')
53
-
54
- expected_url = 'http://localhost:8080/apis/template.openshift.io/v1/namespaces/default/templates'
55
- stub_request(:get, expected_url)
56
- .to_return(body: open_test_file('template_list.json'), status: 200)
57
- client.get_templates(namespace: 'default')
58
- assert_requested(:get, expected_url, times: 1)
59
-
60
- expected_url = 'http://localhost:8080/apis/template.openshift.io/v1/namespaces/default/templates/my-template'
61
- stub_request(:get, expected_url)
62
- .to_return(body: open_test_file('template.json'), status: 200)
63
- client.get_template('my-template', 'default')
64
- assert_requested(:get, expected_url, times: 1)
65
- end
66
-
67
- def test_no_processedtemplates_methods
68
- stub_request(:get, %r{/apis/template\.openshift\.io/v1$}).to_return(
69
- body: open_test_file('template.openshift.io_api_resource_list.json'),
70
- status: 200
71
- )
72
- client = Kubeclient::Client.new('http://localhost:8080/apis/template.openshift.io', 'v1')
73
- client.discover
74
-
75
- refute_respond_to(client, :get_processedtemplates)
76
- refute_respond_to(client, :get_processedtemplate)
77
- refute_respond_to(client, :get_processed_templates)
78
- refute_respond_to(client, :get_processed_template)
79
- end
80
- end
@@ -1,47 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- # Replication Controller entity tests
4
- class TestReplicationController < MiniTest::Test
5
- def test_get_from_json_v1
6
- stub_core_api_list
7
- stub_request(:get, %r{/replicationcontrollers})
8
- .to_return(body: open_test_file('replication_controller.json'),
9
- status: 200)
10
-
11
- client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
12
- rc = client.get_replication_controller('frontendController', 'default')
13
-
14
- assert_instance_of(Kubeclient::Resource, rc)
15
- assert_equal('guestbook-controller', rc.metadata.name)
16
- assert_equal('c71aa4c0-a240-11e4-a265-3c970e4a436a', rc.metadata.uid)
17
- assert_equal('default', rc.metadata.namespace)
18
- assert_equal(3, rc.spec.replicas)
19
- assert_equal('guestbook', rc.spec.selector.name)
20
-
21
- assert_requested(:get,
22
- 'http://localhost:8080/api/v1/namespaces/default/replicationcontrollers/frontendController',
23
- times: 1)
24
- end
25
-
26
- def test_delete_replicaset_cascade
27
- stub_core_api_list
28
- client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
29
- opts = Kubeclient::Resource.new(
30
- apiVersion: 'meta/v1',
31
- gracePeriodSeconds: 0,
32
- kind: 'DeleteOptions',
33
- propagationPolicy: 'Foreground'
34
- )
35
-
36
- stub_request(:delete,
37
- 'http://localhost:8080/api/v1/namespaces/default/replicationcontrollers/frontendController')
38
- .with(body: opts.to_hash.to_json)
39
- .to_return(status: 200, body: open_test_file('replication_controller.json'), headers: {})
40
- rc = client.delete_replication_controller('frontendController', 'default', delete_options: opts)
41
- assert_kind_of(RecursiveOpenStruct, rc)
42
-
43
- assert_requested(:delete,
44
- 'http://localhost:8080/api/v1/namespaces/default/replicationcontrollers/frontendController',
45
- times: 1)
46
- end
47
- end
@@ -1,78 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- # Core api resource list without kind tests
4
- class TestResourceListWithoutKind < MiniTest::Test
5
- def test_get_from_json_api_v1
6
- stub_request(:get, %r{/api/v1$})
7
- .to_return(body: open_test_file('core_api_resource_list_without_kind.json'),
8
- status: 200)
9
-
10
- client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
11
- client.discover
12
-
13
- [
14
- {
15
- entity: 'pod',
16
- type: 'Pod',
17
- name: 'pods',
18
- methods: %w[pod pods]
19
- },
20
- {
21
- entity: 'node',
22
- type: 'Node',
23
- name: 'nodes',
24
- methods: %w[node nodes]
25
- },
26
- {
27
- entity: 'service',
28
- type: 'Service',
29
- name: 'services',
30
- methods: %w[service services]
31
- }
32
- ].each { |h| assert_entities(client.instance_variable_get(:@entities)[h[:entity]], h) }
33
-
34
- assert_requested(:get,
35
- 'http://localhost:8080/api/v1',
36
- times: 1)
37
- end
38
-
39
- def test_get_from_json_oapi_v1
40
- stub_request(:get, %r{/oapi/v1$})
41
- .to_return(body: open_test_file('core_oapi_resource_list_without_kind.json'),
42
- status: 200)
43
-
44
- client = Kubeclient::Client.new('http://localhost:8080/oapi/', 'v1')
45
- client.discover
46
-
47
- [
48
- {
49
- entity: 'template',
50
- type: 'Template',
51
- name: 'templates',
52
- methods: %w[template templates]
53
- },
54
- {
55
- entity: 'build',
56
- type: 'Build',
57
- name: 'builds',
58
- methods: %w[build builds]
59
- },
60
- {
61
- entity: 'project',
62
- type: 'Project',
63
- name: 'projects',
64
- methods: %w[project projects]
65
- }
66
- ].each { |h| assert_entities(client.instance_variable_get(:@entities)[h[:entity]], h) }
67
-
68
- assert_requested(:get,
69
- 'http://localhost:8080/oapi/v1',
70
- times: 1)
71
- end
72
-
73
- def assert_entities(entity, h)
74
- assert_equal(entity.entity_type, h[:type])
75
- assert_equal(entity.resource_name, h[:name])
76
- assert_equal(entity.method_names, h[:methods])
77
- end
78
- end
@@ -1,23 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- # ResourceQuota tests
4
- class TestResourceQuota < MiniTest::Test
5
- def test_get_from_json_v1
6
- stub_core_api_list
7
- stub_request(:get, %r{/resourcequotas})
8
- .to_return(body: open_test_file('resource_quota.json'),
9
- status: 200)
10
-
11
- client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
12
- quota = client.get_resource_quota('quota', 'quota-example')
13
-
14
- assert_instance_of(Kubeclient::Resource, quota)
15
- assert_equal('quota', quota.metadata.name)
16
- assert_equal('20', quota.spec.hard.cpu)
17
- assert_equal('10', quota.spec.hard.secrets)
18
-
19
- assert_requested(:get,
20
- 'http://localhost:8080/api/v1/namespaces/quota-example/resourcequotas/quota',
21
- times: 1)
22
- end
23
- end
data/test/test_secret.rb DELETED
@@ -1,62 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- # Namespace entity tests
4
- class TestSecret < MiniTest::Test
5
- def test_get_secret_v1
6
- stub_core_api_list
7
- stub_request(:get, %r{/secrets})
8
- .to_return(body: open_test_file('created_secret.json'),
9
- status: 200)
10
-
11
- client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
12
- secret = client.get_secret('test-secret', 'dev')
13
-
14
- assert_instance_of(Kubeclient::Resource, secret)
15
- assert_equal('4e38a198-2bcb-11e5-a483-0e840567604d', secret.metadata.uid)
16
- assert_equal('test-secret', secret.metadata.name)
17
- assert_equal('v1', secret.apiVersion)
18
- assert_equal('Y2F0J3MgYXJlIGF3ZXNvbWUK', secret.data['super-secret'])
19
-
20
- assert_requested(:get,
21
- 'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
22
- times: 1)
23
- end
24
-
25
- def test_delete_secret_v1
26
- stub_core_api_list
27
- stub_request(:delete, %r{/secrets})
28
- .to_return(status: 200, body: open_test_file('created_secret.json'))
29
-
30
- client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
31
- secret = client.delete_secret('test-secret', 'dev')
32
- assert_kind_of(RecursiveOpenStruct, secret)
33
-
34
- assert_requested(:delete,
35
- 'http://localhost:8080/api/v1/namespaces/dev/secrets/test-secret',
36
- times: 1)
37
- end
38
-
39
- def test_create_secret_v1
40
- stub_core_api_list
41
- stub_request(:post, %r{/secrets})
42
- .to_return(body: open_test_file('created_secret.json'),
43
- status: 201)
44
-
45
- secret = Kubeclient::Resource.new
46
- secret.metadata = {}
47
- secret.metadata.name = 'test-secret'
48
- secret.metadata.namespace = 'dev'
49
- secret.data = {}
50
- secret.data['super-secret'] = 'Y2F0J3MgYXJlIGF3ZXNvbWUK'
51
-
52
- client = Kubeclient::Client.new('http://localhost:8080/api/')
53
- created_secret = client.create_secret(secret)
54
- assert_instance_of(Kubeclient::Resource, created_secret)
55
- assert_equal(secret.metadata.name, created_secret.metadata.name)
56
- assert_equal(secret.metadata.namespace, created_secret.metadata.namespace)
57
- assert_equal(
58
- secret.data['super-secret'],
59
- created_secret.data['super-secret']
60
- )
61
- end
62
- end
@@ -1,62 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- # kind: 'SecurityContextConstraints' entity tests.
4
- # This is one of the unusual `kind`s that are already plural (https://github.com/kubernetes/kubernetes/issues/8115).
5
- # We force singular in method names like 'create_endpoint',
6
- # but `kind` should remain plural as in kubernetes.
7
- class TestSecurityContextConstraints < MiniTest::Test
8
- def test_create_security_context_constraint
9
- stub_request(:get, %r{/apis/security.openshift.io/v1$}).to_return(
10
- body: open_test_file('security.openshift.io_api_resource_list.json'),
11
- status: 200
12
- )
13
-
14
- testing_scc = Kubeclient::Resource.new(
15
- metadata: {
16
- name: 'teleportation'
17
- },
18
- runAsUser: {
19
- type: 'MustRunAs'
20
- },
21
- seLinuxContext: {
22
- type: 'MustRunAs'
23
- }
24
- )
25
- req_body = '{"metadata":{"name":"teleportation"},"runAsUser":{"type":"MustRunAs"},' \
26
- '"seLinuxContext":{"type":"MustRunAs"},' \
27
- '"kind":"SecurityContextConstraints","apiVersion":"security.openshift.io/v1"}'
28
-
29
- stub_request(:post, 'http://localhost:8080/apis/security.openshift.io/v1/securitycontextconstraints')
30
- .with(body: req_body)
31
- .to_return(body: open_test_file('created_security_context_constraint.json'), status: 201)
32
-
33
- client = Kubeclient::Client.new('http://localhost:8080/apis/security.openshift.io', 'v1')
34
- created_scc = client.create_security_context_constraint(testing_scc)
35
- assert_equal('SecurityContextConstraints', created_scc.kind)
36
- assert_equal('security.openshift.io/v1', created_scc.apiVersion)
37
-
38
- client = Kubeclient::Client.new('http://localhost:8080/apis/security.openshift.io', 'v1',
39
- as: :parsed_symbolized)
40
- created_scc = client.create_security_context_constraint(testing_scc)
41
- assert_equal('SecurityContextConstraints', created_scc[:kind])
42
- assert_equal('security.openshift.io/v1', created_scc[:apiVersion])
43
- end
44
-
45
- def test_get_security_context_constraints
46
- stub_request(:get, %r{/apis/security.openshift.io/v1$}).to_return(
47
- body: open_test_file('security.openshift.io_api_resource_list.json'),
48
- status: 200
49
- )
50
- stub_request(:get, %r{/securitycontextconstraints})
51
- .to_return(body: open_test_file('security_context_constraint_list.json'), status: 200)
52
- client = Kubeclient::Client.new('http://localhost:8080/apis/security.openshift.io', 'v1')
53
-
54
- collection = client.get_security_context_constraints(as: :parsed_symbolized)
55
- assert_equal('SecurityContextConstraintsList', collection[:kind])
56
- assert_equal('security.openshift.io/v1', collection[:apiVersion])
57
-
58
- # Stripping of 'List' in collection.kind RecursiveOpenStruct mode only is historic.
59
- collection = client.get_security_context_constraints
60
- assert_equal('SecurityContextConstraints', collection.kind)
61
- end
62
- end