droplet_kit 2.8.0 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +4 -1
- data/lib/droplet_kit/mappings/cdn_mapping.rb +6 -0
- data/lib/droplet_kit/mappings/load_balancer_mapping.rb +1 -0
- data/lib/droplet_kit/models/cdn.rb +2 -0
- data/lib/droplet_kit/models/load_balancer.rb +1 -0
- data/lib/droplet_kit/resources/cdn_resource.rb +6 -0
- data/lib/droplet_kit/version.rb +1 -1
- metadata +4 -289
- data/.gitignore +0 -23
- data/.rspec +0 -2
- data/.travis.yml +0 -28
- data/CHANGELOG.md +0 -106
- data/Gemfile +0 -15
- data/Rakefile +0 -3
- data/droplet_kit.gemspec +0 -37
- data/spec/fixtures/account/info.json +0 -8
- data/spec/fixtures/actions/all.json +0 -24
- data/spec/fixtures/actions/find.json +0 -19
- data/spec/fixtures/cdns/all.json +0 -16
- data/spec/fixtures/cdns/create.json +0 -9
- data/spec/fixtures/cdns/find.json +0 -9
- data/spec/fixtures/cdns/update_ttl.json +0 -9
- data/spec/fixtures/certificates/all.json +0 -19
- data/spec/fixtures/certificates/find.json +0 -12
- data/spec/fixtures/certificates/lets_encrypt.json +0 -12
- data/spec/fixtures/domain_records/all.json +0 -57
- data/spec/fixtures/domain_records/create.json +0 -12
- data/spec/fixtures/domain_records/find.json +0 -12
- data/spec/fixtures/domain_records/update.json +0 -12
- data/spec/fixtures/domains/all.json +0 -12
- data/spec/fixtures/domains/create.json +0 -7
- data/spec/fixtures/domains/find.json +0 -7
- data/spec/fixtures/droplet_actions/change_kernel.json +0 -27
- data/spec/fixtures/droplet_actions/disable_backups.json +0 -27
- data/spec/fixtures/droplet_actions/enable_backups.json +0 -27
- data/spec/fixtures/droplet_actions/enable_ipv6.json +0 -27
- data/spec/fixtures/droplet_actions/enable_private_networking.json +0 -27
- data/spec/fixtures/droplet_actions/find.json +0 -19
- data/spec/fixtures/droplet_actions/password_reset.json +0 -27
- data/spec/fixtures/droplet_actions/power_cycle.json +0 -27
- data/spec/fixtures/droplet_actions/power_off.json +0 -27
- data/spec/fixtures/droplet_actions/power_on.json +0 -27
- data/spec/fixtures/droplet_actions/reboot.json +0 -27
- data/spec/fixtures/droplet_actions/rebuild.json +0 -27
- data/spec/fixtures/droplet_actions/rename.json +0 -27
- data/spec/fixtures/droplet_actions/resize.json +0 -27
- data/spec/fixtures/droplet_actions/restore.json +0 -27
- data/spec/fixtures/droplet_actions/shutdown.json +0 -27
- data/spec/fixtures/droplet_actions/snapshot.json +0 -27
- data/spec/fixtures/droplet_actions/upgrade.json +0 -27
- data/spec/fixtures/droplet_upgrades/all.json +0 -7
- data/spec/fixtures/droplets/all.json +0 -89
- data/spec/fixtures/droplets/all_empty.json +0 -7
- data/spec/fixtures/droplets/create.json +0 -84
- data/spec/fixtures/droplets/create_multiple.json +0 -168
- data/spec/fixtures/droplets/find.json +0 -84
- data/spec/fixtures/droplets/list_actions.json +0 -24
- data/spec/fixtures/droplets/list_backups.json +0 -18
- data/spec/fixtures/droplets/list_kernels.json +0 -17
- data/spec/fixtures/droplets/list_snapshots.json +0 -18
- data/spec/fixtures/firewalls/all.json +0 -67
- data/spec/fixtures/firewalls/find.json +0 -61
- data/spec/fixtures/floating_ip_actions/all.json +0 -41
- data/spec/fixtures/floating_ip_actions/assign.json +0 -27
- data/spec/fixtures/floating_ip_actions/find.json +0 -19
- data/spec/fixtures/floating_ip_actions/unassign.json +0 -27
- data/spec/fixtures/floating_ips/all.json +0 -186
- data/spec/fixtures/floating_ips/all_empty.json +0 -7
- data/spec/fixtures/floating_ips/create.json +0 -29
- data/spec/fixtures/floating_ips/create_with_droplet.json +0 -44
- data/spec/fixtures/floating_ips/find.json +0 -28
- data/spec/fixtures/image_actions/all.json +0 -36
- data/spec/fixtures/image_actions/convert.json +0 -27
- data/spec/fixtures/image_actions/find.json +0 -19
- data/spec/fixtures/image_actions/transfer.json +0 -27
- data/spec/fixtures/images/all.json +0 -31
- data/spec/fixtures/images/find.json +0 -16
- data/spec/fixtures/images/private.json +0 -31
- data/spec/fixtures/images/type.json +0 -31
- data/spec/fixtures/kubernetes/all.json +0 -70
- data/spec/fixtures/kubernetes/all_empty.json +0 -7
- data/spec/fixtures/kubernetes/cluster_node_pool.json +0 -24
- data/spec/fixtures/kubernetes/cluster_node_pool_create.json +0 -40
- data/spec/fixtures/kubernetes/cluster_node_pool_update.json +0 -31
- data/spec/fixtures/kubernetes/cluster_node_pools.json +0 -33
- data/spec/fixtures/kubernetes/clusters/create.json +0 -65
- data/spec/fixtures/kubernetes/clusters/find.json +0 -65
- data/spec/fixtures/kubernetes/clusters/kubeconfig.txt +0 -20
- data/spec/fixtures/kubernetes/clusters/update.json +0 -63
- data/spec/fixtures/kubernetes/options.json +0 -150
- data/spec/fixtures/load_balancers/all.json +0 -129
- data/spec/fixtures/load_balancers/find.json +0 -59
- data/spec/fixtures/projects/all.json +0 -37
- data/spec/fixtures/projects/all_empty.json +0 -12
- data/spec/fixtures/projects/find.json +0 -14
- data/spec/fixtures/projects/resources.json +0 -84
- data/spec/fixtures/regions/all.json +0 -47
- data/spec/fixtures/sizes/all.json +0 -37
- data/spec/fixtures/snapshots/all.json +0 -32
- data/spec/fixtures/snapshots/find.json +0 -14
- data/spec/fixtures/snapshots/resource_type.json +0 -20
- data/spec/fixtures/ssh_keys/all.json +0 -13
- data/spec/fixtures/ssh_keys/create.json +0 -8
- data/spec/fixtures/ssh_keys/find.json +0 -8
- data/spec/fixtures/ssh_keys/update.json +0 -8
- data/spec/fixtures/tags/all.json +0 -34
- data/spec/fixtures/tags/all_empty.json +0 -7
- data/spec/fixtures/tags/create.json +0 -15
- data/spec/fixtures/tags/find.json +0 -99
- data/spec/fixtures/volume_actions/all.json +0 -41
- data/spec/fixtures/volume_actions/attach.json +0 -34
- data/spec/fixtures/volume_actions/detach.json +0 -34
- data/spec/fixtures/volume_actions/find.json +0 -34
- data/spec/fixtures/volume_actions/resize.json +0 -34
- data/spec/fixtures/volumes/all.json +0 -41
- data/spec/fixtures/volumes/create.json +0 -34
- data/spec/fixtures/volumes/create_snapshot.json +0 -14
- data/spec/fixtures/volumes/find.json +0 -34
- data/spec/lib/droplet_kit/client_spec.rb +0 -102
- data/spec/lib/droplet_kit/models/base_model_spec.rb +0 -21
- data/spec/lib/droplet_kit/models/droplet_spec.rb +0 -32
- data/spec/lib/droplet_kit/paginated_resource_spec.rb +0 -85
- data/spec/lib/droplet_kit/resources/account_resource_spec.rb +0 -30
- data/spec/lib/droplet_kit/resources/action_resource_spec.rb +0 -83
- data/spec/lib/droplet_kit/resources/cdn_resource_spec.rb +0 -124
- data/spec/lib/droplet_kit/resources/certificate_resource_spec.rb +0 -119
- data/spec/lib/droplet_kit/resources/domain_record_resource_spec.rb +0 -99
- data/spec/lib/droplet_kit/resources/domain_resource_spec.rb +0 -65
- data/spec/lib/droplet_kit/resources/droplet_action_resource_spec.rb +0 -223
- data/spec/lib/droplet_kit/resources/droplet_resource_spec.rb +0 -340
- data/spec/lib/droplet_kit/resources/droplet_upgrade_resource_spec.rb +0 -22
- data/spec/lib/droplet_kit/resources/firewall_resource_spec.rb +0 -265
- data/spec/lib/droplet_kit/resources/floating_ip_action_resource_spec.rb +0 -137
- data/spec/lib/droplet_kit/resources/floating_ip_resource_spec.rb +0 -91
- data/spec/lib/droplet_kit/resources/image_action_resource_spec.rb +0 -149
- data/spec/lib/droplet_kit/resources/image_resource_spec.rb +0 -93
- data/spec/lib/droplet_kit/resources/kubernetes_cluster_resource_spec.rb +0 -313
- data/spec/lib/droplet_kit/resources/kubernetes_options_resource_spec.rb +0 -33
- data/spec/lib/droplet_kit/resources/load_balancer_resource_spec.rb +0 -213
- data/spec/lib/droplet_kit/resources/project_resource_spec.rb +0 -126
- data/spec/lib/droplet_kit/resources/region_resource_spec.rb +0 -27
- data/spec/lib/droplet_kit/resources/size_resource_spec.rb +0 -27
- data/spec/lib/droplet_kit/resources/snapshot_resource_spec.rb +0 -61
- data/spec/lib/droplet_kit/resources/ssh_key_resource_spec.rb +0 -92
- data/spec/lib/droplet_kit/resources/tag_resource_spec.rb +0 -135
- data/spec/lib/droplet_kit/resources/volume_action_resource_spec.rb +0 -157
- data/spec/lib/droplet_kit/resources/volume_resource_spec.rb +0 -124
- data/spec/spec_helper.rb +0 -19
- data/spec/support/fake_server.rb +0 -4
- data/spec/support/request_stub_helpers.rb +0 -28
- data/spec/support/resource_context.rb +0 -4
- data/spec/support/shared_examples/common_errors.rb +0 -27
- data/spec/support/shared_examples/paginated_endpoint.rb +0 -16
- data/spec/support/shared_examples/unprocessable_entity.rb +0 -11
@@ -1,313 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe DropletKit::KubernetesClusterResource do
|
4
|
-
subject(:resource) { described_class.new(connection: connection) }
|
5
|
-
let(:kubernetes_node_pool_attributes) { DropletKit::KubernetesNodePool.new.attributes }
|
6
|
-
let(:cluster_id) { "c28bf806-eba8-4a6d-a98f-8fd388740bd0" }
|
7
|
-
include_context 'resources'
|
8
|
-
|
9
|
-
describe '#find' do
|
10
|
-
it 'returns a singular cluster' do
|
11
|
-
stub_do_api('/v2/kubernetes/clusters/20', :get).to_return(body: api_fixture('kubernetes/clusters/find'))
|
12
|
-
cluster = resource.find(id: 20)
|
13
|
-
expect(cluster).to be_kind_of(DropletKit::KubernetesCluster)
|
14
|
-
|
15
|
-
expect(cluster.id).to eq("cluster-1-id")
|
16
|
-
expect(cluster.name).to eq("test-cluster")
|
17
|
-
expect(cluster.region).to eq("nyc1")
|
18
|
-
expect(cluster.version).to eq("1.12.1-do.2")
|
19
|
-
expect(cluster.cluster_subnet).to eq("10.244.0.0/16")
|
20
|
-
expect(cluster.ipv4).to eq("0.0.0.0")
|
21
|
-
expect(cluster.tags).to match_array(["test-k8", "k8s", "k8s:cluster-1-id"])
|
22
|
-
expect(cluster.node_pools.count).to eq(1)
|
23
|
-
end
|
24
|
-
|
25
|
-
it_behaves_like 'resource that handles common errors' do
|
26
|
-
let(:path) { '/v2/kubernetes/clusters/123' }
|
27
|
-
let(:method) { :get }
|
28
|
-
let(:action) { :find }
|
29
|
-
let(:arguments) { { id: 123 } }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#update' do
|
34
|
-
let(:path) { '/v2/kubernetes/clusters' }
|
35
|
-
let(:new_attrs) do
|
36
|
-
{
|
37
|
-
"name" => "new-test-name",
|
38
|
-
"tags" => ["new-test"]
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'for a successful update' do
|
43
|
-
it 'returns the created cluster' do
|
44
|
-
cluster = DropletKit::KubernetesCluster.new(new_attrs)
|
45
|
-
|
46
|
-
as_hash = DropletKit::KubernetesClusterMapping.hash_for(:update, cluster)
|
47
|
-
expect(as_hash['name']).to eq(cluster.name)
|
48
|
-
expect(as_hash['tags']).to eq(cluster.tags)
|
49
|
-
|
50
|
-
|
51
|
-
as_string = DropletKit::KubernetesClusterMapping.representation_for(:update, cluster)
|
52
|
-
stub_do_api(path, :put).with(body: as_string).to_return(body: api_fixture('kubernetes/clusters/update'), status: 202)
|
53
|
-
|
54
|
-
updated_cluster = resource.update(cluster)
|
55
|
-
expect(updated_cluster.name).to eq("new-test-name")
|
56
|
-
expect(updated_cluster.tags).to match_array(["new-test"])
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '#all' do
|
62
|
-
it 'returns all of the clusters' do
|
63
|
-
stub_do_api('/v2/kubernetes/clusters', :get).to_return(body: api_fixture('kubernetes/all'))
|
64
|
-
clusters = resource.all
|
65
|
-
expect(clusters).to all(be_kind_of(DropletKit::KubernetesCluster))
|
66
|
-
|
67
|
-
cluster = clusters.first
|
68
|
-
|
69
|
-
expect(cluster.id).to eq("cluster-1-id")
|
70
|
-
expect(cluster.name).to eq("test-cluster")
|
71
|
-
expect(cluster.region).to eq("nyc1")
|
72
|
-
expect(cluster.version).to eq("1.12.1-do.2")
|
73
|
-
expect(cluster.cluster_subnet).to eq("10.244.0.0/16")
|
74
|
-
expect(cluster.ipv4).to eq("0.0.0.0")
|
75
|
-
expect(cluster.tags).to match_array(["test-k8", "k8s", "k8s:cluster-1-id"])
|
76
|
-
expect(cluster.node_pools.count).to eq(1)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'returns an empty array of droplets' do
|
80
|
-
stub_do_api('/v2/kubernetes/clusters', :get).to_return(body: api_fixture('kubernetes/all_empty'))
|
81
|
-
clusters = resource.all.map(&:id)
|
82
|
-
expect(clusters).to be_empty
|
83
|
-
end
|
84
|
-
|
85
|
-
it_behaves_like 'a paginated index' do
|
86
|
-
let(:fixture_path) { 'kubernetes/all' }
|
87
|
-
let(:api_path) { '/v2/kubernetes/clusters' }
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#create' do
|
92
|
-
let(:path) { '/v2/kubernetes/clusters' }
|
93
|
-
let(:new_attrs) do
|
94
|
-
{
|
95
|
-
"name" => "test-cluster-01",
|
96
|
-
"region" => "nyc1",
|
97
|
-
"version" => "1.12.1-do.2",
|
98
|
-
"tags" => ["test"],
|
99
|
-
"node_pools" => [
|
100
|
-
{
|
101
|
-
"size" => "s-1vcpu-1gb",
|
102
|
-
"count" => 3,
|
103
|
-
"name" => "frontend-pool",
|
104
|
-
"tags" => ["frontend"]
|
105
|
-
},
|
106
|
-
{
|
107
|
-
"size" => "c-4",
|
108
|
-
"count" => 2,
|
109
|
-
"name" => "backend-pool"
|
110
|
-
}
|
111
|
-
]
|
112
|
-
}
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'for a successful create' do
|
116
|
-
it 'returns the created cluster' do
|
117
|
-
cluster = DropletKit::KubernetesCluster.new(new_attrs)
|
118
|
-
|
119
|
-
as_hash = DropletKit::KubernetesClusterMapping.hash_for(:create, cluster)
|
120
|
-
expect(as_hash['name']).to eq(cluster.name)
|
121
|
-
expect(as_hash['region']).to eq(cluster.region)
|
122
|
-
expect(as_hash['version']).to eq(cluster.version)
|
123
|
-
expect(as_hash['tags']).to eq(cluster.tags)
|
124
|
-
expect(as_hash['node_pools']).to eq(cluster.node_pools)
|
125
|
-
|
126
|
-
|
127
|
-
as_string = DropletKit::KubernetesClusterMapping.representation_for(:create, cluster)
|
128
|
-
stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('kubernetes/clusters/create'), status: 201)
|
129
|
-
created_cluster = resource.create(cluster)
|
130
|
-
expect(cluster.id).to eq("cluster-1-id")
|
131
|
-
expect(cluster.name).to eq("test-cluster")
|
132
|
-
expect(cluster.region).to eq("nyc1")
|
133
|
-
expect(cluster.version).to eq("1.12.1-do.2")
|
134
|
-
expect(cluster.cluster_subnet).to eq("10.244.0.0/16")
|
135
|
-
expect(cluster.ipv4).to eq("0.0.0.0")
|
136
|
-
expect(cluster.tags).to match_array(["test-k8", "k8s", "k8s:cluster-1-id"])
|
137
|
-
expect(cluster.node_pools.count).to eq(1)
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'reuses the same object' do
|
141
|
-
cluster = DropletKit::KubernetesCluster.new(new_attrs)
|
142
|
-
|
143
|
-
json = DropletKit::KubernetesClusterMapping.representation_for(:create, cluster)
|
144
|
-
stub_do_api(path, :post).with(body: json).to_return(body: api_fixture('kubernetes/clusters/create'), status: 201)
|
145
|
-
created_cluster = resource.create(cluster)
|
146
|
-
expect(created_cluster).to be cluster
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
it_behaves_like 'an action that handles invalid parameters' do
|
151
|
-
let(:action) { 'create' }
|
152
|
-
let(:arguments) { DropletKit::KubernetesCluster.new }
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe '#delete' do
|
157
|
-
it 'sends a delete request for a cluster' do
|
158
|
-
request = stub_do_api('/v2/kubernetes/clusters/23', :delete).to_return(status: 202)
|
159
|
-
response = resource.delete(id: 23)
|
160
|
-
|
161
|
-
expect(request).to have_been_made
|
162
|
-
expect(response).to eq(true)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe '#kubeconfig' do
|
167
|
-
it 'returns a yaml string kubeconfig' do
|
168
|
-
response = Pathname.new('./spec/fixtures/kubernetes/clusters/kubeconfig.txt').read
|
169
|
-
|
170
|
-
stub_do_api('/v2/kubernetes/clusters/1/kubeconfig', :get).to_return(body: response)
|
171
|
-
|
172
|
-
kubeconfig = resource.kubeconfig(id: '1')
|
173
|
-
|
174
|
-
expect(kubeconfig).to be_kind_of(String)
|
175
|
-
|
176
|
-
parsed_config = YAML.load(kubeconfig)
|
177
|
-
expect(parsed_config.keys).to match_array(["apiVersion", "clusters", "contexts", "current-context", "kind", "preferences", "users"])
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
describe "node_pools" do
|
182
|
-
it 'returns the node_pools for a cluster' do
|
183
|
-
stub_do_api("/v2/kubernetes/clusters/#{cluster_id}/node_pools", :get).to_return(body: api_fixture('kubernetes/cluster_node_pools'))
|
184
|
-
node_pools= resource.node_pools(id: cluster_id)
|
185
|
-
node_pools.each do |pool|
|
186
|
-
expect(pool).to be_kind_of(DropletKit::KubernetesNodePool)
|
187
|
-
expect(pool.attributes.keys).to eq kubernetes_node_pool_attributes.keys
|
188
|
-
end
|
189
|
-
expect(node_pools.length).to eq 1
|
190
|
-
expect(node_pools.first["id"]).to eq "0a209365-2fac-465e-a959-bb91f232923a"
|
191
|
-
expect(node_pools.first["name"]).to eq "k8s-1-12-1-do-1-nyc1-1540837045848-1"
|
192
|
-
expect(node_pools.first["size"]).to eq "s-4vcpu-8gb"
|
193
|
-
expect(node_pools.first["count"]).to eq 2
|
194
|
-
expect(node_pools.first["tags"]).to eq [ "omar-left-his-mark" ]
|
195
|
-
expect(node_pools.first["nodes"].length).to eq 2
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
describe "find_node_pool" do
|
200
|
-
it "should return a single node pool" do
|
201
|
-
node_pool_id = "f9f16e5a-83b8-4c9b-acf1-4f91492a6652"
|
202
|
-
stub_do_api("/v2/kubernetes/clusters/#{cluster_id}/node_pools/#{node_pool_id}", :get).to_return(body: api_fixture('kubernetes/cluster_node_pool'))
|
203
|
-
node_pool = resource.find_node_pool(id: cluster_id, pool_id: node_pool_id)
|
204
|
-
|
205
|
-
expect(node_pool.id).to eq node_pool_id
|
206
|
-
expect(node_pool.name).to eq "k8s-1-12-1-do-2-nyc1-1542638764614-1"
|
207
|
-
expect(node_pool.size).to eq "s-1vcpu-1gb"
|
208
|
-
expect(node_pool.count).to eq 1
|
209
|
-
expect(node_pool.tags).to eq ["k8s", "k8s:c28bf806-eba8-4a6d-a98f-8fd388740bd0", "k8s:worker"]
|
210
|
-
expect(node_pool.nodes.length).to eq 1
|
211
|
-
expect(node_pool.nodes.first.name).to eq "blissful-antonelli-3u87"
|
212
|
-
expect(node_pool.nodes.first.status['state']).to eq "running"
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe "create_node_pool" do
|
217
|
-
it 'should create a node_pool in a cluster' do
|
218
|
-
node_pool = DropletKit::KubernetesNodePool.new(
|
219
|
-
name: 'frontend',
|
220
|
-
size: 's-1vcpu-1gb',
|
221
|
-
count: 3,
|
222
|
-
tags: ['k8-tag']
|
223
|
-
)
|
224
|
-
as_hash = DropletKit::KubernetesNodePoolMapping.hash_for(:create, node_pool)
|
225
|
-
expect(as_hash['name']).to eq(node_pool.name)
|
226
|
-
expect(as_hash['size']).to eq(node_pool.size)
|
227
|
-
expect(as_hash['count']).to eq(node_pool.count)
|
228
|
-
expect(as_hash['tags']).to eq(node_pool.tags)
|
229
|
-
|
230
|
-
as_string = DropletKit::KubernetesNodePoolMapping.representation_for(:create, node_pool)
|
231
|
-
stub_do_api("/v2/kubernetes/clusters/#{cluster_id}/node_pools", :post).with(body: as_string).to_return(body: api_fixture('kubernetes/cluster_node_pool_create'), status: 201)
|
232
|
-
new_node_pool = resource.create_node_pool(node_pool, id: cluster_id)
|
233
|
-
|
234
|
-
expect(new_node_pool).to be_kind_of(DropletKit::KubernetesNodePool)
|
235
|
-
expect(new_node_pool.name).to eq 'frontend'
|
236
|
-
expect(new_node_pool.size).to eq 's-1vcpu-1gb'
|
237
|
-
expect(new_node_pool.count).to eq 3
|
238
|
-
expect(new_node_pool.tags).to eq ['k8-tag']
|
239
|
-
expect(new_node_pool.nodes.length).to eq 3
|
240
|
-
new_node_pool.nodes.each do |node|
|
241
|
-
expect(node['name']).to eq ""
|
242
|
-
expect(node['status']['state']).to eq 'provisioning'
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
describe "update_node_pool" do
|
248
|
-
it "should update an existing node_pool" do
|
249
|
-
stub_do_api("/v2/kubernetes/clusters/#{cluster_id}/node_pools", :get).to_return(body: api_fixture('kubernetes/cluster_node_pools'))
|
250
|
-
node_pools = resource.node_pools(id: cluster_id)
|
251
|
-
node_pools.each do |pool|
|
252
|
-
expect(pool).to be_kind_of(DropletKit::KubernetesNodePool)
|
253
|
-
end
|
254
|
-
node_pool_id = "0a209365-2fac-465e-a959-bb91f232923a"
|
255
|
-
expect(node_pools.length).to eq 1
|
256
|
-
expect(node_pools.first["id"]).to eq node_pool_id
|
257
|
-
expect(node_pools.first["name"]).to eq "k8s-1-12-1-do-1-nyc1-1540837045848-1"
|
258
|
-
expect(node_pools.first["size"]).to eq "s-4vcpu-8gb"
|
259
|
-
expect(node_pools.first["count"]).to eq 2
|
260
|
-
expect(node_pools.first["tags"]).to eq [ "omar-left-his-mark" ]
|
261
|
-
|
262
|
-
node_pool = node_pools.first
|
263
|
-
node_pool.name = 'backend'
|
264
|
-
node_pool.size = 's-1vcpu-1gb'
|
265
|
-
node_pool.count = 2
|
266
|
-
node_pool.tags = ['updated-k8-tag']
|
267
|
-
as_string = DropletKit::KubernetesNodePoolMapping.representation_for(:update, node_pool)
|
268
|
-
stub_do_api("/v2/kubernetes/clusters/#{cluster_id}/node_pools/#{node_pool_id}", :put).with(body: as_string).to_return(body: api_fixture('kubernetes/cluster_node_pool_update'), status: 202)
|
269
|
-
updated_node_pool = resource.update_node_pool(node_pool, id: cluster_id, pool_id: node_pool_id)
|
270
|
-
|
271
|
-
expect(updated_node_pool.id).to eq node_pool_id
|
272
|
-
expect(updated_node_pool.name).to eq 'backend'
|
273
|
-
expect(updated_node_pool.size).to eq 's-1vcpu-1gb'
|
274
|
-
expect(updated_node_pool.count).to eq 2
|
275
|
-
expect(updated_node_pool.tags).to eq ['backend']
|
276
|
-
expect(updated_node_pool.nodes.length).to eq 2
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
describe 'delete_node_pool' do
|
281
|
-
it 'should delete a clusters node_pool' do
|
282
|
-
node_pool_id = "f9f16e5a-83b8-4c9b-acf1-4f91492a6652"
|
283
|
-
stub_do_api("/v2/kubernetes/clusters/#{cluster_id}/node_pools/#{node_pool_id}", :delete).to_return(status: 202)
|
284
|
-
deleted_node_pool = resource.delete_node_pool(id: cluster_id, pool_id: node_pool_id)
|
285
|
-
|
286
|
-
expect(deleted_node_pool).to eq true
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
describe 'recycle_node_pool' do
|
291
|
-
it 'should recycle the clusters node_pool' do
|
292
|
-
stub_do_api("/v2/kubernetes/clusters/#{cluster_id}/node_pools", :get).to_return(body: api_fixture('kubernetes/cluster_node_pools'))
|
293
|
-
node_pools = resource.node_pools(id: cluster_id)
|
294
|
-
node_pools.each do |pool|
|
295
|
-
expect(pool).to be_kind_of(DropletKit::KubernetesNodePool)
|
296
|
-
end
|
297
|
-
node_pool_id = "0a209365-2fac-465e-a959-bb91f232923a"
|
298
|
-
expect(node_pools.length).to eq 1
|
299
|
-
expect(node_pools.first["id"]).to eq node_pool_id
|
300
|
-
expect(node_pools.first["name"]).to eq "k8s-1-12-1-do-1-nyc1-1540837045848-1"
|
301
|
-
expect(node_pools.first["count"]).to eq 2
|
302
|
-
|
303
|
-
nodes = node_pools.first.nodes
|
304
|
-
expect(nodes.length).to eq 2
|
305
|
-
node_ids = nodes.map(&:id)
|
306
|
-
recycle_json = { nodes: node_ids}.to_json
|
307
|
-
stub_do_api("/v2/kubernetes/clusters/#{cluster_id}/node_pools/#{node_pool_id}/recycle", :post).with(body: recycle_json).to_return(status: 202)
|
308
|
-
response = resource.recycle_node_pool(node_ids, id: cluster_id, pool_id: node_pool_id)
|
309
|
-
|
310
|
-
expect(response).to eq true
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe DropletKit::KubernetesOptionsResource do
|
4
|
-
subject(:resource) { described_class.new(connection: connection) }
|
5
|
-
include_context 'resources'
|
6
|
-
|
7
|
-
describe 'all' do
|
8
|
-
it 'should get the kubernetes options' do
|
9
|
-
stub_do_api("/v2/kubernetes/options", :get).to_return(body: api_fixture('kubernetes/options'))
|
10
|
-
options = resource.all
|
11
|
-
expect(options).to be_kind_of(DropletKit::KubernetesOptions)
|
12
|
-
expect(options.versions.length).to eq 9
|
13
|
-
options.versions.each do |version|
|
14
|
-
expect(version).to be_kind_of(DropletKit::KubernetesOptionsMapping::Version)
|
15
|
-
expect(version.slug).to be_present
|
16
|
-
expect(version.kubernetes_version).to be_present
|
17
|
-
end
|
18
|
-
expect(options.regions.length).to eq 13
|
19
|
-
options.regions.each do |region|
|
20
|
-
expect(region).to be_kind_of(DropletKit::KubernetesOptionsMapping::Region)
|
21
|
-
expect(region.name).to be_present
|
22
|
-
expect(region.slug).to be_present
|
23
|
-
end
|
24
|
-
expect(options.sizes.length).to eq 13
|
25
|
-
options.sizes.each do |size|
|
26
|
-
expect(size).to be_kind_of(DropletKit::KubernetesOptionsMapping::Size)
|
27
|
-
expect(size.name).to be_present
|
28
|
-
expect(size.slug).to be_present
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
@@ -1,213 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe DropletKit::LoadBalancerResource do
|
4
|
-
include_context 'resources'
|
5
|
-
|
6
|
-
let(:load_balancer_fixture_path) { 'load_balancers/find' }
|
7
|
-
let(:base_path) { '/v2/load_balancers'}
|
8
|
-
let(:load_balancer_id) { '37e6be88-01ec-4ec7-9bc6-a514d4719057' }
|
9
|
-
|
10
|
-
subject(:resource) { described_class.new(connection: connection) }
|
11
|
-
|
12
|
-
RSpec::Matchers.define :match_load_balancer_fixture do
|
13
|
-
match do |load_balancer|
|
14
|
-
expect(load_balancer.name).to eq('example-lb-01')
|
15
|
-
expect(load_balancer.id).to eq('4de7ac8b-495b-4884-9a69-1050c6793cd6')
|
16
|
-
expect(load_balancer.ip).to eq('104.131.186.241')
|
17
|
-
expect(load_balancer.algorithm).to eq('round_robin')
|
18
|
-
expect(load_balancer.status).to eq('active')
|
19
|
-
expect(load_balancer.created_at).to eq('2017-02-01T22:22:58Z')
|
20
|
-
expect(load_balancer.tag).to be_blank
|
21
|
-
expect(load_balancer.region).to be_kind_of(DropletKit::Region)
|
22
|
-
expect(load_balancer.region.attributes)
|
23
|
-
.to match(a_hash_including(slug: 'nyc3', name: 'New York 3',
|
24
|
-
available: true, sizes: ['512mb'], features: ['private_networking']))
|
25
|
-
expect(load_balancer.droplet_ids).to match_array([3164445, 3164444])
|
26
|
-
expect(load_balancer.sticky_sessions).to be_kind_of(DropletKit::StickySession)
|
27
|
-
expect(load_balancer.sticky_sessions.attributes)
|
28
|
-
.to match(a_hash_including(cookie_ttl_seconds: 5, cookie_name: 'DO-LB', type: 'cookies'))
|
29
|
-
expect(load_balancer.health_check).to be_kind_of(DropletKit::HealthCheck)
|
30
|
-
expect(load_balancer.health_check.attributes)
|
31
|
-
.to match(a_hash_including(protocol: 'http', port: 80, path: '/',
|
32
|
-
check_interval_seconds: 10, response_timeout_seconds: 5,
|
33
|
-
healthy_threshold: 5, unhealthy_threshold: 3))
|
34
|
-
expect(load_balancer.forwarding_rules.count).to eq(2)
|
35
|
-
expect(load_balancer.forwarding_rules.first.attributes)
|
36
|
-
.to match(a_hash_including(entry_protocol: 'http', entry_port: 80,
|
37
|
-
target_protocol: 'http', target_port: 80,
|
38
|
-
certificate_id: '', tls_passthrough: false))
|
39
|
-
expect(load_balancer.forwarding_rules.last.attributes)
|
40
|
-
.to match(a_hash_including(entry_protocol: 'https', entry_port: 444,
|
41
|
-
target_protocol: 'https', target_port: 443,
|
42
|
-
certificate_id: 'my-cert', tls_passthrough: true))
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#find' do
|
47
|
-
it 'returns load balancer' do
|
48
|
-
stub_do_api(File.join(base_path, load_balancer_id), :get).to_return(body: api_fixture(load_balancer_fixture_path))
|
49
|
-
load_balancer = resource.find(id: load_balancer_id)
|
50
|
-
|
51
|
-
expect(load_balancer).to match_load_balancer_fixture
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe '#all' do
|
56
|
-
let(:load_balancers_fixture_path) { 'load_balancers/all' }
|
57
|
-
|
58
|
-
it 'returns all of the load balancers' do
|
59
|
-
stub_do_api(base_path, :get).to_return(body: api_fixture(load_balancers_fixture_path))
|
60
|
-
load_balancers = resource.all
|
61
|
-
|
62
|
-
expect(load_balancers).to all(be_kind_of(DropletKit::LoadBalancer))
|
63
|
-
expect(load_balancers.first).to match_load_balancer_fixture
|
64
|
-
end
|
65
|
-
|
66
|
-
it_behaves_like 'a paginated index' do
|
67
|
-
let(:fixture_path) { load_balancers_fixture_path }
|
68
|
-
let(:api_path) { base_path }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'create and update' do
|
73
|
-
let(:load_balancer) do
|
74
|
-
DropletKit::LoadBalancer.new(
|
75
|
-
name: 'example-lb-01',
|
76
|
-
algorithm: 'round_robin',
|
77
|
-
droplet_ids: [ 3164444, 3164445],
|
78
|
-
redirect_http_to_https: true,
|
79
|
-
region: 'nyc1',
|
80
|
-
forwarding_rules: [
|
81
|
-
DropletKit::ForwardingRule.new(
|
82
|
-
entry_protocol: 'https',
|
83
|
-
entry_port: 444,
|
84
|
-
target_protocol: 'https',
|
85
|
-
target_port: 443,
|
86
|
-
certificate_id: 'my-cert',
|
87
|
-
tls_passthrough: false
|
88
|
-
)
|
89
|
-
],
|
90
|
-
sticky_sessions: DropletKit::StickySession.new(
|
91
|
-
type: 'cookies',
|
92
|
-
cookie_name: 'DO-LB',
|
93
|
-
cookie_ttl_seconds: 5
|
94
|
-
),
|
95
|
-
health_check: DropletKit::HealthCheck.new(
|
96
|
-
protocol: 'http',
|
97
|
-
port: 80,
|
98
|
-
path: 'index.html',
|
99
|
-
check_interval_seconds: 10,
|
100
|
-
response_timeout_seconds: 5,
|
101
|
-
healthy_threshold: 5,
|
102
|
-
unhealthy_threshold: 3
|
103
|
-
)
|
104
|
-
)
|
105
|
-
end
|
106
|
-
|
107
|
-
describe '#create' do
|
108
|
-
let(:path) { base_path }
|
109
|
-
|
110
|
-
it 'returns created load balancer' do
|
111
|
-
json_body = DropletKit::LoadBalancerMapping.representation_for(:create, load_balancer)
|
112
|
-
stub_do_api(path, :post).with(body: json_body).to_return(body: api_fixture(load_balancer_fixture_path), status: 202)
|
113
|
-
|
114
|
-
expect(resource.create(load_balancer)).to match_load_balancer_fixture
|
115
|
-
end
|
116
|
-
|
117
|
-
it_behaves_like 'an action that handles invalid parameters' do
|
118
|
-
let(:action) { 'create' }
|
119
|
-
let(:arguments) { DropletKit::LoadBalancer.new }
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe '#update' do
|
124
|
-
let(:path) { base_path }
|
125
|
-
|
126
|
-
it 'returns updated load balancer' do
|
127
|
-
json_body = DropletKit::LoadBalancerMapping.representation_for(:update, load_balancer)
|
128
|
-
stub_do_api(File.join(base_path, load_balancer_id), :put).with(body: json_body).to_return(body: api_fixture(load_balancer_fixture_path), status: 200)
|
129
|
-
|
130
|
-
expect(resource.update(load_balancer, id: load_balancer_id)).to match_load_balancer_fixture
|
131
|
-
end
|
132
|
-
|
133
|
-
it_behaves_like 'an action that handles invalid parameters' do
|
134
|
-
let(:action) { 'create' }
|
135
|
-
let(:arguments) { DropletKit::LoadBalancer.new }
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe '#delete' do
|
141
|
-
it 'sends a delete request for the load balancer' do
|
142
|
-
request = stub_do_api(File.join(base_path, load_balancer_id), :delete)
|
143
|
-
resource.delete(id: load_balancer_id)
|
144
|
-
|
145
|
-
expect(request).to have_been_made
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'droplets' do
|
150
|
-
let(:droplet_id_1) { 1 }
|
151
|
-
let(:droplet_id_2) { 2 }
|
152
|
-
|
153
|
-
describe '#add_droplets' do
|
154
|
-
it 'sends a post request for the load balancer to add droplets' do
|
155
|
-
request = stub_do_api(File.join(base_path, load_balancer_id, 'droplets'), :post).with(body: { droplet_ids: [droplet_id_1, droplet_id_2] }.to_json)
|
156
|
-
resource.add_droplets([droplet_id_1, droplet_id_2], id: load_balancer_id)
|
157
|
-
|
158
|
-
expect(request).to have_been_made
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
describe '#remove_droplets' do
|
163
|
-
it 'sends a delete request for the load balancer to remove droplet' do
|
164
|
-
request = stub_do_api(File.join(base_path, load_balancer_id, 'droplets'), :delete).with(body: { droplet_ids: [droplet_id_1]}.to_json)
|
165
|
-
resource.remove_droplets([droplet_id_1], id: load_balancer_id)
|
166
|
-
|
167
|
-
expect(request).to have_been_made
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context 'forwarding_rules' do
|
173
|
-
let(:forwarding_rule_1) do
|
174
|
-
DropletKit::ForwardingRule.new(
|
175
|
-
entry_protocol: 'tcp',
|
176
|
-
entry_port: 3306,
|
177
|
-
target_protocol: 'tcp',
|
178
|
-
target_port: 3306
|
179
|
-
)
|
180
|
-
end
|
181
|
-
|
182
|
-
let(:forwarding_rule_2) do
|
183
|
-
DropletKit::ForwardingRule.new(
|
184
|
-
entry_protocol: 'https',
|
185
|
-
entry_port: 444,
|
186
|
-
target_protocol: 'https',
|
187
|
-
target_port: 443,
|
188
|
-
certificate_id: '',
|
189
|
-
tls_passthrough: true
|
190
|
-
)
|
191
|
-
end
|
192
|
-
|
193
|
-
describe '#add_forwarding_rules' do
|
194
|
-
it 'sends a post request for the load balancer to add forwarding rules' do
|
195
|
-
json_body = DropletKit::ForwardingRuleMapping.represent_collection_for(:create, [forwarding_rule_1, forwarding_rule_2])
|
196
|
-
request = stub_do_api(File.join(base_path, load_balancer_id, 'forwarding_rules'), :post).with(body: json_body)
|
197
|
-
resource.add_forwarding_rules([forwarding_rule_1, forwarding_rule_2], id: load_balancer_id)
|
198
|
-
|
199
|
-
expect(request).to have_been_made
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
describe '#remove_forwarding_rules' do
|
204
|
-
it 'sends a delete request for the load balancer to remove forwarding rule' do
|
205
|
-
json_body = DropletKit::ForwardingRuleMapping.represent_collection_for(:update, [forwarding_rule_1])
|
206
|
-
request = stub_do_api(File.join(base_path, load_balancer_id, 'forwarding_rules'), :delete).with(body: json_body)
|
207
|
-
resource.remove_forwarding_rules([forwarding_rule_1], id: load_balancer_id)
|
208
|
-
|
209
|
-
expect(request).to have_been_made
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|