Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly check for discovery errors in graph reconciler #330

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions cmd/objectfinder-tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main

import (
"context"
"errors"
"fmt"

"kubeops.dev/ui-server/pkg/apiserver"
Expand All @@ -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"
Expand Down Expand Up @@ -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-----
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -161,7 +163,7 @@ func main_old() {
fmt.Printf("%+v\n", out)
}

func main_() {
func main_3() {
if err := ListResourceLayouts(); err != nil {
panic(err)
}
Expand Down Expand Up @@ -321,7 +323,7 @@ func findServiceMonitorForPrometheus() error {
return nil
}

func main_34() {
func main() {
//_, kc, err := NewClient()
//if err != nil {
// panic(err)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 13 additions & 1 deletion pkg/graph/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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"
Expand Down Expand Up @@ -73,7 +74,7 @@
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
}
Expand All @@ -91,6 +92,17 @@
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) {

Check failure on line 100 in pkg/graph/reconciler.go

View workflow job for this annotation

GitHub Actions / Build

S1008: should use 'return errors.As(err, &errRDF)' instead of 'if errors.As(err, &errRDF) { return true }; return false' (gosimple)
return true
}
return false
}

// SetupWithManager sets up the controller with the Manager.
func (r *Reconciler) SetupWithManager(mgr manager.Manager) error {
var obj unstructured.Unstructured
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading