Skip to content

Commit

Permalink
Fix deployment create/update --deployment-file (#1577)
Browse files Browse the repository at this point in the history
* Respect hibernation schedules in deployment file for deployment create

* Fix test

* Only set scaling spec when development mode is set

---------

Co-authored-by: Neel Dalsania <[email protected]>
  • Loading branch information
feluelle and neel-astro committed Feb 29, 2024
1 parent ad44036 commit 0d91904
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
32 changes: 26 additions & 6 deletions cloud/deployment/fromfile/fromfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ func createOrUpdateDeployment(deploymentFromFile *inspect.FormattedDeployment, c
WorkerQueues: &listQueuesRequest,
SchedulerSize: schedulerSize,
}
if standardDeploymentRequest.IsDevelopmentMode != nil && *standardDeploymentRequest.IsDevelopmentMode {
hibernationSchedules := ToDeploymentHibernationSchedules(deploymentFromFile.Deployment.HibernationSchedules)
standardDeploymentRequest.ScalingSpec = &astroplatformcore.DeploymentScalingSpecRequest{
HibernationSpec: &astroplatformcore.DeploymentHibernationSpecRequest{
Schedules: &hibernationSchedules,
},
}
}
err := createDeploymentRequest.FromCreateStandardDeploymentRequest(standardDeploymentRequest)
if err != nil {
return err
Expand Down Expand Up @@ -398,6 +406,14 @@ func createOrUpdateDeployment(deploymentFromFile *inspect.FormattedDeployment, c
WorkerQueues: &listQueuesRequest,
SchedulerSize: schedulerSize,
}
if dedicatedDeploymentRequest.IsDevelopmentMode != nil && *dedicatedDeploymentRequest.IsDevelopmentMode {
hibernationSchedules := ToDeploymentHibernationSchedules(deploymentFromFile.Deployment.HibernationSchedules)
dedicatedDeploymentRequest.ScalingSpec = &astroplatformcore.DeploymentScalingSpecRequest{
HibernationSpec: &astroplatformcore.DeploymentHibernationSpecRequest{
Schedules: &hibernationSchedules,
},
}
}
err := createDeploymentRequest.FromCreateDedicatedDeploymentRequest(dedicatedDeploymentRequest)
if err != nil {
return err
Expand Down Expand Up @@ -489,7 +505,6 @@ func createOrUpdateDeployment(deploymentFromFile *inspect.FormattedDeployment, c
deploymentFromFile.Deployment.Configuration.ResourceQuotaMemory = *existingDeployment.ResourceQuotaMemory
}

hibernationSchedules := ToDeploymentHibernationSchedules(deploymentFromFile.Deployment.HibernationSchedules)
standardDeploymentRequest := astroplatformcore.UpdateStandardDeploymentRequest{
Description: &deploymentFromFile.Deployment.Configuration.Description,
Name: deploymentFromFile.Deployment.Configuration.Name,
Expand All @@ -507,11 +522,14 @@ func createOrUpdateDeployment(deploymentFromFile *inspect.FormattedDeployment, c
SchedulerSize: schedulerSize,
ContactEmails: &deploymentFromFile.Deployment.AlertEmails,
EnvironmentVariables: envVars,
ScalingSpec: &astroplatformcore.DeploymentScalingSpecRequest{
}
if existingDeployment.IsDevelopmentMode != nil && *existingDeployment.IsDevelopmentMode {
hibernationSchedules := ToDeploymentHibernationSchedules(deploymentFromFile.Deployment.HibernationSchedules)
standardDeploymentRequest.ScalingSpec = &astroplatformcore.DeploymentScalingSpecRequest{
HibernationSpec: &astroplatformcore.DeploymentHibernationSpecRequest{
Schedules: &hibernationSchedules,
},
},
}
}
err := updateDeploymentRequest.FromUpdateStandardDeploymentRequest(standardDeploymentRequest)
if err != nil {
Expand Down Expand Up @@ -549,7 +567,6 @@ func createOrUpdateDeployment(deploymentFromFile *inspect.FormattedDeployment, c
deploymentFromFile.Deployment.Configuration.ResourceQuotaMemory = *existingDeployment.ResourceQuotaMemory
}

hibernationSchedules := ToDeploymentHibernationSchedules(deploymentFromFile.Deployment.HibernationSchedules)
dedicatedDeploymentRequest := astroplatformcore.UpdateDedicatedDeploymentRequest{
Description: &deploymentFromFile.Deployment.Configuration.Description,
Name: deploymentFromFile.Deployment.Configuration.Name,
Expand All @@ -567,11 +584,14 @@ func createOrUpdateDeployment(deploymentFromFile *inspect.FormattedDeployment, c
SchedulerSize: schedulerSize,
ContactEmails: &deploymentFromFile.Deployment.AlertEmails,
EnvironmentVariables: envVars,
ScalingSpec: &astroplatformcore.DeploymentScalingSpecRequest{
}
if existingDeployment.IsDevelopmentMode != nil && *existingDeployment.IsDevelopmentMode {
hibernationSchedules := ToDeploymentHibernationSchedules(deploymentFromFile.Deployment.HibernationSchedules)
dedicatedDeploymentRequest.ScalingSpec = &astroplatformcore.DeploymentScalingSpecRequest{
HibernationSpec: &astroplatformcore.DeploymentHibernationSpecRequest{
Schedules: &hibernationSchedules,
},
},
}
}
err := updateDeploymentRequest.FromUpdateDedicatedDeploymentRequest(dedicatedDeploymentRequest)
if err != nil {
Expand Down
23 changes: 18 additions & 5 deletions cloud/deployment/fromfile/fromfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (
astroplatformcore_mocks "github.com/astronomer/astro-cli/astro-client-platform-core/mocks"
"github.com/astronomer/astro-cli/cloud/deployment"
"github.com/astronomer/astro-cli/cloud/deployment/inspect"
"github.com/astronomer/astro-cli/pkg/fileutil"
testUtil "github.com/astronomer/astro-cli/pkg/testing"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

"github.com/astronomer/astro-cli/pkg/fileutil"
)

const (
Expand Down Expand Up @@ -1089,9 +1088,23 @@ deployment:
mockPlatformCoreClient.On("ListClustersWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&mockListClustersResponse, nil).Once()
mockPlatformCoreClient.On("ListDeploymentsWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&mockListDeploymentsResponse, nil).Times(1)
mockPlatformCoreClient.On("ListDeploymentsWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&mockListDeploymentsCreateResponse, nil).Times(2)
mockPlatformCoreClient.On("CreateDeploymentWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&mockCreateDeploymentResponse, nil).Once()
mockPlatformCoreClient.On("UpdateDeploymentWithResponse", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&mockUpdateDeploymentResponse, nil).Times(1)
mockPlatformCoreClient.On("GetDeploymentWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&deploymentResponse, nil).Times(3)
mockPlatformCoreClient.On("CreateDeploymentWithResponse", mock.Anything, mock.Anything, mock.MatchedBy(
func(input astroplatformcore.CreateDeploymentRequest) bool {
request, _ := input.AsCreateDedicatedDeploymentRequest()
schedules := *request.ScalingSpec.HibernationSpec.Schedules
schedule := schedules[0]
return request.Name == "test-deployment-label" && request.IsCicdEnforced && request.IsHighAvailability && *request.IsDevelopmentMode && schedule.IsEnabled && *schedule.Description == "hibernation schedule 1" && schedule.HibernateAtCron == "1 * * * *" && schedule.WakeAtCron == "2 * * * *"
},
)).Return(&mockCreateDeploymentResponse, nil).Once()
mockPlatformCoreClient.On("UpdateDeploymentWithResponse", mock.Anything, mock.Anything, mock.Anything, mock.MatchedBy(
func(input astroplatformcore.UpdateDeploymentRequest) bool {
request, _ := input.AsUpdateDedicatedDeploymentRequest()
schedules := *request.ScalingSpec.HibernationSpec.Schedules
schedule := schedules[0]
return request.Name == "test-deployment-label" && request.IsCicdEnforced && request.IsHighAvailability && schedule.IsEnabled && *schedule.Description == "hibernation schedule 1" && schedule.HibernateAtCron == "1 * * * *" && schedule.WakeAtCron == "2 * * * *"
},
)).Return(&mockUpdateDeploymentResponse, nil).Times(1)
mockPlatformCoreClient.On("GetDeploymentWithResponse", mock.Anything, mock.Anything, "test-deployment-id").Return(&deploymentResponse, nil).Times(3)
mockPlatformCoreClient.On("GetClusterWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&mockGetClusterResponse, nil).Once()
err = CreateOrUpdate("deployment.yaml", "create", mockPlatformCoreClient, mockCoreClient, out)
assert.NoError(t, err)
Expand Down

0 comments on commit 0d91904

Please sign in to comment.