chore(sg): cloud ephemeral fix instance check (#62988)

* fix instance check

* fix name sanitization
This commit is contained in:
William Bezuidenhout 2024-05-31 15:39:46 +02:00 committed by GitHub
parent 52059fc947
commit bc73643a5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 13 deletions

View File

@ -95,15 +95,14 @@ func createDeploymentForVersion(ctx context.Context, email, name, version string
// Check if the deployment already exists
pending.Updatef("Checking if deployment %q already exists", name)
_, err = cloudClient.GetInstance(ctx, name)
if err != nil {
if !errors.Is(err, ErrInstanceNotFound) {
return errors.Wrapf(err, "failed to check if instance %q already exists", name)
} else {
pending.Complete(output.Linef(output.EmojiFailure, output.StyleFailure, "Deployment of %q failed", name))
// Deployment exists
return ErrDeploymentExists
}
inst, err := cloudClient.GetInstance(ctx, name)
if err != nil && !errors.Is(err, ErrInstanceNotFound) {
return errors.Wrapf(err, "failed to check if instance %q already exists", name)
}
if inst != nil {
pending.Complete(output.Linef(output.EmojiFailure, output.StyleFailure, "Deployment of %q failed", name))
// Deployment exists
return ErrDeploymentExists
}
pending.Updatef("Fetching license key...")
@ -113,13 +112,13 @@ func createDeploymentForVersion(ctx context.Context, email, name, version string
return err
}
spec := NewDeploymentSpec(
sanitizeInstanceName(name),
name,
version,
license,
)
pending.Updatef("Creating deployment %q for version %q", spec.Name, spec.Version)
inst, err := cloudClient.CreateInstance(ctx, spec)
inst, err = cloudClient.CreateInstance(ctx, spec)
if err != nil {
pending.Complete(output.Linef(output.EmojiFailure, output.StyleFailure, "Deployment of %q failed", spec.Name))
return errors.Wrapf(err, "failed to deploy %q of version %s", spec.Name, spec.Version)
@ -186,7 +185,7 @@ func determineDeploymentName(originalName, version, email, branch string) string
deploymentName = branch
}
return deploymentName
return sanitizeInstanceName(deploymentName)
}

View File

@ -37,7 +37,7 @@ func upgradeDeploymentForVersion(ctx context.Context, email, name, version strin
}
spec := NewDeploymentSpec(
sanitizeInstanceName(name),
name,
version,
"", // we don't need a license during upgrade
)