Skip to content

Commit

Permalink
🍱 [patch] Send PR queue report even if PR trigger fails (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pohfy123 authored Sep 7, 2021
1 parent e644600 commit 7d9f8e7
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 323 deletions.
37 changes: 19 additions & 18 deletions internal/pullrequest/queue/collect_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ func (c *controller) collectPullRequestQueueResult(ctx context.Context, prQueue
prComps := prQueue.Spec.Components
prNamespace := prQueue.Status.PullRequestNamespace

if prQueue.Spec.IsPRTriggerFailed != nil && !*prQueue.Spec.IsPRTriggerFailed {
deployedQueue, err := c.ensurePullRequestComponents(prQueue, prComps)
if err != nil {
return errors.Wrapf(err, "cannot ensure pull request components, namespace %s", prNamespace)
}
prQueue.Status.SetDeploymentQueue(deployedQueue)
deployedQueue, err := c.ensurePullRequestComponents(prQueue, prComps)
if err != nil {
return errors.Wrapf(err, "cannot ensure pull request components, namespace %s", prNamespace)
}

prQueue.Status.SetDeploymentQueue(deployedQueue)
prQueue.SetState(s2hv1.PullRequestQueueEnvDestroying)
prQueue.Status.SetCondition(s2hv1.PullRequestQueueCondResultCollected, corev1.ConditionTrue,
"Pull request queue result has been collected")
Expand All @@ -36,11 +33,9 @@ func (c *controller) collectPullRequestQueueResult(ctx context.Context, prQueue

prQueue.Status.SetPullRequestQueueHistoryName(prQueueHistName)

// sent report only when pull request trigger success
if prQueue.Spec.IsPRTriggerFailed != nil && !*prQueue.Spec.IsPRTriggerFailed {
if err := c.sendPullRequestQueueReport(ctx, prQueue); err != nil {
return err
}
// sent report even if pull request trigger fails
if err := c.sendPullRequestQueueReport(ctx, prQueue); err != nil {
return err
}
return nil
}
Expand Down Expand Up @@ -70,13 +65,19 @@ func (c *controller) sendPullRequestQueueReport(ctx context.Context, prQueue *s2
return err
}

missingImgListRPC := make([]*samsahairpc.Image, 0)
for _, img := range prQueue.Spec.ImageMissingList {
missingImgListRPC = append(missingImgListRPC, &samsahairpc.Image{Repository: img.Repository, Tag: img.Tag})
}

prQueueRPC := &samsahairpc.TeamWithPullRequest{
TeamName: c.teamName,
BundleName: prQueue.Spec.BundleName,
PRNumber: prQueue.Spec.PRNumber,
CommitSHA: prQueue.Spec.CommitSHA,
Namespace: prQueue.Status.PullRequestNamespace,
MaxRetryQueue: prConfig.MaxRetry,
TeamName: c.teamName,
BundleName: prQueue.Spec.BundleName,
PRNumber: prQueue.Spec.PRNumber,
CommitSHA: prQueue.Spec.CommitSHA,
Namespace: prQueue.Status.PullRequestNamespace,
MaxRetryQueue: prConfig.MaxRetry,
ImageMissingList: missingImgListRPC,
}

prQueueHistName, prQueueHistNamespace := prQueue.Status.PullRequestQueueHistoryName, c.namespace
Expand Down
21 changes: 13 additions & 8 deletions internal/pullrequest/queue/queue_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,21 @@ func (c *controller) ensurePullRequestComponents(
prQueue *s2hv1.PullRequestQueue,
prComps s2hv1.QueueComponents,
) (*s2hv1.Queue, error) {
runtimeClient, err := c.getRuntimeClient()
if err != nil {
return nil, err
}

prNamespace := prQueue.Status.PullRequestNamespace
deployedQueue, err := queue.EnsurePullRequestComponents(runtimeClient, c.teamName, prNamespace, prQueue.Name,
deployedQueue := queue.NewInitialPullRequestQueue(c.teamName, prNamespace, prQueue.Name,
prQueue.Spec.BundleName, prQueue.Spec.PRNumber, prComps, prQueue.Spec.NoOfRetry)
if err != nil {
return nil, err

if prQueue.Spec.IsPRTriggerFailed != nil && !*prQueue.Spec.IsPRTriggerFailed {
runtimeClient, err := c.getRuntimeClient()
if err != nil {
return nil, err
}

deployedQueue, err = queue.EnsurePullRequestComponents(runtimeClient, c.teamName, prNamespace, prQueue.Name,
prQueue.Spec.BundleName, prQueue.Spec.PRNumber, prComps, prQueue.Spec.NoOfRetry)
if err != nil {
return nil, err
}
}

return deployedQueue, nil
Expand Down
6 changes: 3 additions & 3 deletions internal/pullrequest/trigger/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,17 @@ func (c *controller) createPullRequestQueue(namespace, name, prNumber, commitSHA

func (c *controller) deleteAndSendPullRequestTriggerResult(ctx context.Context,
prTrigger *s2hv1.PullRequestTrigger) error {
outImgList := make([]*samsahairpc.Image, 0)
missingImgListRPC := make([]*samsahairpc.Image, 0)
for _, img := range prTrigger.Status.ImageMissingList {
outImgList = append(outImgList, &samsahairpc.Image{Repository: img.Repository, Tag: img.Tag})
missingImgListRPC = append(missingImgListRPC, &samsahairpc.Image{Repository: img.Repository, Tag: img.Tag})
}

prTriggerRPC := &samsahairpc.PullRequestTrigger{
Name: prTrigger.Name,
Namespace: prTrigger.Namespace,
TeamName: c.teamName,
Result: string(prTrigger.Status.Result),
ImageMissingList: outImgList,
ImageMissingList: missingImgListRPC,
}
if _, err := c.s2hClient.RunPostPullRequestTrigger(ctx, prTriggerRPC); err != nil {
return errors.Wrapf(err,
Expand Down
37 changes: 25 additions & 12 deletions internal/queue/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,11 @@ func EnsureDemoteFromActiveComponents(c client.Client, teamName, namespace strin
return
}

// EnsurePullRequestComponents ensures that pull request components were deployed with `pull-request` config and tested
func EnsurePullRequestComponents(c client.Client, teamName, namespace, queueName, prBundleName, prNumber string,
comps s2hv1.QueueComponents, noOfRetry int) (q *s2hv1.Queue, err error) {
// NewInitialPullRequestQueue returns initial value of PullRequestQueue
func NewInitialPullRequestQueue(teamName, namespace, queueName, prBundleName, prNumber string,
comps s2hv1.QueueComponents, noOfRetry int) *s2hv1.Queue {

q = &s2hv1.Queue{
return &s2hv1.Queue{
ObjectMeta: metav1.ObjectMeta{
Name: queueName,
Namespace: namespace,
Expand All @@ -587,6 +587,13 @@ func EnsurePullRequestComponents(c client.Client, teamName, namespace, queueName
NoOfRetry: noOfRetry,
},
}
}

// EnsurePullRequestComponents ensures that pull request components were deployed with `pull-request` config and tested
func EnsurePullRequestComponents(c client.Client, teamName, namespace, queueName, prBundleName, prNumber string,
comps s2hv1.QueueComponents, noOfRetry int) (q *s2hv1.Queue, err error) {

q = NewInitialPullRequestQueue(teamName, namespace, queueName, prBundleName, prNumber, comps, noOfRetry)

err = ensureQueue(context.TODO(), c, q)
return
Expand Down Expand Up @@ -655,9 +662,9 @@ func GetComponentUpgradeRPCFromQueue(
prQueueRPC *samsahairpc.TeamWithPullRequest,
) *samsahairpc.ComponentUpgrade {

outImgList := make([]*samsahairpc.Image, 0)
outMissingImgList := make([]*samsahairpc.Image, 0)
for _, img := range queue.Status.ImageMissingList {
outImgList = append(outImgList, &samsahairpc.Image{Repository: img.Repository, Tag: img.Tag})
outMissingImgList = append(outMissingImgList, &samsahairpc.Image{Repository: img.Repository, Tag: img.Tag})
}

rpcComps := make([]*samsahairpc.Component, 0)
Expand All @@ -672,24 +679,30 @@ func GetComponentUpgradeRPCFromQueue(
}

isReverify := queue.IsReverify()
if prQueueRPC != nil && prQueueRPC.PRNumber != "" {
isReverify = int(prQueueRPC.MaxRetryQueue) >= queue.Spec.NoOfRetry
}

prNamespace := ""
if prQueueRPC != nil {
prNamespace = prQueueRPC.Namespace

if prQueueRPC.PRNumber != "" {
isReverify = int(prQueueRPC.MaxRetryQueue) >= queue.Spec.NoOfRetry
}

// if there are missing images on PullRequestQueue
// implies that this queue failed already
if len(prQueueRPC.ImageMissingList) != 0 {
outMissingImgList = prQueueRPC.ImageMissingList
}
}

comp := &samsahairpc.ComponentUpgrade{
Status: comStatus,
Name: queue.Spec.Name,
TeamName: queue.Spec.TeamName,
Components: rpcComps,
IssueType: getIssueTypeRPC(outImgList, queue),
IssueType: getIssueTypeRPC(outMissingImgList, queue),
QueueHistoryName: queueHistName,
Namespace: queueHistNamespace,
ImageMissingList: outImgList,
ImageMissingList: outMissingImgList,
Runs: int32(queue.Spec.NoOfRetry + 1),
IsReverify: isReverify,
ReverificationStatus: getReverificationStatusRPC(queue),
Expand Down
Loading

0 comments on commit 7d9f8e7

Please sign in to comment.