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

save the spec to the status event when a resource is deleted #225

Merged
merged 1 commit into from
Dec 11, 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
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
Loading