@@ -25,6 +25,7 @@ import (
2525 "go.opentelemetry.io/otel/trace"
2626 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727 "k8s.io/apimachinery/pkg/types"
28+ "k8s.io/apimachinery/pkg/watch"
2829 "k8s.io/klog/v2"
2930)
3031
@@ -134,9 +135,35 @@ func (p *dbPackage) DeletePackageRevision(ctx context.Context, old repository.Pa
134135 return pkgDeleteFromDB (ctx , p .Key ())
135136 }
136137
138+ if dbPR .IsLatestRevision () {
139+ updateCtx , cancel := context .WithTimeout (context .Background (), 3 * time .Minute )
140+ defer cancel ()
141+ go p .sendLatestPkgUpdateNotification (updateCtx )
142+ }
143+
137144 return nil
138145}
139146
147+ func (p * dbPackage ) sendLatestPkgUpdateNotification (ctx context.Context ) {
148+ _ , span := tracer .Start (ctx , "dbPackage:sendLatestPkgUpdateNotification" , trace .WithAttributes ())
149+ defer span .End ()
150+
151+ klog .V (2 ).Infoln ("dbPackage: sending latest PackageRevision update notification if found" )
152+
153+ latestRevision , err := pkgRevReadLatestPRFromDB (ctx , p .Key ())
154+ if err != nil {
155+ klog .Error (err )
156+ return
157+ } else if latestRevision == nil {
158+ klog .Infof ("dbPackage %+v: no new latest PackageRevision found. Notification not sent." , p .Key ())
159+ return
160+ }
161+
162+ sent := p .repo .repoPRChangeNotifier .NotifyPackageRevisionChange (watch .Modified , latestRevision )
163+ klog .Infof ("dbcache: sent %d for latest PackageRevision %s/%s" , sent , latestRevision .KubeObjectNamespace (), latestRevision .KubeObjectName ())
164+
165+ }
166+
140167func (p * dbPackage ) GetLatestRevision (ctx context.Context ) int {
141168 _ , span := tracer .Start (ctx , "dbPackage:GetLatestRevision" , trace .WithAttributes ())
142169 defer span .End ()
0 commit comments