From f3ab08d5446cba97a584b889c65cd942ea28926f Mon Sep 17 00:00:00 2001 From: David Koenitzer Date: Tue, 20 Feb 2024 13:24:18 -0500 Subject: [PATCH] Deployment file doesn't work with Deployment tokens (#1559) * Deployment file doesn't work with Deployment tokens * fix lint and test * test no longer needed --- cloud/deployment/fromfile/fromfile.go | 9 ++- cloud/deployment/fromfile/fromfile_test.go | 82 ++-------------------- 2 files changed, 8 insertions(+), 83 deletions(-) diff --git a/cloud/deployment/fromfile/fromfile.go b/cloud/deployment/fromfile/fromfile.go index 6dadce2a3..ed0a9b9ec 100644 --- a/cloud/deployment/fromfile/fromfile.go +++ b/cloud/deployment/fromfile/fromfile.go @@ -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 } @@ -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 @@ -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. diff --git a/cloud/deployment/fromfile/fromfile_test.go b/cloud/deployment/fromfile/fromfile_test.go index f293ebeef..2db8b9a87 100644 --- a/cloud/deployment/fromfile/fromfile_test.go +++ b/cloud/deployment/fromfile/fromfile_test.go @@ -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) @@ -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) {