diff --git a/astro-client/astro.go b/astro-client/astro.go index aa3a6f578..d9326da4b 100644 --- a/astro-client/astro.go +++ b/astro-client/astro.go @@ -21,8 +21,8 @@ type Client interface { // Image CreateImage(input ImageCreateInput) (*Image, error) DeployImage(input ImageDeployInput) (*Image, error) - // Orchestrator - ListOrchestrators(vars map[string]interface{}) ([]Orchestrator, error) + // Cluster + ListClusters(vars map[string]interface{}) ([]Cluster, error) // RuntimeRelease ListInternalRuntimeReleases() ([]RuntimeRelease, error) ListPublicRuntimeReleases() ([]RuntimeRelease, error) @@ -174,17 +174,17 @@ func (c *HTTPClient) DeployImage(input ImageDeployInput) (*Image, error) { return resp.Data.DeployImage, nil } -func (c *HTTPClient) ListOrchestrators(vars map[string]interface{}) ([]Orchestrator, error) { +func (c *HTTPClient) ListClusters(vars map[string]interface{}) ([]Cluster, error) { req := Request{ - Query: GetOrchestrators, + Query: GetClusters, Variables: map[string]interface{}{"input": vars}, } resp, err := req.DoWithClient(c) if err != nil { - return []Orchestrator{}, err + return []Cluster{}, err } - return resp.Data.GetOrchestrators, nil + return resp.Data.GetClusters, nil } func (c *HTTPClient) ListInternalRuntimeReleases() ([]RuntimeRelease, error) { diff --git a/astro-client/astro_test.go b/astro-client/astro_test.go index 6932b2b0b..323e1ab8e 100644 --- a/astro-client/astro_test.go +++ b/astro-client/astro_test.go @@ -565,11 +565,11 @@ func TestDeployImage(t *testing.T) { }) } -func TestListOrchestrators(t *testing.T) { +func TestListClusters(t *testing.T) { testUtil.InitTestConfig(testUtil.CloudPlatform) mockResponse := &Response{ Data: ResponseData{ - GetOrchestrators: []Orchestrator{ + GetClusters: []Cluster{ { ID: "test-id", Name: "test-name", @@ -592,9 +592,9 @@ func TestListOrchestrators(t *testing.T) { }) astroClient := NewAstroClient(client) - resp, err := astroClient.ListOrchestrators(map[string]interface{}{}) + resp, err := astroClient.ListClusters(map[string]interface{}{}) assert.NoError(t, err) - assert.Equal(t, resp, mockResponse.Data.GetOrchestrators) + assert.Equal(t, resp, mockResponse.Data.GetClusters) }) t.Run("error", func(t *testing.T) { @@ -607,7 +607,7 @@ func TestListOrchestrators(t *testing.T) { }) astroClient := NewAstroClient(client) - _, err := astroClient.ListOrchestrators(map[string]interface{}{}) + _, err := astroClient.ListClusters(map[string]interface{}{}) assert.Contains(t, err.Error(), "Internal Server Error") }) } diff --git a/astro-client/mocks/Client.go b/astro-client/mocks/Client.go index 74ad57427..4dd0e6ab6 100644 --- a/astro-client/mocks/Client.go +++ b/astro-client/mocks/Client.go @@ -188,16 +188,16 @@ func (_m *Client) ListInternalRuntimeReleases() ([]astro.RuntimeRelease, error) return r0, r1 } -// ListOrchestrators provides a mock function with given fields: vars -func (_m *Client) ListOrchestrators(vars map[string]interface{}) ([]astro.Orchestrator, error) { +// ListClusters provides a mock function with given fields: vars +func (_m *Client) ListClusters(vars map[string]interface{}) ([]astro.Cluster, error) { ret := _m.Called(vars) - var r0 []astro.Orchestrator - if rf, ok := ret.Get(0).(func(map[string]interface{}) []astro.Orchestrator); ok { + var r0 []astro.Cluster + if rf, ok := ret.Get(0).(func(map[string]interface{}) []astro.Cluster); ok { r0 = rf(vars) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]astro.Orchestrator) + r0 = ret.Get(0).([]astro.Cluster) } } diff --git a/astro-client/queries.go b/astro-client/queries.go index 035fbecbd..dbdc673ba 100644 --- a/astro-client/queries.go +++ b/astro-client/queries.go @@ -107,12 +107,12 @@ var ( } ` - GetOrchestrators = ` - query orchestrators($input: OrchestratorInput!) { - orchestrators(input: $input) { + GetClusters = ` + query clusters($organizationId: Id) { + clusters(organizationId: $organizationId) { id - cloudProvider name + cloudProvider } } ` diff --git a/astro-client/types.go b/astro-client/types.go index 30757bcad..3ae9bb4be 100644 --- a/astro-client/types.go +++ b/astro-client/types.go @@ -14,7 +14,7 @@ type ResponseData struct { GetDeployment Deployment `json:"deployment,omitempty"` GetDeployments []Deployment `json:"deployments,omitempty"` GetWorkspaces []Workspace `json:"workspaces,omitempty"` - GetOrchestrators []Orchestrator `json:"orchestrators,omitempty"` + GetClusters []Cluster `json:"clusters,omitempty"` SelfQuery *Self `json:"self,omitempty"` RuntimeReleases []RuntimeRelease `json:"runtimeReleases,omitempty"` DeploymentCreate Deployment `json:"DeploymentCreate,omitempty"` @@ -64,7 +64,14 @@ type Deployment struct { UpdatedAt string `json:"updatedAt"` } -// Orchestrator contains all components of an Astronomer Orchestrator +// Cluster contains all components of an Astronomer Cluster +type Cluster struct { + ID string `json:"id"` + Name string `json:"name"` + IsManaged bool `json:"isManaged"` + CloudProvider string `json:"cloudProvider"` +} + type Orchestrator struct { ID string `json:"id"` Name string `json:"name"` diff --git a/cloud/deployment/deployment.go b/cloud/deployment/deployment.go index 11a704831..45d539528 100644 --- a/cloud/deployment/deployment.go +++ b/cloud/deployment/deployment.go @@ -291,7 +291,7 @@ func selectCluster(clusterID, organizationID string, client astro.Client) (newCl } // cluster request clusterInput := map[string]interface{}{"organizationId": organizationID} - cs, err := client.ListOrchestrators(clusterInput) + cs, err := client.ListClusters(clusterInput) if err != nil { return "", errors.Wrap(err, astro.AstronomerConnectionErrMsg) } @@ -300,7 +300,7 @@ func selectCluster(clusterID, organizationID string, client astro.Client) (newCl if clusterID == "" { fmt.Println("\nPlease select a Cluster for your Deployment:") - clusterMap := map[string]astro.Orchestrator{} + clusterMap := map[string]astro.Cluster{} for i := range cs { index := i + 1 clusterTab.AddRow([]string{strconv.Itoa(index), cs[i].Name, cs[i].CloudProvider, cs[i].ID}, false) diff --git a/cloud/deployment/deployment_test.go b/cloud/deployment/deployment_test.go index 80ae9bfae..8c0a74830 100644 --- a/cloud/deployment/deployment_test.go +++ b/cloud/deployment/deployment_test.go @@ -111,7 +111,7 @@ func TestCreate(t *testing.T) { mockClient := new(astro_mocks.Client) mockClient.On("GetDeploymentConfig").Return(astro.DeploymentConfig{RuntimeReleases: []astro.RuntimeRelease{{Version: "4.2.5"}}}, nil).Once() mockClient.On("ListWorkspaces").Return([]astro.Workspace{{ID: ws, OrganizationID: "test-org-id"}}, nil).Once() - mockClient.On("ListOrchestrators", map[string]interface{}{"organizationId": "test-org-id"}).Return([]astro.Orchestrator{{ID: csID}}, nil).Once() + mockClient.On("ListClusters", map[string]interface{}{"organizationId": "test-org-id"}).Return([]astro.Cluster{{ID: csID}}, nil).Once() mockClient.On("CreateDeployment", mock.Anything).Return(astro.Deployment{ID: "test-id"}, nil).Once() // mock os.Stdin @@ -198,9 +198,9 @@ func TestSelectCluster(t *testing.T) { orgID := "test-org-id" csID := "test-cluster-id" - t.Run("list orchestrator failure", func(t *testing.T) { + t.Run("list cluster failure", func(t *testing.T) { mockClient := new(astro_mocks.Client) - mockClient.On("ListOrchestrators", map[string]interface{}{"organizationId": orgID}).Return([]astro.Orchestrator{}, errMock).Once() + mockClient.On("ListClusters", map[string]interface{}{"organizationId": orgID}).Return([]astro.Cluster{}, errMock).Once() _, err := selectCluster("", orgID, mockClient) assert.ErrorIs(t, err, errMock) @@ -209,7 +209,7 @@ func TestSelectCluster(t *testing.T) { t.Run("cluster id via selection", func(t *testing.T) { mockClient := new(astro_mocks.Client) - mockClient.On("ListOrchestrators", map[string]interface{}{"organizationId": orgID}).Return([]astro.Orchestrator{{ID: csID}}, nil).Once() + mockClient.On("ListClusters", map[string]interface{}{"organizationId": orgID}).Return([]astro.Cluster{{ID: csID}}, nil).Once() // mock os.Stdin input := []byte("1") @@ -234,7 +234,7 @@ func TestSelectCluster(t *testing.T) { t.Run("cluster id invalid selection", func(t *testing.T) { mockClient := new(astro_mocks.Client) - mockClient.On("ListOrchestrators", map[string]interface{}{"organizationId": orgID}).Return([]astro.Orchestrator{{ID: csID}}, nil).Once() + mockClient.On("ListClusters", map[string]interface{}{"organizationId": orgID}).Return([]astro.Cluster{{ID: csID}}, nil).Once() // mock os.Stdin input := []byte("4") @@ -258,7 +258,7 @@ func TestSelectCluster(t *testing.T) { t.Run("not able to find cluster", func(t *testing.T) { mockClient := new(astro_mocks.Client) - mockClient.On("ListOrchestrators", map[string]interface{}{"organizationId": orgID}).Return([]astro.Orchestrator{{ID: csID}}, nil).Once() + mockClient.On("ListClusters", map[string]interface{}{"organizationId": orgID}).Return([]astro.Cluster{{ID: csID}}, nil).Once() _, err := selectCluster("test-invalid-id", orgID, mockClient) assert.Error(t, err) diff --git a/cmd/cloud/deployment_test.go b/cmd/cloud/deployment_test.go index 6b98c0c15..a32903ed3 100644 --- a/cmd/cloud/deployment_test.go +++ b/cmd/cloud/deployment_test.go @@ -82,7 +82,7 @@ func TestDeploymentCreate(t *testing.T) { mockClient := new(astro_mocks.Client) mockClient.On("GetDeploymentConfig").Return(astro.DeploymentConfig{RuntimeReleases: []astro.RuntimeRelease{{Version: "4.2.5"}}}, nil).Once() mockClient.On("ListWorkspaces").Return([]astro.Workspace{{ID: ws, OrganizationID: "test-org-id"}}, nil).Once() - mockClient.On("ListOrchestrators", map[string]interface{}{"organizationId": "test-org-id"}).Return([]astro.Orchestrator{{ID: csID}}, nil).Once() + mockClient.On("ListClusters", map[string]interface{}{"organizationId": "test-org-id"}).Return([]astro.Cluster{{ID: csID}}, nil).Once() mockClient.On("CreateDeployment", mock.Anything).Return(astro.Deployment{ID: "test-id"}, nil).Once() astroClient = mockClient