Skip to content

Commit 00463a6

Browse files
authored
Add notification event DEPLOYMENT_STARTED (#5340)
* 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]>
1 parent d4cdb13 commit 00463a6

File tree

10 files changed

+843
-240
lines changed

10 files changed

+843
-240
lines changed

docs/content/en/docs-dev/user-guide/managing-piped/configuring-notifications.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Below is the list of supporting event names and their groups.
2020
|-|-|-|-|
2121
| DEPLOYMENT_TRIGGERED | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" checked disabled></p> | |
2222
| DEPLOYMENT_PLANNED | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" checked disabled></p> | |
23+
| DEPLOYMENT_STARTED | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" checked disabled></p> | |
2324
| DEPLOYMENT_APPROVED | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" checked disabled></p> | |
2425
| DEPLOYMENT_WAIT_APPROVAL | DEPLOYMENT | <p style="text-align: center;"><input type="checkbox" checked disabled></p> | |
2526
| 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) |

pkg/app/piped/controller/scheduler.go

+15
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ func (s *scheduler) Run(ctx context.Context) error {
216216
return err
217217
}
218218
controllermetrics.UpdateDeploymentStatus(s.deployment, model.DeploymentStatus_DEPLOYMENT_RUNNING)
219+
220+
// notify the deployment started event
221+
users, groups, err := s.getApplicationNotificationMentions(model.NotificationEventType_EVENT_DEPLOYMENT_STARTED)
222+
if err != nil {
223+
s.logger.Error("failed to get the list of users or groups", zap.Error(err))
224+
}
225+
226+
s.notifier.Notify(model.NotificationEvent{
227+
Type: model.NotificationEventType_EVENT_DEPLOYMENT_STARTED,
228+
Metadata: &model.NotificationEventDeploymentStarted{
229+
Deployment: s.deployment,
230+
MentionedAccounts: users,
231+
MentionedGroups: groups,
232+
},
233+
})
219234
}
220235

221236
var (

pkg/app/piped/notifier/slack.go

+7
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string)
271271
text = md.Summary
272272
generateDeploymentEventData(md.Deployment, md.MentionedAccounts, md.MentionedGroups)
273273

274+
case model.NotificationEventType_EVENT_DEPLOYMENT_STARTED:
275+
md := event.Metadata.(*model.NotificationEventDeploymentStarted)
276+
md.MentionedAccounts = append(md.MentionedAccounts, s.config.MentionedAccounts...)
277+
md.MentionedGroups = append(md.MentionedGroups, s.config.MentionedGroups...)
278+
title = fmt.Sprintf("Deployment for %q was started", md.Deployment.ApplicationName)
279+
generateDeploymentEventData(md.Deployment, md.MentionedAccounts, md.MentionedGroups)
280+
274281
case model.NotificationEventType_EVENT_DEPLOYMENT_WAIT_APPROVAL:
275282
md := event.Metadata.(*model.NotificationEventDeploymentWaitApproval)
276283
md.MentionedAccounts = append(md.MentionedAccounts, s.config.MentionedAccounts...)

pkg/app/pipedv1/controller/scheduler.go

+15
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,21 @@ func (s *scheduler) Run(ctx context.Context) error {
212212
return err
213213
}
214214
controllermetrics.UpdateDeploymentStatus(s.deployment, model.DeploymentStatus_DEPLOYMENT_RUNNING)
215+
216+
// notify the deployment started event
217+
users, groups, err := s.getApplicationNotificationMentions(model.NotificationEventType_EVENT_DEPLOYMENT_STARTED)
218+
if err != nil {
219+
s.logger.Error("failed to get the list of users or groups", zap.Error(err))
220+
}
221+
222+
s.notifier.Notify(model.NotificationEvent{
223+
Type: model.NotificationEventType_EVENT_DEPLOYMENT_STARTED,
224+
Metadata: &model.NotificationEventDeploymentStarted{
225+
Deployment: s.deployment,
226+
MentionedAccounts: users,
227+
MentionedGroups: groups,
228+
},
229+
})
215230
}
216231

217232
var (

pkg/app/pipedv1/notifier/slack.go

+7
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ func (s *slack) buildSlackMessage(event model.NotificationEvent, webURL string)
271271
text = md.Summary
272272
generateDeploymentEventData(md.Deployment, md.MentionedAccounts, md.MentionedGroups)
273273

274+
case model.NotificationEventType_EVENT_DEPLOYMENT_STARTED:
275+
md := event.Metadata.(*model.NotificationEventDeploymentStarted)
276+
md.MentionedAccounts = append(md.MentionedAccounts, s.config.MentionedAccounts...)
277+
md.MentionedGroups = append(md.MentionedGroups, s.config.MentionedGroups...)
278+
title = fmt.Sprintf("Deployment for %q was started", md.Deployment.ApplicationName)
279+
generateDeploymentEventData(md.Deployment, md.MentionedAccounts, md.MentionedGroups)
280+
274281
case model.NotificationEventType_EVENT_DEPLOYMENT_WAIT_APPROVAL:
275282
md := event.Metadata.(*model.NotificationEventDeploymentWaitApproval)
276283
md.MentionedAccounts = append(md.MentionedAccounts, s.config.MentionedAccounts...)

0 commit comments

Comments
 (0)