Skip to content

Commit

Permalink
Change reflect.Ptr to reflect.Pointer
Browse files Browse the repository at this point in the history
Kubernetes-commit: df168d5b5c2dab7414fc00ead1a51257ec326a98
  • Loading branch information
wqld authored and k8s-publishing-bot committed Jun 25, 2022
1 parent e74e8a9 commit 55378ba
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pkg/api/apitesting/fuzzer/valuefuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func valueFuzz(obj reflect.Value) {
valueFuzz(obj.Index(i))
}
}
case reflect.Interface, reflect.Ptr:
case reflect.Interface, reflect.Pointer:
if obj.IsNil() {
// TODO: set non-nil value
} else {
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/apitesting/naming/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func ensureNoTags(gvk schema.GroupVersionKind, tp reflect.Type, parents []reflec
parents = append(parents, tp)

switch tp.Kind() {
case reflect.Map, reflect.Slice, reflect.Ptr:
case reflect.Map, reflect.Slice, reflect.Pointer:
errs = append(errs, ensureNoTags(gvk, tp.Elem(), parents, typesAllowedTags)...)

case reflect.String, reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Interface:
Expand Down Expand Up @@ -106,7 +106,7 @@ func ensureNoTags(gvk schema.GroupVersionKind, tp reflect.Type, parents []reflec
func ensureTags(gvk schema.GroupVersionKind, tp reflect.Type, parents []reflect.Type, allowedNonstandardJSONNames map[reflect.Type]string) []error {
errs := []error{}
// This type handles its own encoding/decoding and doesn't need json tags
if tp.Implements(marshalerType) && (tp.Implements(unmarshalerType) || reflect.PtrTo(tp).Implements(unmarshalerType)) {
if tp.Implements(marshalerType) && (tp.Implements(unmarshalerType) || reflect.PointerTo(tp).Implements(unmarshalerType)) {
return errs
}

Expand All @@ -117,7 +117,7 @@ func ensureTags(gvk schema.GroupVersionKind, tp reflect.Type, parents []reflect.
parents = append(parents, tp)

switch tp.Kind() {
case reflect.Map, reflect.Slice, reflect.Ptr:
case reflect.Map, reflect.Slice, reflect.Pointer:
errs = append(errs, ensureTags(gvk, tp.Elem(), parents, allowedNonstandardJSONNames)...)

case reflect.String, reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Interface:
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/apitesting/roundtrip/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func fill(dataString string, dataInt int, t reflect.Type, v reflect.Value, fillF
defer delete(filledTypes, t)

// if nil, populate pointers with a zero-value instance of the underlying type
if t.Kind() == reflect.Ptr && v.IsNil() {
if t.Kind() == reflect.Pointer && v.IsNil() {
if v.CanSet() {
v.Set(reflect.New(t.Elem()))
} else if v.IsNil() {
Expand Down Expand Up @@ -155,10 +155,10 @@ func fill(dataString string, dataInt int, t reflect.Type, v reflect.Value, fillF
fieldType := field.Type
fieldValue := v.Field(i)

fill(dataString, dataInt, reflect.PtrTo(fieldType), fieldValue.Addr(), fillFuncs, filledTypes)
fill(dataString, dataInt, reflect.PointerTo(fieldType), fieldValue.Addr(), fillFuncs, filledTypes)
}

case reflect.Ptr:
case reflect.Pointer:
fill(dataString, dataInt, t.Elem(), v.Elem(), fillFuncs, filledTypes)

case reflect.String:
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/meta/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func getItemsPtr(list runtime.Object) (interface{}, error) {
return nil, errExpectFieldItems
}
switch items.Kind() {
case reflect.Interface, reflect.Ptr:
case reflect.Interface, reflect.Pointer:
target := reflect.TypeOf(items.Interface()).Elem()
if target.Kind() != reflect.Slice {
return nil, errExpectSliceItems
Expand Down Expand Up @@ -130,7 +130,7 @@ func EachListItem(obj runtime.Object, fn func(runtime.Object) error) error {
return nil
}
takeAddr := false
if elemType := items.Type().Elem(); elemType.Kind() != reflect.Ptr && elemType.Kind() != reflect.Interface {
if elemType := items.Type().Elem(); elemType.Kind() != reflect.Pointer && elemType.Kind() != reflect.Interface {
if !items.Index(0).CanAddr() {
return fmt.Errorf("unable to take address of items in %T for EachListItem", obj)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (a genericAccessor) SetFinalizers(finalizers []string) {
func (a genericAccessor) GetOwnerReferences() []metav1.OwnerReference {
var ret []metav1.OwnerReference
s := a.ownerReferences
if s.Kind() != reflect.Ptr || s.Elem().Kind() != reflect.Slice {
if s.Kind() != reflect.Pointer || s.Elem().Kind() != reflect.Slice {
klog.Errorf("expect %v to be a pointer to slice", s)
return ret
}
Expand All @@ -617,7 +617,7 @@ func (a genericAccessor) GetOwnerReferences() []metav1.OwnerReference {

func (a genericAccessor) SetOwnerReferences(references []metav1.OwnerReference) {
s := a.ownerReferences
if s.Kind() != reflect.Ptr || s.Elem().Kind() != reflect.Slice {
if s.Kind() != reflect.Pointer || s.Elem().Kind() != reflect.Slice {
klog.Errorf("expect %v to be a pointer to slice", s)
}
s = s.Elem()
Expand Down
8 changes: 4 additions & 4 deletions pkg/conversion/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ type ConversionFuncs struct {
// previously defined functions.
func (c ConversionFuncs) AddUntyped(a, b interface{}, fn ConversionFunc) error {
tA, tB := reflect.TypeOf(a), reflect.TypeOf(b)
if tA.Kind() != reflect.Ptr {
if tA.Kind() != reflect.Pointer {
return fmt.Errorf("the type %T must be a pointer to register as an untyped conversion", a)
}
if tB.Kind() != reflect.Ptr {
if tB.Kind() != reflect.Pointer {
return fmt.Errorf("the type %T must be a pointer to register as an untyped conversion", b)
}
c.untyped[typePair{tA, tB}] = fn
Expand Down Expand Up @@ -179,10 +179,10 @@ func (c *Converter) RegisterGeneratedUntypedConversionFunc(a, b interface{}, fn
func (c *Converter) RegisterIgnoredConversion(from, to interface{}) error {
typeFrom := reflect.TypeOf(from)
typeTo := reflect.TypeOf(to)
if typeFrom.Kind() != reflect.Ptr {
if typeFrom.Kind() != reflect.Pointer {
return fmt.Errorf("expected pointer arg for 'from' param 0, got: %v", typeFrom)
}
if typeTo.Kind() != reflect.Ptr {
if typeTo.Kind() != reflect.Pointer {
return fmt.Errorf("expected pointer arg for 'to' param 1, got: %v", typeTo)
}
c.ignoredUntypedConversions[typePair{typeFrom, typeTo}] = struct{}{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/conversion/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// Returns an error if this is not possible.
func EnforcePtr(obj interface{}) (reflect.Value, error) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr {
if v.Kind() != reflect.Pointer {
if v.Kind() == reflect.Invalid {
return reflect.Value{}, fmt.Errorf("expected pointer, but got invalid kind")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/conversion/queryparams/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func jsonTag(field reflect.StructField) (string, bool) {
}

func isPointerKind(kind reflect.Kind) bool {
return kind == reflect.Ptr
return kind == reflect.Pointer
}

func isStructKind(kind reflect.Kind) bool {
Expand Down Expand Up @@ -139,7 +139,7 @@ func Convert(obj interface{}) (url.Values, error) {
}
var sv reflect.Value
switch reflect.TypeOf(obj).Kind() {
case reflect.Ptr, reflect.Interface:
case reflect.Pointer, reflect.Interface:
sv = reflect.ValueOf(obj).Elem()
default:
return nil, fmt.Errorf("expecting a pointer or interface")
Expand Down
16 changes: 8 additions & 8 deletions pkg/runtime/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (c *fromUnstructuredContext) pushKey(key string) {
func (c *unstructuredConverter) FromUnstructuredWithValidation(u map[string]interface{}, obj interface{}, returnUnknownFields bool) error {
t := reflect.TypeOf(obj)
value := reflect.ValueOf(obj)
if t.Kind() != reflect.Ptr || value.IsNil() {
if t.Kind() != reflect.Pointer || value.IsNil() {
return fmt.Errorf("FromUnstructured requires a non-nil pointer to an object, got %v", t)
}

Expand Down Expand Up @@ -291,7 +291,7 @@ func fromUnstructured(sv, dv reflect.Value, ctx *fromUnstructuredContext) error
st, dt := sv.Type(), dv.Type()

switch dt.Kind() {
case reflect.Map, reflect.Slice, reflect.Ptr, reflect.Struct, reflect.Interface:
case reflect.Map, reflect.Slice, reflect.Pointer, reflect.Struct, reflect.Interface:
// Those require non-trivial conversion.
default:
// This should handle all simple types.
Expand Down Expand Up @@ -353,7 +353,7 @@ func fromUnstructured(sv, dv reflect.Value, ctx *fromUnstructuredContext) error
return mapFromUnstructured(sv, dv, ctx)
case reflect.Slice:
return sliceFromUnstructured(sv, dv, ctx)
case reflect.Ptr:
case reflect.Pointer:
return pointerFromUnstructured(sv, dv, ctx)
case reflect.Struct:
return structFromUnstructured(sv, dv, ctx)
Expand Down Expand Up @@ -496,13 +496,13 @@ func sliceFromUnstructured(sv, dv reflect.Value, ctx *fromUnstructuredContext) e
func pointerFromUnstructured(sv, dv reflect.Value, ctx *fromUnstructuredContext) error {
st, dt := sv.Type(), dv.Type()

if st.Kind() == reflect.Ptr && sv.IsNil() {
if st.Kind() == reflect.Pointer && sv.IsNil() {
dv.Set(reflect.Zero(dt))
return nil
}
dv.Set(reflect.New(dt.Elem()))
switch st.Kind() {
case reflect.Ptr, reflect.Interface:
case reflect.Pointer, reflect.Interface:
return fromUnstructured(sv.Elem(), dv.Elem(), ctx)
default:
return fromUnstructured(sv, dv.Elem(), ctx)
Expand Down Expand Up @@ -579,7 +579,7 @@ func (c *unstructuredConverter) ToUnstructured(obj interface{}) (map[string]inte
} else {
t := reflect.TypeOf(obj)
value := reflect.ValueOf(obj)
if t.Kind() != reflect.Ptr || value.IsNil() {
if t.Kind() != reflect.Pointer || value.IsNil() {
return nil, fmt.Errorf("ToUnstructured requires a non-nil pointer to an object, got %v", t)
}
u = map[string]interface{}{}
Expand Down Expand Up @@ -686,7 +686,7 @@ func toUnstructured(sv, dv reflect.Value) error {
return mapToUnstructured(sv, dv)
case reflect.Slice:
return sliceToUnstructured(sv, dv)
case reflect.Ptr:
case reflect.Pointer:
return pointerToUnstructured(sv, dv)
case reflect.Struct:
return structToUnstructured(sv, dv)
Expand Down Expand Up @@ -790,7 +790,7 @@ func isZero(v reflect.Value) bool {
case reflect.Map, reflect.Slice:
// TODO: It seems that 0-len maps are ignored in it.
return v.IsNil() || v.Len() == 0
case reflect.Ptr, reflect.Interface:
case reflect.Pointer, reflect.Interface:
return v.IsNil()
}
return false
Expand Down
6 changes: 3 additions & 3 deletions pkg/runtime/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (s *Scheme) AddKnownTypes(gv schema.GroupVersion, types ...Object) {
s.addObservedVersion(gv)
for _, obj := range types {
t := reflect.TypeOf(obj)
if t.Kind() != reflect.Ptr {
if t.Kind() != reflect.Pointer {
panic("All types must be pointers to structs.")
}
t = t.Elem()
Expand All @@ -159,7 +159,7 @@ func (s *Scheme) AddKnownTypeWithName(gvk schema.GroupVersionKind, obj Object) {
if len(gvk.Version) == 0 {
panic(fmt.Sprintf("version is required on all types: %s %v", gvk, t))
}
if t.Kind() != reflect.Ptr {
if t.Kind() != reflect.Pointer {
panic("All types must be pointers to structs.")
}
t = t.Elem()
Expand Down Expand Up @@ -462,7 +462,7 @@ func (s *Scheme) convertToVersion(copy bool, in Object, target GroupVersioner) (
} else {
// determine the incoming kinds with as few allocations as possible.
t = reflect.TypeOf(in)
if t.Kind() != reflect.Ptr {
if t.Kind() != reflect.Pointer {
return nil, fmt.Errorf("only pointer types may be converted: %v", t)
}
t = t.Elem()
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func IgnoreUnset() cmp.Option {
if v2.Len() == 0 {
return true
}
case reflect.Interface, reflect.Ptr:
case reflect.Interface, reflect.Pointer:
if v2.IsNil() {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/strategicpatch/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s PatchMetaFromStruct) LookupPatchMetadataForSlice(key string) (LookupPatc
// If the underlying element is neither an array nor a slice, the pointer is pointing to a slice,
// e.g. https://github.com/kubernetes/kubernetes/blob/bc22e206c79282487ea0bf5696d5ccec7e839a76/staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch_test.go#L2782-L2822
// If the underlying element is either an array or a slice, return its element type.
case reflect.Ptr:
case reflect.Pointer:
t = t.Elem()
if t.Kind() == reflect.Array || t.Kind() == reflect.Slice {
t = t.Elem()
Expand All @@ -129,7 +129,7 @@ func getTagStructType(dataStruct interface{}) (reflect.Type, error) {

t := reflect.TypeOf(dataStruct)
// Get the underlying type for pointers
if t.Kind() == reflect.Ptr {
if t.Kind() == reflect.Pointer {
t = t.Elem()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/validation/field/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (v *Error) ErrorBody() string {
valueType := reflect.TypeOf(value)
if value == nil || valueType == nil {
value = "null"
} else if valueType.Kind() == reflect.Ptr {
} else if valueType.Kind() == reflect.Pointer {
if reflectValue := reflect.ValueOf(value); reflectValue.IsNil() {
value = "null"
} else {
Expand Down
4 changes: 2 additions & 2 deletions third_party/forked/golang/json/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
// TODO: fix the returned errors to be introspectable.
func LookupPatchMetadataForStruct(t reflect.Type, jsonField string) (
elemType reflect.Type, patchStrategies []string, patchMergeKey string, e error) {
if t.Kind() == reflect.Ptr {
if t.Kind() == reflect.Pointer {
t = t.Elem()
}

Expand Down Expand Up @@ -183,7 +183,7 @@ func typeFields(t reflect.Type) []field {
index[len(f.index)] = i

ft := sf.Type
if ft.Name() == "" && ft.Kind() == reflect.Ptr {
if ft.Name() == "" && ft.Kind() == reflect.Pointer {
// Follow pointer.
ft = ft.Elem()
}
Expand Down
4 changes: 2 additions & 2 deletions third_party/forked/golang/reflect/deep_equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (e Equalities) deepValueEqual(v1, v2 reflect.Value, visited map[visit]bool,
return v1.IsNil() == v2.IsNil()
}
return e.deepValueEqual(v1.Elem(), v2.Elem(), visited, depth+1)
case reflect.Ptr:
case reflect.Pointer:
return e.deepValueEqual(v1.Elem(), v2.Elem(), visited, depth+1)
case reflect.Struct:
for i, n := 0, v1.NumField(); i < n; i++ {
Expand Down Expand Up @@ -327,7 +327,7 @@ func (e Equalities) deepValueDerive(v1, v2 reflect.Value, visited map[visit]bool
return true
}
return e.deepValueDerive(v1.Elem(), v2.Elem(), visited, depth+1)
case reflect.Ptr:
case reflect.Pointer:
if v1.IsNil() {
return true
}
Expand Down

0 comments on commit 55378ba

Please sign in to comment.