镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions internal/knowledge/datasources/plugins/openstack/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"net/http"
"sync"
"time"

"github.com/cobaltcore-dev/cortex/api/v1alpha1"
Expand Down Expand Up @@ -63,6 +64,10 @@ type OpenStackDatasourceReconciler struct {

// Config for the reconciler.
conf config
// Tracks datasources that have completed at least one reconcile this process lifetime.
// On first reconcile the timestamp skip is bypassed, so a DB wipe + operator restart
// forces an immediate re-sync of all datasources.
reconciledOnce sync.Map
}

// Reconcile is part of the main kubernetes reconciliation loop which aims to
Expand Down Expand Up @@ -91,8 +96,11 @@ func (r *OpenStackDatasourceReconciler) Reconcile(ctx context.Context, req ctrl.
return ctrl.Result{}, nil
}
if datasource.Status.NextSyncTime.After(time.Now()) && datasource.Status.NumberOfObjects != 0 {
log.Info("skipping datasource sync, not yet time", "name", datasource.Name)
return ctrl.Result{RequeueAfter: time.Until(datasource.Status.NextSyncTime.Time)}, nil
if _, seen := r.reconciledOnce.Load(req.NamespacedName); seen {
log.Info("skipping datasource sync, not yet time", "name", datasource.Name)
return ctrl.Result{RequeueAfter: time.Until(datasource.Status.NextSyncTime.Time)}, nil
}
log.Info("first reconcile this process lifetime, forcing sync despite timestamp", "name", datasource.Name)
}

// Authenticate with the database based on the secret provided in the datasource.
Expand Down Expand Up @@ -263,6 +271,7 @@ func (r *OpenStackDatasourceReconciler) Reconcile(ctx context.Context, req ctrl.

// Calculate the next sync time based on the configured sync interval.
log.Info("Finished reconcile", "next", nextTime)
r.reconciledOnce.Store(req.NamespacedName, struct{}{})
return ctrl.Result{RequeueAfter: datasource.Spec.OpenStack.SyncInterval.Duration}, nil
}

Expand Down
13 changes: 11 additions & 2 deletions internal/knowledge/datasources/plugins/prometheus/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package prometheus
import (
"context"
"net/http"
"sync"
"time"

"github.com/cobaltcore-dev/cortex/api/v1alpha1"
Expand Down Expand Up @@ -50,6 +51,10 @@ type PrometheusDatasourceReconciler struct {
conf config
// Monitor for tracking the datasource syncs.
Monitor datasources.Monitor
// Tracks datasources that have completed at least one reconcile this process lifetime.
// On first reconcile the timestamp skip is bypassed, so a DB wipe + operator restart
// forces an immediate re-sync of all datasources.
reconciledOnce sync.Map
}

// Reconcile is part of the main kubernetes reconciliation loop which aims to
Expand All @@ -67,8 +72,11 @@ func (r *PrometheusDatasourceReconciler) Reconcile(ctx context.Context, req ctrl
return ctrl.Result{}, nil
}
if datasource.Status.NextSyncTime.After(time.Now()) && datasource.Status.NumberOfObjects != 0 {
log.Info("skipping datasource sync, not yet time", "name", datasource.Name)
return ctrl.Result{RequeueAfter: time.Until(datasource.Status.NextSyncTime.Time)}, nil
if _, seen := r.reconciledOnce.Load(req.NamespacedName); seen {
log.Info("skipping datasource sync, not yet time", "name", datasource.Name)
return ctrl.Result{RequeueAfter: time.Until(datasource.Status.NextSyncTime.Time)}, nil
}
log.Info("first reconcile this process lifetime, forcing sync despite timestamp", "name", datasource.Name)
}

newSyncerFunc, ok := supportedMetricSyncers[datasource.Spec.Prometheus.Type]
Expand Down Expand Up @@ -201,6 +209,7 @@ func (r *PrometheusDatasourceReconciler) Reconcile(ctx context.Context, req ctrl
}

// Calculate the next sync time based on the configured sync interval.
r.reconciledOnce.Store(req.NamespacedName, struct{}{})
return ctrl.Result{RequeueAfter: time.Until(nextSync)}, nil
}

Expand Down