mirror of https://github.com/knative/pkg.git
Drop redundant pointers and decoders (#2211)
This commit is contained in:
parent
bf176d5654
commit
35bcd16656
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue