Class: EksCli::NodeGroup
- Inherits:
-
Object
- Object
- EksCli::NodeGroup
- Defined in:
- lib/eks_cli/nodegroup.rb
Constant Summary collapse
- T =
{cluster_name: "ClusterName", control_plane_sg_id: "ClusterControlPlaneSecurityGroup", nodes_sg_id: "ClusterSecurityGroup", min: "NodeAutoScalingGroupMinSize", max: "NodeAutoScalingGroupMaxSize", instance_type: "NodeInstanceType", ami: "NodeImageId", volume_size: "NodeVolumeSize", ssh_key_name: "KeyName", vpc_id: "VpcId", subnets: "Subnets", group_name: "NodeGroupName", bootstrap_args: "BootstrapArguments"}
- AMIS =
{"us-west-2" => "ami-0a54c984b9f908c81", "us-east-1" => "ami-0440e4f6b9713faf6", "us-east-2" => "ami-0958a76db2d150238", "us-west-1" => "ami-00c3b2d35bddd4f5c"}
- GPU_AMIS =
{"us-west-2" => "ami-08156e8fd65879a13", "us-east-1" => "ami-0c974dde3f6d691a1", "us-east-2" => "ami-089849e811ace242f", "us-west-1" => "ami-0c3479bcd739094f0"}
- CAPABILITIES =
["CAPABILITY_IAM"]
Instance Method Summary collapse
- #asg ⇒ Object
- #cf_stack ⇒ Object
- #create(wait_for_completion: true) ⇒ Object
- #delete ⇒ Object
- #detach_iam_policies ⇒ Object
- #export_to_spotinst ⇒ Object
-
#initialize(cluster_name, name) ⇒ NodeGroup
constructor
A new instance of NodeGroup.
- #instance_type ⇒ Object
- #scale(min, max) ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(cluster_name, name) ⇒ NodeGroup
Returns a new instance of NodeGroup.
39 40 41 42 43 |
# File 'lib/eks_cli/nodegroup.rb', line 39 def initialize(cluster_name, name) @cluster_name = cluster_name @name = name @group = Config[cluster_name].for_group(name) end |
Instance Method Details
#asg ⇒ Object
69 70 71 |
# File 'lib/eks_cli/nodegroup.rb', line 69 def asg @asg ||= cf_stack.resource("NodeGroup") end |
#cf_stack ⇒ Object
82 83 84 85 86 87 |
# File 'lib/eks_cli/nodegroup.rb', line 82 def cf_stack CloudFormation::Stack.find(@cluster_name, stack_name) rescue Aws::CloudFormation::Errors::ValidationError => e Log.error("could not find stack for nodegroup #{@name} - please make sure to run eks create-nodegroup --all --yes -c <cluster_name> to sync config") raise e end |
#create(wait_for_completion: true) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/eks_cli/nodegroup.rb', line 45 def create(wait_for_completion: true) Log.info "creating stack for nodegroup #{@group["group_name"]}" stack = CloudFormation::Stack.create(@cluster_name, cloudformation_config) Log.info "stack created - #{@group["group_name"]} - #{stack.id}" if wait_for_completion await(stack) end stack end |
#delete ⇒ Object
64 65 66 67 |
# File 'lib/eks_cli/nodegroup.rb', line 64 def delete detach_iam_policies cf_stack.delete end |
#detach_iam_policies ⇒ Object
60 61 62 |
# File 'lib/eks_cli/nodegroup.rb', line 60 def detach_iam_policies IAM::Client.new(@cluster_name).detach_node_policies(cf_stack.node_instance_role_name) end |
#export_to_spotinst ⇒ Object
77 78 79 80 |
# File 'lib/eks_cli/nodegroup.rb', line 77 def export_to_spotinst Log.info "exporting nodegroup #{@name} to spotinst" Log.info Spotinst::Client.new.import_asg(config["region"], asg, [instance_type]) end |
#instance_type ⇒ Object
73 74 75 |
# File 'lib/eks_cli/nodegroup.rb', line 73 def instance_type @group["instance_type"] end |
#scale(min, max) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/eks_cli/nodegroup.rb', line 89 def scale(min, max) Log.info "scaling #{asg}: min -> #{min}, max -> #{max}" Log.info asg_client.update_auto_scaling_group({ auto_scaling_group_name: asg, max_size: max, min_size: min }) end |
#tags ⇒ Object
55 56 57 58 |
# File 'lib/eks_cli/nodegroup.rb', line 55 def [{key: "eks-nodegroup", value: @group["group_name"]}, {key: "eks-cluster", value: @cluster_name}] end |