From d27116280cb8fa113247e8a7f3133d6a350615b3 Mon Sep 17 00:00:00 2001 From: Sam Starling <42478+samstarling@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:47:08 +0000 Subject: [PATCH] Log when duplicate external IDs are encountered (#152) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit External IDs have to be unique — currently if you provide an array of models with identical external IDs, only the last one wins. To reduce any confusion here, log a message that explains what's happening. --- reconcile/entries.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/reconcile/entries.go b/reconcile/entries.go index 5d905d0..5b6838b 100644 --- a/reconcile/entries.go +++ b/reconcile/entries.go @@ -82,10 +82,23 @@ func Entries(ctx context.Context, logger kitlog.Logger, cl EntriesClient, output return errors.Wrap(err, "listing entries") } - // Prepare a quick lookup of model by external ID, to power deletion. - modelsByExternalID := map[string]*output.CatalogEntryModel{} + // Prepare a quick lookup of model by external ID, to power deletion. We only need + // to store a boolean here, because we only care about the presence of a model by + // external ID. + modelsByExternalID := map[string]bool{} for _, model := range entryModels { - modelsByExternalID[model.ExternalID] = model + // If we encounter two (or more) models with the same external ID, then we should + // log a warning. The external ID must be unique, so in the next phase we'll only + // create one catalog entry per external ID. + _, ok := modelsByExternalID[model.ExternalID] + if ok { + logger.Log( + "msg", "two entries with the same external ID provided, the first will be ignored", + "external_id", model.ExternalID, + ) + } + + modelsByExternalID[model.ExternalID] = true } {