eks_cli 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f3f3482b85b1f958736fc15f42ca78a0758bb260f41fc2b9a82b8ac4d41290d
4
- data.tar.gz: f8716d74941af68b46f7b969af80d5d0747f140f4eaf09d0ca5d32d32c66f4d7
3
+ metadata.gz: 4f9a211d597363f1bed8d7d5da00a16a235fa64bbce4b406597999f4d1646f39
4
+ data.tar.gz: 52066dc17593bb64e4f57f6e2888385a96148cc3ba089928655bd81a57dd460f
5
5
  SHA512:
6
- metadata.gz: 7632811983ed89098c1be2f08cc92f612641863ce0aa90d0b6c19dfbdf3d6de75a9e06a1133f673db9f0a90205511b930de790db47a099b253b24f4c043b8bce
7
- data.tar.gz: d4592a8ee34300d7b87b63aa32146bd5fcfbd150760ee36ea4a8a3e86332566aa6b2a93173cdbb6199cd7ab798d5739f8c8f1e1fc5e06c4c41dea147d2e3d61e
6
+ metadata.gz: 92894a3cc1f53d3bc641bc493a1c1050202ed613b636fc91bbc14901da6646e42c3c93114e18df7fd8c3d14c3a3ce61dedb3aef2294c6494b2881687f6e41c0d
7
+ data.tar.gz: a8f1ea587bc68568347fae185878f4727677aeed81a8dc0da72cbe050bd4e55df8cf91a49085a8e9fe911a148562216af5d0c801a5140a32b5479e6572aeda89
data/lib/eks_cli/cli.rb CHANGED
@@ -65,9 +65,9 @@ module EksCli
65
65
  option :group_name, desc: "group name to show configuration for"
66
66
  def show_config
67
67
  if options[:group_name]
68
- puts JSON.pretty_generate(Config[cluster_name].for_group(options[:group_name]))
68
+ puts JSON.pretty_generate(config.for_group(options[:group_name]))
69
69
  else
70
- puts JSON.pretty_generate(Config[cluster_name].read_from_disk)
70
+ puts JSON.pretty_generate(config.read_from_disk)
71
71
  end
72
72
  end
73
73
 
@@ -95,7 +95,7 @@ module EksCli
95
95
  option :all, type: :boolean, default: false, desc: "create all nodegroups. must be used in conjunction with --yes"
96
96
  option :group_name, type: :string, default: "Workers", desc: "create a specific nodegroup. can't be used with --all"
97
97
  option :ami, desc: "AMI for the nodegroup"
98
- option :instance_type, default: "m5.xlarge", desc: "EC2 instance type (m5.xlarge etc...)"
98
+ option :instance_type, default: "m4.xlarge", desc: "EC2 instance type (m5.xlarge etc...)"
99
99
  option :subnets, type: :array, default: ["1", "2", "3"], desc: "subnets to run on. for example --subnets=1 3 will run the nodegroup on subnet1 and subnet 3"
100
100
  option :ssh_key_name, desc: "name of the default SSH key for the nodes"
101
101
  option :taints, desc: "Kubernetes taints to put on the nodes for example \"dedicated=critical:NoSchedule\""
@@ -117,12 +117,20 @@ module EksCli
117
117
  end
118
118
 
119
119
  desc "scale-nodegroup", "scales a nodegroup"
120
- option :group_name, type: :string, required: true, desc: "nodegroup name to scale"
121
- option :min, required: true, type: :numeric, desc: "Minimum number of nodes on the nodegroup"
122
- option :max, required: true, type: :numeric, desc: "Maximum number of nodes on the nodegroup"
120
+ option :all, type: :boolean, default: false, desc: "scale all nodegroups"
121
+ option :group_name, type: :string, required: false, desc: "nodegroup name to scale"
122
+ option :min, required: false, type: :numeric, desc: "minimum number of nodes on the nodegroup. defaults to nodegroup configuration."
123
+ option :max, required: false, type: :numeric, desc: "maximum number of nodes on the nodegroup. default to nodegroup configuration"
124
+ option :spotinst, type: :boolean, default: false, desc: "scale spotinst elastigroup if such exists"
125
+ option :asg, type: :boolean, default: true, desc: "scale ec2 auto scaling group"
126
+ option :update, type: :boolean, default: false, desc: "update the nodegroup attributes"
123
127
  def scale_nodegroup
124
- NodeGroup.new(cluster_name, options[:group_name]).scale(options[:min].to_i, options[:max].to_i)
125
- Config[cluster_name].update_nodegroup(options)
128
+ nodegroups.each do |ng|
129
+ min = (options[:min] || config.for_group(ng.name)["min"]).to_i
130
+ max = (options[:max] || config.for_group(ng.name)["max"]).to_i
131
+ ng.scale(min, max, options[:asg], options[:spotinst])
132
+ Config[cluster_name].update_nodegroup(options.slice("min", "max").merge({"group_name" => ng.name})) if options[:update]
133
+ end
126
134
  end
127
135
 
