droplet_kit 2.6.1 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +34 -0
  4. data/lib/droplet_kit.rb +10 -0
  5. data/lib/droplet_kit/client.rb +2 -0
  6. data/lib/droplet_kit/mappings/kubernetes_cluster_mapping.rb +20 -0
  7. data/lib/droplet_kit/mappings/kubernetes_node_mapping.rb +15 -0
  8. data/lib/droplet_kit/mappings/kubernetes_node_pool_mapping.rb +27 -0
  9. data/lib/droplet_kit/mappings/kubernetes_options_mapping.rb +30 -0
  10. data/lib/droplet_kit/models/kubernetes_cluster.rb +7 -0
  11. data/lib/droplet_kit/models/kubernetes_node.rb +7 -0
  12. data/lib/droplet_kit/models/kubernetes_node_pool.rb +7 -0
  13. data/lib/droplet_kit/models/kubernetes_options.rb +7 -0
  14. data/lib/droplet_kit/resources/kubernetes_cluster_resource.rb +70 -0
  15. data/lib/droplet_kit/resources/kubernetes_options_resource.rb +10 -0
  16. data/lib/droplet_kit/version.rb +1 -1
  17. data/spec/fixtures/kubernetes/all.json +70 -0
  18. data/spec/fixtures/kubernetes/all_empty.json +7 -0
  19. data/spec/fixtures/kubernetes/cluster_node_pool.json +24 -0
  20. data/spec/fixtures/kubernetes/cluster_node_pool_create.json +40 -0
  21. data/spec/fixtures/kubernetes/cluster_node_pool_update.json +31 -0
  22. data/spec/fixtures/kubernetes/cluster_node_pools.json +33 -0
  23. data/spec/fixtures/kubernetes/clusters/create.json +65 -0
  24. data/spec/fixtures/kubernetes/clusters/find.json +65 -0
  25. data/spec/fixtures/kubernetes/clusters/kubeconfig.txt +20 -0
  26. data/spec/fixtures/kubernetes/clusters/update.json +63 -0
  27. data/spec/fixtures/kubernetes/options.json +150 -0
  28. data/spec/lib/droplet_kit/resources/kubernetes_cluster_resource_spec.rb +313 -0
  29. data/spec/lib/droplet_kit/resources/kubernetes_options_resource_spec.rb +33 -0
  30. data/test.rb +9 -0
  31. metadata +40 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86f7ab1bde3cbd736afb675cef233f4d24775c32
4
- data.tar.gz: 8d525afec4d2bf96b3e77cafa35dd475584210f6
3
+ metadata.gz: cc932d61ca690fb4a81e55d15b6f8c733ffa1599
4
+ data.tar.gz: 0451b7c0f8fb34965cb6bb4450b8794f0cd5591c
5
5
  SHA512:
6
- metadata.gz: 9d8b775dea7c1d4f2972e22a4c27d00d697f1f028fe27b9caf232ea3643bd21f545591cc736893730f2cccc0294b563d13a1a003e61396266d4150acd4b34e16
7
- data.tar.gz: fed45dc62fe67d39777503472e32345bcb9ac0d886792782fe4ab914cf5f7197d349dcb1ce23c827160531d7a65d7620fa691470abf44aa5a1203dad417a93da
6
+ metadata.gz: 98cbeaaaa47c810447898415d480e3d5a6ba0bb3f0bad57da13192411dd109c0ae569760a92771f8f738bdac758eedd66ee9ce18b21b49cb0c2b7f2409407094
7
+ data.tar.gz: 71a7bf51defafd88379603eb7f6525be77ef7b20c00d13bc9b6ea4050545f535f22cae2b3fd58de9df68cdd7a86ad4f45ca3a038fc1ceca04c478b5ab2216ad6
@@ -1,3 +1,8 @@
1
+ ### Version 2.7.0
2
+ * Added KubernetesCluster resource
3
+ * Added KubernetesOptions resource
4
+ * Added kubernetes cluster and node pool functionality
5
+
1
6
  ### Version 2.6.1
2
7
  * Added custom User-Agent for DropletKit
3
8
 
data/README.md CHANGED
@@ -288,6 +288,40 @@ Image Actions Supported:
288
288
  * `client.image_actions.transfer(image_id: 123, region: 'nyc3')`
289
289
 
290
290
 
