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"}
CAPABILITIES =
["CAPABILITY_IAM"]

Instance Method Summary collapse

Constructor Details

#initialize(cluster_name, name) ⇒ NodeGroup

Returns a new instance of NodeGroup.



28
29
30
31
32
# File 'lib/eks_cli/nodegroup.rb', line 28

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

Instance Method Details

#asgObject



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

def asg
  cf_stack.resource("NodeGroup")
end

#create(wait_for_completion: true) ⇒ Object



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

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



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

def delete
  detach_iam_policies
  cf_stack.delete
end

#detach_iam_policiesObject



49
50
51
# File 'lib/eks_cli/nodegroup.rb', line 49

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

#export_to_spotinstObject



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

def export_to_spotinst
  Log.info "exporting nodegroup #{@name} to spotinst"
  Log.info Spotinst::Client.new.import_asg(Config[@cluster_name]["region"], asg, [instance_type])
end

#instance_typeObject



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

def instance_type
  @group["instance_type"]
end

#tagsObject



44
45
46
47
# File 'lib/eks_cli/nodegroup.rb', line 44

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