forked from solo-io/gloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_syncer.go
41 lines (35 loc) · 1.21 KB
/
setup_syncer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package setuputils
import (
"context"
"github.com/solo-io/gloo/pkg/utils/settingsutil"
v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
"github.com/solo-io/solo-kit/pkg/api/v1/clients/kube"
"github.com/solo-io/solo-kit/pkg/api/v1/clients/memory"
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"
"github.com/solo-io/solo-kit/pkg/errors"
)
// tell us how to setup
type SetupFunc func(ctx context.Context,
kubeCache kube.SharedCache,
inMemoryCache memory.InMemoryResourceCache,
settings *v1.Settings) error
type SetupSyncer struct {
settingsRef core.ResourceRef
setupFunc SetupFunc
inMemoryCache memory.InMemoryResourceCache
}
func NewSetupSyncer(settingsRef core.ResourceRef, setupFunc SetupFunc) *SetupSyncer {
return &SetupSyncer{
settingsRef: settingsRef,
setupFunc: setupFunc,
inMemoryCache: memory.NewInMemoryResourceCache(),
}
}
func (s *SetupSyncer) Sync(ctx context.Context, snap *v1.SetupSnapshot) error {
settings, err := snap.Settings.Find(s.settingsRef.Strings())
if err != nil {
return errors.Wrapf(err, "finding bootstrap configuration")
}
ctx = settingsutil.WithSettings(ctx, settings)
return s.setupFunc(ctx, kube.NewKubeCache(ctx), s.inMemoryCache, settings)
}