Update kube-openapi to fix race

This commit is contained in:
Jefftree
2023-05-01 17:19:03 +00:00
parent d33853edcf
commit de34540248
44 changed files with 71 additions and 75 deletions

View File

@@ -22,6 +22,7 @@ import (
"fmt"
"net/http"
"strconv"
"sync"
"time"
"github.com/NYTimes/gziphandler"
@@ -98,16 +99,6 @@ func NewOpenAPIServiceLazy(swagger cached.Data[*spec.Swagger]) *OpenAPIService {
return o
}
func (o *OpenAPIService) getSwaggerBytes() (timedSpec, string, error) {
result := o.jsonCache.Get()
return result.Data, result.Etag, result.Err
}
func (o *OpenAPIService) getSwaggerPbBytes() (timedSpec, string, error) {
result := o.protoCache.Get()
return result.Data, result.Etag, result.Err
}
func (o *OpenAPIService) UpdateSpec(swagger *spec.Swagger) error {
o.UpdateSpecLazy(cached.NewResultOK(swagger, uuid.New().String()))
return nil
@@ -135,6 +126,9 @@ func RegisterOpenAPIVersionedService(spec *spec.Swagger, servePath string, handl
// RegisterOpenAPIVersionedService registers a handler to provide access to provided swagger spec.
func (o *OpenAPIService) RegisterOpenAPIVersionedService(servePath string, handler common.PathHandler) error {
// Mutex protects the cache chain
var mutex sync.Mutex
accepted := []struct {
Type string
SubType string
@@ -163,7 +157,9 @@ func (o *OpenAPIService) RegisterOpenAPIVersionedService(servePath string, handl
continue
}
// serve the first matching media type in the sorted clause list
mutex.Lock()
result := accepts.GetDataAndEtag.Get()
mutex.Unlock()
if result.Err != nil {
klog.Errorf("Error in OpenAPI handler: %s", result.Err)
// only return a 503 if we have no older cache data to serve