Skip to content

Commit

Permalink
Confirm from user when deployment is created/upserted, if current dep…
Browse files Browse the repository at this point in the history
…loyment type or new deployment type is dag_deploy (#1543)

* Confirm from user when deployment is created/upserted, if deployment type is dag_deploy

* Fixed linting issues

* Fixed tests

* Fixed tests

* Fixed tests

* Fixed tests

* Fixed tests

* Added test when GetDeployment throws an error
  • Loading branch information
rujhan-arora-astronomer authored and kushalmalani committed Feb 13, 2024
1 parent c3c276b commit 8d7ea5e
Show file tree
Hide file tree
Showing 4 changed files with 475 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cmd/software/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewDeployCmd() *cobra.Command {
cmd.Flags().BoolVarP(&ignoreCacheDeploy, "no-cache", "", false, "Do not use cache when building container image")
cmd.Flags().StringVar(&workspaceID, "workspace-id", "", "workspace assigned to deployment")
if !context.IsCloudContext() && houston.VerifyVersionMatch(houstonVersion, houston.VersionRestrictions{GTE: "0.34.0"}) {
cmd.Flags().BoolVarP(&isDagOnlyDeploy, "dags", "", false, "Push only DAGs to your Deployment")
cmd.Flags().BoolVarP(&isDagOnlyDeploy, "dags", "d", false, "Push only DAGs to your Deployment")
}
return cmd
}
Expand Down
51 changes: 49 additions & 2 deletions cmd/software/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"

"github.com/astronomer/astro-cli/houston"
"github.com/astronomer/astro-cli/pkg/input"
"github.com/astronomer/astro-cli/software/deployment"
"github.com/spf13/cobra"
Expand All @@ -15,11 +16,18 @@ const (
kubernetesExecutorArg = "kubernetes"
k8sExecutorArg = "k8s"

cliDeploymentHardDeletePrompt = "\nWarning: This action permanently deletes all data associated with this Deployment, including the database. You will not be able to recover it. Proceed with hard delete?"
deploymentTypeCmdMessage = "DAG Deployment mechanism: image, volume, git_sync, dag_deploy"
cliDeploymentHardDeletePrompt = "\nWarning: This action permanently deletes all data associated with this Deployment, including the database. You will not be able to recover it. Proceed with hard delete?"
deploymentTypeCmdMessage = "DAG Deployment mechanism: image, volume, git_sync, dag_deploy"
continueSubMsg = " for more details. Do you want to continue?"
CreateDeploymentWithTypeDagDeployPromptMsg = "\nthis is an experimental feature. Please use with caution. See the Software documentation at " + houston.DagDeployDocsLink + continueSubMsg
UpdateDeploymentTypeToDagDeployPromptMsg = "\nthis is an experimental feature. Please use with caution. Changing to a DAG-only Deployment will erase all of the currently deployed DAGs in this deployment. To keep running your DAGs, you must redeploy them to the deployment. See the Software documentation at " + houston.DagDeployDocsLink + continueSubMsg
UpdateDeploymentTypeFromDagDeployPromptMsg = "\nchanging from a DAG-only deployment will erase all of the currently deployed DAGs in this deployment. To keep running your DAGs, you must redeploy them to the deployment. See the Software documentation at " + houston.DeployViaCLIDocsLink + continueSubMsg
SkipUserPromptMsgForCreateDeployment = "Skip user confirmation prompt for creating a deployment with type: dag_deploy (experimental feature)"
SkipUserPromptMsgForUpdateDeployment = "Skip user confirmation prompt for updating the deployment type to/from dag_deploy (experimental feature)"
)

var (
skipPrompt bool
allDeployments bool
cancel bool
hardDelete bool
Expand Down Expand Up @@ -121,6 +129,8 @@ func newDeploymentCreateCmd(out io.Writer) *cobra.Command {
},
}

cmd.Flags().BoolVarP(&skipPrompt, "force", "f", false, SkipUserPromptMsgForCreateDeployment)

var nfsMountDAGDeploymentEnabled, triggererEnabled, gitSyncDAGDeploymentEnabled, runtimeEnabled, dagOnlyDeployEnabled bool
if appConfig != nil {
nfsMountDAGDeploymentEnabled = appConfig.Flags.NfsMountDagDeployment
Expand Down Expand Up @@ -212,6 +222,8 @@ $ astro deployment update [deployment ID] --dag-deployment-type=volume --nfs-loc
},
}

cmd.Flags().BoolVarP(&skipPrompt, "force", "f", false, SkipUserPromptMsgForUpdateDeployment)

var nfsMountDAGDeploymentEnabled, triggererEnabled, gitSyncDAGDeploymentEnabled, dagOnlyDeployEnabled bool
if appConfig != nil {
nfsMountDAGDeploymentEnabled = appConfig.Flags.NfsMountDagDeployment
Expand Down Expand Up @@ -374,6 +386,15 @@ func deploymentCreate(cmd *cobra.Command, out io.Writer) error {
createTriggererReplicas = -1
}

// If it's a dag_deploy type, validate from the user first
if !skipPrompt && dagDeploymentType == houston.DagOnlyDeploymentType {
y, _ := input.Confirm(CreateDeploymentWithTypeDagDeployPromptMsg)
if !y {
fmt.Println("canceling deployment create..")
return nil
}
}

// we should validate only in case when this feature has been enabled
if nfsMountDAGDeploymentEnabled || gitSyncDAGDeploymentEnabled || dagOnlyDeployEnabled {
err = validateDagDeploymentArgs(dagDeploymentType, nfsLocation, gitRepoURL, false)
Expand Down Expand Up @@ -453,6 +474,32 @@ func deploymentUpdate(cmd *cobra.Command, args []string, dagDeploymentType, nfsL
dagOnlyDeployEnabled = appConfig.Flags.DagOnlyDeployment
}

// new dag deployment type or current dag deployment type is dag_deploy, confirm from user
if !skipPrompt {
deploymentInfo, err := houston.Call(houstonClient.GetDeployment)(args[0])
if err != nil {
return fmt.Errorf("failed to get deployment info: %w", err)
}

// non dag_deploy to dag_deploy
if deploymentInfo.DagDeployment.Type != houston.DagOnlyDeploymentType && dagDeploymentType == houston.DagOnlyDeploymentType {
y, _ := input.Confirm(UpdateDeploymentTypeToDagDeployPromptMsg)
if !y {
fmt.Println("canceling deployment update..")
return nil
}
}

// dag_deploy to non dag_deploy
if deploymentInfo.DagDeployment.Type == houston.DagOnlyDeploymentType && dagDeploymentType != houston.DagOnlyDeploymentType {
y, _ := input.Confirm(UpdateDeploymentTypeFromDagDeployPromptMsg)
if !y {
fmt.Println("canceling deployment update..")
return nil
}
}
}

// we should validate only in case when this feature has been enabled
if nfsMountDAGDeploymentEnabled || gitSyncDAGDeploymentEnabled || dagOnlyDeployEnabled {
err := validateDagDeploymentArgs(dagDeploymentType, nfsLocation, gitRepoURL, true)
Expand Down
Loading

0 comments on commit 8d7ea5e

Please sign in to comment.