Skip to content

Commit

Permalink
Merge pull request #587 from astronomer/cluster-query
Browse files Browse the repository at this point in the history
change orchestrator query to cluster
  • Loading branch information
sunkickr authored Jun 6, 2022
2 parents a721c5c + 92097b8 commit 0cc93a9
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 31 deletions.
12 changes: 6 additions & 6 deletions astro-client/astro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions astro-client/astro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) {
Expand All @@ -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")
})
}
Expand Down
10 changes: 5 additions & 5 deletions astro-client/mocks/Client.go

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

8 changes: 4 additions & 4 deletions astro-client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
`
Expand Down
11 changes: 9 additions & 2 deletions astro-client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions cloud/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions cloud/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cloud/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0cc93a9

Please sign in to comment.