ruboty-k8s 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruboty/k8s/version.rb +1 -1
- data/ruboty-k8s.gemspec +1 -9
- metadata +4 -183
- data/lib/kubeclient/.gitignore +0 -15
- data/lib/kubeclient/.rubocop.yml +0 -16
- data/lib/kubeclient/.travis.yml +0 -12
- data/lib/kubeclient/Gemfile +0 -4
- data/lib/kubeclient/LICENSE.txt +0 -22
- data/lib/kubeclient/README.md +0 -428
- data/lib/kubeclient/Rakefile +0 -12
- data/lib/kubeclient/kubeclient.gemspec +0 -31
- data/lib/kubeclient/lib/kubeclient.rb +0 -32
- data/lib/kubeclient/lib/kubeclient/common.rb +0 -512
- data/lib/kubeclient/lib/kubeclient/config.rb +0 -126
- data/lib/kubeclient/lib/kubeclient/entity_list.rb +0 -16
- data/lib/kubeclient/lib/kubeclient/kube_exception.rb +0 -14
- data/lib/kubeclient/lib/kubeclient/missing_kind_compatibility.rb +0 -68
- data/lib/kubeclient/lib/kubeclient/version.rb +0 -4
- data/lib/kubeclient/lib/kubeclient/watch_notice.rb +0 -7
- data/lib/kubeclient/lib/kubeclient/watch_stream.rb +0 -80
- data/lib/kubeclient/test/cassettes/kubernetes_guestbook.yml +0 -879
- data/lib/kubeclient/test/config/allinone.kubeconfig +0 -20
- data/lib/kubeclient/test/config/external-ca.pem +0 -18
- data/lib/kubeclient/test/config/external-cert.pem +0 -19
- data/lib/kubeclient/test/config/external-key.rsa +0 -27
- data/lib/kubeclient/test/config/external.kubeconfig +0 -20
- data/lib/kubeclient/test/config/nouser.kubeconfig +0 -16
- data/lib/kubeclient/test/config/userauth.kubeconfig +0 -28
- data/lib/kubeclient/test/json/bindings_list.json +0 -10
- data/lib/kubeclient/test/json/component_status.json +0 -17
- data/lib/kubeclient/test/json/component_status_list.json +0 -52
- data/lib/kubeclient/test/json/config_map_list.json +0 -9
- data/lib/kubeclient/test/json/core_api_resource_list.json +0 -181
- data/lib/kubeclient/test/json/core_api_resource_list_without_kind.json +0 -129
- data/lib/kubeclient/test/json/core_oapi_resource_list_without_kind.json +0 -197
- data/lib/kubeclient/test/json/created_endpoint.json +0 -28
- data/lib/kubeclient/test/json/created_namespace.json +0 -20
- data/lib/kubeclient/test/json/created_secret.json +0 -16
- data/lib/kubeclient/test/json/created_service.json +0 -31
- data/lib/kubeclient/test/json/empty_pod_list.json +0 -9
- data/lib/kubeclient/test/json/endpoint_list.json +0 -48
- data/lib/kubeclient/test/json/entity_list.json +0 -56
- data/lib/kubeclient/test/json/event_list.json +0 -35
- data/lib/kubeclient/test/json/limit_range.json +0 -23
- data/lib/kubeclient/test/json/limit_range_list.json +0 -31
- data/lib/kubeclient/test/json/namespace.json +0 -13
- data/lib/kubeclient/test/json/namespace_exception.json +0 -8
- data/lib/kubeclient/test/json/namespace_list.json +0 -32
- data/lib/kubeclient/test/json/node.json +0 -29
- data/lib/kubeclient/test/json/node_list.json +0 -37
- data/lib/kubeclient/test/json/persistent_volume.json +0 -37
- data/lib/kubeclient/test/json/persistent_volume_claim.json +0 -32
- data/lib/kubeclient/test/json/persistent_volume_claim_list.json +0 -40
- data/lib/kubeclient/test/json/persistent_volume_claims_nil_items.json +0 -8
- data/lib/kubeclient/test/json/persistent_volume_list.json +0 -45
- data/lib/kubeclient/test/json/pod.json +0 -92
- data/lib/kubeclient/test/json/pod_list.json +0 -79
- data/lib/kubeclient/test/json/pod_template_list.json +0 -9
- data/lib/kubeclient/test/json/processed_template.json +0 -27
- data/lib/kubeclient/test/json/replication_controller.json +0 -57
- data/lib/kubeclient/test/json/replication_controller_list.json +0 -66
- data/lib/kubeclient/test/json/resource_quota.json +0 -46
- data/lib/kubeclient/test/json/resource_quota_list.json +0 -54
- data/lib/kubeclient/test/json/secret_list.json +0 -44
- data/lib/kubeclient/test/json/service.json +0 -33
- data/lib/kubeclient/test/json/service_account.json +0 -25
- data/lib/kubeclient/test/json/service_account_list.json +0 -82
- data/lib/kubeclient/test/json/service_illegal_json_404.json +0 -1
- data/lib/kubeclient/test/json/service_list.json +0 -97
- data/lib/kubeclient/test/json/service_patch.json +0 -25
- data/lib/kubeclient/test/json/service_update.json +0 -22
- data/lib/kubeclient/test/json/versions_list.json +0 -6
- data/lib/kubeclient/test/json/watch_stream.json +0 -3
- data/lib/kubeclient/test/test_common.rb +0 -32
- data/lib/kubeclient/test/test_component_status.rb +0 -30
- data/lib/kubeclient/test/test_config.rb +0 -72
- data/lib/kubeclient/test/test_endpoint.rb +0 -35
- data/lib/kubeclient/test/test_guestbook_go.rb +0 -238
- data/lib/kubeclient/test/test_helper.rb +0 -10
- data/lib/kubeclient/test/test_kubeclient.rb +0 -611
- data/lib/kubeclient/test/test_limit_range.rb +0 -27
- data/lib/kubeclient/test/test_missing_methods.rb +0 -42
- data/lib/kubeclient/test/test_namespace.rb +0 -61
- data/lib/kubeclient/test/test_node.rb +0 -33
- data/lib/kubeclient/test/test_persistent_volume.rb +0 -30
- data/lib/kubeclient/test/test_persistent_volume_claim.rb +0 -30
- data/lib/kubeclient/test/test_pod.rb +0 -29
- data/lib/kubeclient/test/test_pod_log.rb +0 -50
- data/lib/kubeclient/test/test_process_template.rb +0 -44
- data/lib/kubeclient/test/test_replication_controller.rb +0 -27
- data/lib/kubeclient/test/test_resource_list_without_kind.rb +0 -78
- data/lib/kubeclient/test/test_resource_quota.rb +0 -25
- data/lib/kubeclient/test/test_secret.rb +0 -70
- data/lib/kubeclient/test/test_service.rb +0 -293
- data/lib/kubeclient/test/test_service_account.rb +0 -28
- data/lib/kubeclient/test/test_watch.rb +0 -119
- data/lib/kubeclient/test/txt/pod_log.txt +0 -6
- data/lib/kubeclient/test/valid_token_file +0 -1
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# LimitRange tests
|
4
|
-
class TestLimitRange < MiniTest::Test
|
5
|
-
def test_get_from_json_v1
|
6
|
-
stub_request(:get, %r{/api/v1$})
|
7
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
8
|
-
|
9
|
-
stub_request(:get, %r{/limitranges})
|
10
|
-
.to_return(body: open_test_file('limit_range.json'), status: 200)
|
11
|
-
|
12
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
13
|
-
limit_range = client.get_limit_range 'limits', 'quota-example'
|
14
|
-
|
15
|
-
assert_instance_of(Kubeclient::LimitRange, limit_range)
|
16
|
-
assert_equal('limits', limit_range.metadata.name)
|
17
|
-
assert_equal('Container', limit_range.spec.limits[0].type)
|
18
|
-
assert_equal('100m', limit_range.spec.limits[0].default.cpu)
|
19
|
-
assert_equal('512Mi', limit_range.spec.limits[0].default.memory)
|
20
|
-
|
21
|
-
assert_requested(
|
22
|
-
:get,
|
23
|
-
'http://localhost:8080/api/v1/namespaces/quota-example/limitranges/limits',
|
24
|
-
times: 1
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Test method_missing, respond_to? and respond_to_missing behaviour
|
4
|
-
class TestMissingMethods < MiniTest::Test
|
5
|
-
def test_missing
|
6
|
-
stub_request(:get, %r{/api/v1$}).to_return(
|
7
|
-
body: open_test_file('core_api_resource_list.json'),
|
8
|
-
status: 200
|
9
|
-
)
|
10
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
11
|
-
assert_equal(true, client.respond_to?(:get_pod))
|
12
|
-
assert_equal(true, client.respond_to?(:get_pods))
|
13
|
-
assert_equal(false, client.respond_to?(:get_pie))
|
14
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1') # Reset discovery
|
15
|
-
assert_equal(false, client.respond_to?(:get_pie))
|
16
|
-
assert_equal(true, client.respond_to?(:get_pods))
|
17
|
-
assert_equal(true, client.respond_to?(:get_pod))
|
18
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1') # Reset discovery
|
19
|
-
assert_instance_of(Method, client.method(:get_pods))
|
20
|
-
assert_raises(NameError) do
|
21
|
-
client.method(:get_pies)
|
22
|
-
end
|
23
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1') # Reset discovery
|
24
|
-
assert_raises(NameError) do
|
25
|
-
client.method(:get_pies)
|
26
|
-
end
|
27
|
-
assert_instance_of(Method, client.method(:get_pods))
|
28
|
-
|
29
|
-
stub_request(:get, %r{/api/v1$}).to_return(
|
30
|
-
body: '',
|
31
|
-
status: 404
|
32
|
-
) # If discovery fails we expect the below raise an exception
|
33
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
34
|
-
assert_raises(KubeException) do
|
35
|
-
client.method(:get_pods)
|
36
|
-
end
|
37
|
-
client = Kubeclient::Client.new('http://localhost:8080/api/', 'v1')
|
38
|
-
assert_raises(KubeException) do
|
39
|
-
client.respond_to?(:get_pods)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Namespace entity tests
|
4
|
-
class TestNamespace < MiniTest::Test
|
5
|
-
def test_get_namespace_v1
|
6
|
-
stub_request(:get, %r{/api/v1$})
|
7
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
8
|
-
stub_request(:get, %r{/namespaces})
|
9
|
-
.to_return(body: open_test_file('namespace.json'), status: 200)
|
10
|
-
|
11
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
12
|
-
namespace = client.get_namespace 'staging'
|
13
|
-
|
14
|
-
assert_instance_of(Kubeclient::Namespace, namespace)
|
15
|
-
assert_equal('e388bc10-c021-11e4-a514-3c970e4a436a', namespace.metadata.uid)
|
16
|
-
assert_equal('staging', namespace.metadata.name)
|
17
|
-
assert_equal('1168', namespace.metadata.resourceVersion)
|
18
|
-
assert_equal('v1', namespace.apiVersion)
|
19
|
-
|
20
|
-
assert_requested(
|
21
|
-
:get,
|
22
|
-
'http://localhost:8080/api/v1/namespaces/staging',
|
23
|
-
times: 1
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_delete_namespace_v1
|
28
|
-
our_namespace = Kubeclient::Resource.new
|
29
|
-
our_namespace.metadata = {}
|
30
|
-
our_namespace.metadata.name = 'staging'
|
31
|
-
|
32
|
-
stub_request(:get, %r{/api/v1$})
|
33
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
34
|
-
stub_request(:delete, %r{/namespaces})
|
35
|
-
.to_return(status: 200)
|
36
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
37
|
-
client.delete_namespace our_namespace.metadata.name
|
38
|
-
|
39
|
-
assert_requested(
|
40
|
-
:delete,
|
41
|
-
'http://localhost:8080/api/v1/namespaces/staging',
|
42
|
-
times: 1
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_create_namespace
|
47
|
-
stub_request(:get, %r{/api/v1$})
|
48
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
49
|
-
stub_request(:post, %r{/namespaces})
|
50
|
-
.to_return(body: open_test_file('created_namespace.json'), status: 201)
|
51
|
-
|
52
|
-
namespace = Kubeclient::Resource.new
|
53
|
-
namespace.metadata = {}
|
54
|
-
namespace.metadata.name = 'development'
|
55
|
-
|
56
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/'
|
57
|
-
created_namespace = client.create_namespace namespace
|
58
|
-
assert_instance_of(Kubeclient::Namespace, created_namespace)
|
59
|
-
assert_equal(namespace.metadata.name, created_namespace.metadata.name)
|
60
|
-
end
|
61
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Node entity tests
|
4
|
-
class TestNode < MiniTest::Test
|
5
|
-
def test_get_from_json_v1
|
6
|
-
stub_request(:get, %r{/nodes})
|
7
|
-
.to_return(body: open_test_file('node.json'), status: 200)
|
8
|
-
stub_request(:get, %r{/api/v1$})
|
9
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
10
|
-
|
11
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
12
|
-
node = client.get_node('127.0.0.1')
|
13
|
-
|
14
|
-
assert_instance_of(Kubeclient::Node, node)
|
15
|
-
|
16
|
-
assert_equal('041143c5-ce39-11e4-ac24-3c970e4a436a', node.metadata.uid)
|
17
|
-
assert_equal('127.0.0.1', node.metadata.name)
|
18
|
-
assert_equal('1724', node.metadata.resourceVersion)
|
19
|
-
assert_equal('v1', node.apiVersion)
|
20
|
-
assert_equal('2015-03-19T15:08:20+02:00', node.metadata.creationTimestamp)
|
21
|
-
|
22
|
-
assert_requested(
|
23
|
-
:get,
|
24
|
-
'http://localhost:8080/api/v1',
|
25
|
-
times: 1
|
26
|
-
)
|
27
|
-
assert_requested(
|
28
|
-
:get,
|
29
|
-
'http://localhost:8080/api/v1/nodes/127.0.0.1',
|
30
|
-
times: 1
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# PersistentVolume tests
|
4
|
-
class TestPersistentVolume < MiniTest::Test
|
5
|
-
def test_get_from_json_v1
|
6
|
-
stub_request(:get, %r{/persistentvolumes})
|
7
|
-
.to_return(body: open_test_file('persistent_volume.json'), status: 200)
|
8
|
-
stub_request(:get, %r{/api/v1$})
|
9
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
10
|
-
|
11
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
12
|
-
volume = client.get_persistent_volume 'pv0001'
|
13
|
-
|
14
|
-
assert_instance_of(Kubeclient::PersistentVolume, volume)
|
15
|
-
assert_equal('pv0001', volume.metadata.name)
|
16
|
-
assert_equal('10Gi', volume.spec.capacity.storage)
|
17
|
-
assert_equal('/tmp/data01', volume.spec.hostPath.path)
|
18
|
-
|
19
|
-
assert_requested(
|
20
|
-
:get,
|
21
|
-
'http://localhost:8080/api/v1',
|
22
|
-
times: 1
|
23
|
-
)
|
24
|
-
assert_requested(
|
25
|
-
:get,
|
26
|
-
'http://localhost:8080/api/v1/persistentvolumes/pv0001',
|
27
|
-
times: 1
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# PersistentVolumeClaim tests
|
4
|
-
class TestPersistentVolumeClaim < MiniTest::Test
|
5
|
-
def test_get_from_json_v1
|
6
|
-
stub_request(:get, %r{/persistentvolumeclaims})
|
7
|
-
.to_return(body: open_test_file('persistent_volume_claim.json'), status: 200)
|
8
|
-
stub_request(:get, %r{/api/v1$})
|
9
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
10
|
-
|
11
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
12
|
-
claim = client.get_persistent_volume_claim 'myclaim-1', 'default'
|
13
|
-
|
14
|
-
assert_instance_of(Kubeclient::PersistentVolumeClaim, claim)
|
15
|
-
assert_equal('myclaim-1', claim.metadata.name)
|
16
|
-
assert_equal('3Gi', claim.spec.resources.requests.storage)
|
17
|
-
assert_equal('pv0001', claim.spec.volumeName)
|
18
|
-
|
19
|
-
assert_requested(
|
20
|
-
:get,
|
21
|
-
'http://localhost:8080/api/v1',
|
22
|
-
times: 1
|
23
|
-
)
|
24
|
-
assert_requested(
|
25
|
-
:get,
|
26
|
-
'http://localhost:8080/api/v1/namespaces/default/persistentvolumeclaims/myclaim-1',
|
27
|
-
times: 1
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Pod entity tests
|
4
|
-
class TestPod < MiniTest::Test
|
5
|
-
def test_get_from_json_v1
|
6
|
-
stub_request(:get, %r{/pods})
|
7
|
-
.to_return(body: open_test_file('pod.json'), status: 200)
|
8
|
-
stub_request(:get, %r{/api/v1$})
|
9
|
-
.to_return(body: open_test_file('core_api_resource_list.json'), status: 200)
|
10
|
-
|
11
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
12
|
-
pod = client.get_pod 'redis-master-pod', 'default'
|
13
|
-
|
14
|
-
assert_instance_of(Kubeclient::Pod, pod)
|
15
|
-
assert_equal('redis-master3', pod.metadata.name)
|
16
|
-
assert_equal('dockerfile/redis', pod.spec.containers[0]['image'])
|
17
|
-
|
18
|
-
assert_requested(
|
19
|
-
:get,
|
20
|
-
'http://localhost:8080/api/v1',
|
21
|
-
times: 1
|
22
|
-
)
|
23
|
-
assert_requested(
|
24
|
-
:get,
|
25
|
-
'http://localhost:8080/api/v1/namespaces/default/pods/redis-master-pod',
|
26
|
-
times: 1
|
27
|
-
)
|
28
|
-
end
|
29
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Pod log tests
|
4
|
-
class TestPodLog < MiniTest::Test
|
5
|
-
def test_get_pod_log
|
6
|
-
stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log})
|
7
|
-
.to_return(body: open_test_file('pod_log.txt'),
|
8
|
-
status: 200)
|
9
|
-
|
10
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
11
|
-
retrieved_log = client.get_pod_log('redis-master-pod', 'default')
|
12
|
-
|
13
|
-
assert_equal(open_test_file('pod_log.txt').read, retrieved_log)
|
14
|
-
|
15
|
-
assert_requested(:get,
|
16
|
-
'http://localhost:8080/api/v1/namespaces/default/pods/redis-master-pod/log',
|
17
|
-
times: 1)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_get_pod_log_container
|
21
|
-
stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log})
|
22
|
-
.to_return(body: open_test_file('pod_log.txt'),
|
23
|
-
status: 200)
|
24
|
-
|
25
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
26
|
-
retrieved_log = client.get_pod_log('redis-master-pod', 'default', container: 'ruby')
|
27
|
-
|
28
|
-
assert_equal(open_test_file('pod_log.txt').read, retrieved_log)
|
29
|
-
|
30
|
-
assert_requested(:get,
|
31
|
-
'http://localhost:8080/api/v1/namespaces/default/pods/redis-master-pod/log?container=ruby',
|
32
|
-
times: 1)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_watch_pod_log
|
36
|
-
expected_lines = open_test_file('pod_log.txt').read.split("\n")
|
37
|
-
|
38
|
-
stub_request(:get, %r{/namespaces/default/pods/[a-z0-9-]+/log\?.*follow})
|
39
|
-
.to_return(body: open_test_file('pod_log.txt'),
|
40
|
-
status: 200)
|
41
|
-
|
42
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
43
|
-
|
44
|
-
stream = client.watch_pod_log('redis-master-pod', 'default')
|
45
|
-
stream.to_enum.with_index do |notice, index|
|
46
|
-
assert_instance_of(String, notice)
|
47
|
-
assert_equal(expected_lines[index], notice)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require '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
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# Replication Controller entity tests
|
4
|
-
class TestReplicationController < MiniTest::Test
|
5
|
-
def test_get_from_json_v1
|
6
|
-
stub_request(:get, %r{/api/v1$})
|
7
|
-
.to_return(body: open_test_file('core_api_resource_list.json'),
|
8
|
-
status: 200)
|
9
|
-
stub_request(:get, %r{/replicationcontrollers})
|
10
|
-
.to_return(body: open_test_file('replication_controller.json'),
|
11
|
-
status: 200)
|
12
|
-
|
13
|
-
client = Kubeclient::Client.new 'http://localhost:8080/api/', 'v1'
|
14
|
-
rc = client.get_replication_controller 'frontendController', 'default'
|
15
|
-
|
16
|
-
assert_instance_of(Kubeclient::ReplicationController, rc)
|
17
|
-
assert_equal('guestbook-controller', rc.metadata.name)
|
18
|
-
assert_equal('c71aa4c0-a240-11e4-a265-3c970e4a436a', rc.metadata.uid)
|
19
|
-
assert_equal('default', rc.metadata.namespace)
|
20
|
-
assert_equal(3, rc.spec.replicas)
|
21
|
-
assert_equal('guestbook', rc.spec.selector.name)
|
22
|
-
|
23
|
-
assert_requested(:get,
|
24
|
-
'http://localhost:8080/api/v1/namespaces/default/replicationcontrollers/frontendController',
|
25
|
-
times: 1)
|
26
|
-
end
|
27
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require '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
|