Skip to content

Commit

Permalink
Add notification event DEPLOYMENT_STARTED (#5340)
Browse files Browse the repository at this point in the history
* Add deployment started notification event and related handling

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Add DEPLOYMENT_STARTED event to notifications documentation

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
  • Loading branch information
Warashi authored Nov 15, 2024
1 parent d4cdb13 commit 00463a6
Show file tree
Hide file tree
Showing 10 changed files with 843 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Below is the list of supporting event names and their groups.
|-|-|-|-|
| DEPLOYMENT_TRIGGERED | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" checked disabled></p> | |
| DEPLOYMENT_PLANNED | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" checked disabled></p> | |
| DEPLOYMENT_STARTED | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" checked disabled></p> | |
| DEPLOYMENT_APPROVED | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" checked disabled></p> | |
| DEPLOYMENT_WAIT_APPROVAL | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" checked disabled></p> | |
| DEPLOYMENT_ROLLING_BACK | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" disabled></p> | PipeCD sends a notification when a deployment is completed, while it does not send a notification when a deployment status changes to DEPLOYMENT_ROLLING_BACK because it is not a completion status. See [#4547](https://github.com/pipe-cd/pipecd/issues/4547) |
Expand Down
15 changes: 15 additions & 0 deletions pkg/app/piped/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ func (s *scheduler) Run(ctx context.Context) error {
return err
}
controllermetrics.UpdateDeploymentStatus(s.deployment, model.DeploymentStatus_DEPLOYMENT_RUNNING)

// notify the deployment started event
users, groups, err := s.getApplicationNotificationMentions(model.NotificationEventType_EVENT_DEPLOYMENT_STARTED)
if err != nil {
s.logger.Error("failed to get the list of users or groups", zap.Error(err))
}

s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_STARTED,
Metadata: &model.NotificationEventDeploymentStarted{
Deployment: s.deployment,
MentionedAccounts: users,
MentionedGroups: groups,
},
})
}

var (
Expand Down
7 changes: 7 additions & 0 deletions pkg/app/piped/notifier/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string)
text = md.Summary
generateDeploymentEventData(md.Deployment, md.MentionedAccounts, md.MentionedGroups)

case model.NotificationEventType_EVENT_DEPLOYMENT_STARTED:
md := event.Metadata.(*model.NotificationEventDeploymentStarted)
md.MentionedAccounts = append(md.MentionedAccounts, s.config.MentionedAccounts...)
md.MentionedGroups = append(md.MentionedGroups, s.config.MentionedGroups...)
title = fmt.Sprintf("Deployment for %q was started", md.Deployment.ApplicationName)
generateDeploymentEventData(md.Deployment, md.MentionedAccounts, md.MentionedGroups)

case model.NotificationEventType_EVENT_DEPLOYMENT_WAIT_APPROVAL:
md := event.Metadata.(*model.NotificationEventDeploymentWaitApproval)
md.MentionedAccounts = append(md.MentionedAccounts, s.config.MentionedAccounts...)
Expand Down
15 changes: 15 additions & 0 deletions pkg/app/pipedv1/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ func (s *scheduler) Run(ctx context.Context) error {
return err
}
controllermetrics.UpdateDeploymentStatus(s.deployment, model.DeploymentStatus_DEPLOYMENT_RUNNING)

// notify the deployment started event
users, groups, err := s.getApplicationNotificationMentions(model.NotificationEventType_EVENT_DEPLOYMENT_STARTED)
if err != nil {
s.logger.Error("failed to get the list of users or groups", zap.Error(err))
}

s.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_STARTED,
Metadata: &model.NotificationEventDeploymentStarted{
Deployment: s.deployment,
MentionedAccounts: users,
MentionedGroups: groups,
},
})
}

var (
Expand Down
7 changes: 7 additions & 0 deletions pkg/app/pipedv1/notifier/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string)
text = md.Summary
generateDeploymentEventData(md.Deployment, md.MentionedAccounts, md.MentionedGroups)

case model.NotificationEventType_EVENT_DEPLOYMENT_STARTED:
md := event.Metadata.(*model.NotificationEventDeploymentStarted)
md.MentionedAccounts = append(md.MentionedAccounts, s.config.MentionedAccounts...)
md.MentionedGroups = append(md.MentionedGroups, s.config.MentionedGroups...)
title = fmt.Sprintf("Deployment for %q was started", md.Deployment.ApplicationName)
generateDeploymentEventData(md.Deployment, md.MentionedAccounts, md.MentionedGroups)

case model.NotificationEventType_EVENT_DEPLOYMENT_WAIT_APPROVAL:
md := event.Metadata.(*model.NotificationEventDeploymentWaitApproval)
md.MentionedAccounts = append(md.MentionedAccounts, s.config.MentionedAccounts...)
Expand Down
Loading

0 comments on commit 00463a6

Please sign in to comment.