aws: name instances for CCM

This commit is contained in:
Leonard Cohnen 2022-11-02 13:00:22 +01:00 committed by 3u13r
parent 0d0191ba4d
commit 1f9a788c21
2 changed files with 3 additions and 24 deletions

View File

@ -96,17 +96,13 @@ func (m *Metadata) Self(ctx context.Context) (metadata.InstanceMetadata, error)
return metadata.InstanceMetadata{}, fmt.Errorf("retrieving instance identity: %w", err)
}
name, err := readInstanceTag(ctx, m.imds, tagName)
if err != nil {
return metadata.InstanceMetadata{}, fmt.Errorf("retrieving name tag: %w", err)
}
instanceRole, err := readInstanceTag(ctx, m.imds, cloud.TagRole)
if err != nil {
return metadata.InstanceMetadata{}, fmt.Errorf("retrieving role tag: %w", err)
}
return metadata.InstanceMetadata{
Name: name,
Name: identity.InstanceID,
ProviderID: fmt.Sprintf("aws:///%s/%s", identity.AvailabilityZone, identity.InstanceID),
Role: role.FromString(instanceRole),
VPCIP: identity.PrivateIP,

View File

@ -47,12 +47,11 @@ func TestSelf(t *testing.T) {
},
},
tags: map[string]string{
tagName: "test-instance",
cloud.TagRole: "controlplane",
},
},
wantSelf: metadata.InstanceMetadata{
Name: "test-instance",
Name: "test-instance-id",
ProviderID: "aws:///test-zone/test-instance-id",
Role: role.ControlPlane,
VPCIP: "192.0.2.1",
@ -68,12 +67,11 @@ func TestSelf(t *testing.T) {
},
},
tags: map[string]string{
tagName: "test-instance",
cloud.TagRole: "worker",
},
},
wantSelf: metadata.InstanceMetadata{
Name: "test-instance",
Name: "test-instance-id",
ProviderID: "aws:///test-zone/test-instance-id",
Role: role.Worker,
VPCIP: "192.0.2.1",
@ -102,21 +100,6 @@ func TestSelf(t *testing.T) {
},
wantErr: true,
},
"name not set": {
imds: &stubIMDS{
instanceDocumentResp: &imds.GetInstanceIdentityDocumentOutput{
InstanceIdentityDocument: imds.InstanceIdentityDocument{
InstanceID: "test-instance-id",
AvailabilityZone: "test-zone",
PrivateIP: "192.0.2.1",
},
},
tags: map[string]string{
cloud.TagRole: "controlplane",
},
},
wantErr: true,
},
"role not set": {
imds: &stubIMDS{
instanceDocumentResp: &imds.GetInstanceIdentityDocumentOutput{