Skip to content

Commit

Permalink
Fix read cache by delegating to uncached client
Browse files Browse the repository at this point in the history
Signed-off-by: Hongxin Liang <[email protected]>
  • Loading branch information
honnix committed Jan 19, 2024
1 parent 2866d5a commit 77a16fb
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions flytepropeller/pkg/controller/executors/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Check warning on line 43 in flytepropeller/pkg/controller/executors/kube.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/executors/kube.go#L38-L43

Added lines #L38 - L43 were not covered by tests
// 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},

Check warning on line 47 in flytepropeller/pkg/controller/executors/kube.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/executors/kube.go#L46-L47

Added lines #L46 - L47 were not covered by tests
}

options.Cache.Reader = reader
}

// create the k8s client
Expand All @@ -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
}
Expand Down

0 comments on commit 77a16fb

Please sign in to comment.