-
Notifications
You must be signed in to change notification settings - Fork 20
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(deployments datasource): get by name #343
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,29 +60,30 @@ func (c *DeploymentsClient) Create(ctx context.Context, data api.DeploymentCreat | |
return &deployment, nil | ||
} | ||
|
||
// List returns a list of Deployments based on the provided list of names. | ||
func (c *DeploymentsClient) List(ctx context.Context, _ []string) ([]*api.Deployment, error) { | ||
// Get returns details for a Deployment by ID. | ||
func (c *DeploymentsClient) Get(ctx context.Context, deploymentID uuid.UUID) (*api.Deployment, error) { | ||
cfg := requestConfig{ | ||
method: http.MethodPost, | ||
url: fmt.Sprintf("%s/filter", c.routePrefix), | ||
method: http.MethodGet, | ||
url: fmt.Sprintf("%s/%s", c.routePrefix, deploymentID.String()), | ||
body: http.NoBody, | ||
apiKey: c.apiKey, | ||
successCodes: successCodesStatusOK, | ||
} | ||
|
||
var deployments []*api.Deployment | ||
if err := requestWithDecodeResponse(ctx, c.hc, cfg, &deployments); err != nil { | ||
return nil, fmt.Errorf("failed to list deployments: %w", err) | ||
var deployment api.Deployment | ||
if err := requestWithDecodeResponse(ctx, c.hc, cfg, &deployment); err != nil { | ||
return nil, fmt.Errorf("failed to get deployment: %w", err) | ||
} | ||
|
||
return deployments, nil | ||
return &deployment, nil | ||
} | ||
|
||
// Get returns details for a Deployment by ID. | ||
func (c *DeploymentsClient) Get(ctx context.Context, deploymentID uuid.UUID) (*api.Deployment, error) { | ||
// GetByName returns details for a Deployment by name. | ||
func (c *DeploymentsClient) GetByName(ctx context.Context, flowName, deploymentName string) (*api.Deployment, error) { | ||
url := fmt.Sprintf("%s/name/%s/%s", c.routePrefix, flowName, deploymentName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It surprised me that the API requires the flow_name to get a deployment by name. I started by adding that field as an optional attribute on the datasource specifically, and then validate that either id or name and flow_name are set. Alternatives considered so far:
Open to any opinions here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, the option we choose will depend on what interface we're choosing to expose to the user, which is coupled to what we think they're going to use the datasource for:
type DeploymentFilter struct {
Deployments struct {
Name struct {
Any []string `json:"any_"`
} `json:"name"`
} `json:"deployments"`
}
# usage:
filter := DeploymentFilter{}
filter.Deployments.Name.Any = []string{"deployment-1", "deployment-2"} I don't think the "find all deployments and do the filtering at runtime" is better than either of those options, just given that we have a filtering endpoint that pretty much does this if we're able to represent the filtering payload There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great points - I could see that advanced datasource logic being really helpful. I created #344 to track that. I think for now it makes sense to proceed with the current PR since it addresses the bug based on how we currently say this datasource should work. That's just my 2 cents though, happy to pivot |
||
cfg := requestConfig{ | ||
method: http.MethodGet, | ||
url: fmt.Sprintf("%s/%s", c.routePrefix, deploymentID.String()), | ||
url: url, | ||
body: http.NoBody, | ||
apiKey: c.apiKey, | ||
successCodes: successCodesStatusOK, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ data "prefect_deployment" "test_by_id" { | |
|
||
data "prefect_deployment" "test_by_name" { | ||
name = prefect_deployment.test.name | ||
flow_name = prefect_flow.test.name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect this was only passing before because there was only one deployment in the test workspace, meaning the existing logic actually worked. This obviously breaks in the real world when there is more than one deployment (of any name). |
||
|
||
account_id = "%s" | ||
workspace_id = prefect_workspace.test.id | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff shows things in kind of a weird way. I technically replaced
List
withGetByName
.So to clarify:
Get
is unchangedGetByName
is addedList
is removed