Skip to content

Commit

Permalink
fixes #99 (#100)
Browse files Browse the repository at this point in the history
* fixes #99

* fetch ami info from instance id
  • Loading branch information
surajnarwade authored Sep 6, 2023
1 parent d7d39b6 commit e2f0a08
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions cmd/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ func nodes(cmd *cobra.Command, args []string) error {
// AMI
if i.Labels[kube.NodeGroupImage] == "" {
amiID = i.Labels[kube.KarpenterImage]
dis, _ := ec2Client.DescribeImages(ctx, &ec2.DescribeImagesInput{ImageIds: []string{amiID}})
amiName = aws.ToString(dis.Images[0].Name)
if amiID != "" {
dis, err := ec2Client.DescribeImages(ctx, &ec2.DescribeImagesInput{ImageIds: []string{amiID}})
if err != nil {
log.Fatal(err)
}
amiName = aws.ToString(dis.Images[0].Name)
}

} else {
amiID = i.Labels[kube.NodeGroupImage]
dis, err := ec2Client.DescribeImages(ctx, &ec2.DescribeImagesInput{ImageIds: []string{amiID}})
Expand All @@ -63,6 +69,22 @@ func nodes(cmd *cobra.Command, args []string) error {
amiName = aws.ToString(dis.Images[0].Name)
}

if amiID == "" {
instanceId := strings.Split(i.Spec.ProviderID, "/")[len(strings.Split(i.Spec.ProviderID, "/"))-1]
out, err := ec2Client.DescribeInstances(ctx, &ec2.DescribeInstancesInput{
InstanceIds: []string{instanceId},
})
if err != nil {
log.Fatal(err)
}
amiID = *out.Reservations[0].Instances[0].ImageId
dis, err := ec2Client.DescribeImages(ctx, &ec2.DescribeImagesInput{ImageIds: []string{amiID}})
if err != nil {
log.Fatal(err)
}
amiName = aws.ToString(dis.Images[0].Name)
}

// Capacity Type
if i.Labels[kube.CapacityTypeLabel] != "" {
capacityType = i.Labels[kube.CapacityTypeLabel]
Expand Down

0 comments on commit e2f0a08

Please sign in to comment.