291
+ ## Kubernetes Resource
292
+
293
+ ```
294
+ client = DropletKit::Client.new(access_token: 'TOKEN')
295
+ client.kubernetes_clusters #=> DropletKit::KubernetesClusterResource
296
+ ```
297
+
298
+ Actions supported
299
+
300
+ When the arguments below refer to cluster, they refer to:
301
+ ```
302
+ cluster = DropletKit::KubernetesCluster.new(name: "foo", region: "nyc1", ...) # cluster attributes
303
+ ```
304
+
305
+ When the arguments below refer to node_pool, they refer to:
306
+ ```
307
+ node_pool = DropletKit::KubernetesNodePool.new(name: 'frontend', size: 's-1vcpu-1gb', count: 3, ...) # Node Pool attributes
308
+ ```
309
+
310
+ * `client.kubernetes_clusters.all()`
311
+ * `client.kubernetes_clusters.find(id: 'cluster_id')`
312
+ * `client.kubernetes_clusters.create(cluster, id: 'cluster_id')`
313
+ * `client.kubernetes_clusters.kubeconfig(id: 'cluster_id')`
314
+ * `client.kubernetes_clusters.update(cluster, id: 'cluster_id')`
315
+ * `client.kubernetes_clusters.delete(id: 'cluster_id')`
316
+ * `client.kubernetes_clusters.node_pools(id: 'cluster_id')`
317
+ * `client.kubernetes_clusters.find_node_pool(id: 'cluster_id', pool_id: 'node_pool_id')`
318
+ * `client.kubernetes_clusters.create_node_pool(node_pool, id: 'cluster_id')`
319
+ * `client.kubernetes_clusters.update_node_pool(node_pool, id: 'cluster_id', pool_id: 'node_pool_id')`
320
+ * `client.kubernetes_clusters.delete_node_pool(id: 'cluster_id', pool_id: 'node_pool_id')`
321
+ * `client.kubernetes_clusters.recycle_node_pool([node_id, node_id, ...], id: 'cluster_id', pool_id: 'node_pool_id')`
322
+ * `client.kubernetes_options.all()`
323
+
324
+
291
325
  ## Load balancer resource
