Skip to content

Commit

Permalink
Do not throw the error for astro deploy if dag-deploy itself is disab…
Browse files Browse the repository at this point in the history
…led (#1538)

* Do not throw the error for astro deploy if dag-deploy itself is disabled

* Do not throw the error for astro deploy if dag-deploy itself is disabled

* Do not throw the error for astro deploy if dag-deploy itself is disabled
  • Loading branch information
rujhan-arora-astronomer authored and kushalmalani committed Feb 9, 2024
1 parent 2b9b949 commit 3407f5a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
9 changes: 8 additions & 1 deletion cmd/software/deploy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package software

import (
"errors"
"fmt"

"github.com/astronomer/astro-cli/cmd/utils"
Expand Down Expand Up @@ -104,5 +105,11 @@ func deployAirflow(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
return DagsOnlyDeploy(houstonClient, appConfig, ws, deploymentID, config.WorkingPath, nil, true)

err = DagsOnlyDeploy(houstonClient, appConfig, ws, deploymentID, config.WorkingPath, nil, true)
// Don't throw the error if dag-deploy itself is disabled
if errors.Is(err, deploy.ErrDagOnlyDeployDisabledInConfig) || errors.Is(err, deploy.ErrDagOnlyDeployNotEnabledForDeployment) {
return nil
}
return err
}
13 changes: 11 additions & 2 deletions cmd/software/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@ func TestDeploy(t *testing.T) {
}
})

t.Run("error should be returned for astro deploy, if dags deploy throws error", func(t *testing.T) {
t.Run("error should be returned for astro deploy, if dags deploy throws error and the feature is enabled", func(t *testing.T) {
DagsOnlyDeploy = func(houstonClient houston.ClientInterface, appConfig *houston.AppConfig, wsID, deploymentID, dagsParentPath string, dagDeployURL *string, cleanUpFiles bool) error {
return deploy.ErrNoWorkspaceID
}
err := execDeployCmd([]string{"-f"}...)
assert.ErrorIs(t, err, deploy.ErrDagOnlyDeployDisabledInConfig)
assert.ErrorIs(t, err, deploy.ErrNoWorkspaceID)
DagsOnlyDeploy = deploy.DagsOnlyDeploy
})

t.Run("No error should be returned for astro deploy, if dags deploy throws error but the feature itself is disabled", func(t *testing.T) {
err := execDeployCmd([]string{"-f"}...)
assert.ErrorIs(t, err, nil)
})

t.Run("Test for the flag --dags", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions software/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
errDeploymentNotFound = errors.New("no airflow deployments found")
errInvalidDeploymentSelected = errors.New("invalid deployment selection\n") //nolint
ErrDagOnlyDeployDisabledInConfig = errors.New("to perform this operation, set both deployments.dagOnlyDeployment and deployments.configureDagDeployment to true in your Astronomer cluster")
errDagOnlyDeployNotEnabledForDeployment = errors.New("to perform this operation, first set the Deployment type to 'dag_deploy' via the UI or the API")
ErrDagOnlyDeployNotEnabledForDeployment = errors.New("to perform this operation, first set the Deployment type to 'dag_deploy' via the UI or the API or the CLI")
ErrEmptyDagFolderUserCancelledOperation = errors.New("no DAGs found in the dags folder. User canceled the operation")
)

Expand Down Expand Up @@ -354,7 +354,7 @@ func DagsOnlyDeploy(houstonClient houston.ClientInterface, appConfig *houston.Ap
return fmt.Errorf("failed to get deployment info: %w", err)
}
if !isDagOnlyDeploymentEnabledForDeployment(deploymentInfo) {
return errDagOnlyDeployNotEnabledForDeployment
return ErrDagOnlyDeployNotEnabledForDeployment
}

uploadURL := ""
Expand Down
2 changes: 1 addition & 1 deletion software/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func TestDeployDagsOnlyFailure(t *testing.T) {
}
houstonMock.On("GetDeployment", mock.Anything).Return(deployment, nil).Once()
err := DagsOnlyDeploy(houstonMock, appConfig, wsID, deploymentID, config.WorkingPath, nil, false)
assert.ErrorIs(t, err, errDagOnlyDeployNotEnabledForDeployment)
assert.ErrorIs(t, err, ErrDagOnlyDeployNotEnabledForDeployment)
houstonMock.AssertExpectations(t)
})

Expand Down

0 comments on commit 3407f5a

Please sign in to comment.