Skip to content

Commit

Permalink
Throw error on custom deploy when dag deploy is enabled (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalmalani authored Oct 18, 2022
1 parent 881df4a commit 8932fbc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
8 changes: 7 additions & 1 deletion cloud/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ var (
azureUploader = azure.Upload
)

var errDagsParseFailed = errors.New("your local DAGs did not parse. Fix the listed errors or use `astro deploy [deployment-id] -f` to force deploy") //nolint:revive
var (
errDagsParseFailed = errors.New("your local DAGs did not parse. Fix the listed errors or use `astro deploy [deployment-id] -f` to force deploy") //nolint:revive
customDeployError = errors.New("Dag Deploy is enabled. To perform custom image deploy, you will need to contact Astronomer Support to disable dag deploy") //nolint:revive
)

type deploymentInfo struct {
deploymentID string
Expand Down Expand Up @@ -525,6 +528,9 @@ func buildImage(c *config.Context, path, currentVersion, deployImage, imageName
}
}
} else {
if dagDeployEnabled {
return "", customDeployError
}
// skip build if an imageName is passed
fmt.Println(composeSkipImageBuildingPromptMsg)

Expand Down
25 changes: 11 additions & 14 deletions cloud/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ func TestDeployWithDagsDeploySuccess(t *testing.T) {

mockClient.On("GetDeployment", mock.Anything).Return(mockDeplyResp, nil).Times(5)
mockClient.On("ListDeployments", org, ws).Return([]astro.Deployment{{ID: "test-id", DagDeployEnabled: true}}, nil).Times(1)
mockClient.On("GetDeploymentConfig").Return(astro.DeploymentConfig{RuntimeReleases: []astro.RuntimeRelease{{Version: "4.2.5"}}}, nil).Times(6)
mockClient.On("CreateImage", mock.Anything).Return(&astro.Image{}, nil).Times(6)
mockClient.On("DeployImage", mock.Anything).Return(&astro.Image{}, nil).Times(6)
mockClient.On("InitiateDagDeployment", astro.InitiateDagDeploymentInput{RuntimeID: runtimeID}).Return(astro.InitiateDagDeployment{ID: initiatedDagDeploymentID, DagURL: dagURL}, nil).Times(2)
mockClient.On("GetDeploymentConfig").Return(astro.DeploymentConfig{RuntimeReleases: []astro.RuntimeRelease{{Version: "4.2.5"}}}, nil).Times(5)
mockClient.On("CreateImage", mock.Anything).Return(&astro.Image{}, nil).Times(5)
mockClient.On("DeployImage", mock.Anything).Return(&astro.Image{}, nil).Times(5)
mockClient.On("InitiateDagDeployment", astro.InitiateDagDeploymentInput{RuntimeID: runtimeID}).Return(astro.InitiateDagDeployment{ID: initiatedDagDeploymentID, DagURL: dagURL}, nil).Times(5)

azureUploader = func(sasLink string, file io.Reader) (string, error) {
return "version-id", nil
Expand All @@ -175,14 +175,13 @@ func TestDeployWithDagsDeploySuccess(t *testing.T) {
Status: "SUCCEEDED",
Message: "Dags uploaded successfully",
}
mockClient.On("ReportDagDeploymentStatus", reportDagDeploymentStatusInput).Return(astro.DagDeploymentStatus{}, nil).Times(2)
mockClient.On("ReportDagDeploymentStatus", reportDagDeploymentStatusInput).Return(astro.DagDeploymentStatus{}, nil).Times(5)

mockImageHandler := new(mocks.ImageHandler)
airflowImageHandler = func(image string) airflow.ImageHandler {
mockImageHandler.On("Build", mock.Anything).Return(nil)
mockImageHandler.On("Push", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
mockImageHandler.On("GetLabel", runtimeImageLabel).Return("", nil)
mockImageHandler.On("TagLocalImage", mock.Anything).Return(nil)
return mockImageHandler
}

Expand Down Expand Up @@ -224,14 +223,6 @@ func TestDeployWithDagsDeploySuccess(t *testing.T) {
deployInput.Pytest = "pytest"
deployInput.Prompt = false
err = Deploy(deployInput, mockClient)

assert.NoError(t, err)

// test custom image
defer testUtil.MockUserInput(t, "y")()
deployInput.ImageName = "custom-image"
err = Deploy(deployInput, mockClient)

assert.NoError(t, err)

config.CFG.ProjectDeployment.SetProjectString("test-id")
Expand All @@ -251,6 +242,12 @@ func TestDeployWithDagsDeploySuccess(t *testing.T) {
err = Deploy(deployInput, mockClient)
assert.NoError(t, err)

// test custom image with dag deploy enabled
defer testUtil.MockUserInput(t, "y")()
deployInput.ImageName = "custom-image"
err = Deploy(deployInput, mockClient)
assert.ErrorIs(t, err, customDeployError)

defer os.RemoveAll("./testfiles/dags/")

mockClient.AssertExpectations(t)
Expand Down

0 comments on commit 8932fbc

Please sign in to comment.