Skip to content

Commit

Permalink
Add instance info to detached nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Markus With committed Sep 2, 2020
1 parent cf0466b commit 8cce475
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions upup/pkg/fi/cloudup/awsup/aws_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,17 +788,7 @@ func awsBuildCloudInstanceGroup(c AWSCloud, cluster *kops.Cluster, ig *kops.Inst
return nil, fmt.Errorf("error creating cloud instance group member: %v", err)
}

cm.MachineType = aws.StringValue(i.InstanceType)
instance := instances[id]
for _, tag := range instance.Tags {
key := aws.StringValue(tag.Key)
if !strings.HasPrefix(key, TagNameRolePrefix) {
continue
}
role := strings.TrimPrefix(key, TagNameRolePrefix)
cm.Roles = append(cm.Roles, role)
cm.PrivateIP = aws.StringValue(instance.PrivateIpAddress)
}
addCloudInstanceData(cm, instances[id])

}

Expand All @@ -815,17 +805,31 @@ func awsBuildCloudInstanceGroup(c AWSCloud, cluster *kops.Cluster, ig *kops.Inst
}
for _, id := range detached {
if id != nil && *id != "" && !instanceSeen[*id] {
_, err := cg.NewCloudInstance(*id, cloudinstances.CloudInstanceStatusDetached, nodeMap)
cm, err := cg.NewCloudInstance(*id, cloudinstances.CloudInstanceStatusDetached, nodeMap)
if err != nil {
return nil, fmt.Errorf("error creating cloud instance group member: %v", err)
}
instanceSeen[*id] = true
addCloudInstanceData(cm, instances[aws.StringValue(id)])
}
}

return cg, nil
}

func addCloudInstanceData(cm *cloudinstances.CloudInstance, instance *ec2.Instance) {
cm.MachineType = aws.StringValue(instance.InstanceType)
for _, tag := range instance.Tags {
key := aws.StringValue(tag.Key)
if !strings.HasPrefix(key, TagNameRolePrefix) {
continue
}
role := strings.TrimPrefix(key, TagNameRolePrefix)
cm.Roles = append(cm.Roles, role)
cm.PrivateIP = aws.StringValue(instance.PrivateIpAddress)
}
}

func findInstances(c AWSCloud, ig *kops.InstanceGroup) (map[string]*ec2.Instance, error) {
req := &ec2.DescribeInstancesInput{
Filters: []*ec2.Filter{
Expand Down

0 comments on commit 8cce475

Please sign in to comment.