Skip to content

Commit

Permalink
save the spec to the status event when a resource is deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
skeeey committed Dec 10, 2024
1 parent 3a56948 commit 2a77173
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cmd/maestro/server/grpc_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ func (bkr *GRPCBroker) OnDelete(ctx context.Context, id string) error {
// It does two things:
// 1. build the resource status and broadcast it to subscribers
// 2. add the event instance record to mark the event has been processed by the current instance
// TODO consider using a same way (pulse_server.OnStatusUpdate) to handle this
func (bkr *GRPCBroker) OnStatusUpdate(ctx context.Context, eventID, resourceID string) error {
statusEvent, sErr := bkr.statusEventService.Get(ctx, eventID)
if sErr != nil {
Expand All @@ -443,9 +444,10 @@ func (bkr *GRPCBroker) OnStatusUpdate(ctx context.Context, eventID, resourceID s
Meta: api.Meta{
ID: resourceID,
},
Source: statusEvent.ResourceSource,
Type: statusEvent.ResourceType,
Status: statusEvent.Status,
Source: statusEvent.ResourceSource,
Type: statusEvent.ResourceType,
Payload: statusEvent.Payload,
Status: statusEvent.Status,
}
} else {
resource, sErr = bkr.resourceService.Get(ctx, resourceID)
Expand Down
8 changes: 5 additions & 3 deletions cmd/maestro/server/pulse_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ func (s *PulseServer) OnStatusUpdate(ctx context.Context, eventID, resourceID st
Meta: api.Meta{
ID: resourceID,
},
Source: statusEvent.ResourceSource,
Type: statusEvent.ResourceType,
Status: statusEvent.Status,
Source: statusEvent.ResourceSource,
Type: statusEvent.ResourceType,
Payload: statusEvent.Payload,
Status: statusEvent.Status,
}
} else {
resource, sErr = s.resourceService.Get(ctx, resourceID)
Expand Down Expand Up @@ -317,6 +318,7 @@ func handleStatusUpdate(ctx context.Context, resource *api.Resource, resourceSer
ResourceID: resource.ID,
ResourceSource: resource.Source,
ResourceType: resource.Type,
Payload: found.Payload,
Status: resource.Status,
StatusEventType: api.StatusDeleteEventType,
})
Expand Down
1 change: 1 addition & 0 deletions pkg/api/status_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type StatusEvent struct {
ResourceID string
ResourceSource string
ResourceType ResourceType
Payload datatypes.JSONMap
Status datatypes.JSONMap
StatusEventType StatusEventType // Update|Delete
ReconciledDate *time.Time `json:"gorm:null"`
Expand Down
1 change: 1 addition & 0 deletions pkg/db/migrations/202406241426_add_status_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func addStatusEvents() *gormigrate.Migration {
ResourceID string `gorm:"index"` // resource id
ResourceSource string
ResourceType string
Payload datatypes.JSON `gorm:"type:json"`
Status datatypes.JSON `gorm:"type:json"`
StatusEventType string // Update|Delete, any string
ReconciledDate *time.Time `gorm:"null;index"`
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/pkg/sourceclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ func AssertWatchResult(result *WatchedResult) error {
}

if meta.IsStatusConditionTrue(watchedWork.Status.Conditions, common.ManifestsDeleted) && !watchedWork.DeletionTimestamp.IsZero() {
if len(watchedWork.Spec.Workload.Manifests) == 0 {
return fmt.Errorf("expected the deleted work has spec, but failed %v", watchedWork.Spec)
}

hasDeletedWork = true
}
}
Expand Down

0 comments on commit 2a77173

Please sign in to comment.