Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/sync/kubernetes/kubernetes_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Sync struct {
client client.Client
URI string
ready bool

informer cache.SharedInformer
}

func (k *Sync) Init(ctx context.Context) error {
Expand Down Expand Up @@ -92,6 +94,19 @@ func (k *Sync) Sync(ctx context.Context, dataSync chan<- sync.DataSync) error {
}

func (k *Sync) fetch(ctx context.Context) (string, error) {
// first check the store - avoid overloading API
item, exist, _ := k.informer.GetStore().GetByKey(k.URI)
if exist {
var ffOldObj v1alpha1.FeatureFlagConfiguration
u := item.(*unstructured.Unstructured)
err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &ffOldObj)
if err != nil {
return "", err
}

return ffOldObj.Spec.FeatureFlagSpec, nil
}

if k.URI == "" {
k.Logger.Error("no target feature flag configuration set")
return "{}", nil
Expand Down Expand Up @@ -178,6 +193,8 @@ func (k *Sync) notify(ctx context.Context, c chan<- INotify) {
factory := dynamicinformer.NewFilteredDynamicSharedInformerFactory(clusterClient,
resyncPeriod, corev1.NamespaceAll, nil)
informer := factory.ForResource(resource).Informer()
k.informer = informer

objectKey := client.ObjectKey{
Name: name,
Namespace: ns,
Expand Down