From be5779679410ee6aeb3eca079447b5cc1c64219c Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Thu, 29 Aug 2024 07:52:58 -0700 Subject: [PATCH] Properly check for discovery errors in graph reconciler Signed-off-by: Tamal Saha --- cmd/objectfinder-tester/main.go | 25 ++++++++++++++----- go.mod | 6 ++--- go.sum | 12 ++++----- pkg/graph/reconciler.go | 14 ++++++++++- .../v1alpha1/proxysql_mapping.go | 2 +- vendor/modules.txt | 6 ++--- 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/cmd/objectfinder-tester/main.go b/cmd/objectfinder-tester/main.go index 565d48691..e92b08c7b 100644 --- a/cmd/objectfinder-tester/main.go +++ b/cmd/objectfinder-tester/main.go @@ -19,6 +19,7 @@ package main import ( "context" + "errors" "fmt" "kubeops.dev/ui-server/pkg/apiserver" @@ -35,6 +36,7 @@ import ( "k8s.io/apiserver/pkg/authentication/user" "k8s.io/apiserver/pkg/endpoints/request" apirequest "k8s.io/apiserver/pkg/endpoints/request" + "k8s.io/client-go/discovery" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/klog/v2" @@ -78,7 +80,7 @@ func NewClient() (kubernetes.Interface, client.Client, error) { return kc, rtc, err } -func main_5() { +func main_1() { baseURL := "https://172.104.39.12/" token := "5311e401d" caCert := []byte(`-----BEGIN CERTIFICATE----- @@ -115,7 +117,7 @@ z/a8um5nj/IwBclvfKVnJxacjA+988adIevA2lnhSI3d++GxIbzAdLtpVuF6Ka5N fmt.Printf("%+v\n", *md) } -func main_old() { +func main_2() { kc, rtc, err := NewClient() if err != nil { panic(err) @@ -161,7 +163,7 @@ func main_old() { fmt.Printf("%+v\n", out) } -func main_() { +func main_3() { if err := ListResourceLayouts(); err != nil { panic(err) } @@ -321,7 +323,7 @@ func findServiceMonitorForPrometheus() error { return nil } -func main_34() { +func main() { //_, kc, err := NewClient() //if err != nil { // panic(err) @@ -380,14 +382,25 @@ func findForPostgres() error { finder := graph.ObjectFinder{Client: kc} result, err := finder.ListConnectedObjectIDs(&src, rd.Spec.Connections) + if errors.Is(err, &discovery.ErrGroupDiscoveryFailed{}) { + fmt.Println(err) + } + + var errRDF *apiutil.ErrResourceDiscoveryFailed + if errors.As(err, &errRDF) { + fmt.Println(err) + } if err != nil { return err } + // kerr.IsServiceUnavailable() + // kerr.IsNotFound() + fmt.Printf("%+v\n", result) return nil } -func main() { +func main_5() { kc, rtc, err := NewClient() if err != nil { panic(err) @@ -416,7 +429,7 @@ func main() { fmt.Printf("%+v\n", result) } -func main_List_ResourceService() { +func main_6() { kc, rtc, err := NewClient() if err != nil { panic(err) diff --git a/go.mod b/go.mod index 323db34ca..41f241e7e 100644 --- a/go.mod +++ b/go.mod @@ -49,9 +49,9 @@ require ( kmodules.xyz/custom-resources v0.30.0 kmodules.xyz/go-containerregistry v0.0.12 kmodules.xyz/monitoring-agent-api v0.29.0 - kmodules.xyz/resource-metadata v0.18.13-0.20240829103836-604e102fc093 - kmodules.xyz/resource-metrics v0.30.3 - kmodules.xyz/resource-metrics/utils v0.30.3 + kmodules.xyz/resource-metadata v0.18.13-0.20240829141024-4c20f42d62b7 + kmodules.xyz/resource-metrics v0.30.4 + kmodules.xyz/resource-metrics/utils v0.30.4 kmodules.xyz/sets v0.29.0 kubeops.dev/falco-ui-server v0.0.4 kubeops.dev/scanner v0.0.18 diff --git a/go.sum b/go.sum index 361d30091..d38cddc25 100644 --- a/go.sum +++ b/go.sum @@ -922,12 +922,12 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9 kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI= kmodules.xyz/offshoot-api v0.30.0 h1:dq9F93pu4Q8rL9oTcCk+vGGy8vpS7RNt0GSwx7Bvhec= kmodules.xyz/offshoot-api v0.30.0/go.mod h1:o9VoA3ImZMDBp3lpLb8+kc2d/KBxioRwCpaKDfLIyDw= -kmodules.xyz/resource-metadata v0.18.13-0.20240829103836-604e102fc093 h1:OJiR1UbizOYQruXOIjrsRt+TEhLji/ynT8Pon94QZK4= -kmodules.xyz/resource-metadata v0.18.13-0.20240829103836-604e102fc093/go.mod h1:VvUjfIzmM08SZ9ssZKhduzSrggKjY93ES2Bk+/m04hs= -kmodules.xyz/resource-metrics v0.30.3 h1:x5sdhDL2lTCor82nn/hZjIlY3RzkD4JzITfk+1zAJko= -kmodules.xyz/resource-metrics v0.30.3/go.mod h1:UYcQQLN+3o8rNPQJwJa2D9bt5ihJCeo5bCDuQ4O3MPY= -kmodules.xyz/resource-metrics/utils v0.30.3 h1:M997admKMRAeT76RroOJmfi9deHfFpXieMt0yjrIiRY= -kmodules.xyz/resource-metrics/utils v0.30.3/go.mod h1:9Zl9Ih7pvhmRjHtkjJYh1BSZKysIaDY+aewMM1qZCpw= +kmodules.xyz/resource-metadata v0.18.13-0.20240829141024-4c20f42d62b7 h1:OXs4sBzu0EujJ7y2DplGtcFbNq5Sm6SDtO+XbfJgYws= +kmodules.xyz/resource-metadata v0.18.13-0.20240829141024-4c20f42d62b7/go.mod h1:cP78KvHOSrtPRPeQAyzmrkZQSXPYO5gQdd5DrUDAk1Y= +kmodules.xyz/resource-metrics v0.30.4 h1:8HBPtYmo9ETY91gsc55JE8Z986+3ZuRq57M0wZ9npqI= +kmodules.xyz/resource-metrics v0.30.4/go.mod h1:w9+rz7/s/kGP1GWzYSuRdCn+l7EwpesmESSEHkLBnIQ= +kmodules.xyz/resource-metrics/utils v0.30.4 h1:bJS/x0Qr7N1FFdxugFbzZ/Es6HVs4ptsFlhkmgj3jac= +kmodules.xyz/resource-metrics/utils v0.30.4/go.mod h1:EedHEDZu1iVfkpKsTsSTfHkG5MUf77TdjDmCYRY4UR0= kmodules.xyz/sets v0.29.0 h1:ZX/qOECzUob95JhhRtngJElHSlJ1UNNdwK4hTEy+nl0= kmodules.xyz/sets v0.29.0/go.mod h1:1oi3fR9c3SWywEjBLlHC8BBMCSz0b1/W+EofKmBoj3g= kubeops.dev/falco-ui-server v0.0.4 h1:47kA+B4pJTgru3P60ng9eC+c3TP8Gcq61c91FB3ZoBQ= diff --git a/pkg/graph/reconciler.go b/pkg/graph/reconciler.go index cda627448..4f490ca05 100644 --- a/pkg/graph/reconciler.go +++ b/pkg/graph/reconciler.go @@ -29,6 +29,7 @@ import ( kmapi "kmodules.xyz/client-go/api/v1" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/apiutil" logger "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -73,7 +74,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco if result, err := finder.ListConnectedObjectIDs(&obj, rd.Spec.Connections); err != nil { // In case of discovery error, we don't return error because errors are rate limited. // We need to keep trying until the reconciliation is successful. - if errors.Is(err, &discovery.ErrGroupDiscoveryFailed{}) { + if IsDiscoveryError(err) { log.Error(err, "unable to list connections", "group", r.R.Group, "kind", r.R.Kind) return reconcile.Result{RequeueAfter: 500 * time.Millisecond}, nil } @@ -91,6 +92,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco return reconcile.Result{}, nil } +func IsDiscoveryError(err error) bool { + if errors.Is(err, &discovery.ErrGroupDiscoveryFailed{}) { + return true + } + var errRDF *apiutil.ErrResourceDiscoveryFailed + if errors.As(err, &errRDF) { + return true + } + return false +} + // SetupWithManager sets up the controller with the Manager. func (r *Reconciler) SetupWithManager(mgr manager.Manager) error { var obj unstructured.Unstructured diff --git a/vendor/kmodules.xyz/resource-metrics/ops.kubedb.com/v1alpha1/proxysql_mapping.go b/vendor/kmodules.xyz/resource-metrics/ops.kubedb.com/v1alpha1/proxysql_mapping.go index 3f2e17223..cbd2426f9 100644 --- a/vendor/kmodules.xyz/resource-metrics/ops.kubedb.com/v1alpha1/proxysql_mapping.go +++ b/vendor/kmodules.xyz/resource-metrics/ops.kubedb.com/v1alpha1/proxysql_mapping.go @@ -43,7 +43,7 @@ func (m *ProxySQLOpsRequest) VolumeExpansionPathMapping() map[OpsReqPath]Referen } func (m *ProxySQLOpsRequest) GetAppRefPath() []string { - return []string{"spec", "proxyRef", "referencedDB"} + return []string{"spec", "proxyRef"} } func (m *ProxySQLOpsRequest) GroupVersionKind() schema.GroupVersionKind { diff --git a/vendor/modules.txt b/vendor/modules.txt index 6c4c3a4f1..ae2da7fa9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2011,7 +2011,7 @@ kmodules.xyz/monitoring-agent-api/client ## explicit; go 1.22.0 kmodules.xyz/offshoot-api/api/v1 kmodules.xyz/offshoot-api/api/v2 -# kmodules.xyz/resource-metadata v0.18.13-0.20240829103836-604e102fc093 +# kmodules.xyz/resource-metadata v0.18.13-0.20240829141024-4c20f42d62b7 ## explicit; go 1.22.1 kmodules.xyz/resource-metadata/apis/core/install kmodules.xyz/resource-metadata/apis/core/v1alpha1 @@ -2042,7 +2042,7 @@ kmodules.xyz/resource-metadata/pkg/layouts kmodules.xyz/resource-metadata/pkg/tableconvertor kmodules.xyz/resource-metadata/pkg/tableconvertor/lib kmodules.xyz/resource-metadata/pkg/tableconvertor/printers -# kmodules.xyz/resource-metrics v0.30.3 +# kmodules.xyz/resource-metrics v0.30.4 ## explicit; go 1.22.1 kmodules.xyz/resource-metrics kmodules.xyz/resource-metrics/api @@ -2055,7 +2055,7 @@ kmodules.xyz/resource-metrics/kubedb.com/v1 kmodules.xyz/resource-metrics/kubedb.com/v1alpha2 kmodules.xyz/resource-metrics/kubevault.com/v1alpha2 kmodules.xyz/resource-metrics/ops.kubedb.com/v1alpha1 -# kmodules.xyz/resource-metrics/utils v0.30.3 +# kmodules.xyz/resource-metrics/utils v0.30.4 ## explicit; go 1.22.1 kmodules.xyz/resource-metrics/utils # kmodules.xyz/sets v0.29.0