kubeclient 4.7.0 → 4.12.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.
- checksums.yaml +4 -4
- data/.github/workflows/actions.yml +43 -0
- data/.rubocop.yml +111 -14
- data/CHANGELOG.md +119 -0
- data/README.md +41 -4
- data/RELEASING.md +8 -8
- data/kubeclient.gemspec +11 -7
- data/lib/kubeclient/aws_eks_credentials.rb +17 -8
- data/lib/kubeclient/common.rb +55 -21
- data/lib/kubeclient/config.rb +33 -13
- data/lib/kubeclient/exec_credentials.rb +33 -4
- data/lib/kubeclient/version.rb +1 -1
- data/lib/kubeclient/watch_stream.rb +1 -0
- metadata +46 -222
- data/.travis.yml +0 -29
- data/test/cassettes/kubernetes_guestbook.yml +0 -879
- data/test/config/allinone.kubeconfig +0 -20
- data/test/config/execauth.kubeconfig +0 -62
- data/test/config/external-ca.pem +0 -18
- data/test/config/external-cert.pem +0 -19
- data/test/config/external-key.rsa +0 -27
- data/test/config/external.kubeconfig +0 -20
- data/test/config/gcpauth.kubeconfig +0 -22
- data/test/config/gcpcmdauth.kubeconfig +0 -26
- data/test/config/nouser.kubeconfig +0 -16
- data/test/config/oidcauth.kubeconfig +0 -25
- data/test/config/timestamps.kubeconfig +0 -25
- data/test/config/userauth.kubeconfig +0 -28
- data/test/json/bindings_list.json +0 -10
- data/test/json/component_status.json +0 -17
- data/test/json/component_status_list.json +0 -52
- data/test/json/config.istio.io_api_resource_list.json +0 -679
- data/test/json/config_map_list.json +0 -9
- data/test/json/core_api_resource_list.json +0 -181
- data/test/json/core_api_resource_list_without_kind.json +0 -129
- data/test/json/core_oapi_resource_list_without_kind.json +0 -197
- data/test/json/created_endpoint.json +0 -28
- data/test/json/created_namespace.json +0 -20
- data/test/json/created_secret.json +0 -16
- data/test/json/created_security_context_constraint.json +0 -65
- data/test/json/created_service.json +0 -31
- data/test/json/empty_pod_list.json +0 -9
- data/test/json/endpoint_list.json +0 -48
- data/test/json/entity_list.json +0 -56
- data/test/json/event_list.json +0 -35
- data/test/json/extensions_v1beta1_api_resource_list.json +0 -217
- data/test/json/limit_range.json +0 -23
- data/test/json/limit_range_list.json +0 -31
- data/test/json/namespace.json +0 -13
- data/test/json/namespace_exception.json +0 -8
- data/test/json/namespace_list.json +0 -32
- data/test/json/node.json +0 -29
- data/test/json/node_list.json +0 -37
- data/test/json/node_notice.json +0 -160
- data/test/json/persistent_volume.json +0 -37
- data/test/json/persistent_volume_claim.json +0 -32
- data/test/json/persistent_volume_claim_list.json +0 -40
- data/test/json/persistent_volume_claims_nil_items.json +0 -8
- data/test/json/persistent_volume_list.json +0 -45
- data/test/json/pod.json +0 -92
- data/test/json/pod_list.json +0 -79
- data/test/json/pod_template_list.json +0 -9
- data/test/json/pods_1.json +0 -265
- data/test/json/pods_2.json +0 -102
- data/test/json/pods_410.json +0 -9
- data/test/json/processed_template.json +0 -27
- data/test/json/replication_controller.json +0 -57
- data/test/json/replication_controller_list.json +0 -66
- data/test/json/resource_quota.json +0 -46
- data/test/json/resource_quota_list.json +0 -54
- data/test/json/secret_list.json +0 -44
- data/test/json/security.openshift.io_api_resource_list.json +0 -69
- data/test/json/security_context_constraint_list.json +0 -375
- data/test/json/service.json +0 -33
- data/test/json/service_account.json +0 -25
- data/test/json/service_account_list.json +0 -82
- data/test/json/service_illegal_json_404.json +0 -1
- data/test/json/service_json_patch.json +0 -26
- data/test/json/service_list.json +0 -97
- data/test/json/service_merge_patch.json +0 -26
- data/test/json/service_patch.json +0 -25
- data/test/json/service_update.json +0 -22
- data/test/json/template.json +0 -27
- data/test/json/template.openshift.io_api_resource_list.json +0 -75
- data/test/json/template_list.json +0 -35
- data/test/json/versions_list.json +0 -6
- data/test/json/watch_stream.json +0 -3
- data/test/test_common.rb +0 -95
- data/test/test_component_status.rb +0 -29
- data/test/test_config.rb +0 -222
- data/test/test_endpoint.rb +0 -54
- data/test/test_exec_credentials.rb +0 -125
- data/test/test_gcp_command_credentials.rb +0 -27
- data/test/test_google_application_default_credentials.rb +0 -15
- data/test/test_guestbook_go.rb +0 -235
- data/test/test_helper.rb +0 -18
- data/test/test_kubeclient.rb +0 -881
- data/test/test_limit_range.rb +0 -25
- data/test/test_missing_methods.rb +0 -80
- data/test/test_namespace.rb +0 -59
- data/test/test_node.rb +0 -70
- data/test/test_oidc_auth_provider.rb +0 -103
- data/test/test_persistent_volume.rb +0 -29
- data/test/test_persistent_volume_claim.rb +0 -28
- data/test/test_pod.rb +0 -81
- data/test/test_pod_log.rb +0 -157
- data/test/test_process_template.rb +0 -80
- data/test/test_replication_controller.rb +0 -47
- data/test/test_resource_list_without_kind.rb +0 -78
- data/test/test_resource_quota.rb +0 -23
- data/test/test_secret.rb +0 -62
- data/test/test_security_context_constraint.rb +0 -62
- data/test/test_service.rb +0 -330
- data/test/test_service_account.rb +0 -26
- data/test/test_watch.rb +0 -195
- data/test/txt/pod_log.txt +0 -6
- 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
|
data/test/test_resource_quota.rb
DELETED
@@ -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
|
data/test/test_service.rb
DELETED
@@ -1,330 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
# Service entity tests
|
4
|
-
class TestService < MiniTest::Test
|
5
|
-
def test_construct_our_own_service
|
6
|
-
our_service = Kubeclient::Resource.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 = [{
|
15
|
-
'port' => 3000,
|
16
|
-
'targetPort' => 'http-server',
|
17
|
-
'protocol' => 'TCP'
|
18
|
-
}]
|
19
|
-
|
20
|
-
assert_equal('guestbook', our_service.metadata.labels.name)
|
21
|
-
|
22
|
-
hash = our_service.to_h
|
23
|
-
|
24
|
-
assert_equal(our_service.metadata.labels.name,
|
25
|
-
hash[:metadata][:labels][:name])
|
26
|
-
|
27
|
-
expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
|
28
|
-
stub_core_api_list
|
29
|
-
stub_request(:post, expected_url)
|
30
|
-
.to_return(body: open_test_file('created_service.json'), status: 201)
|
31
|
-
|
32
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/')
|
33
|
-
created = client.create_service(our_service)
|
34
|
-
|
35
|
-
assert_instance_of(Kubeclient::Resource, created)
|
36
|
-
assert_equal(created.metadata.name, our_service.metadata.name)
|
37
|
-
assert_equal(created.spec.ports.size, our_service.spec.ports.size)
|
38
|
-
|
39
|
-
# Check that original entity_config is not modified by kind/apiVersion patches:
|
40
|
-
assert_nil(our_service.kind)
|
41
|
-
|
42
|
-
assert_requested(:post, expected_url, times: 1) do |req|
|
43
|
-
data = JSON.parse(req.body)
|
44
|
-
data['kind'] == 'Service' &&
|
45
|
-
data['apiVersion'] == 'v1' &&
|
46
|
-
data['metadata']['name'] == 'guestbook' &&
|
47
|
-
data['metadata']['namespace'] == 'staging'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_construct_service_from_symbol_keys
|
52
|
-
service = Kubeclient::Resource.new
|
53
|
-
service.metadata = {
|
54
|
-
labels: { tier: 'frontend' },
|
55
|
-
name: 'test-service',
|
56
|
-
namespace: 'staging'
|
57
|
-
}
|
58
|
-
service.spec = {
|
59
|
-
ports: [{
|
60
|
-
port: 3000,
|
61
|
-
targetPort: 'http-server',
|
62
|
-
protocol: 'TCP'
|
63
|
-
}]
|
64
|
-
}
|
65
|
-
|
66
|
-
expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
|
67
|
-
stub_core_api_list
|
68
|
-
stub_request(:post, expected_url)
|
69
|
-
.to_return(body: open_test_file('created_service.json'), status: 201)
|
70
|
-
|
71
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/')
|
72
|
-
client.create_service(service)
|
73
|
-
|
74
|
-
assert_requested(:post, expected_url, times: 1) do |req|
|
75
|
-
data = JSON.parse(req.body)
|
76
|
-
data['kind'] == 'Service' &&
|
77
|
-
data['apiVersion'] == 'v1' &&
|
78
|
-
data['metadata']['name'] == 'test-service' &&
|
79
|
-
data['metadata']['labels']['tier'] == 'frontend' &&
|
80
|
-
data['metadata']['namespace'] == 'staging'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_construct_service_from_string_keys
|
85
|
-
service = Kubeclient::Resource.new
|
86
|
-
service.metadata = {
|
87
|
-
'labels' => { 'tier' => 'frontend' },
|
88
|
-
'name' => 'test-service',
|
89
|
-
'namespace' => 'staging'
|
90
|
-
}
|
91
|
-
service.spec = {
|
92
|
-
'ports' => [{
|
93
|
-
'port' => 3000,
|
94
|
-
'targetPort' => 'http-server',
|
95
|
-
'protocol' => 'TCP'
|
96
|
-
}]
|
97
|
-
}
|
98
|
-
|
99
|
-
stub_core_api_list
|
100
|
-
expected_url = 'http://localhost:8080/api/v1/namespaces/staging/services'
|
101
|
-
stub_request(:post, %r{namespaces/staging/services})
|
102
|
-
.to_return(body: open_test_file('created_service.json'), status: 201)
|
103
|
-
|
104
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/')
|
105
|
-
client.create_service(service)
|
106
|
-
|
107
|
-
assert_requested(:post, expected_url, times: 1) do |req|
|
108
|
-
data = JSON.parse(req.body)
|
109
|
-
data['kind'] == 'Service' &&
|
110
|
-
data['apiVersion'] == 'v1' &&
|
111
|
-
data['metadata']['name'] == 'test-service' &&
|
112
|
-
data['metadata']['labels']['tier'] == 'frontend' &&
|
113
|
-
data['metadata']['namespace'] == 'staging'
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_conversion_from_json_v1
|
118
|
-
stub_core_api_list
|
119
|
-
stub_request(:get, %r{/services})
|
120
|
-
.to_return(body: open_test_file('service.json'),
|
121
|
-
status: 200)
|
122
|
-
|
123
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/')
|
124
|
-
service = client.get_service('redis-slave', 'development')
|
125
|
-
|
126
|
-
assert_instance_of(Kubeclient::Resource, service)
|
127
|
-
assert_equal('2015-04-05T13:00:31Z',
|
128
|
-
service.metadata.creationTimestamp)
|
129
|
-
assert_equal('bdb80a8f-db93-11e4-b293-f8b156af4ae1', service.metadata.uid)
|
130
|
-
assert_equal('redis-slave', service.metadata.name)
|
131
|
-
assert_equal('2815', service.metadata.resourceVersion)
|
132
|
-
assert_equal('v1', service.apiVersion)
|
133
|
-
assert_equal('10.0.0.140', service.spec.clusterIP)
|
134
|
-
assert_equal('development', service.metadata.namespace)
|
135
|
-
|
136
|
-
assert_equal('TCP', service.spec.ports[0].protocol)
|
137
|
-
assert_equal(6379, service.spec.ports[0].port)
|
138
|
-
assert_equal('', service.spec.ports[0].name)
|
139
|
-
assert_equal('redis-server', service.spec.ports[0].targetPort)
|
140
|
-
|
141
|
-
assert_requested(:get,
|
142
|
-
'http://localhost:8080/api/v1/namespaces/development/services/redis-slave',
|
143
|
-
times: 1)
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_delete_service
|
147
|
-
our_service = Kubeclient::Resource.new
|
148
|
-
our_service.name = 'redis-service'
|
149
|
-
# TODO, new ports assignment to be added
|
150
|
-
our_service.labels = {}
|
151
|
-
our_service.labels.component = 'apiserver'
|
152
|
-
our_service.labels.provider = 'kubernetes'
|
153
|
-
|
154
|
-
stub_core_api_list
|
155
|
-
stub_request(:delete, %r{/namespaces/default/services})
|
156
|
-
.to_return(body: open_test_file('service.json'), status: 200)
|
157
|
-
|
158
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
159
|
-
our_service = client.delete_service(our_service.name, 'default')
|
160
|
-
assert_kind_of(RecursiveOpenStruct, our_service)
|
161
|
-
|
162
|
-
assert_requested(:delete,
|
163
|
-
'http://localhost:8080/api/v1/namespaces/default/services/redis-service',
|
164
|
-
times: 1)
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_get_service_no_ns
|
168
|
-
stub_core_api_list
|
169
|
-
# when not specifying namespace for entities which
|
170
|
-
# are not node or namespace, the request will fail
|
171
|
-
stub_request(:get, %r{/services/redis-slave})
|
172
|
-
.to_return(status: 404)
|
173
|
-
|
174
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/')
|
175
|
-
|
176
|
-
exception = assert_raises(Kubeclient::HttpError) do
|
177
|
-
client.get_service('redis-slave')
|
178
|
-
end
|
179
|
-
assert_equal(404, exception.error_code)
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_get_service
|
183
|
-
stub_core_api_list
|
184
|
-
stub_request(:get, %r{/namespaces/development/services/redis-slave})
|
185
|
-
.to_return(body: open_test_file('service.json'),
|
186
|
-
status: 200)
|
187
|
-
|
188
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/')
|
189
|
-
service = client.get_service('redis-slave', 'development')
|
190
|
-
assert_equal('redis-slave', service.metadata.name)
|
191
|
-
|
192
|
-
assert_requested(:get,
|
193
|
-
'http://localhost:8080/api/v1/namespaces/development/services/redis-slave',
|
194
|
-
times: 1)
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_update_service
|
198
|
-
service = Kubeclient::Resource.new
|
199
|
-
name = 'my_service'
|
200
|
-
|
201
|
-
service.metadata = {}
|
202
|
-
service.metadata.name = name
|
203
|
-
service.metadata.namespace = 'development'
|
204
|
-
|
205
|
-
stub_core_api_list
|
206
|
-
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
207
|
-
stub_request(:put, expected_url)
|
208
|
-
.to_return(body: open_test_file('service_update.json'), status: 201)
|
209
|
-
|
210
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
211
|
-
service = client.update_service(service)
|
212
|
-
assert_kind_of(RecursiveOpenStruct, service)
|
213
|
-
|
214
|
-
assert_requested(:put, expected_url, times: 1) do |req|
|
215
|
-
data = JSON.parse(req.body)
|
216
|
-
data['metadata']['name'] == name &&
|
217
|
-
data['metadata']['namespace'] == 'development'
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_update_service_with_string_keys
|
222
|
-
service = Kubeclient::Resource.new
|
223
|
-
name = 'my_service'
|
224
|
-
|
225
|
-
service.metadata = {
|
226
|
-
'name' => name,
|
227
|
-
'namespace' => 'development'
|
228
|
-
}
|
229
|
-
|
230
|
-
stub_core_api_list
|
231
|
-
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
232
|
-
stub_request(:put, expected_url)
|
233
|
-
.to_return(body: open_test_file('service_update.json'), status: 201)
|
234
|
-
|
235
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
236
|
-
service = client.update_service(service)
|
237
|
-
assert_kind_of(RecursiveOpenStruct, service)
|
238
|
-
|
239
|
-
assert_requested(:put, expected_url, times: 1) do |req|
|
240
|
-
data = JSON.parse(req.body)
|
241
|
-
data['metadata']['name'] == name &&
|
242
|
-
data['metadata']['namespace'] == 'development'
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
def test_patch_service
|
247
|
-
service = Kubeclient::Resource.new
|
248
|
-
name = 'my_service'
|
249
|
-
|
250
|
-
service.metadata = {}
|
251
|
-
service.metadata.name = name
|
252
|
-
service.metadata.namespace = 'development'
|
253
|
-
|
254
|
-
stub_core_api_list
|
255
|
-
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
256
|
-
stub_request(:patch, expected_url)
|
257
|
-
.to_return(body: open_test_file('service_patch.json'), status: 200)
|
258
|
-
|
259
|
-
patch = {
|
260
|
-
metadata: {
|
261
|
-
annotations: {
|
262
|
-
key: 'value'
|
263
|
-
}
|
264
|
-
}
|
265
|
-
}
|
266
|
-
|
267
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
268
|
-
service = client.patch_service(name, patch, 'development')
|
269
|
-
assert_kind_of(RecursiveOpenStruct, service)
|
270
|
-
|
271
|
-
assert_requested(:patch, expected_url, times: 1) do |req|
|
272
|
-
data = JSON.parse(req.body)
|
273
|
-
data['metadata']['annotations']['key'] == 'value'
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_json_patch_service
|
278
|
-
service = Kubeclient::Resource.new
|
279
|
-
name = 'my-service'
|
280
|
-
|
281
|
-
service.metadata = {}
|
282
|
-
service.metadata.name = name
|
283
|
-
service.metadata.namespace = 'development'
|
284
|
-
|
285
|
-
stub_core_api_list
|
286
|
-
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
287
|
-
stub_request(:patch, expected_url)
|
288
|
-
.to_return(body: open_test_file('service_json_patch.json'), status: 200)
|
289
|
-
|
290
|
-
patch = [
|
291
|
-
{ 'op' => 'add', 'path' => '/spec/type', 'value' => 'LoadBalancer' }
|
292
|
-
]
|
293
|
-
|
294
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
295
|
-
service = client.json_patch_service(name, patch, 'development')
|
296
|
-
assert_kind_of(RecursiveOpenStruct, service)
|
297
|
-
|
298
|
-
assert_requested(:patch, expected_url, times: 1) do |req|
|
299
|
-
data = JSON.parse(req.body)
|
300
|
-
req.headers['Content-Type'] == 'application/json-patch+json' &&
|
301
|
-
data == patch
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
def test_merge_patch_service
|
306
|
-
service = Kubeclient::Resource.new
|
307
|
-
name = 'my-service'
|
308
|
-
|
309
|
-
service.metadata = {}
|
310
|
-
service.metadata.name = name
|
311
|
-
service.metadata.namespace = 'development'
|
312
|
-
|
313
|
-
stub_core_api_list
|
314
|
-
expected_url = "http://localhost:8080/api/v1/namespaces/development/services/#{name}"
|
315
|
-
stub_request(:patch, expected_url)
|
316
|
-
.to_return(body: open_test_file('service_merge_patch.json'), status: 200)
|
317
|
-
|
318
|
-
patch = { spec: { type: 'NodePort' } }
|
319
|
-
|
320
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
321
|
-
service = client.merge_patch_service(name, patch, 'development')
|
322
|
-
assert_kind_of(RecursiveOpenStruct, service)
|
323
|
-
|
324
|
-
assert_requested(:patch, expected_url, times: 1) do |req|
|
325
|
-
data = JSON.parse(req.body)
|
326
|
-
req.headers['Content-Type'] == 'application/merge-patch+json' &&
|
327
|
-
data['spec']['type'] == 'NodePort'
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|