mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-25 12:39:50 +02:00
zero: resource bundle reconciler (#4445)
This commit is contained in:
parent
788376bf60
commit
3b65049d2f
18 changed files with 1560 additions and 0 deletions
34
internal/zero/reconciler/reconciler.go
Normal file
34
internal/zero/reconciler/reconciler.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue