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 11, 2024
1 parent 3a56948 commit 2c087ea
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 16 deletions.
10 changes: 5 additions & 5 deletions .tekton/maestro-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec:
- name: name
value: summary
- name: bundle
value: quay.io/redhat-appstudio-tekton-catalog/task-summary:0.2@sha256:ac5b078500566c204eaa23e3aea1e2f7e003ac750514198419cb322a2eaf177a
value: quay.io/redhat-appstudio-tekton-catalog/task-summary:0.2@sha256:716d50d6f79c119e729a41ddf4eca7ddc521dbfb32cc10c7e1ef1942da887e26
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -191,7 +191,7 @@ spec:
- name: name
value: prefetch-dependencies
- name: bundle
value: quay.io/redhat-appstudio-tekton-catalog/task-prefetch-dependencies:0.1@sha256:cdf98845bbed169e488daef426d1cfdde85c586655abcf89c61da6538d93f70c
value: quay.io/redhat-appstudio-tekton-catalog/task-prefetch-dependencies:0.1@sha256:cd873246e0d830d8b3d0dc76334348474361101487457f65bc02aab9861aad2c
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -226,7 +226,7 @@ spec:
- name: name
value: buildah
- name: bundle
value: quay.io/redhat-appstudio-tekton-catalog/task-buildah:0.2@sha256:570831e48df71f3578eb6f083d5fe5ee5c9affa5edbd1c648474ceef4553373e
value: quay.io/redhat-appstudio-tekton-catalog/task-buildah:0.2@sha256:ccd1cebde461112883df1fa2be45d3f81b142e9fb72fb04347840e9830f2a66e
- name: kind
value: task
resolver: bundles
Expand All @@ -249,7 +249,7 @@ spec:
- name: name
value: source-build
- name: bundle
value: quay.io/redhat-appstudio-tekton-catalog/task-source-build:0.1@sha256:c07c3f9813e87832468fc72912c6e8ef995a442a32248cc35d77b8c0f5e516e2
value: quay.io/redhat-appstudio-tekton-catalog/task-source-build:0.1@sha256:399cddeda7b33ef16872d469d0e2bb5f44a3ff0efa7d3cffa4bd9ff7130faea6
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -347,7 +347,7 @@ spec:
- name: name
value: clamav-scan
- name: bundle
value: quay.io/redhat-appstudio-tekton-catalog/task-clamav-scan:0.1@sha256:3e2891c232dc03fb5c7746fc615e1827afbd6931843e42b19cb8a6c04276ed32
value: quay.io/redhat-appstudio-tekton-catalog/task-clamav-scan:0.2@sha256:d586428498a2e27ff7c0eb2591181f05e783871db0cc16112acd2e1ee0a77b8b
- name: kind
value: task
resolver: bundles
Expand Down
10 changes: 5 additions & 5 deletions .tekton/maestro-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
- name: name
value: summary
- name: bundle
value: quay.io/redhat-appstudio-tekton-catalog/task-summary:0.2@sha256:ac5b078500566c204eaa23e3aea1e2f7e003ac750514198419cb322a2eaf177a
value: quay.io/redhat-appstudio-tekton-catalog/task-summary:0.2@sha256:716d50d6f79c119e729a41ddf4eca7ddc521dbfb32cc10c7e1ef1942da887e26
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -188,7 +188,7 @@ spec:
- name: name
value: prefetch-dependencies
- name: bundle
value: quay.io/redhat-appstudio-tekton-catalog/task-prefetch-dependencies:0.1@sha256:cdf98845bbed169e488daef426d1cfdde85c586655abcf89c61da6538d93f70c
value: quay.io/redhat-appstudio-tekton-catalog/task-prefetch-dependencies:0.1@sha256:cd873246e0d830d8b3d0dc76334348474361101487457f65bc02aab9861aad2c
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -223,7 +223,7 @@ spec:
- name: name
value: buildah
- name: bundle
value: quay.io/redhat-appstudio-tekton-catalog/task-buildah:0.2@sha256:570831e48df71f3578eb6f083d5fe5ee5c9affa5edbd1c648474ceef4553373e
value: quay.io/redhat-appstudio-tekton-catalog/task-buildah:0.2@sha256:ccd1cebde461112883df1fa2be45d3f81b142e9fb72fb04347840e9830f2a66e
- name: kind
value: task
resolver: bundles
Expand All @@ -246,7 +246,7 @@ spec:
- name: name
value: source-build
- name: bundle
value: quay.io/redhat-appstudio-tekton-catalog/task-source-build:0.1@sha256:c07c3f9813e87832468fc72912c6e8ef995a442a32248cc35d77b8c0f5e516e2
value: quay.io/redhat-appstudio-tekton-catalog/task-source-build:0.1@sha256:399cddeda7b33ef16872d469d0e2bb5f44a3ff0efa7d3cffa4bd9ff7130faea6
- name: kind
value: task
resolver: bundles
Expand Down Expand Up @@ -344,7 +344,7 @@ spec:
- name: name
value: clamav-scan
- name: bundle
value: quay.io/redhat-appstudio-tekton-catalog/task-clamav-scan:0.1@sha256:3e2891c232dc03fb5c7746fc615e1827afbd6931843e42b19cb8a6c04276ed32
value: quay.io/redhat-appstudio-tekton-catalog/task-clamav-scan:0.2@sha256:d586428498a2e27ff7c0eb2591181f05e783871db0cc16112acd2e1ee0a77b8b
- name: kind
value: task
resolver: bundles
Expand Down
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 2c087ea

Please sign in to comment.