mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
rebase: bump sigs.k8s.io/controller-runtime
Bumps the k8s-dependencies group with 1 update: [sigs.k8s.io/controller-runtime](https://github.com/kubernetes-sigs/controller-runtime). Updates `sigs.k8s.io/controller-runtime` from 0.20.4 to 0.21.0 - [Release notes](https://github.com/kubernetes-sigs/controller-runtime/releases) - [Changelog](https://github.com/kubernetes-sigs/controller-runtime/blob/main/RELEASE.md) - [Commits](https://github.com/kubernetes-sigs/controller-runtime/compare/v0.20.4...v0.21.0) --- updated-dependencies: - dependency-name: sigs.k8s.io/controller-runtime dependency-version: 0.21.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: k8s-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
mergify[bot]
parent
d05ebd3456
commit
eb13efc9df
118
vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go
generated
vendored
118
vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go
generated
vendored
@ -174,65 +174,12 @@ func (c *Controller[request]) Start(ctx context.Context) error {
|
||||
defer c.mu.Unlock()
|
||||
|
||||
// TODO(pwittrock): Reconsider HandleCrash
|
||||
defer utilruntime.HandleCrash()
|
||||
defer utilruntime.HandleCrashWithLogger(c.LogConstructor(nil))
|
||||
|
||||
// NB(directxman12): launch the sources *before* trying to wait for the
|
||||
// caches to sync so that they have a chance to register their intended
|
||||
// caches.
|
||||
errGroup := &errgroup.Group{}
|
||||
for _, watch := range c.startWatches {
|
||||
log := c.LogConstructor(nil)
|
||||
_, ok := watch.(interface {
|
||||
String() string
|
||||
})
|
||||
|
||||
if !ok {
|
||||
log = log.WithValues("source", fmt.Sprintf("%T", watch))
|
||||
} else {
|
||||
log = log.WithValues("source", fmt.Sprintf("%s", watch))
|
||||
}
|
||||
didStartSyncingSource := &atomic.Bool{}
|
||||
errGroup.Go(func() error {
|
||||
// Use a timeout for starting and syncing the source to avoid silently
|
||||
// blocking startup indefinitely if it doesn't come up.
|
||||
sourceStartCtx, cancel := context.WithTimeout(ctx, c.CacheSyncTimeout)
|
||||
defer cancel()
|
||||
|
||||
sourceStartErrChan := make(chan error, 1) // Buffer chan to not leak goroutine if we time out
|
||||
go func() {
|
||||
defer close(sourceStartErrChan)
|
||||
log.Info("Starting EventSource")
|
||||
if err := watch.Start(ctx, c.Queue); err != nil {
|
||||
sourceStartErrChan <- err
|
||||
return
|
||||
}
|
||||
syncingSource, ok := watch.(source.TypedSyncingSource[request])
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
didStartSyncingSource.Store(true)
|
||||
if err := syncingSource.WaitForSync(sourceStartCtx); err != nil {
|
||||
err := fmt.Errorf("failed to wait for %s caches to sync %v: %w", c.Name, syncingSource, err)
|
||||
log.Error(err, "Could not wait for Cache to sync")
|
||||
sourceStartErrChan <- err
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-sourceStartErrChan:
|
||||
return err
|
||||
case <-sourceStartCtx.Done():
|
||||
if didStartSyncingSource.Load() { // We are racing with WaitForSync, wait for it to let it tell us what happened
|
||||
return <-sourceStartErrChan
|
||||
}
|
||||
if ctx.Err() != nil { // Don't return an error if the root context got cancelled
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("timed out waiting for source %s to Start. Please ensure that its Start() method is non-blocking", watch)
|
||||
}
|
||||
})
|
||||
}
|
||||
if err := errGroup.Wait(); err != nil {
|
||||
if err := c.startEventSources(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -271,6 +218,65 @@ func (c *Controller[request]) Start(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// startEventSources launches all the sources registered with this controller and waits
|
||||
// for them to sync. It returns an error if any of the sources fail to start or sync.
|
||||
func (c *Controller[request]) startEventSources(ctx context.Context) error {
|
||||
errGroup := &errgroup.Group{}
|
||||
for _, watch := range c.startWatches {
|
||||
log := c.LogConstructor(nil)
|
||||
_, ok := watch.(interface {
|
||||
String() string
|
||||
})
|
||||
|
||||
if !ok {
|
||||
log = log.WithValues("source", fmt.Sprintf("%T", watch))
|
||||
} else {
|
||||
log = log.WithValues("source", fmt.Sprintf("%s", watch))
|
||||
}
|
||||
didStartSyncingSource := &atomic.Bool{}
|
||||
errGroup.Go(func() error {
|
||||
// Use a timeout for starting and syncing the source to avoid silently
|
||||
// blocking startup indefinitely if it doesn't come up.
|
||||
sourceStartCtx, cancel := context.WithTimeout(ctx, c.CacheSyncTimeout)
|
||||
defer cancel()
|
||||
|
||||
sourceStartErrChan := make(chan error, 1) // Buffer chan to not leak goroutine if we time out
|
||||
go func() {
|
||||
defer close(sourceStartErrChan)
|
||||
log.Info("Starting EventSource")
|
||||
if err := watch.Start(ctx, c.Queue); err != nil {
|
||||
sourceStartErrChan <- err
|
||||
return
|
||||
}
|
||||
syncingSource, ok := watch.(source.TypedSyncingSource[request])
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
didStartSyncingSource.Store(true)
|
||||
if err := syncingSource.WaitForSync(sourceStartCtx); err != nil {
|
||||
err := fmt.Errorf("failed to wait for %s caches to sync %v: %w", c.Name, syncingSource, err)
|
||||
log.Error(err, "Could not wait for Cache to sync")
|
||||
sourceStartErrChan <- err
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-sourceStartErrChan:
|
||||
return err
|
||||
case <-sourceStartCtx.Done():
|
||||
if didStartSyncingSource.Load() { // We are racing with WaitForSync, wait for it to let it tell us what happened
|
||||
return <-sourceStartErrChan
|
||||
}
|
||||
if ctx.Err() != nil { // Don't return an error if the root context got cancelled
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("timed out waiting for source %s to Start. Please ensure that its Start() method is non-blocking", watch)
|
||||
}
|
||||
})
|
||||
}
|
||||
return errGroup.Wait()
|
||||
}
|
||||
|
||||
// processNextWorkItem will read a single work item off the workqueue and
|
||||
// attempt to process it, by calling the reconcileHandler.
|
||||
func (c *Controller[request]) processNextWorkItem(ctx context.Context) bool {
|
||||
@ -354,7 +360,7 @@ func (c *Controller[request]) reconcileHandler(ctx context.Context, req request,
|
||||
c.Queue.Forget(req)
|
||||
c.Queue.AddWithOpts(priorityqueue.AddOpts{After: result.RequeueAfter, Priority: priority}, req)
|
||||
ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, labelRequeueAfter).Inc()
|
||||
case result.Requeue:
|
||||
case result.Requeue: //nolint: staticcheck // We have to handle it until it is removed
|
||||
log.V(5).Info("Reconcile done, requeueing")
|
||||
c.Queue.AddWithOpts(priorityqueue.AddOpts{RateLimited: true, Priority: priority}, req)
|
||||
ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, labelRequeue).Inc()
|
||||
|
9
vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/metrics/metrics.go
generated
vendored
9
vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/metrics/metrics.go
generated
vendored
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
"sigs.k8s.io/controller-runtime/pkg/metrics"
|
||||
@ -60,6 +62,9 @@ var (
|
||||
Help: "Length of time per reconciliation per controller",
|
||||
Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0,
|
||||
1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40, 50, 60},
|
||||
NativeHistogramBucketFactor: 1.1,
|
||||
NativeHistogramMaxBucketNumber: 100,
|
||||
NativeHistogramMinResetDuration: 1 * time.Hour,
|
||||
}, []string{"controller"})
|
||||
|
||||
// WorkerCount is a prometheus metric which holds the number of
|
||||
@ -88,7 +93,7 @@ func init() {
|
||||
ActiveWorkers,
|
||||
// expose process metrics like CPU, Memory, file descriptor usage etc.
|
||||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
||||
// expose Go runtime metrics like GC stats, memory stats etc.
|
||||
collectors.NewGoCollector(),
|
||||
// expose all Go runtime metrics like GC stats, memory stats etc.
|
||||
collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(collectors.MetricsAll)),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user