Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions v1/providers/shadeform/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
hostname = "shadecloud"
refIDTagName = "refID"
cloudCredRefIDTagName = "cloudCredRefID" //nolint:gosec // not a secret
instanceNameFormat = "%v_%v"
instanceNameSeparator = "_"
)

func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateInstanceAttrs) (*v1.Instance, error) { //nolint:gocyclo,funlen // ok
Expand Down Expand Up @@ -88,7 +90,7 @@ func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateIns
Cloud: *cloudEnum,
Region: region,
ShadeInstanceType: shadeInstanceType,
Name: attrs.Name,
Name: c.getInstanceNameForShadeform(attrs.RefID, attrs.Name),
ShadeCloud: true,
Tags: tags,
SshKeyId: &sshKeyID,
Expand Down Expand Up @@ -123,6 +125,19 @@ func (c *ShadeformClient) CreateInstance(ctx context.Context, attrs v1.CreateIns
return createdInstance, nil
}

func (c *ShadeformClient) getInstanceNameForShadeform(refID string, providedName string) string {
return fmt.Sprintf(instanceNameFormat, refID, providedName)
}

func (c *ShadeformClient) getProvidedInstanceName(shadeformInstanceName string) string {
before, after, found := strings.Cut(shadeformInstanceName, instanceNameSeparator)
if found {
return after
} else {
return before
}
}

func (c *ShadeformClient) addSSHKey(ctx context.Context, keyPairName string, publicKey string) (string, error) {
authCtx := c.makeAuthContext(ctx)

Expand Down Expand Up @@ -261,7 +276,7 @@ func (c *ShadeformClient) convertInstanceInfoResponseToV1Instance(instanceInfo o
delete(tags, cloudCredRefIDTagName)

instance := &v1.Instance{
Name: instanceInfo.Name,
Name: c.getProvidedInstanceName(instanceInfo.Name),
CreatedAt: instanceInfo.CreatedAt,
CloudID: v1.CloudProviderInstanceID(instanceInfo.Id),
PublicIP: instanceInfo.Ip,
Expand Down
Loading