go.*: Update k8s packages
- update k8s client_go - update k8s apiextensions-apiserver - update k8s controller-tools Signed-off-by: leonnicolas <leonloechner@gmx.de>
This commit is contained in:
51
vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go
generated
vendored
51
vendor/sigs.k8s.io/controller-tools/pkg/crd/schema.go
generated
vendored
@@ -17,8 +17,10 @@ limitations under the License.
|
||||
package crd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"strings"
|
||||
|
||||
@@ -37,12 +39,10 @@ const (
|
||||
defPrefix = "#/definitions/"
|
||||
)
|
||||
|
||||
var (
|
||||
// byteType is the types.Type for byte (see the types documention
|
||||
// for why we need to look this up in the Universe), saved
|
||||
// for quick comparison.
|
||||
byteType = types.Universe.Lookup("byte").Type()
|
||||
)
|
||||
// byteType is the types.Type for byte (see the types documention
|
||||
// for why we need to look this up in the Universe), saved
|
||||
// for quick comparison.
|
||||
var byteType = types.Universe.Lookup("byte").Type()
|
||||
|
||||
// SchemaMarker is any marker that needs to modify the schema of the underlying type or field.
|
||||
type SchemaMarker interface {
|
||||
@@ -109,6 +109,15 @@ func (c *schemaContext) requestSchema(pkgPath, typeName string) {
|
||||
|
||||
// infoToSchema creates a schema for the type in the given set of type information.
|
||||
func infoToSchema(ctx *schemaContext) *apiext.JSONSchemaProps {
|
||||
// If the obj implements a JSON marshaler and has a marker, use the markers value and do not traverse as
|
||||
// the marshaler could be doing anything. If there is no marker, fall back to traversing.
|
||||
if obj := ctx.pkg.Types.Scope().Lookup(ctx.info.Name); obj != nil && implementsJSONMarshaler(obj.Type()) {
|
||||
schema := &apiext.JSONSchemaProps{}
|
||||
applyMarkers(ctx, ctx.info.Markers, schema, ctx.info.RawSpec.Type)
|
||||
if schema.Type != "" {
|
||||
return schema
|
||||
}
|
||||
}
|
||||
return typeToSchema(ctx, ctx.info.RawSpec.Type)
|
||||
}
|
||||
|
||||
@@ -298,14 +307,12 @@ func mapToSchema(ctx *schemaContext, mapType *ast.MapType) *apiext.JSONSchemaPro
|
||||
valSchema = namedToSchema(ctx.ForInfo(&markers.TypeInfo{}), val)
|
||||
case *ast.ArrayType:
|
||||
valSchema = arrayToSchema(ctx.ForInfo(&markers.TypeInfo{}), val)
|
||||
if valSchema.Type == "array" && valSchema.Items.Schema.Type != "string" {
|
||||
ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("map values must be a named type, not %T", mapType.Value), mapType.Value))
|
||||
return &apiext.JSONSchemaProps{}
|
||||
}
|
||||
case *ast.StarExpr:
|
||||
valSchema = typeToSchema(ctx.ForInfo(&markers.TypeInfo{}), val)
|
||||
case *ast.MapType:
|
||||
valSchema = typeToSchema(ctx.ForInfo(&markers.TypeInfo{}), val)
|
||||
default:
|
||||
ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("map values must be a named type, not %T", mapType.Value), mapType.Value))
|
||||
ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("not a supported map value type: %T", mapType.Value), mapType.Value))
|
||||
return &apiext.JSONSchemaProps{}
|
||||
}
|
||||
|
||||
@@ -415,10 +422,13 @@ func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, fo
|
||||
typ = "string"
|
||||
case basicInfo&types.IsInteger != 0:
|
||||
typ = "integer"
|
||||
case basicInfo&types.IsFloat != 0 && allowDangerousTypes:
|
||||
typ = "number"
|
||||
case basicInfo&types.IsFloat != 0:
|
||||
if allowDangerousTypes {
|
||||
typ = "number"
|
||||
} else {
|
||||
return "", "", errors.New("found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true")
|
||||
}
|
||||
default:
|
||||
// NB(directxman12): floats are *NOT* allowed in kubernetes APIs
|
||||
return "", "", fmt.Errorf("unsupported type %q", basic.String())
|
||||
}
|
||||
|
||||
@@ -431,3 +441,16 @@ func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, fo
|
||||
|
||||
return typ, format, nil
|
||||
}
|
||||
|
||||
// Open coded go/types representation of encoding/json.Marshaller
|
||||
var jsonMarshaler = types.NewInterfaceType([]*types.Func{
|
||||
types.NewFunc(token.NoPos, nil, "MarshalJSON",
|
||||
types.NewSignature(nil, nil,
|
||||
types.NewTuple(
|
||||
types.NewVar(token.NoPos, nil, "", types.NewSlice(types.Universe.Lookup("byte").Type())),
|
||||
types.NewVar(token.NoPos, nil, "", types.Universe.Lookup("error").Type())), false)),
|
||||
}, nil).Complete()
|
||||
|
||||
func implementsJSONMarshaler(typ types.Type) bool {
|
||||
return types.Implements(typ, jsonMarshaler) || types.Implements(types.NewPointer(typ), jsonMarshaler)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user