Class: EksCli::NodeGroup

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(cluster_name, name) ⇒ NodeGroup

Returns a new instance of NodeGroup.



38
39
40
41
42
# File 'lib/eks_cli/nodegroup.rb', line 38

def initialize(cluster_name, name)
  @cluster_name = cluster_name
  @name = name
  @group = Config[cluster_name].for_group(name)
end

Instance Method Details

#asgObject



68
69
70
# File 'lib/eks_cli/nodegroup.rb', line 68

def asg
  cf_stack.resource("NodeGroup")
end

#cf_stackObject



81
82
83
84
85
86
# File 'lib/eks_cli/nodegroup.rb', line 81

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



44
45
46
47
48
49
50
51
52
# File 'lib/eks_cli/nodegroup.rb', line 44

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

#deleteObject



63
64
65
66
# File 'lib/eks_cli/nodegroup.rb', line 63

def delete
  detach_iam_policies
  cf_stack.delete
end

#detach_iam_policiesObject



59
60
61
# File 'lib/eks_cli/nodegroup.rb', line 59

def detach_iam_policies
  IAM::Client.new(@cluster_name).detach_node_policies(cf_stack.node_instance_role_name)
end

#export_to_spotinstObject



76
77
78
79
# File 'lib/eks_cli/nodegroup.rb', line 76

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_typeObject



72
73
74
# File 'lib/eks_cli/nodegroup.rb', line 72

def instance_type
  @group["instance_type"]
end

#tagsObject



54
55
56
57
# File 'lib/eks_cli/nodegroup.rb', line 54

def tags
  [{key: "eks-nodegroup", value: @group["group_name"]},
   {key: "eks-cluster", value: @cluster_name}]
end