Skip to content

Conversation

@khanhtc1202
Copy link
Member

What this PR does / why we need it:

This PR adds an RPC which be used by piped to determine whether to start planning a deployment that is triggered by the DeploymentChain model.

Which issue(s) this PR fixes:

Follow PR #2815

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.79%. This pull request decreases coverage by -0.06%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.InChainDeploymentPlannable -- 0.00% +0.00%
pkg/datastore/deploymentchainstore.go deploymentChainStore.GetDeploymentChain -- 0.00% +0.00%

prevBlock := dc.Blocks[req.Deployment.DeploymentChainBlockIndex-1]
plannable := true
for _, node := range prevBlock.Nodes {
dp, err := a.deploymentStore.GetDeployment(ctx, node.DeploymentRef.DeploymentId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need the deployment status in the chain model for rendering on the web so how about having that status field in the node. Then we can use it directly instead of retrieving from DB like this.

Copy link
Member Author

@khanhtc1202 khanhtc1202 Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, when piped submits deployment status (planed, running, etc) we also need to update its status in deployment chain model too, that's quite annoying. How do you think about adding just IsCompleted to the deploymentRef in the chain model?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the second thought, status is required for showing in the UI, so I think I will go with your suggestion 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nghialv Can I add a TODO note here and address it later since that change requires updates in other RPCs unrelated to this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by e883d32

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.79%. This pull request decreases coverage by -0.06%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.InChainDeploymentPlannable -- 0.00% +0.00%
pkg/datastore/deploymentchainstore.go deploymentChainStore.GetDeploymentChain -- 0.00% +0.00%

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.79%. This pull request decreases coverage by -0.06%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.InChainDeploymentPlannable -- 0.00% +0.00%
pkg/datastore/deploymentchainstore.go deploymentChainStore.GetDeploymentChain -- 0.00% +0.00%
pkg/model/deployment.go IsCompletedSuccessfullyDeployment -- 0.00% +0.00%

@ono-max
Copy link
Member

ono-max commented Nov 24, 2021

/lgtm

@pipecd-bot pipecd-bot removed the lgtm label Nov 24, 2021
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.79%. This pull request decreases coverage by -0.06%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.InChainDeploymentPlannable -- 0.00% +0.00%
pkg/datastore/deploymentchainstore.go deploymentChainStore.GetDeploymentChain -- 0.00% +0.00%
pkg/model/deployment.go IsCompletedSuccessfullyDeployment -- 0.00% +0.00%

return nil, status.Error(codes.InvalidArgument, "invalid deployment with chain block index provided")
}

prevBlock := dc.Blocks[req.Deployment.DeploymentChainBlockIndex-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since DeploymentChainBlockIndex is int32 which is signed integer whose range is -2147483648 to 2147483647, this is a bit likely to be panic.

How about making DeploymentChainBlockIndex an unsigned integer, or adding a simple validation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, golang does not support negative indexes for slide, right? In that case, lets me address it in a separated PR since other place that not related to this change need to be updated too 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to me 👍

}

// IsCompletedSuccessfullyDeployment checks whether the deployment is successfully addressed.
func IsCompletedSuccessfullyDeployment(status DeploymentStatus) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I feel like this is more natural but it's on you

Suggested change
func IsCompletedSuccessfullyDeployment(status DeploymentStatus) bool {
func IsSuccessfullyCompletedDeployment(status DeploymentStatus) bool {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, lets me adopt your suggestion 🙆

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed by 640e172

@pipecd-bot
Copy link
Collaborator

TODO

The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use /todo skip command.

Details

1. Consider add deployment status to the deployment ref in the deployment chain model

https://github.com/pipe-cd/pipe/blob/ac17a844b3a6ddce09b594da66440f5acac6e836/pkg/app/api/grpcapi/piped_api.go#L1141-L1144

This was created by todo plugin since "TODO:" was found in ac17a84 when #2832 was merged. cc: @khanhtc1202.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 31.79%. This pull request decreases coverage by -0.06%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.InChainDeploymentPlannable -- 0.00% +0.00%
pkg/datastore/deploymentchainstore.go deploymentChainStore.GetDeploymentChain -- 0.00% +0.00%
pkg/model/deployment.go IsSuccessfullyCompletedDeployment -- 0.00% +0.00%

@nakabonne
Copy link
Member

Keep it up!
/lgtm

@nghialv
Copy link
Member

nghialv commented Nov 24, 2021

/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by nghialv.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit 0ab6cf0 into master Nov 24, 2021
@pipecd-bot pipecd-bot deleted the add-check-deployment-plannable-rpc branch November 24, 2021 10:13
pipecd-bot pushed a commit that referenced this pull request Nov 24, 2021
**What this PR does / why we need it**:

- Remove unused ChainBlockIndex field from DeploymentChain model's block
- Change type of DeploymentChainBlockIndex from `int32` to `uinit32`

**Which issue(s) this PR fixes**:

As discussed in #2832 (comment)

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
-->
```release-note
NONE
```

This PR was merged by Kapetanios.
pipecd-bot pushed a commit that referenced this pull request Nov 29, 2021
**What this PR does / why we need it**:

**Which issue(s) this PR fixes**:

Follow PR #2832

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
-->
```release-note
NONE
```

This PR was merged by Kapetanios.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants