Skip to content
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

Add notification event DEPLOYMENT_STARTED #5340

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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))
}

Check warning on line 224 in pkg/app/piped/controller/scheduler.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/piped/controller/scheduler.go#L219-L224

Added lines #L219 - L224 were not covered by tests

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

Check warning on line 233 in pkg/app/piped/controller/scheduler.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/piped/controller/scheduler.go#L226-L233

Added lines #L226 - L233 were not covered by tests
}

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 @@
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)

Check warning on line 279 in pkg/app/piped/notifier/slack.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/piped/notifier/slack.go#L274-L279

Added lines #L274 - L279 were not covered by tests

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 @@
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))
}

Check warning on line 220 in pkg/app/pipedv1/controller/scheduler.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/controller/scheduler.go#L215-L220

Added lines #L215 - L220 were not covered by tests

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

Check warning on line 229 in pkg/app/pipedv1/controller/scheduler.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/controller/scheduler.go#L222-L229

Added lines #L222 - L229 were not covered by tests
}

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 @@
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)

Check warning on line 279 in pkg/app/pipedv1/notifier/slack.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/notifier/slack.go#L274-L279

Added lines #L274 - L279 were not covered by tests

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