cloud: use instanceid as name in aws (#2210)

This commit is contained in:
3u13r 2023-08-11 12:09:29 +02:00 committed by GitHub
parent aa787a3ea6
commit 4acfcaf723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 88 deletions

View File

@ -302,14 +302,9 @@ func (c *Cloud) convertToMetadataInstance(ec2Instances []ec2Types.Instance) ([]m
newInstance := metadata.InstanceMetadata{
VPCIP: *ec2Instance.PrivateIpAddress,
Name: *ec2Instance.InstanceId,
}
name, err := findTag(ec2Instance.Tags, tagName)
if err != nil {
return nil, fmt.Errorf("retrieving tag for instance %s: %w", *ec2Instance.InstanceId, err)
}
newInstance.Name = name
instanceRole, err := findTag(ec2Instance.Tags, cloud.TagRole)
if err != nil {
return nil, fmt.Errorf("retrieving tag for instance %s: %w", *ec2Instance.InstanceId, err)

View File

@ -121,10 +121,6 @@ func TestSelf(t *testing.T) {
{
InstanceId: aws.String("test-instance-id"),
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("test-instance"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("controlplane"),
@ -170,12 +166,7 @@ func TestSelf(t *testing.T) {
Instances: []ec2Types.Instance{
{
InstanceId: aws.String("test-instance-id"),
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("test-instance"),
},
},
Tags: []ec2Types.Tag{},
},
},
},
@ -221,10 +212,6 @@ func TestList(t *testing.T) {
AvailabilityZone: aws.String("test-zone"),
},
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-1"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("controlplane"),
@ -243,10 +230,6 @@ func TestList(t *testing.T) {
AvailabilityZone: aws.String("test-zone"),
},
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-2"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("worker"),
@ -284,10 +267,6 @@ func TestList(t *testing.T) {
{
InstanceId: aws.String("id-1"),
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-1"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("controlplane"),
@ -306,13 +285,13 @@ func TestList(t *testing.T) {
},
wantList: []metadata.InstanceMetadata{
{
Name: "name-1",
Name: "id-1",
Role: role.ControlPlane,
ProviderID: "aws:///test-zone/id-1",
VPCIP: "192.0.2.1",
},
{
Name: "name-2",
Name: "id-2",
Role: role.Worker,
ProviderID: "aws:///test-zone/id-2",
VPCIP: "192.0.2.2",
@ -335,10 +314,6 @@ func TestList(t *testing.T) {
{
InstanceId: aws.String("id-1"),
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-1"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("controlplane"),
@ -365,10 +340,6 @@ func TestList(t *testing.T) {
AvailabilityZone: aws.String("test-zone-2"),
},
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-3"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("worker"),
@ -388,19 +359,19 @@ func TestList(t *testing.T) {
},
wantList: []metadata.InstanceMetadata{
{
Name: "name-3",
Name: "id-3",
Role: role.Worker,
ProviderID: "aws:///test-zone-2/id-3",
VPCIP: "192.0.2.3",
},
{
Name: "name-1",
Name: "id-1",
Role: role.ControlPlane,
ProviderID: "aws:///test-zone/id-1",
VPCIP: "192.0.2.1",
},
{
Name: "name-2",
Name: "id-2",
Role: role.Worker,
ProviderID: "aws:///test-zone/id-2",
VPCIP: "192.0.2.2",
@ -423,10 +394,6 @@ func TestList(t *testing.T) {
{
InstanceId: aws.String("id-1"),
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-1"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("controlplane"),
@ -846,10 +813,6 @@ func TestConvertToMetadataInstance(t *testing.T) {
AvailabilityZone: aws.String("test-zone"),
},
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-1"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("controlplane"),
@ -859,7 +822,7 @@ func TestConvertToMetadataInstance(t *testing.T) {
},
wantInstances: []metadata.InstanceMetadata{
{
Name: "name-1",
Name: "id-1",
Role: role.ControlPlane,
ProviderID: "aws:///test-zone/id-1",
VPCIP: "192.0.2.1",
@ -873,10 +836,6 @@ func TestConvertToMetadataInstance(t *testing.T) {
InstanceId: aws.String("id-1"),
PrivateIpAddress: aws.String("192.0.2.1"),
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-1"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("controlplane"),
@ -887,7 +846,7 @@ func TestConvertToMetadataInstance(t *testing.T) {
wantInstances: []metadata.InstanceMetadata{
{
Name: "name-1",
Name: "id-1",
Role: role.ControlPlane,
ProviderID: "aws:///id-1",
VPCIP: "192.0.2.1",
@ -913,10 +872,6 @@ func TestConvertToMetadataInstance(t *testing.T) {
AvailabilityZone: aws.String("test-zone"),
},
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-1"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("controlplane"),
@ -934,29 +889,6 @@ func TestConvertToMetadataInstance(t *testing.T) {
Placement: &ec2Types.Placement{
AvailabilityZone: aws.String("test-zone"),
},
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-1"),
},
{
Key: aws.String(cloud.TagRole),
Value: aws.String("controlplane"),
},
},
},
},
wantErr: true,
},
"missing name tag": {
in: []ec2Types.Instance{
{
State: &ec2Types.InstanceState{Name: ec2Types.InstanceStateNameRunning},
InstanceId: aws.String("id-1"),
PrivateIpAddress: aws.String("192.0.2.1"),
Placement: &ec2Types.Placement{
AvailabilityZone: aws.String("test-zone"),
},
Tags: []ec2Types.Tag{
{
Key: aws.String(cloud.TagRole),
@ -976,12 +908,7 @@ func TestConvertToMetadataInstance(t *testing.T) {
Placement: &ec2Types.Placement{
AvailabilityZone: aws.String("test-zone"),
},
Tags: []ec2Types.Tag{
{
Key: aws.String(tagName),
Value: aws.String("name-1"),
},
},
Tags: []ec2Types.Tag{},
},
},
wantErr: true,