Update kube-openapi (#108895)

* upgrade k8s.io/kube-openapi

* fix open-api v3 blank aggregator output

* use keys as API group

in ./hack/update-openapi-spec.sh

* fix import grouping

* update openapiv3 integration tests
This commit is contained in:
Alex Zielenski
2022-03-24 14:01:01 -07:00
committed by GitHub
parent bd1e7dc3cb
commit 11b3a18cca
52 changed files with 688 additions and 158 deletions

View File

@@ -17,31 +17,22 @@ limitations under the License.
package handler
import (
"crypto/sha512"
"fmt"
"sync"
)
func computeETag(data []byte) string {
if data == nil {
return ""
}
return fmt.Sprintf("\"%X\"", sha512.Sum512(data))
}
// HandlerCache represents an OpenAPI v2/v3 marshaling cache.
// HandlerCache represents a lazy cache for generating a byte array
// It is used to lazily marshal OpenAPI v2/v3 and lazily generate the ETag
type HandlerCache struct {
BuildCache func() ([]byte, error)
once sync.Once
bytes []byte
etag string
err error
}
// Get either returns the cached value or calls BuildCache() once before caching and returning
// its results. If BuildCache returns an error, the last valid value for the cache (from prior
// calls to New()) is used instead if possible.
func (c *HandlerCache) Get() ([]byte, string, error) {
func (c *HandlerCache) Get() ([]byte, error) {
c.once.Do(func() {
bytes, err := c.BuildCache()
// if there is an error updating the cache, there can be situations where
@@ -51,10 +42,9 @@ func (c *HandlerCache) Get() ([]byte, string, error) {
if c.err == nil {
// don't override previous spec if we had an error
c.bytes = bytes
c.etag = computeETag(c.bytes)
}
})
return c.bytes, c.etag, c.err
return c.bytes, c.err
}
// New creates a new HandlerCache for situations where a cache refresh is needed.
@@ -62,7 +52,6 @@ func (c *HandlerCache) Get() ([]byte, string, error) {
func (c *HandlerCache) New(cacheBuilder func() ([]byte, error)) HandlerCache {
return HandlerCache{
bytes: c.bytes,
etag: c.etag,
BuildCache: cacheBuilder,
}
}