mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-20 04:28:07 -04:00
cloud: use instanceid as name in aws (#2210)
This commit is contained in:
parent
aa787a3ea6
commit
4acfcaf723
2 changed files with 10 additions and 88 deletions
|
@ -302,14 +302,9 @@ func (c *Cloud) convertToMetadataInstance(ec2Instances []ec2Types.Instance) ([]m
|
||||||
|
|
||||||
newInstance := metadata.InstanceMetadata{
|
newInstance := metadata.InstanceMetadata{
|
||||||
VPCIP: *ec2Instance.PrivateIpAddress,
|
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)
|
instanceRole, err := findTag(ec2Instance.Tags, cloud.TagRole)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("retrieving tag for instance %s: %w", *ec2Instance.InstanceId, err)
|
return nil, fmt.Errorf("retrieving tag for instance %s: %w", *ec2Instance.InstanceId, err)
|
||||||
|
|
|
@ -121,10 +121,6 @@ func TestSelf(t *testing.T) {
|
||||||
{
|
{
|
||||||
InstanceId: aws.String("test-instance-id"),
|
InstanceId: aws.String("test-instance-id"),
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("test-instance"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
Value: aws.String("controlplane"),
|
Value: aws.String("controlplane"),
|
||||||
|
@ -170,12 +166,7 @@ func TestSelf(t *testing.T) {
|
||||||
Instances: []ec2Types.Instance{
|
Instances: []ec2Types.Instance{
|
||||||
{
|
{
|
||||||
InstanceId: aws.String("test-instance-id"),
|
InstanceId: aws.String("test-instance-id"),
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{},
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("test-instance"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -221,10 +212,6 @@ func TestList(t *testing.T) {
|
||||||
AvailabilityZone: aws.String("test-zone"),
|
AvailabilityZone: aws.String("test-zone"),
|
||||||
},
|
},
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("name-1"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
Value: aws.String("controlplane"),
|
Value: aws.String("controlplane"),
|
||||||
|
@ -243,10 +230,6 @@ func TestList(t *testing.T) {
|
||||||
AvailabilityZone: aws.String("test-zone"),
|
AvailabilityZone: aws.String("test-zone"),
|
||||||
},
|
},
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("name-2"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
Value: aws.String("worker"),
|
Value: aws.String("worker"),
|
||||||
|
@ -284,10 +267,6 @@ func TestList(t *testing.T) {
|
||||||
{
|
{
|
||||||
InstanceId: aws.String("id-1"),
|
InstanceId: aws.String("id-1"),
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("name-1"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
Value: aws.String("controlplane"),
|
Value: aws.String("controlplane"),
|
||||||
|
@ -306,13 +285,13 @@ func TestList(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantList: []metadata.InstanceMetadata{
|
wantList: []metadata.InstanceMetadata{
|
||||||
{
|
{
|
||||||
Name: "name-1",
|
Name: "id-1",
|
||||||
Role: role.ControlPlane,
|
Role: role.ControlPlane,
|
||||||
ProviderID: "aws:///test-zone/id-1",
|
ProviderID: "aws:///test-zone/id-1",
|
||||||
VPCIP: "192.0.2.1",
|
VPCIP: "192.0.2.1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "name-2",
|
Name: "id-2",
|
||||||
Role: role.Worker,
|
Role: role.Worker,
|
||||||
ProviderID: "aws:///test-zone/id-2",
|
ProviderID: "aws:///test-zone/id-2",
|
||||||
VPCIP: "192.0.2.2",
|
VPCIP: "192.0.2.2",
|
||||||
|
@ -335,10 +314,6 @@ func TestList(t *testing.T) {
|
||||||
{
|
{
|
||||||
InstanceId: aws.String("id-1"),
|
InstanceId: aws.String("id-1"),
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("name-1"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
Value: aws.String("controlplane"),
|
Value: aws.String("controlplane"),
|
||||||
|
@ -365,10 +340,6 @@ func TestList(t *testing.T) {
|
||||||
AvailabilityZone: aws.String("test-zone-2"),
|
AvailabilityZone: aws.String("test-zone-2"),
|
||||||
},
|
},
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("name-3"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
Value: aws.String("worker"),
|
Value: aws.String("worker"),
|
||||||
|
@ -388,19 +359,19 @@ func TestList(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantList: []metadata.InstanceMetadata{
|
wantList: []metadata.InstanceMetadata{
|
||||||
{
|
{
|
||||||
Name: "name-3",
|
Name: "id-3",
|
||||||
Role: role.Worker,
|
Role: role.Worker,
|
||||||
ProviderID: "aws:///test-zone-2/id-3",
|
ProviderID: "aws:///test-zone-2/id-3",
|
||||||
VPCIP: "192.0.2.3",
|
VPCIP: "192.0.2.3",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "name-1",
|
Name: "id-1",
|
||||||
Role: role.ControlPlane,
|
Role: role.ControlPlane,
|
||||||
ProviderID: "aws:///test-zone/id-1",
|
ProviderID: "aws:///test-zone/id-1",
|
||||||
VPCIP: "192.0.2.1",
|
VPCIP: "192.0.2.1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "name-2",
|
Name: "id-2",
|
||||||
Role: role.Worker,
|
Role: role.Worker,
|
||||||
ProviderID: "aws:///test-zone/id-2",
|
ProviderID: "aws:///test-zone/id-2",
|
||||||
VPCIP: "192.0.2.2",
|
VPCIP: "192.0.2.2",
|
||||||
|
@ -423,10 +394,6 @@ func TestList(t *testing.T) {
|
||||||
{
|
{
|
||||||
InstanceId: aws.String("id-1"),
|
InstanceId: aws.String("id-1"),
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("name-1"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
Value: aws.String("controlplane"),
|
Value: aws.String("controlplane"),
|
||||||
|
@ -846,10 +813,6 @@ func TestConvertToMetadataInstance(t *testing.T) {
|
||||||
AvailabilityZone: aws.String("test-zone"),
|
AvailabilityZone: aws.String("test-zone"),
|
||||||
},
|
},
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("name-1"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
Value: aws.String("controlplane"),
|
Value: aws.String("controlplane"),
|
||||||
|
@ -859,7 +822,7 @@ func TestConvertToMetadataInstance(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantInstances: []metadata.InstanceMetadata{
|
wantInstances: []metadata.InstanceMetadata{
|
||||||
{
|
{
|
||||||
Name: "name-1",
|
Name: "id-1",
|
||||||
Role: role.ControlPlane,
|
Role: role.ControlPlane,
|
||||||
ProviderID: "aws:///test-zone/id-1",
|
ProviderID: "aws:///test-zone/id-1",
|
||||||
VPCIP: "192.0.2.1",
|
VPCIP: "192.0.2.1",
|
||||||
|
@ -873,10 +836,6 @@ func TestConvertToMetadataInstance(t *testing.T) {
|
||||||
InstanceId: aws.String("id-1"),
|
InstanceId: aws.String("id-1"),
|
||||||
PrivateIpAddress: aws.String("192.0.2.1"),
|
PrivateIpAddress: aws.String("192.0.2.1"),
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("name-1"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
Value: aws.String("controlplane"),
|
Value: aws.String("controlplane"),
|
||||||
|
@ -887,7 +846,7 @@ func TestConvertToMetadataInstance(t *testing.T) {
|
||||||
|
|
||||||
wantInstances: []metadata.InstanceMetadata{
|
wantInstances: []metadata.InstanceMetadata{
|
||||||
{
|
{
|
||||||
Name: "name-1",
|
Name: "id-1",
|
||||||
Role: role.ControlPlane,
|
Role: role.ControlPlane,
|
||||||
ProviderID: "aws:///id-1",
|
ProviderID: "aws:///id-1",
|
||||||
VPCIP: "192.0.2.1",
|
VPCIP: "192.0.2.1",
|
||||||
|
@ -913,10 +872,6 @@ func TestConvertToMetadataInstance(t *testing.T) {
|
||||||
AvailabilityZone: aws.String("test-zone"),
|
AvailabilityZone: aws.String("test-zone"),
|
||||||
},
|
},
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("name-1"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
Value: aws.String("controlplane"),
|
Value: aws.String("controlplane"),
|
||||||
|
@ -934,29 +889,6 @@ func TestConvertToMetadataInstance(t *testing.T) {
|
||||||
Placement: &ec2Types.Placement{
|
Placement: &ec2Types.Placement{
|
||||||
AvailabilityZone: aws.String("test-zone"),
|
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{
|
Tags: []ec2Types.Tag{
|
||||||
{
|
{
|
||||||
Key: aws.String(cloud.TagRole),
|
Key: aws.String(cloud.TagRole),
|
||||||
|
@ -976,12 +908,7 @@ func TestConvertToMetadataInstance(t *testing.T) {
|
||||||
Placement: &ec2Types.Placement{
|
Placement: &ec2Types.Placement{
|
||||||
AvailabilityZone: aws.String("test-zone"),
|
AvailabilityZone: aws.String("test-zone"),
|
||||||
},
|
},
|
||||||
Tags: []ec2Types.Tag{
|
Tags: []ec2Types.Tag{},
|
||||||
{
|
|
||||||
Key: aws.String(tagName),
|
|
||||||
Value: aws.String("name-1"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue