Drop redundant pointers and decoders (#2211)

This commit is contained in:
Markus Thömmes 2021-08-17 11:04:16 +02:00 committed by GitHub
parent bf176d5654
commit 35bcd16656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 8 deletions

View File

@ -17,7 +17,6 @@ limitations under the License.
package configmaps
import (
"bytes"
"context"
"encoding/json"
"errors"
@ -192,8 +191,7 @@ func (ac *reconciler) validate(ctx context.Context, req *admissionv1.AdmissionRe
var newObj corev1.ConfigMap
if len(newBytes) != 0 {
newDecoder := json.NewDecoder(bytes.NewBuffer(newBytes))
if err := newDecoder.Decode(&newObj); err != nil {
if err := json.Unmarshal(newBytes, &newObj); err != nil {
return fmt.Errorf("cannot decode incoming new object: %w", err)
}
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package psbinding
import (
"bytes"
"context"
"encoding/json"
"fmt"
@ -178,8 +177,7 @@ func (ac *Reconciler) Admit(ctx context.Context, request *admissionv1.AdmissionR
}
orig := &duckv1.WithPod{}
decoder := json.NewDecoder(bytes.NewBuffer(request.Object.Raw))
if err := decoder.Decode(&orig); err != nil {
if err := json.Unmarshal(request.Object.Raw, orig); err != nil {
return webhook.MakeErrorStatus("unable to decode object: %v", err)
}

View File

@ -201,8 +201,7 @@ func (ac *reconciler) callback(ctx context.Context, req *admissionv1.AdmissionRe
if c, ok := ac.callbacks[gvk]; ok {
if _, supported := c.supportedVerbs[req.Operation]; supported {
unstruct := &unstructured.Unstructured{}
newDecoder := json.NewDecoder(bytes.NewBuffer(toDecode))
if err := newDecoder.Decode(&unstruct); err != nil {
if err := json.Unmarshal(toDecode, unstruct); err != nil {
return fmt.Errorf("cannot decode incoming new object: %w", err)
}