diff --git a/pkg/app/piped/driftdetector/cloudrun/detector.go b/pkg/app/piped/driftdetector/cloudrun/detector.go index a3fb460a3e..143da87ba5 100644 --- a/pkg/app/piped/driftdetector/cloudrun/detector.go +++ b/pkg/app/piped/driftdetector/cloudrun/detector.go @@ -47,7 +47,7 @@ type secretDecrypter interface { } type reporter interface { - ReportApplicationSyncState(ctx context.Context, appID string, state model.ApplicationSyncState) error + ReportApplicationSyncState(ctx context.Context, app model.Application, state model.ApplicationSyncState) error } type Detector interface { @@ -219,7 +219,7 @@ func (d *detector) checkApplication(ctx context.Context, app *model.Application, state := makeSyncState(result, headCommit.Hash) - return d.reporter.ReportApplicationSyncState(ctx, app.Id, state) + return d.reporter.ReportApplicationSyncState(ctx, *app, state) } func (d *detector) loadHeadServiceManifest(app *model.Application, repo git.Repo, headCommit git.Commit) (provider.ServiceManifest, error) { diff --git a/pkg/app/piped/driftdetector/detector.go b/pkg/app/piped/driftdetector/detector.go index 4960aa4fb4..daf47cfa2b 100644 --- a/pkg/app/piped/driftdetector/detector.go +++ b/pkg/app/piped/driftdetector/detector.go @@ -190,9 +190,9 @@ func (d *detector) Run(ctx context.Context) error { return nil } -func (d *detector) ReportApplicationSyncState(ctx context.Context, appID string, state model.ApplicationSyncState) error { +func (d *detector) ReportApplicationSyncState(ctx context.Context, app model.Application, state model.ApplicationSyncState) error { d.mu.RLock() - curState, ok := d.syncStates[appID] + curState, ok := d.syncStates[app.Id] d.mu.RUnlock() if ok && !curState.HasChanged(state) { @@ -200,22 +200,41 @@ func (d *detector) ReportApplicationSyncState(ctx context.Context, appID string, } _, err := d.apiClient.ReportApplicationSyncState(ctx, &pipedservice.ReportApplicationSyncStateRequest{ - ApplicationId: appID, + ApplicationId: app.Id, State: &state, }) if err != nil { d.logger.Error("failed to report application sync state", - zap.String("application-id", appID), + zap.String("application-id", app.Id), zap.Any("state", state), zap.Error(err), ) return err } - // TODO notify a event of NotificationEventType_EVENT_APPLICATION_OUT_OF_SYNC - // TODO notify a event of NotificationEventType_EVENT_APPLICATION_SYNCED + + defer func() { + switch state.Status { + case model.ApplicationSyncStatus_SYNCED: + d.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_APPLICATION_SYNCED, + Metadata: &model.NotificationEventApplicationSynced{ + Application: &app, + State: &state, + }, + }) + case model.ApplicationSyncStatus_OUT_OF_SYNC: + d.notifier.Notify(model.NotificationEvent{ + Type: model.NotificationEventType_EVENT_APPLICATION_OUT_OF_SYNC, + Metadata: &model.NotificationEventApplicationOutOfSync{ + Application: &app, + State: &state, + }, + }) + } + }() d.mu.Lock() - d.syncStates[appID] = state + d.syncStates[app.Id] = state d.mu.Unlock() return nil diff --git a/pkg/app/piped/driftdetector/kubernetes/detector.go b/pkg/app/piped/driftdetector/kubernetes/detector.go index 6eb37b67da..5681d6ec29 100644 --- a/pkg/app/piped/driftdetector/kubernetes/detector.go +++ b/pkg/app/piped/driftdetector/kubernetes/detector.go @@ -47,7 +47,7 @@ type secretDecrypter interface { } type reporter interface { - ReportApplicationSyncState(ctx context.Context, appID string, state model.ApplicationSyncState) error + ReportApplicationSyncState(ctx context.Context, app model.Application, state model.ApplicationSyncState) error } type Detector interface { @@ -218,7 +218,7 @@ func (d *detector) checkApplication(ctx context.Context, app *model.Application, state := makeSyncState(result, headCommit.Hash) - return d.reporter.ReportApplicationSyncState(ctx, app.Id, state) + return d.reporter.ReportApplicationSyncState(ctx, *app, state) } func (d *detector) loadHeadManifests(ctx context.Context, app *model.Application, repo git.Repo, headCommit git.Commit, watchingResourceKinds []provider.APIVersionKind) ([]provider.Manifest, error) { diff --git a/pkg/app/piped/driftdetector/terraform/detector.go b/pkg/app/piped/driftdetector/terraform/detector.go index 7edd099c86..15db724a34 100644 --- a/pkg/app/piped/driftdetector/terraform/detector.go +++ b/pkg/app/piped/driftdetector/terraform/detector.go @@ -48,7 +48,7 @@ type secretDecrypter interface { } type reporter interface { - ReportApplicationSyncState(ctx context.Context, appID string, state model.ApplicationSyncState) error + ReportApplicationSyncState(ctx context.Context, app model.Application, state model.ApplicationSyncState) error } type Detector interface { @@ -278,7 +278,7 @@ func (d *detector) checkApplication(ctx context.Context, app *model.Application, return err } - return d.reporter.ReportApplicationSyncState(ctx, app.Id, *state) + return d.reporter.ReportApplicationSyncState(ctx, *app, *state) } func makeSyncState(r provider.PlanResult, commit string) (*model.ApplicationSyncState, error) {