29
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go
generated
vendored
29
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/helpers.go
generated
vendored
@ -17,7 +17,9 @@ limitations under the License.
|
||||
package v1
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
@ -250,18 +252,31 @@ func ResetObjectMetaForStatus(meta, existingMeta Object) {
|
||||
meta.SetAnnotations(existingMeta.GetAnnotations())
|
||||
meta.SetFinalizers(existingMeta.GetFinalizers())
|
||||
meta.SetOwnerReferences(existingMeta.GetOwnerReferences())
|
||||
meta.SetManagedFields(existingMeta.GetManagedFields())
|
||||
// managedFields must be preserved since it's been modified to
|
||||
// track changed fields in the status update.
|
||||
//meta.SetManagedFields(existingMeta.GetManagedFields())
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler
|
||||
func (f Fields) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(&f.Map)
|
||||
// MarshalJSON may get called on pointers or values, so implement MarshalJSON on value.
|
||||
// http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go
|
||||
func (f FieldsV1) MarshalJSON() ([]byte, error) {
|
||||
if f.Raw == nil {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
return f.Raw, nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler
|
||||
func (f *Fields) UnmarshalJSON(b []byte) error {
|
||||
return json.Unmarshal(b, &f.Map)
|
||||
func (f *FieldsV1) UnmarshalJSON(b []byte) error {
|
||||
if f == nil {
|
||||
return errors.New("metav1.Fields: UnmarshalJSON on nil pointer")
|
||||
}
|
||||
if !bytes.Equal(b, []byte("null")) {
|
||||
f.Raw = append(f.Raw[0:0], b...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ json.Marshaler = Fields{}
|
||||
var _ json.Unmarshaler = &Fields{}
|
||||
var _ json.Marshaler = FieldsV1{}
|
||||
var _ json.Unmarshaler = &FieldsV1{}
|
||||
|
Reference in New Issue
Block a user