zero: resource bundle reconciler (#4445)

This commit is contained in:
Denis Mishin 2023-08-17 13:19:51 -04:00 committed by GitHub
parent 788376bf60
commit 3b65049d2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 1560 additions and 0 deletions

View file

@ -0,0 +1,34 @@
package reconciler
import (
"context"
"fmt"
"github.com/pomerium/pomerium/pkg/grpc/databroker"
)
// Reconcile reconciles the target and current record sets with the databroker.
func Reconcile(
ctx context.Context,
client databroker.DataBrokerServiceClient,
target, current RecordSetBundle[DatabrokerRecord],
) error {
updates := NewDatabrokerChangeSet()
for _, rec := range current.GetRemoved(target).Flatten() {
updates.Remove(rec.GetType(), rec.GetID())
}
for _, rec := range current.GetModified(target).Flatten() {
updates.Upsert(rec.V)
}
for _, rec := range current.GetAdded(target).Flatten() {
updates.Upsert(rec.V)
}
err := ApplyChanges(ctx, client, updates)
if err != nil {
return fmt.Errorf("apply databroker changes: %w", err)
}
return nil
}