Skip to content

Commit

Permalink
Deployment file doesn't work with Deployment tokens (#1559)
Browse files Browse the repository at this point in the history
* Deployment file doesn't work with Deployment tokens

* fix lint and test

* test no longer needed
  • Loading branch information
sunkickr committed Feb 20, 2024
1 parent 3846e49 commit f3ab08d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 83 deletions.
9 changes: 4 additions & 5 deletions cloud/deployment/fromfile/fromfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func CreateOrUpdate(inputFile, action string, astroPlatformCore astroplatformcor
if err != nil {
return err
}
workspaceID, err = getWorkspaceIDFromName(formattedDeployment.Deployment.Configuration.WorkspaceName, c.Organization, coreClient)
workspaceID, err = getWorkspaceIDFromName(formattedDeployment.Deployment.Configuration.WorkspaceName, coreClient)
if err != nil {
return err
}
Expand Down Expand Up @@ -745,10 +745,10 @@ func getClusterInfoFromName(clusterName, organizationID string, platformCoreClie
return "", nil, err
}

// getWorkspaceIDFromName takes workspaceName and organizationID as its arguments.
// getWorkspaceIDFromName takes workspaceName as its argument.
// It returns the workspaceID if the workspace is found in the organization.
// It returns an errWorkspaceNotFound if the workspace does not exist in the organization.
func getWorkspaceIDFromName(workspaceName, organizationID string, client astrocore.CoreClient) (string, error) {
func getWorkspaceIDFromName(workspaceName string, client astrocore.CoreClient) (string, error) {
var (
existingWorkspaces []astrocore.Workspace
err error
Expand All @@ -763,8 +763,7 @@ func getWorkspaceIDFromName(workspaceName, organizationID string, client astroco
return existingWorkspaces[i].Id, nil
}
}
err = fmt.Errorf("workspace_name: %s %w in organization: %s", workspaceName, errNotFound, organizationID)
return "", err
return "", nil
}

// getNodePoolIDFromWorkerType maps the node pool id in nodePools to a worker type.
Expand Down
82 changes: 4 additions & 78 deletions cloud/deployment/fromfile/fromfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,70 +1262,6 @@ deployment:
mockPlatformCoreClient.AssertExpectations(t)
mockCoreClient.AssertExpectations(t)
})
t.Run("returns an error if workspace does not exist", func(t *testing.T) {
testUtil.InitTestConfig(testUtil.CloudPlatform)
mockCoreClient := new(astrocore_mocks.ClientWithResponsesInterface)
filePath = "./deployment.yaml"
data = `
deployment:
environment_variables:
- is_secret: false
key: foo
updated_at: NOW
value: bar
- is_secret: true
key: bar
updated_at: NOW+1
value: baz
configuration:
name: test-deployment-label
description: description
runtime_version: 6.0.0
dag_deploy_enabled: true
executor: CeleryExecutor
scheduler_au: 5
scheduler_count: 3
cluster_name: test-cluster
workspace_name: test-workspace
deployment_type: HYBRID
worker_queues:
- name: default
is_default: true
max_worker_count: 130
min_worker_count: 12
worker_concurrency: 180
worker_type: test-worker-1
- name: test-queue-1
is_default: false
max_worker_count: 175
min_worker_count: 8
worker_concurrency: 176
worker_type: test-worker-2
metadata:
deployment_id: test-deployment-id
workspace_id: test-ws-id
cluster_id: cluster-id
release_name: great-release-name
airflow_version: 2.4.0
status: UNHEALTHY
created_at: 2022-11-17T13:25:55.275697-08:00
updated_at: 2022-11-17T13:25:55.275697-08:00
deployment_url: cloud.astronomer.io/test-ws-id/deployments/test-deployment-id/overview
webserver_url: some-url
alert_emails:
- test1@test.com
- test2@test.com
`
fileutil.WriteStringToFile(filePath, data)
defer afero.NewOsFs().Remove(filePath)
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)
mockCoreClient.On("ListWorkspacesWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&EmptyListWorkspacesResponseOK, nil).Times(1)
err = CreateOrUpdate("deployment.yaml", "create", mockPlatformCoreClient, mockCoreClient, nil)
assert.ErrorIs(t, err, errNotFound)
mockCoreClient.AssertExpectations(t)
mockPlatformCoreClient.AssertExpectations(t)
})
t.Run("returns an error if listing workspace fails", func(t *testing.T) {
testUtil.InitTestConfig(testUtil.CloudPlatform)
mockCoreClient := new(astrocore_mocks.ClientWithResponsesInterface)
Expand Down Expand Up @@ -3204,37 +3140,27 @@ func TestGetClusterFromName(t *testing.T) {

func TestGetWorkspaceIDFromName(t *testing.T) {
var (
workspaceName, expectedWorkspaceID, actualWorkspaceID, orgID string
err error
workspaceName, expectedWorkspaceID, actualWorkspaceID string
err error
)
testUtil.InitTestConfig(testUtil.LocalPlatform)
expectedWorkspaceID = "test-ws-id"
workspaceName = "test-workspace"
orgID = "test-org-id"
mockCoreClient := new(astrocore_mocks.ClientWithResponsesInterface)
t.Run("returns a workspace id if workspace exists in organization", func(t *testing.T) {
mockCoreClient.On("ListWorkspacesWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&ListWorkspacesResponseOK, nil).Once()
actualWorkspaceID, err = getWorkspaceIDFromName(workspaceName, orgID, mockCoreClient)
actualWorkspaceID, err = getWorkspaceIDFromName(workspaceName, mockCoreClient)
assert.NoError(t, err)
assert.Equal(t, expectedWorkspaceID, actualWorkspaceID)
mockCoreClient.AssertExpectations(t)
})
t.Run("returns error from api if listing workspace fails", func(t *testing.T) {
mockCoreClient.On("ListWorkspacesWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(nil, errTest).Once()
actualWorkspaceID, err = getWorkspaceIDFromName(workspaceName, orgID, mockCoreClient)
actualWorkspaceID, err = getWorkspaceIDFromName(workspaceName, mockCoreClient)
assert.ErrorIs(t, err, errTest)
assert.Equal(t, "", actualWorkspaceID)
mockCoreClient.AssertExpectations(t)
})
t.Run("returns an error if workspace does not exist in organization", func(t *testing.T) {
mockCoreClient.On("ListWorkspacesWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&EmptyListWorkspacesResponseOK, nil).Once()

actualWorkspaceID, err = getWorkspaceIDFromName(workspaceName, orgID, mockCoreClient)
assert.ErrorIs(t, err, errNotFound)
assert.ErrorContains(t, err, "workspace_name: test-workspace does not exist in organization: test-org-id")
assert.Equal(t, "", actualWorkspaceID)
mockCoreClient.AssertExpectations(t)
})
}

func TestGetNodePoolIDFromName(t *testing.T) {
Expand Down

0 comments on commit f3ab08d

Please sign in to comment.