Browse Source

Improve error reporting

Alfonso Acosta 4 months ago
parent
commit
ac4ba0f078
3 changed files with 14 additions and 6 deletions
  1. 9
    3
      cluster/kubernetes/cached_disco.go
  2. 4
    2
      cmd/fluxd/main.go
  3. 1
    1
      daemon/loop.go

+ 9
- 3
cluster/kubernetes/cached_disco.go View File

@@ -1,6 +1,7 @@
1 1
 package kubernetes
2 2
 
3 3
 import (
4
+	"fmt"
4 5
 	"sync"
5 6
 	"time"
6 7
 
@@ -10,7 +11,7 @@ import (
10 11
 	"k8s.io/apimachinery/pkg/runtime"
11 12
 	"k8s.io/apimachinery/pkg/watch"
12 13
 	"k8s.io/client-go/discovery"
13
-	discocache "k8s.io/client-go/discovery/cached"
14
+	"k8s.io/client-go/discovery/cached/memory"
14 15
 	toolscache "k8s.io/client-go/tools/cache"
15 16
 )
16 17
 
@@ -46,7 +47,12 @@ func (d *cachedDiscovery) ServerResourcesForGroupVersion(groupVersion string) (*
46 47
 	if invalid {
47 48
 		d.CachedDiscoveryInterface.Invalidate()
48 49
 	}
49
-	return d.CachedDiscoveryInterface.ServerResourcesForGroupVersion(groupVersion)
50
+	result, err := d.CachedDiscoveryInterface.ServerResourcesForGroupVersion(groupVersion)
51
+	if err == memory.ErrCacheNotFound {
52
+		// improve the error returned from memcacheclient
53
+		err = fmt.Errorf("server resources for %s not found in cache; cache refreshes every 5 minutes", groupVersion)
54
+	}
55
+	return result, err
50 56
 }
51 57
 
52 58
 // MakeCachedDiscovery constructs a CachedDicoveryInterface that will
@@ -81,7 +87,7 @@ type makeHandle func(discovery.CachedDiscoveryInterface) toolscache.ResourceEven
81 87
 // flexibility than MakeCachedDiscovery; e.g., with extra handlers for
82 88
 // testing.
83 89
 func makeCachedDiscovery(d discovery.DiscoveryInterface, c crd.Interface, shutdown <-chan struct{}, handlerFn makeHandle) (*cachedDiscovery, toolscache.Store, toolscache.Controller) {
84
-	cachedDisco := &cachedDiscovery{CachedDiscoveryInterface: discocache.NewMemCacheClient(d)}
90
+	cachedDisco := &cachedDiscovery{CachedDiscoveryInterface: memory.NewMemCacheClient(d)}
85 91
 	// We have an empty cache, so it's _a priori_ invalid. (Yes, that's the zero value, but better safe than sorry)
86 92
 	cachedDisco.Invalidate()
87 93
 

+ 4
- 2
cmd/fluxd/main.go View File

@@ -192,7 +192,10 @@ func main() {
192 192
 	logger.Log("version", version)
193 193
 
194 194
 	// Silence access errors logged internally by client-go
195
-	k8slog := log.With(logger, "type", "internal kubernetes error")
195
+	k8slog := log.With(logger,
196
+		"type", "internal kubernetes error",
197
+		"ts", log.DefaultTimestampUTC,
198
+		"caller", log.Caller(5)) // we want to log one level deeper than k8sruntime.HandleError
196 199
 	logErrorUnlessAccessRelated := func(err error) {
197 200
 		errLower := strings.ToLower(err.Error())
198 201
 		if k8serrors.IsForbidden(err) || k8serrors.IsNotFound(err) ||
@@ -203,7 +206,6 @@ func main() {
203 206
 		k8slog.Log("err", err)
204 207
 	}
205 208
 	k8sruntime.ErrorHandlers = []func(error){logErrorUnlessAccessRelated}
206
-
207 209
 	// Argument validation
208 210
 
209 211
 	// Sort out values for the git tag and notes ref. There are

+ 1
- 1
daemon/loop.go View File

@@ -207,9 +207,9 @@ func (d *Daemon) doSync(logger log.Logger, lastKnownSyncTagRev *string, warnedAb
207 207
 
208 208
 	var resourceErrors []event.ResourceError
209 209
 	if err := fluxsync.Sync(syncSetName, allResources, d.Cluster); err != nil {
210
-		logger.Log("err", err)
211 210
 		switch syncerr := err.(type) {
212 211
 		case cluster.SyncError:
212
+			logger.Log("err", err)
213 213
 			for _, e := range syncerr {
214 214
 				resourceErrors = append(resourceErrors, event.ResourceError{
215 215
 					ID:    e.ResourceID,

Loading…
Cancel
Save