Skip to content

Commit

Permalink
Remove warnings from different reconcilers
Browse files Browse the repository at this point in the history
Various spurious warnings were spamming the logs due to
conflicts where one reconciler had already performed the work.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Oct 25, 2023
1 parent 3b93fb6 commit 38c5edf
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 569 deletions.
11 changes: 7 additions & 4 deletions controllers/namespace_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"

"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -49,10 +50,12 @@ func (r *NamespaceWatcher) Reconcile(ctx context.Context, req ctrl.Request) (ctr
for _, pullSecret := range pullSecretList.Items {
err := r.SecretReconciler.Reconcile(pullSecret, namespace.Name)
if err != nil {
r.Log.Info(fmt.Sprintf("error reconciling namespace: %s with cluster pull secret: %s, error: %s",
namespace.Name,
pullSecret.Name,
err.Error()))
if !errors.IsConflict(err) {
r.Log.Info(fmt.Sprintf("error reconciling namespace: %s with cluster pull secret: %s, error: %s",
namespace.Name,
pullSecret.Name,
err.Error()))
}
}
}

Expand Down
21 changes: 14 additions & 7 deletions controllers/secret_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,13 @@ func (r *SecretReconciler) appendSecretToSA(clusterPullSecret v1.ClusterPullSecr
sa := &corev1.ServiceAccount{}
err := r.Client.Get(ctx, client.ObjectKey{Name: serviceAccountName, Namespace: ns}, sa)
if err != nil {
r.Log.Info(fmt.Sprintf("error getting SA in namespace: %s, %s", ns, err.Error()))
wrappedErr := fmt.Errorf("unable to append pull secret to service account: %s", err)
r.Log.Info(wrappedErr.Error())
return wrappedErr
if !apierrors.IsConflict(err) {
r.Log.Info(fmt.Sprintf("error getting SA in namespace: %s, %s", ns, err.Error()))
wrappedErr := fmt.Errorf("unable to append pull secret to service account: %s", err)
r.Log.Info(wrappedErr.Error())
return wrappedErr
}
return err
}

r.Log.V(10).Info(fmt.Sprintf("Pull secrets: %v", sa.ImagePullSecrets))
Expand All @@ -170,9 +173,13 @@ func (r *SecretReconciler) appendSecretToSA(clusterPullSecret v1.ClusterPullSecr

err = r.Update(ctx, sa.DeepCopy())
if err != nil {
wrappedErr := fmt.Errorf("unable to append pull secret to service account: %s", err)
r.Log.Info(wrappedErr.Error())
return err
if !apierrors.IsConflict(err) {

wrappedErr := fmt.Errorf("unable to append pull secret to service account: %s", err)
r.Log.Info(wrappedErr.Error())
return err
}
return nil
}
}

Expand Down
29 changes: 19 additions & 10 deletions controllers/serviceaccount_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"

"github.com/pkg/errors"
kerrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -75,12 +76,16 @@ func (r *ServiceAccountWatcher) appendSecretToSA(clusterPullSecret v1.ClusterPul
secretKey := clusterPullSecret.Name + secretSuffix

sa := &corev1.ServiceAccount{}
err := r.Client.Get(ctx, client.ObjectKey{Name: serviceAccountName, Namespace: ns}, sa)
if err != nil {
r.Log.Info(fmt.Sprintf("error getting SA in namespace: %s, %s", ns, err.Error()))
wrappedErr := fmt.Errorf("unable to append pull secret to service account: %s", err)
r.Log.Info(wrappedErr.Error())
return wrappedErr
if err := r.Client.Get(ctx, client.ObjectKey{Name: serviceAccountName, Namespace: ns}, sa); err != nil {
if !kerrors.IsConflict(err) {

r.Log.Info(fmt.Sprintf("error getting SA in namespace: %s, %s", ns, err.Error()))
wrappedErr := fmt.Errorf("unable to append pull secret to service account: %s", err)
r.Log.Info(wrappedErr.Error())
return wrappedErr
}
return nil

}

r.Log.V(10).Info(fmt.Sprintf("Pull secrets: %v", sa.ImagePullSecrets))
Expand All @@ -92,10 +97,14 @@ func (r *ServiceAccountWatcher) appendSecretToSA(clusterPullSecret v1.ClusterPul
Name: secretKey,
})

if err = r.Update(ctx, sa.DeepCopy()); err != nil {
wrappedErr := fmt.Errorf("unable to append pull secret to service account: %s", err)
r.Log.Info(wrappedErr.Error())
return err
if err := r.Update(ctx, sa.DeepCopy()); err != nil {
if !kerrors.IsConflict(err) {

wrappedErr := fmt.Errorf("unable to append pull secret to service account: %s", err)
r.Log.Info(wrappedErr.Error())
return err
}
return nil
}
}

Expand Down
74 changes: 36 additions & 38 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,64 @@ go 1.20
require (
github.com/go-logr/logr v1.2.4
github.com/pkg/errors v0.9.1
k8s.io/api v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
sigs.k8s.io/controller-runtime v0.14.1
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
sigs.k8s.io/controller-runtime v0.16.3
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/ginkgo/v2 v2.7.0 // indirect
github.com/onsi/gomega v1.26.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/term v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.26.0 // indirect
k8s.io/component-base v0.26.0 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/apiextensions-apiserver v0.28.3 // indirect
k8s.io/component-base v0.28.3 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

0 comments on commit 38c5edf

Please sign in to comment.