mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Merge pull request #75576 from smarterclayton/bad_2
Remove use of `%#v` in frequently accessed code
This commit is contained in:
commit
9f15368c5c
@ -54,9 +54,8 @@ func fieldPath(pod *v1.Pod, container *v1.Container) (string, error) {
|
|||||||
if here.Name == container.Name {
|
if here.Name == container.Name {
|
||||||
if here.Name == "" {
|
if here.Name == "" {
|
||||||
return fmt.Sprintf("spec.containers[%d]", i), nil
|
return fmt.Sprintf("spec.containers[%d]", i), nil
|
||||||
} else {
|
|
||||||
return fmt.Sprintf("spec.containers{%s}", here.Name), nil
|
|
||||||
}
|
}
|
||||||
|
return fmt.Sprintf("spec.containers{%s}", here.Name), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := range pod.Spec.InitContainers {
|
for i := range pod.Spec.InitContainers {
|
||||||
@ -64,10 +63,9 @@ func fieldPath(pod *v1.Pod, container *v1.Container) (string, error) {
|
|||||||
if here.Name == container.Name {
|
if here.Name == container.Name {
|
||||||
if here.Name == "" {
|
if here.Name == "" {
|
||||||
return fmt.Sprintf("spec.initContainers[%d]", i), nil
|
return fmt.Sprintf("spec.initContainers[%d]", i), nil
|
||||||
} else {
|
|
||||||
return fmt.Sprintf("spec.initContainers{%s}", here.Name), nil
|
|
||||||
}
|
}
|
||||||
|
return fmt.Sprintf("spec.initContainers{%s}", here.Name), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("container %#v not found in pod %#v", container, pod)
|
return "", fmt.Errorf("container %q not found in pod %s/%s", container.Name, pod.Namespace, pod.Name)
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func UnsafeObjectConvertor(scheme *Scheme) ObjectConvertor {
|
|||||||
func SetField(src interface{}, v reflect.Value, fieldName string) error {
|
func SetField(src interface{}, v reflect.Value, fieldName string) error {
|
||||||
field := v.FieldByName(fieldName)
|
field := v.FieldByName(fieldName)
|
||||||
if !field.IsValid() {
|
if !field.IsValid() {
|
||||||
return fmt.Errorf("couldn't find %v field in %#v", fieldName, v.Interface())
|
return fmt.Errorf("couldn't find %v field in %T", fieldName, v.Interface())
|
||||||
}
|
}
|
||||||
srcValue := reflect.ValueOf(src)
|
srcValue := reflect.ValueOf(src)
|
||||||
if srcValue.Type().AssignableTo(field.Type()) {
|
if srcValue.Type().AssignableTo(field.Type()) {
|
||||||
@ -70,7 +70,7 @@ func SetField(src interface{}, v reflect.Value, fieldName string) error {
|
|||||||
func Field(v reflect.Value, fieldName string, dest interface{}) error {
|
func Field(v reflect.Value, fieldName string, dest interface{}) error {
|
||||||
field := v.FieldByName(fieldName)
|
field := v.FieldByName(fieldName)
|
||||||
if !field.IsValid() {
|
if !field.IsValid() {
|
||||||
return fmt.Errorf("couldn't find %v field in %#v", fieldName, v.Interface())
|
return fmt.Errorf("couldn't find %v field in %T", fieldName, v.Interface())
|
||||||
}
|
}
|
||||||
destValue, err := conversion.EnforcePtr(dest)
|
destValue, err := conversion.EnforcePtr(dest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -93,7 +93,7 @@ func Field(v reflect.Value, fieldName string, dest interface{}) error {
|
|||||||
func FieldPtr(v reflect.Value, fieldName string, dest interface{}) error {
|
func FieldPtr(v reflect.Value, fieldName string, dest interface{}) error {
|
||||||
field := v.FieldByName(fieldName)
|
field := v.FieldByName(fieldName)
|
||||||
if !field.IsValid() {
|
if !field.IsValid() {
|
||||||
return fmt.Errorf("couldn't find %v field in %#v", fieldName, v.Interface())
|
return fmt.Errorf("couldn't find %v field in %T", fieldName, v.Interface())
|
||||||
}
|
}
|
||||||
v, err := conversion.EnforcePtr(dest)
|
v, err := conversion.EnforcePtr(dest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -592,7 +592,7 @@ func (r *Request) WatchWithSpecificDecoders(wrapperDecoderFn func(io.ReadCloser)
|
|||||||
if result := r.transformResponse(resp, req); result.err != nil {
|
if result := r.transformResponse(resp, req); result.err != nil {
|
||||||
return nil, result.err
|
return nil, result.err
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("for request '%+v', got status: %v", url, resp.StatusCode)
|
return nil, fmt.Errorf("for request %s, got status: %v", url, resp.StatusCode)
|
||||||
}
|
}
|
||||||
wrapperDecoder := wrapperDecoderFn(resp.Body)
|
wrapperDecoder := wrapperDecoderFn(resp.Body)
|
||||||
return watch.NewStreamWatcher(restclientwatch.NewDecoder(wrapperDecoder, embeddedDecoder)), nil
|
return watch.NewStreamWatcher(restclientwatch.NewDecoder(wrapperDecoder, embeddedDecoder)), nil
|
||||||
@ -845,13 +845,13 @@ func (r *Request) transformResponse(resp *http.Response, req *http.Request) Resu
|
|||||||
// 3. Apiserver closes connection.
|
// 3. Apiserver closes connection.
|
||||||
// 4. client-go should catch this and return an error.
|
// 4. client-go should catch this and return an error.
|
||||||
klog.V(2).Infof("Stream error %#v when reading response body, may be caused by closed connection.", err)
|
klog.V(2).Infof("Stream error %#v when reading response body, may be caused by closed connection.", err)
|
||||||
streamErr := fmt.Errorf("Stream error %#v when reading response body, may be caused by closed connection. Please retry.", err)
|
streamErr := fmt.Errorf("Stream error when reading response body, may be caused by closed connection. Please retry. Original error: %v", err)
|
||||||
return Result{
|
return Result{
|
||||||
err: streamErr,
|
err: streamErr,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
klog.Errorf("Unexpected error when reading response body: %#v", err)
|
klog.Errorf("Unexpected error when reading response body: %v", err)
|
||||||
unexpectedErr := fmt.Errorf("Unexpected error %#v when reading response body. Please retry.", err)
|
unexpectedErr := fmt.Errorf("Unexpected error when reading response body. Please retry. Original error: %v", err)
|
||||||
return Result{
|
return Result{
|
||||||
err: unexpectedErr,
|
err: unexpectedErr,
|
||||||
}
|
}
|
||||||
|
@ -555,7 +555,7 @@ func (p *processorListener) run() {
|
|||||||
case deleteNotification:
|
case deleteNotification:
|
||||||
p.handler.OnDelete(notification.oldObj)
|
p.handler.OnDelete(notification.oldObj)
|
||||||
default:
|
default:
|
||||||
utilruntime.HandleError(fmt.Errorf("unrecognized notification: %#v", next))
|
utilruntime.HandleError(fmt.Errorf("unrecognized notification: %T", next))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// the only way to get here is if the p.nextCh is empty and closed
|
// the only way to get here is if the p.nextCh is empty and closed
|
||||||
|
Loading…
Reference in New Issue
Block a user