Skip to content

Commit

Permalink
Add appropriate error message when trying to create standard deployme…
Browse files Browse the repository at this point in the history
…nt with a clusterId (#1563)
  • Loading branch information
vandyliu authored and kushalmalani committed Feb 23, 2024
1 parent af32037 commit 0540a8a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/cloud/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,9 @@ func deploymentCreate(cmd *cobra.Command, _ []string, out io.Writer) error { //n
if deploymentCreateEnforceCD && cicdEnforcement == disable {
return errors.New("flags --enforce-cicd and --cicd-enforcment contradict each other. Use only --cicd-enforcment")
}
if organization.IsOrgHosted() && clusterID != "" && (deploymentType == standard || deploymentType == fromfile.HostedStandard || deploymentType == fromfile.HostedShared) {
return errors.New("flag --cluster-id cannot be used to create a standard deployment. If you want to create a dedicated deployment, use --type dedicated along with --cluster-id")
}
if deploymentCreateEnforceCD {
cicdEnforcement = enable
}
Expand Down
23 changes: 22 additions & 1 deletion cmd/cloud/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ func TestDeploymentCreate(t *testing.T) {
testUtil.InitTestConfig(testUtil.LocalPlatform)

ws := "workspace-id"
csID := "test-cluster-id"
mockCoreClient := new(astrocore_mocks.ClientWithResponsesInterface)
mockPlatformCoreClient := new(astroplatformcore_mocks.ClientWithResponsesInterface)

Expand Down Expand Up @@ -862,6 +861,28 @@ deployment:
_, err = execDeploymentCmd(cmdArgs...)
assert.ErrorContains(t, err, "Invalid --high-availability value")
})
t.Run("returns an error if cluster-id is provided with implicit standard deployment", func(t *testing.T) {
ctx, err := context.GetCurrentContext()
assert.NoError(t, err)
ctx.SetContextKey("organization_product", "HOSTED")
ctx.SetContextKey("organization", "test-org-id")
ctx.SetContextKey("workspace", ws)
cmdArgs := []string{"create", "--name", "test-name", "--workspace-id", ws, "--cluster-id", csID}
_, err = execDeploymentCmd(cmdArgs...)
assert.Error(t, err)
assert.ErrorContains(t, err, "flag --cluster-id cannot be used to create a standard deployment")
})
t.Run("returns an error if cluster-id is provided with explicit standard deployment", func(t *testing.T) {
ctx, err := context.GetCurrentContext()
assert.NoError(t, err)
ctx.SetContextKey("organization_product", "HOSTED")
ctx.SetContextKey("organization", "test-org-id")
ctx.SetContextKey("workspace", ws)
cmdArgs := []string{"create", "--name", "test-name", "--workspace-id", ws, "--cluster-id", csID, "--type", standard}
_, err = execDeploymentCmd(cmdArgs...)
assert.Error(t, err)
assert.ErrorContains(t, err, "flag --cluster-id cannot be used to create a standard deployment")
})
}

func TestDeploymentDelete(t *testing.T) {
Expand Down

0 comments on commit 0540a8a

Please sign in to comment.