292
326
  ```ruby
293
327
  client = DropletKit::Client.new(access_token: 'TOKEN')
@@ -43,6 +43,10 @@ module DropletKit
43
43
  autoload :FirewallOutboundRule, 'droplet_kit/models/firewall_outbound_rule'
44
44
  autoload :FirewallPendingChange, 'droplet_kit/models/firewall_pending_change'
45
45
  autoload :CDN, 'droplet_kit/models/cdn'
46
+ autoload :KubernetesCluster, 'droplet_kit/models/kubernetes_cluster'
47
+ autoload :KubernetesNodePool, 'droplet_kit/models/kubernetes_node_pool'
48
+ autoload :KubernetesNode, 'droplet_kit/models/kubernetes_node'
49
+ autoload :KubernetesOptions, 'droplet_kit/models/kubernetes_options'
46
50
 
47
51
  # Resources
48
52
  autoload :DropletResource, 'droplet_kit/resources/droplet_resource'
@@ -68,6 +72,8 @@ module DropletKit
68
72
  autoload :CertificateResource, 'droplet_kit/resources/certificate_resource'
69
73
  autoload :FirewallResource, 'droplet_kit/resources/firewall_resource'
70
74
  autoload :CDNResource, 'droplet_kit/resources/cdn_resource'
75
+ autoload :KubernetesClusterResource, 'droplet_kit/resources/kubernetes_cluster_resource'
76
+ autoload :KubernetesOptionsResource, 'droplet_kit/resources/kubernetes_options_resource'
71
77
 
72
78
  # JSON Maps
73
79
  autoload :DropletMapping, 'droplet_kit/mappings/droplet_mapping'
@@ -106,6 +112,10 @@ module DropletKit
106
112
  autoload :FirewallOutboundRuleMapping, 'droplet_kit/mappings/firewall_outbound_rule_mapping'
107
113
  autoload :FirewallPendingChangeMapping, 'droplet_kit/mappings/firewall_pending_change_mapping'
108
114
  autoload :CDNMapping, 'droplet_kit/mappings/cdn_mapping'
115
+ autoload :KubernetesClusterMapping, 'droplet_kit/mappings/kubernetes_cluster_mapping'
116
+ autoload :KubernetesNodePoolMapping, 'droplet_kit/mappings/kubernetes_node_pool_mapping'
117
+ autoload :KubernetesNodeMapping, 'droplet_kit/mappings/kubernetes_node_mapping'
118
+ autoload :KubernetesOptionsMapping, 'droplet_kit/mappings/kubernetes_options_mapping'
109
119
 
110
120
  # Utils
111
121
  autoload :PaginatedResource, 'droplet_kit/paginated_resource'
@@ -23,6 +23,8 @@ module DropletKit
23
23
  cdns: CDNResource,
24
24
  certificates: CertificateResource,
25
25
  droplets: DropletResource,
26
+ kubernetes_clusters: KubernetesClusterResource,
27
+ kubernetes_options: KubernetesOptionsResource,
26
28
  domains: DomainResource,
27
29
  domain_records: DomainRecordResource,
28
30
  droplet_actions: DropletActionResource,
@@ -0,0 +1,20 @@
1
+ module DropletKit
2
+ class KubernetesClusterMapping
3
+ include Kartograph::DSL
4
+ kartograph do
5
+ mapping KubernetesCluster
6
+ root_key plural: 'kubernetes_clusters', singular: 'kubernetes_cluster', scopes: [:read]
7
+
8
+ property :id, scopes: [:read]
9
+ property :name, scopes: [:read, :update, :create]
10
+ property :region, scopes: [:read, :create]
11
+ property :version, scopes: [:read, :create]
12
+ property :cluster_subnet, scopes: [:read]
13
+ property :service_subnet, scopes: [:read]
14
+ property :ipv4, scopes: [:read]
15
+ property :endpoint, scopes: [:read]
16
+ property :tags, scopes: [:read, :update, :create]
17
+ property :node_pools, scopes: [:read, :create]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ module DropletKit
2
+ class KubernetesNodeMapping
3
+ include Kartograph::DSL
4
+ kartograph do
5
+ mapping KubernetesNode
6
+
7
+ property :id, scopes: [:read]
8
+ property :name, scopes: [:read]
9
+ property :status, scopes: [:read]
10
+ property :created_at, scopes: [:read]
11
+ property :updated_at, scopes: [:read]
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,27 @@
1
+ module DropletKit
2
+ class KubernetesNodePoolMapping
3
+ include Kartograph::DSL
4
+ kartograph do
5
+ mapping KubernetesNodePool
6
+ root_key plural: 'node_pools', singular: 'node_pool', scopes: [:read]
7
+
8
+ property :id, scopes: [:read]
9
+ property :name, scopes: [:read]
10
+ property :size, scopes: [:read]
11
+ property :count, scopes: [:read]
12
+ property :tags, scopes: [:read]
13
+
14
+ property :nodes, plural: true, scopes: [:read], include: KubernetesNodeMapping
15
+
16
+ # Create properties
17
+ property :name, scopes: [:create, :update]
18
+ property :size, scopes: [:create, :update]
19
+ property :count, scopes: [:create, :update]
20
+ property :tags, scopes: [:create, :update]
21
+
22
+ # recycle
23
+ property :nodes, plural: true, scopes: [:recycle]
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,30 @@
1
+ module DropletKit
2
+ class KubernetesOptionsMapping
3
+ include Kartograph::DSL
4
+ kartograph do
5
+ mapping KubernetesOptions
6
+ root_key singular: 'options', scopes: [:read]
7
+
8
+ Version = Struct.new(:slug, :kubernetes_version)
9
+ property :versions, plural: true, scopes: [:read] do
10
+ mapping Version
11
+ property :slug, scopes: [:read]
12
+ property :kubernetes_version, scopes: [:read]
13
+ end
14
+
15
+ Region = Struct.new(:name, :slug)
16
+ property :regions, plural: true, scopes: [:read] do
17
+ mapping Region
18
+ property :name, scopes: [:read]
19
+ property :slug, scopes: [:read]
20
+ end
21
+
22
+ Size = Struct.new(:name, :slug)
23
+ property :sizes, plural: true, scopes: [:read] do
24
+ mapping Size
25
+ property :name, scopes: [:read]
26
+ property :slug, scopes: [:read]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ module DropletKit
2
+ class KubernetesCluster < BaseModel
3
+ [:id, :name, :region, :version, :cluster_subnet, :service_subnet, :ipv4, :endpoint, :tags, :node_pools].each do |key|
4
+ attribute(key)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module DropletKit
2
+ class KubernetesNode < BaseModel
3
+ [:id, :name, :status, :created_at, :updated_at].each do |key|
4
+ attribute(key)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module DropletKit
2
+ class KubernetesNodePool < BaseModel
3
+ [:id, :name, :size, :count, :tags, :nodes].each do |key|
4
+ attribute(key)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module DropletKit
2
+ class KubernetesOptions < BaseModel
3
+ attribute :versions
4
+ attribute :regions
5
+ attribute :sizes
6
+ end
7
+ end
@@ -0,0 +1,70 @@
1
+ module DropletKit
2
+ class KubernetesClusterResource < ResourceKit::Resource
3
+ include ErrorHandlingResourcable
4
+
5
+ resources do
6
+ action :all, 'GET /v2/kubernetes/clusters' do
7
+ query_keys :per_page, :page, :tag_name
8
+ handler(200) { |response| KubernetesClusterMapping.extract_collection(response.body, :read) }
9
+ end
10
+
11
+ action :find, 'GET /v2/kubernetes/clusters/:id' do
12
+ handler(200) { |response| KubernetesClusterMapping.extract_single(response.body, :read) }
13
+ end
14
+
15
+ action :create, 'POST /v2/kubernetes/clusters' do
16
+ body { |object| KubernetesClusterMapping.representation_for(:create, object) }
17
+ handler(201) { |response, cluster| KubernetesClusterMapping.extract_into_object(cluster, response.body, :read) }
18
+ handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) }
19
+ end
20
+
21
+ action :kubeconfig, 'GET /v2/kubernetes/clusters/:id/kubeconfig' do
22
+ handler(200) { |response| response.body }
23
+ end
24
+
25
+ action :update, 'PUT /v2/kubernetes/clusters/:id' do
26
+ body { |cluster| KubernetesClusterMapping.representation_for(:update, cluster) }
27
+ handler(202) { |response| KubernetesClusterMapping.extract_single(response.body, :read) }
28
+ handler(422) { |response| ErrorMapping.fail_with(FailedUpdate, response.body) }
29
+ end
30
+
31
+ action :delete, 'DELETE /v2/kubernetes/clusters/:id' do
32
+ handler(202) { |response| true }
33
+ end
34
+
35
+ action :node_pools, 'GET /v2/kubernetes/clusters/:id/node_pools' do
36
+ handler(200) { |response| KubernetesNodePoolMapping.extract_collection(response.body, :read) }
37
+ end
38
+
39
+ action :find_node_pool, 'GET /v2/kubernetes/clusters/:id/node_pools/:pool_id' do
40
+ handler(200) { |response| KubernetesNodePoolMapping.extract_single(response.body, :read) }
41
+ end
42
+
43
+ action :create_node_pool, 'POST /v2/kubernetes/clusters/:id/node_pools' do
44
+ body { |node_pool| KubernetesNodePoolMapping.representation_for(:create, node_pool) }
45
+ handler(201) { |response| KubernetesNodePoolMapping.extract_single(response.body, :read) }
46
+ handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) }
47
+ end
48
+
49
+ action :update_node_pool, 'PUT /v2/kubernetes/clusters/:id/node_pools/:pool_id' do
50
+ body { |node_pool| KubernetesNodePoolMapping.representation_for(:update, node_pool) }
51
+ handler(202) { |response| KubernetesNodePoolMapping.extract_single(response.body, :read) }
52
+ handler(404) { |response| ErrorMapping.fail_with(FailedUpdate, response.body) }
53
+ end
54
+
55
+ action :delete_node_pool, 'DELETE /v2/kubernetes/clusters/:id/node_pools/:pool_id' do
56
+ handler(202) { |response| true }
57
+ end
58
+
59
+ action :recycle_node_pool, 'POST /v2/kubernetes/clusters/:id/node_pools/:pool_id/recycle' do
60
+ body { |node_ids| { nodes: node_ids }.to_json }
61
+ handler(202) { |response| true }
62
+ handler(404) { |response| ErrorMapping.fail_with(FailedUpdate, response.body) }
63
+ end
64
+ end
65
+
66
+ def all(*args)
67
+ PaginatedResource.new(action(:all), self, *args)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,10 @@
1
+ module DropletKit
2
+ class KubernetesOptionsResource < ResourceKit::Resource
3
+ include ErrorHandlingResourcable
4
+ resources do
5
+ action :all, 'GET /v2/kubernetes/options' do
6
+ handler(200) { |response| KubernetesOptionsMapping.extract_single(response.body, :read) }
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module DropletKit
2
- VERSION = "2.6.1"
2
+ VERSION = "2.7.0"
3
3
  end
@@ -0,0 +1,70 @@
1
+ {
2
+ "kubernetes_clusters": [
3
+ {
4
+ "id": "cluster-1-id",
5
+ "name": "test-cluster",
6
+ "region": "nyc1",
7
+ "version": "1.12.1-do.2",
8
+ "cluster_subnet": "10.244.0.0/16",
9
+ "service_subnet": "",
10
+ "ipv4": "0.0.0.0",
11
+ "endpoint": "",
12
+ "tags": [
13
+ "test-k8",
14
+ "k8s",
15
+ "k8s:cluster-1-id"
16
+ ],
17
+ "node_pools": [
18
+ {
19
+ "id": "node-pool-id",
20
+ "name": "node-pool-1",
21
+ "size": "s-1vcpu-1gb",
22
+ "count": 3,
23
+ "tags": [
24
+ "k8s",
25
+ "k8s:node-pool-id",
26
+ "k8s:worker",
27
+ "test-k8"
28
+ ],
29
+ "nodes": [
30
+ {
31
+ "id": "node-1-id",
32
+ "name": "node-1",
33
+ "status": {
34
+ "state": "running"
35
+ },
36
+ "created_at": "2018-11-16T20:41:44Z",
37
+ "updated_at": "2018-11-16T20:44:27Z"
38
+ },
39
+ {
40
+ "id": "node-2-id",
41
+ "name": "node-2",
42
+ "status": {
43
+ "state": "running"
44
+ },
45
+ "created_at": "2018-11-16T20:41:44Z",
46
+ "updated_at": "2018-11-16T20:44:27Z"
47
+ },
48
+ {
49
+ "id": "node-3-id",
50
+ "name": "node-3",
51
+ "status": {
52
+ "state": "running"
53
+ },
54
+ "created_at": "2018-11-16T20:41:44Z",
55
+ "updated_at": "2018-11-16T20:44:27Z"
56
+ }
57
+ ]
58
+ }
59
+ ],
60
+ "status": {
61
+ "state": "running"
62
+ },
63
+ "created_at": "2018-11-16T20:41:43Z",
64
+ "updated_at": "2018-11-16T20:44:27Z"
65
+ }
66
+ ],
67
+ "meta": {
68
+ "total": 1
69
+ }
70
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "kubernetes_clusters": [
3
+ ],
4
+ "meta": {
5
+ "total": 0
6
+ }
7
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "node_pool": {
3
+ "id": "f9f16e5a-83b8-4c9b-acf1-4f91492a6652",
4
+ "name": "k8s-1-12-1-do-2-nyc1-1542638764614-1",
5
+ "size": "s-1vcpu-1gb",
6
+ "count": 1,
7
+ "tags": [
8
+ "k8s",
9
+ "k8s:c28bf806-eba8-4a6d-a98f-8fd388740bd0",
10
+ "k8s:worker"
11
+ ],
12
+ "nodes": [
13
+ {
14
+ "id": "1607ad61-2d9b-4366-9cb4-5ab6483a7e09",
15
+ "name": "blissful-antonelli-3u87",
16
+ "status": {
17
+ "state": "running"
18
+ },
19
+ "created_at": "2018-11-19T14:46:38Z",
20
+ "updated_at": "2018-11-19T14:56:42Z"
21
+ }
22
+ ]
23
+ }
24
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "node_pool": {
3
+ "id": "5abb80b7-de9e-4e47-bf2d-9318e64ef390",
4
+ "name": "frontend",
5
+ "size": "s-1vcpu-1gb",
6
+ "count": 3,
7
+ "tags": [
8
+ "k8-tag"
9
+ ],
10
+ "nodes": [
11
+ {
12
+ "id": "6f981ff5-560e-4375-a46d-03336d18b4d2",
13
+ "name": "",
14
+ "status": {
15
+ "state": "provisioning"
16
+ },
17
+ "created_at": "2018-11-19T17:34:37Z",
18
+ "updated_at": "2018-11-19T17:34:37Z"
19
+ },
20
+ {
21
+ "id": "af4a3da4-b4c5-490c-a481-0b780d67842a",
22
+ "name": "",
23
+ "status": {
24
+ "state": "provisioning"
25
+ },
26
+ "created_at": "2018-11-19T17:34:37Z",
27
+ "updated_at": "2018-11-19T17:34:37Z"
28
+ },
29
+ {
30
+ "id": "e58e0d0b-52e5-4f3a-8d7d-c7efd34b5f8a",
31
+ "name": "",
32
+ "status": {
33
+ "state": "provisioning"
34
+ },
35
+ "created_at": "2018-11-19T17:34:37Z",
36
+ "updated_at": "2018-11-19T17:34:37Z"
37
+ }
38
+ ]
39
+ }
40
+ }