128
136
  desc "delete-nodegroup", "deletes cloudformation stack for nodegroup"
@@ -62,7 +62,7 @@ module EksCli
62
62
  end
63
63
 
64
64
  def update_nodegroup(options)
65
- options = options.slice("ami", "group_name", "instance_type", "subnets", "ssh_key_name", "volume_size", "taints", "min", "max", "enable_docker_bridge", "desired")
65
+ options = options.slice("ami", "group_name", "instance_type", "subnets", "ssh_key_name", "volume_size", "taints", "min", "max", "enable_docker_bridge", "desired", "spotinst")
66
66
  raise "bad nodegroup name #{options["group_name"]}" if options["group_name"] == nil || options["group_name"].empty?
67
67
  write({groups: { options["group_name"] => options }}, :groups)
68
68
  end
@@ -57,6 +57,8 @@ module EksCli
57
57
  stack
58
58
  end
59
59
 
60
+ def name; @name; end
61
+
60
62
  def tags
61
63
  [{key: "eks-nodegroup", value: @group["group_name"]},
62
64
  {key: "eks-cluster", value: @cluster_name}]
@@ -64,6 +66,9 @@ module EksCli
64
66
 
65
67
  def delete
66
68
  cf_stack.delete
69
+ if @group["spotinst"]
70
+ spotinst.delete_elastigroup(@group["spotinst"]["id"])
71
+ end
67
72
  end
68
73
 
69
74
  def asg
@@ -77,7 +82,14 @@ module EksCli
77
82
  def export_to_spotinst(exact_instance_type)
78
83
  Log.info "exporting nodegroup #{@name} to spotinst"
79
84
  instance_types = exact_instance_type ? [instance_type] : nil
80
- Log.info Spotinst::Client.new.import_asg(config["region"], asg, instance_types)
85
+ response = spotinst.import_asg(config["region"], asg, instance_types)
86
+ if response.code == 200
87
+ Log.info "Successfully created elastigroup"
88
+ elastigroup = response.parsed_response["response"]["items"].first
89
+ config.update_nodegroup({"group_name" => @name, "spotinst" => elastigroup})
90
+ else
91
+ Log.warn "Error creating elastigroup:\n #{response}"
92
+ end
81
93
  end
82
94
 
83
95
  def cf_stack
@@ -87,16 +99,30 @@ module EksCli
87
99
  raise e
88
100
  end
89
101
 
90
- def scale(min, max)
91
- Log.info "scaling #{asg}: min -> #{min}, max -> #{max}"
102
+ def scale(min, max, asg = true, spotinst = false)
103
+ scale_asg(min, max) if asg
104
+ scale_spotinst(min, max) if spotinst
105
+ end
106
+
107
+ private
108
+
109
+ def scale_spotinst(min, max)
110
+ if eid = @group.dig("spotinst", "id")
111
+ spotinst.scale(eid, min, max)
112
+ else
113
+ Log.warn "could not find spotinst elastigroup for nodegroup #{@name}"
114
+ end
115
+ end
116
+
117
+ def scale_asg(min, max)
118
+ Log.info "scaling ASG #{asg}: min -> #{min}, max -> #{max}"
92
119
  Log.info asg_client.update_auto_scaling_group({
93
120
  auto_scaling_group_name: asg,
94
121
  max_size: max,
95
122
  min_size: min
96
123
  })
97
- end
98
124
 
99
- private
125
+ end
100
126
 
101
127
  def cf_template_body
102
128
  @cf_template_body ||= File.read(File.join($root_dir, '/assets/cf/nodegroup.yaml'))
@@ -185,6 +211,10 @@ module EksCli
185
211
  @asg_client ||= Aws::AutoScaling::Client.new(region: config["region"])
186
212
  end
187
213
 
214
+ def spotinst
215
+ @spotinst ||= Spotinst::Client.new
216
+ end
217
+
188
218
  end
189
219
 
190
220
  end
@@ -1,4 +1,5 @@
1
1
  require 'httparty'
2
+ require 'log'
2
3
  module EksCli
3
4
  module Spotinst
4
5
  class Client
@@ -29,6 +30,16 @@ module EksCli
29
30
  def list_groups
30
31
  self.class.get("/aws/ec2/group?accountId=#{@account_id}")
31
32
  end
33
+
34
+ def scale(group_id, min, max)
35
+ Log.info "scaling elastigroup #{group_id} {#{min}, #{max}}"
36
+ Log.info self.class.put("/aws/ec2/group/#{group_id}/capacity?accountId=#{@account_id}", body: {capacity: {minimum: min, maximum: max, target: max}}.to_json)
37
+ end
38
+
39
+ def delete_elastigroup(group_id)
40
+ Log.info "deleting elastigroup #{group_id}"
41
+ Log.info self.class.delete("/aws/ec2/group/#{group_id}?accountId=#{@account_id}")
42
+ end
32
43
  end
33
44
  end
34
45
  end
@@ -1,3 +1,3 @@
1
1
  module EksCli
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eks_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erez Rabih