Skip to content

Commit

Permalink
Cleanup: remove unnecessary check controllerutil.IsCacheNotStarted in…
Browse files Browse the repository at this point in the history
… controllers (#9168)

* remove function util.IsCacheNotStarted

since controller-runtime v0.8.1, manager start all caches before other Runnables so this function is not need anymore cf kubernetes-sigs/controller-runtime#1327

Signed-off-by: Vincent Gramer <vincent@kubermatic.com>

* master-controller-manager/usersshkeyssynchronizer/controller.go: remove unecessary check

since controller-runtime v0.8.1 the manager start all cache before running runables, so this error can not happen.

Signed-off-by: Vincent Gramer <vincent@kubermatic.com>

* master-controller-manager/project-label-synchronizer/project_label_synchronizer.go: remove unecessary check

since controller-runtime v0.8.1 the manager start all cache before running runables, so this error can not happen.

Signed-off-by: Vincent Gramer <vincent@kubermatic.com>

* master-controller-manager/master-constraint-template-controller/controller.go: remove unecessary check

since controller-runtime v0.8.1 the manager start all cache before running runables, so this error can not happen.

Signed-off-by: Vincent Gramer <vincent@kubermatic.com>

* master-controller-manager/master-constraint-controller/controller.go: remove unecessary check

since controller-runtime v0.8.1 the manager start all cache before running runables, so this error can not happen.

Signed-off-by: Vincent Gramer <vincent@kubermatic.com>

* master-controller-manager/cluster-template-synchronizer/controller.go: remove unecessary check

since controller-runtime v0.8.1 the manager start all cache before running runables, so this error can not happen.

Signed-off-by: Vincent Gramer <vincent@kubermatic.com>
  • Loading branch information
vgramer committed Mar 1, 2022
1 parent d58d5e3 commit 4eb2eb7
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 51 deletions.
Expand Up @@ -19,13 +19,11 @@ package clustertemplatesynchronizer
import (
"context"
"fmt"
"time"

"go.uber.org/zap"

kubermaticapiv1 "k8c.io/kubermatic/v2/pkg/api/v1"
kubermaticv1 "k8c.io/kubermatic/v2/pkg/apis/kubermatic/v1"
controllerutil "k8c.io/kubermatic/v2/pkg/controller/util"
kuberneteshelper "k8c.io/kubermatic/v2/pkg/kubernetes"
"k8c.io/kubermatic/v2/pkg/resources"
"k8c.io/kubermatic/v2/pkg/resources/reconciling"
Expand Down Expand Up @@ -90,9 +88,6 @@ func (r *reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
log.Debug("Processing")

err := r.reconcile(ctx, log, request)
if controllerutil.IsCacheNotStarted(err) {
return reconcile.Result{RequeueAfter: 5 * time.Second}, nil
}
if err != nil {
log.Errorw("ReconcilingError", zap.Error(err))
}
Expand Down
Expand Up @@ -19,13 +19,11 @@ package masterconstraintsynchronizer
import (
"context"
"fmt"
"time"

"go.uber.org/zap"

kubermaticapiv1 "k8c.io/kubermatic/v2/pkg/api/v1"
kubermaticv1 "k8c.io/kubermatic/v2/pkg/apis/kubermatic/v1"
controllerutil "k8c.io/kubermatic/v2/pkg/controller/util"
"k8c.io/kubermatic/v2/pkg/controller/util/predicate"
kuberneteshelper "k8c.io/kubermatic/v2/pkg/kubernetes"
"k8c.io/kubermatic/v2/pkg/resources/reconciling"
Expand Down Expand Up @@ -104,9 +102,6 @@ func (r *reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
log.Debug("Processing")

err := r.reconcile(ctx, log, request)
if controllerutil.IsCacheNotStarted(err) {
return reconcile.Result{RequeueAfter: 5 * time.Second}, nil
}
if err != nil {
log.Errorw("ReconcilingError", zap.Error(err))
}
Expand All @@ -132,10 +127,6 @@ func (r *reconciler) syncAllSeeds(ctx context.Context, log *zap.SugaredLogger, c
func (r *reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, request reconcile.Request) error {
constraint := &kubermaticv1.Constraint{}
if err := r.masterClient.Get(ctx, request.NamespacedName, constraint); err != nil {
if controllerutil.IsCacheNotStarted(err) {
return err
}

return ctrlruntimeclient.IgnoreNotFound(err)
}

Expand Down
Expand Up @@ -19,13 +19,11 @@ package masterconstrainttemplatecontroller
import (
"context"
"fmt"
"time"

"go.uber.org/zap"

kubermaticapiv1 "k8c.io/kubermatic/v2/pkg/api/v1"
kubermaticv1 "k8c.io/kubermatic/v2/pkg/apis/kubermatic/v1"
controllerutil "k8c.io/kubermatic/v2/pkg/controller/util"
"k8c.io/kubermatic/v2/pkg/controller/util/predicate"
kuberneteshelper "k8c.io/kubermatic/v2/pkg/kubernetes"
"k8c.io/kubermatic/v2/pkg/provider"
Expand Down Expand Up @@ -107,10 +105,6 @@ func (r *reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
log.Debug("constraint template not found, returning")
return reconcile.Result{}, nil
}
if controllerutil.IsCacheNotStarted(err) {
return reconcile.Result{RequeueAfter: 5 * time.Second}, nil
}

return reconcile.Result{}, fmt.Errorf("failed to get constraint template %s: %w", constraintTemplate.Name, err)
}

Expand Down
Expand Up @@ -19,13 +19,11 @@ package projectlabelsynchronizer
import (
"context"
"fmt"
"time"

"go.uber.org/zap"

kubermaticv1 "k8c.io/kubermatic/v2/pkg/apis/kubermatic/v1"
helper "k8c.io/kubermatic/v2/pkg/apis/kubermatic/v1/helper"
controllerutil "k8c.io/kubermatic/v2/pkg/controller/util"
"k8c.io/kubermatic/v2/pkg/util/workerlabel"

kerrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -128,9 +126,6 @@ func (r *reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
log.Debug("Processing")

err := r.reconcile(ctx, log, request)
if controllerutil.IsCacheNotStarted(err) {
return reconcile.Result{RequeueAfter: 5 * time.Second}, nil
}
if err != nil {
log.Errorw("ReconcilingError", zap.Error(err))
}
Expand All @@ -140,10 +135,6 @@ func (r *reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
func (r *reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, request reconcile.Request) error {
project := &kubermaticv1.Project{}
if err := r.masterClient.Get(ctx, request.NamespacedName, project); err != nil {
if controllerutil.IsCacheNotStarted(err) {
return err
}

if kerrors.IsNotFound(err) {
log.Debug("Didn't find project, returning")
return nil
Expand Down Expand Up @@ -180,12 +171,7 @@ func (r *reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, requ

unfilteredClusters := &kubermaticv1.ClusterList{}
if err := seedClient.List(ctx, unfilteredClusters, listOpts); err != nil {
if controllerutil.IsCacheNotStarted(err) {
log.Debug("cache for seed client was not yet started, cannot list Clusters")
} else {
errs = append(errs, fmt.Errorf("failed to list clusters in seed %q: %w", seedName, err))
}

errs = append(errs, fmt.Errorf("failed to list clusters in seed %q: %w", seedName, err))
continue
}

Expand Down
Expand Up @@ -19,7 +19,6 @@ package usersshkeyssynchronizer
import (
"context"
"fmt"
"time"

"go.uber.org/zap"

Expand Down Expand Up @@ -129,9 +128,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
log.Debug("Processing")

err := r.reconcile(ctx, log, request)
if controllerutil.IsCacheNotStarted(err) {
return reconcile.Result{RequeueAfter: 5 * time.Second}, nil
}
if err != nil {
log.Errorw("Reconciliation failed", zap.Error(err))
}
Expand All @@ -149,10 +145,6 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, requ
// find all clusters in this seed
cluster := &kubermaticv1.Cluster{}
if err := seedClient.Get(ctx, types.NamespacedName{Name: request.Name}, cluster); err != nil {
if controllerutil.IsCacheNotStarted(err) {
return err
}

if kubeapierrors.IsNotFound(err) {
log.Debug("Could not find cluster")
return nil
Expand Down
8 changes: 0 additions & 8 deletions pkg/controller/util/util.go
Expand Up @@ -18,7 +18,6 @@ package util

import (
"context"
"errors"
"fmt"

kubermaticv1 "k8c.io/kubermatic/v2/pkg/apis/kubermatic/v1"
Expand All @@ -28,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/cache"
ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down Expand Up @@ -186,9 +184,3 @@ func ConcurrencyLimitReached(ctx context.Context, client ctrlruntimeclient.Clien

return clustersUpdatingInProgressCount >= limit, nil
}

// IsCacheNotStarted returns true if the given error is not nil and an instance of
// cache.ErrCacheNotStarted.
func IsCacheNotStarted(err error) bool {
return errors.Is(err, &cache.ErrCacheNotStarted{})
}

0 comments on commit 4eb2eb7

Please sign in to comment.