Skip to content

Commit 7b22346

Browse files
authored
fix: add ref id as a prefix for instance name (#43)
1 parent f1ac8aa commit 7b22346

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

v1/providers/shadeform/instance.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const (
1717
hostname = "shadecloud"
1818
refIDTagName = "refID"
1919
cloudCredRefIDTagName = "cloudCredRefID" //nolint:gosec // not a secret
20+
instanceNameFormat = "%v_%v"
21+
instanceNameSeparator = "_"
2022
)
2123

2224
func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateInstanceAttrs) (*v1.Instance, error) { //nolint:gocyclo,funlen // ok
@@ -88,7 +90,7 @@ func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateIns
8890
Cloud: *cloudEnum,
8991
Region: region,
9092
ShadeInstanceType: shadeInstanceType,
91-
Name: attrs.Name,
93+
Name: c.getInstanceNameForShadeform(attrs.RefID, attrs.Name),
9294
ShadeCloud: true,
9395
Tags: tags,
9496
SshKeyId: &sshKeyID,
@@ -123,6 +125,19 @@ func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateIns
123125
return createdInstance, nil
124126
}
125127

128+
func (c *ShadeformClient) getInstanceNameForShadeform(refID string, providedName string) string {
129+
return fmt.Sprintf(instanceNameFormat, refID, providedName)
130+
}
131+
132+
func (c *ShadeformClient) getProvidedInstanceName(shadeformInstanceName string) string {
133+
before, after, found := strings.Cut(shadeformInstanceName, instanceNameSeparator)
134+
if found {
135+
return after
136+
} else {
137+
return before
138+
}
139+
}
140+
126141
func (c *ShadeformClient) addSSHKey(ctx context.Context, keyPairName string, publicKey string) (string, error) {
127142
authCtx := c.makeAuthContext(ctx)
128143

@@ -261,7 +276,7 @@ func (c *ShadeformClient) convertInstanceInfoResponseToV1Instance(instanceInfo o
261276
delete(tags, cloudCredRefIDTagName)
262277

263278
instance := &v1.Instance{
264-
Name: instanceInfo.Name,
279+
Name: c.getProvidedInstanceName(instanceInfo.Name),
265280
CreatedAt: instanceInfo.CreatedAt,
266281
CloudID: v1.CloudProviderInstanceID(instanceInfo.Id),
267282
PublicIP: instanceInfo.Ip,

0 commit comments

Comments
 (0)