Filter tracked images to only included mirrored registries

This commit is contained in:
Philip Laine 2023-03-10 00:03:02 +01:00
parent 3dc6461299
commit 8fa939b9dd
3 changed files with 10 additions and 2 deletions

View File

@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- [#51](https://github.com/XenitAB/spegel/pull/51) Filter tracked images to only included mirrored registries.
### Security
## v0.0.4

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/url"
"strings"
"time"
@ -40,7 +41,7 @@ var advertisedKeys = promauto.NewGauge(prometheus.GaugeOpts{
})
// TODO: Update metrics on subscribed events. This will require keeping state in memory to know about key count changes.
func Track(ctx context.Context, containerdClient *containerd.Client, router routing.Router, imageFilter string) error {
func Track(ctx context.Context, containerdClient *containerd.Client, router routing.Router, registries []url.URL, imageFilter string) error {
log := logr.FromContextOrDiscard(ctx)
imageFilters := []string{}
@ -49,6 +50,11 @@ func Track(ctx context.Context, containerdClient *containerd.Client, router rout
eventFilters = append(eventFilters, fmt.Sprintf(`event.name~="%s"`, imageFilter))
imageFilters = append(imageFilters, fmt.Sprintf(`name~=%s`, imageFilter))
}
for _, registry := range registries {
eventFilters = append(eventFilters, fmt.Sprintf(`event.name~="%s"`, registry.Host))
imageFilters = append(imageFilters, fmt.Sprintf(`name~=%s`, registry.Host))
}
log.Info("tracking images with filters", "event", eventFilters, "image", imageFilters)
// Subscribe to image events before doing the initial sync to catch any changes which may occur inbetween.
envelopeCh, errCh := containerdClient.EventService().Subscribe(ctx, eventFilters...)

View File

@ -125,7 +125,7 @@ func run(log logr.Logger, args *arguments) error {
return router.Close()
})
g.Go(func() error {
return state.Track(ctx, containerdClient, router, args.ImageFilter)
return state.Track(ctx, containerdClient, router, args.Registries, args.ImageFilter)
})
reg, err := registry.NewRegistry(ctx, args.RegistryAddr, containerdClient, router)