From 8e7dc16fc8bda3bcd6fc963128292e54cb67df72 Mon Sep 17 00:00:00 2001 From: mogliang Date: Tue, 19 Aug 2025 06:00:09 +0000 Subject: [PATCH 1/3] make 2nd probe call to test new connection --- controllers/clustercache/cluster_accessor.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/controllers/clustercache/cluster_accessor.go b/controllers/clustercache/cluster_accessor.go index 0bbc92f2380d..6e2713674651 100644 --- a/controllers/clustercache/cluster_accessor.go +++ b/controllers/clustercache/cluster_accessor.go @@ -344,12 +344,20 @@ func (ca *clusterAccessor) HealthCheck(ctx context.Context) (bool, bool) { ca.rLock(ctx) restClient := ca.lockedState.connection.restClient + restConfig := ca.lockedState.connection.restConfig ca.rUnlock(ctx) log.V(6).Info("Run health probe") // Executing the health probe is intentionally done without a lock to avoid blocking other reconcilers. _, err := restClient.Get().AbsPath("/").Timeout(ca.config.HealthProbe.Timeout).DoRaw(ctx) + if err == nil { + // Execute health probe with a new restClient (this verifies that a new connection works). + restClient, err = rest.UnversionedRESTClientFor(restConfig) + if err == nil { + _, err = restClient.Get().AbsPath("/").Timeout(ca.config.HealthProbe.Timeout).DoRaw(ctx) + } + } ca.lock(ctx) defer ca.unlock(ctx) From 8ce65c7d9ccadac8d10e66d4245f6c904a08b34f Mon Sep 17 00:00:00 2001 From: mogliang Date: Tue, 19 Aug 2025 09:09:57 +0000 Subject: [PATCH 2/3] fix clustercache break --- controllers/clustercache/cluster_accessor_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/clustercache/cluster_accessor_test.go b/controllers/clustercache/cluster_accessor_test.go index bfe5acdf1d88..d793e4fe7cb6 100644 --- a/controllers/clustercache/cluster_accessor_test.go +++ b/controllers/clustercache/cluster_accessor_test.go @@ -305,6 +305,7 @@ func TestHealthCheck(t *testing.T) { }, }) accessor.lockedState.connection = &clusterAccessorLockedConnectionState{ + restConfig: env.Config, restClient: &fake.RESTClient{ NegotiatedSerializer: scheme.Codecs, Resp: tt.restClientHTTPResponse, From 754d34afb6052a79b8a6b62e5ee3106c37efae75 Mon Sep 17 00:00:00 2001 From: mogliang Date: Wed, 20 Aug 2025 02:31:11 +0000 Subject: [PATCH 3/3] fix restclient creation issue --- controllers/clustercache/cluster_accessor.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/controllers/clustercache/cluster_accessor.go b/controllers/clustercache/cluster_accessor.go index 6e2713674651..b9c59cf05478 100644 --- a/controllers/clustercache/cluster_accessor.go +++ b/controllers/clustercache/cluster_accessor.go @@ -27,7 +27,9 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/cache" @@ -353,7 +355,10 @@ func (ca *clusterAccessor) HealthCheck(ctx context.Context) (bool, bool) { _, err := restClient.Get().AbsPath("/").Timeout(ca.config.HealthProbe.Timeout).DoRaw(ctx) if err == nil { // Execute health probe with a new restClient (this verifies that a new connection works). - restClient, err = rest.UnversionedRESTClientFor(restConfig) + codec := runtime.NoopEncoder{Decoder: scheme.Codecs.UniversalDecoder()} + restClientConfig := rest.CopyConfig(restConfig) + restClientConfig.NegotiatedSerializer = serializer.NegotiatedSerializerWrapper(runtime.SerializerInfo{Serializer: codec}) + restClient, err = rest.UnversionedRESTClientFor(restClientConfig) if err == nil { _, err = restClient.Get().AbsPath("/").Timeout(ca.config.HealthProbe.Timeout).DoRaw(ctx) }