Skip to content

Commit

Permalink
Change reflect.Ptr to reflect.Pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
wqld committed Jun 25, 2022
1 parent d2c5779 commit df168d5
Show file tree
Hide file tree
Showing 38 changed files with 70 additions and 70 deletions.
4 changes: 2 additions & 2 deletions pkg/api/pod/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func collectResourcePaths(t *testing.T, resourcename string, path *field.Path, n
resourcename = strings.ToLower(resourcename)
resourcePaths := sets.NewString()

if tp.Kind() == reflect.Ptr {
if tp.Kind() == reflect.Pointer {
resourcePaths.Insert(collectResourcePaths(t, resourcename, path, name, tp.Elem()).List()...)
return resourcePaths
}
Expand All @@ -399,7 +399,7 @@ func collectResourcePaths(t *testing.T, resourcename string, path *field.Path, n
}

switch tp.Kind() {
case reflect.Ptr:
case reflect.Pointer:
resourcePaths.Insert(collectResourcePaths(t, resourcename, path, name, tp.Elem()).List()...)
case reflect.Struct:
// ObjectMeta is generic and therefore should never have a field with a specific resource's name;
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/testing/serialization_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestAllFieldsHaveTags(t *testing.T) {

func fieldsHaveProtobufTags(obj reflect.Type) error {
switch obj.Kind() {
case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Array:
case reflect.Slice, reflect.Map, reflect.Pointer, reflect.Array:
return fieldsHaveProtobufTags(obj.Elem())
case reflect.Struct:
for i := 0; i < obj.NumField(); i++ {
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/persistentvolume/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func TestPVSecrets(t *testing.T) {
func collectSecretPaths(t *testing.T, path *field.Path, name string, tp reflect.Type) sets.String {
secretPaths := sets.NewString()

if tp.Kind() == reflect.Ptr {
if tp.Kind() == reflect.Pointer {
secretPaths.Insert(collectSecretPaths(t, path, name, tp.Elem()).List()...)
return secretPaths
}
Expand All @@ -276,7 +276,7 @@ func collectSecretPaths(t *testing.T, path *field.Path, name string, tp reflect.
}

switch tp.Kind() {
case reflect.Ptr:
case reflect.Pointer:
secretPaths.Insert(collectSecretPaths(t, path, name, tp.Elem()).List()...)
case reflect.Struct:
// ObjectMeta should not have any field with the word "secret" in it;
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/pod/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func collectResourcePaths(t *testing.T, resourcename string, path *field.Path, n
resourcename = strings.ToLower(resourcename)
resourcePaths := sets.NewString()

if tp.Kind() == reflect.Ptr {
if tp.Kind() == reflect.Pointer {
resourcePaths.Insert(collectResourcePaths(t, resourcename, path, name, tp.Elem()).List()...)
return resourcePaths
}
Expand All @@ -565,7 +565,7 @@ func collectResourcePaths(t *testing.T, resourcename string, path *field.Path, n
}

switch tp.Kind() {
case reflect.Ptr:
case reflect.Pointer:
resourcePaths.Insert(collectResourcePaths(t, resourcename, path, name, tp.Elem()).List()...)
case reflect.Struct:
// ObjectMeta is generic and therefore should never have a field with a specific resource's name;
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/core/v1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func detectDefaults(t *testing.T, obj runtime.Object, v reflect.Value) map[strin
t.Logf("unhandled non-primitive map type %s: %s", visit.path, visit.value.Type().Elem())
}

case visit.value.Kind() == reflect.Ptr:
case visit.value.Kind() == reflect.Pointer:
if visit.value.IsNil() {
if visit.value.Type().Elem().Kind() == reflect.Struct {
visit.value.Set(reflect.New(visit.value.Type().Elem()))
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/core/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17759,7 +17759,7 @@ func collectResourcePaths(t *testing.T, skipRecurseList sets.String, tp reflect.

paths := sets.NewString()
switch tp.Kind() {
case reflect.Ptr:
case reflect.Pointer:
paths.Insert(collectResourcePaths(t, skipRecurseList, tp.Elem(), path).List()...)
case reflect.Struct:
for i := 0; i < tp.NumField(); i++ {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/apis/config/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func allPrimitiveFieldPaths(t *testing.T, skipRecurseList sets.String, tp reflec

paths := sets.NewString()
switch tp.Kind() {
case reflect.Ptr:
case reflect.Pointer:
paths.Insert(allPrimitiveFieldPaths(t, skipRecurseList, tp.Elem(), path).List()...)
case reflect.Struct:
for i := 0; i < tp.NumField(); i++ {
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubelet/cri/remote/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func assertEqualTypes(t *testing.T, path []string, a, b reflect.Type) {
path = path[:len(path)-1]
}

case reflect.Ptr, reflect.Slice:
case reflect.Pointer, reflect.Slice:
aElemType := a.Elem()
bElemType := b.Elem()
assertEqualTypes(t, path, aElemType, bElemType)
Expand Down Expand Up @@ -170,14 +170,14 @@ func fillField(field reflect.Value, v int) {
field.Set(slice)
first := slice.Index(0)

if first.Type().Kind() == reflect.Ptr {
if first.Type().Kind() == reflect.Pointer {
first.Set(reflect.New(first.Type().Elem()))
fillFieldsOffset(first.Interface(), v)
} else {
fillField(first, v)
}

case reflect.Ptr:
case reflect.Pointer:
val := reflect.New(field.Type().Elem())
field.Set(val)
fillFieldsOffset(field.Interface(), v)
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/iptables/testing/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func findParamField(value reflect.Value, param string) (*reflect.Value, bool) {
var wordRegex = regexp.MustCompile(`(?:^|\s)("[^"]*"|[^"]\S*)`)

// Used by ParseRule
var boolPtrType = reflect.PtrTo(reflect.TypeOf(true))
var boolPtrType = reflect.PointerTo(reflect.TypeOf(true))
var ipTablesValuePtrType = reflect.TypeOf((*IPTablesValue)(nil))

// ParseRule parses rule. If strict is false, it will parse the recognized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
default:
isValue := true
switch field.Type.Kind() {
case reflect.Interface, reflect.Map, reflect.Slice, reflect.Ptr:
case reflect.Interface, reflect.Map, reflect.Slice, reflect.Pointer:
isValue = false
}
if isValue || c.Intn(10) == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ func assertEqualTypes(t *testing.T, path []string, a, b reflect.Type) {
path = path[:len(path)-1]
}

case reflect.Ptr, reflect.Slice:
case reflect.Pointer, reflect.Slice:
aElemType := a.Elem()
bElemType := b.Elem()
assertEqualTypes(t, path, aElemType, bElemType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (s *Validator) validateExpressions(ctx context.Context, fldPath *field.Path
if oldObj != nil {
v := reflect.ValueOf(oldObj)
switch v.Kind() {
case reflect.Map, reflect.Ptr, reflect.Interface, reflect.Slice:
case reflect.Map, reflect.Pointer, reflect.Interface, reflect.Slice:
if v.IsNil() {
oldObj = nil // +k8s:verify-mutation:reason=clone
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,17 @@ func (sv *structValue) AddField(field *Field) {
func (sv *structValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error) {
if typeDesc.Kind() != reflect.Map &&
typeDesc.Kind() != reflect.Struct &&
typeDesc.Kind() != reflect.Ptr &&
typeDesc.Kind() != reflect.Pointer &&
typeDesc.Kind() != reflect.Interface {
return nil, fmt.Errorf("type conversion error from object to '%v'", typeDesc)
}

// Unwrap pointers, but track their use.
isPtr := false
if typeDesc.Kind() == reflect.Ptr {
if typeDesc.Kind() == reflect.Pointer {
tk := typeDesc
typeDesc = typeDesc.Elem()
if typeDesc.Kind() == reflect.Ptr {
if typeDesc.Kind() == reflect.Pointer {
return nil, fmt.Errorf("unsupported type conversion to '%v'", tk)
}
isPtr = true
Expand Down
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
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
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 staging/src/k8s.io/apimachinery/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 staging/src/k8s.io/apimachinery/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 staging/src/k8s.io/apimachinery/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 staging/src/k8s.io/apimachinery/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
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 staging/src/k8s.io/apimachinery/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
Loading

0 comments on commit df168d5

Please sign in to comment.