Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix runtime validation on deployment create #1418

Merged
merged 15 commits into from
Oct 24, 2023
14 changes: 14 additions & 0 deletions astro-client/astro.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Client interface {
DeleteDeployment(input DeleteDeploymentInput) (Deployment, error)
GetDeploymentHistory(vars map[string]interface{}) (DeploymentHistory, error)
GetDeploymentConfig() (DeploymentConfig, error)
GetDeploymentConfigWithOrganization(organizationID string) (DeploymentConfig, error)
ModifyDeploymentVariable(input EnvironmentVariablesInput) ([]EnvironmentVariablesObject, error)
InitiateDagDeployment(input InitiateDagDeploymentInput) (InitiateDagDeployment, error)
ReportDagDeploymentStatus(input *ReportDagDeploymentStatusInput) (DagDeploymentStatus, error)
Expand Down Expand Up @@ -125,6 +126,19 @@ func (c *HTTPClient) GetDeploymentConfig() (DeploymentConfig, error) {
return resp.Data.GetDeploymentConfig, nil
}

func (c *HTTPClient) GetDeploymentConfigWithOrganization(organizationID string) (DeploymentConfig, error) {
req := Request{
Query: GetDeploymentConfigOptionsWithOrganization,
Variables: map[string]interface{}{"organizationId": organizationID},
}

resp, err := req.DoWithPublicClient(c)
if err != nil {
return DeploymentConfig{}, err
}
return resp.Data.GetDeploymentConfig, nil
}

func (c *HTTPClient) ModifyDeploymentVariable(input EnvironmentVariablesInput) ([]EnvironmentVariablesObject, error) {
req := Request{
Query: CreateDeploymentVariables,
Expand Down
51 changes: 51 additions & 0 deletions astro-client/astro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,57 @@ func TestGetDeploymentConfig(t *testing.T) {
})
}

func TestGetDeploymentConfigWithOrganization(t *testing.T) {
testUtil.InitTestConfig(testUtil.CloudPlatform)
mockResponse := &Response{
Data: ResponseData{
GetDeploymentConfig: DeploymentConfig{
AstronomerUnit: AstronomerUnit{CPU: 1, Memory: 1024},
RuntimeReleases: []RuntimeRelease{
{
Version: "4.2.5",
AirflowVersion: "2.2.5",
Channel: "stable",
ReleaseDate: "2020-06-25",
AirflowDatabaseMigration: true,
},
},
},
},
}
jsonResponse, err := json.Marshal(mockResponse)
assert.NoError(t, err)

t.Run("success", func(t *testing.T) {
client := testUtil.NewTestClient(func(req *http.Request) *http.Response {
return &http.Response{
StatusCode: 200,
Body: io.NopCloser(bytes.NewBuffer(jsonResponse)),
Header: make(http.Header),
}
})
astroClient := NewAstroClient(client)

deploymentConfig, err := astroClient.GetDeploymentConfigWithOrganization("test-org-id")
assert.NoError(t, err)
assert.Equal(t, deploymentConfig, mockResponse.Data.GetDeploymentConfig)
})

t.Run("error", func(t *testing.T) {
client := testUtil.NewTestClient(func(req *http.Request) *http.Response {
return &http.Response{
StatusCode: 500,
Body: io.NopCloser(bytes.NewBufferString("Internal Server Error")),
Header: make(http.Header),
}
})
astroClient := NewAstroClient(client)

_, err := astroClient.GetDeploymentConfigWithOrganization("test-org-id")
assert.Contains(t, err.Error(), "Internal Server Error")
})
}

func TestModifyDeploymentVariable(t *testing.T) {
testUtil.InitTestConfig(testUtil.CloudPlatform)
mockResponse := &Response{
Expand Down
24 changes: 24 additions & 0 deletions astro-client/mocks/Client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions astro-client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,51 @@ var (
}
`

GetDeploymentConfigOptionsWithOrganization = `
query deploymentConfigOptions($organizationId: Id!) {
deploymentConfigOptions(organizationId: $organizationId) {
components
astroUnit {
cpu
memory
}
executors
runtimeReleases {
channel
version
}
astroMachines {
concurrentTasks
concurrentTasksMax
cpu
memory
nodePoolType
storageSize
type
}
defaultAstroMachine {
concurrentTasks
concurrentTasksMax
cpu
memory
nodePoolType
storageSize
type
}
defaultSchedulerSize {
cpu
memory
size
}
schedulerSizes {
cpu
memory
size
}
}
}
`

GetWorkerQueueOptions = `
query workerQueueOptions {
workerQueueOptions {
Expand Down
11 changes: 8 additions & 3 deletions cloud/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,12 @@ func validateResources(schedulerAU, schedulerReplicas int, configOption astro.De
}

func validateRuntimeVersion(runtimeVersion string, client astro.Client) (bool, error) {
runtimeReleases, err := GetRuntimeReleases(client)
c, err := config.GetCurrentContext()
if err != nil {
return false, err
}

runtimeReleases, err := GetRuntimeReleases(c.Organization, client)
if err != nil {
return false, err
}
Expand All @@ -394,11 +399,11 @@ func validateRuntimeVersion(runtimeVersion string, client astro.Client) (bool, e
return true, nil
}

func GetRuntimeReleases(client astro.Client) ([]string, error) {
func GetRuntimeReleases(organizationID string, client astro.Client) ([]string, error) {
// get deployment config options
runtimeReleases := []string{}

ConfigOptions, err := client.GetDeploymentConfig()
ConfigOptions, err := client.GetDeploymentConfigWithOrganization(organizationID)
if err != nil {
return runtimeReleases, errors.Wrap(err, astro.AstronomerConnectionErrMsg)
}
Expand Down
Loading