From ab70c1dbcef7b43bf678981d2cd6a5d2cd901900 Mon Sep 17 00:00:00 2001 From: Hongxin Liang Date: Fri, 19 Jan 2024 13:09:13 +0100 Subject: [PATCH] Fix read cache by delegating to uncached client --- flytepropeller/pkg/controller/executors/kube.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/flytepropeller/pkg/controller/executors/kube.go b/flytepropeller/pkg/controller/executors/kube.go index bdab0d91bea..a4966689b9d 100644 --- a/flytepropeller/pkg/controller/executors/kube.go +++ b/flytepropeller/pkg/controller/executors/kube.go @@ -34,15 +34,18 @@ var NewCache = func(config *rest.Config, options cache.Options) (cache.Cache, er } var NewClient = func(config *rest.Config, options client.Options) (client.Client, error) { - var reader *fallbackClientReader if options.Cache != nil && options.Cache.Reader != nil { + uncachedOptions := options + uncachedOptions.Cache = nil + uncachedK8sClient, err := client.New(config, uncachedOptions) + if err != nil { + return nil, err + } // if caching is enabled we create a fallback reader so we can attempt the client if the cache // reader does not have the object - reader = &fallbackClientReader{ - orderedClients: []client.Reader{options.Cache.Reader}, + options.Cache.Reader = fallbackClientReader{ + orderedClients: []client.Reader{options.Cache.Reader, uncachedK8sClient}, } - - options.Cache.Reader = reader } // create the k8s client @@ -52,10 +55,6 @@ var NewClient = func(config *rest.Config, options client.Options) (client.Client } k8sOtelClient := otelutils.WrapK8sClient(k8sClient) - if reader != nil { - // once the k8s client is created we set the fallback reader's client to the k8s client - reader.orderedClients = append(reader.orderedClients, k8sOtelClient) - } return k8sOtelClient, nil }