Beispiel #1
0
func HashObject(obj runtime.Object, codec runtime.Codec) (string, error) {
	data, err := codec.Encode(obj)
	if err != nil {
		return "", err
	}
	return fmt.Sprintf("%x", md5.Sum(data)), nil
}
Beispiel #2
0
func DecodeFromPathInto(obj runtime.Object, c runtime.Codec, filename string) error {
	b, err := ioutil.ReadFile(filename)
	c = runtime.YAMLDecoder(c)

	if err != nil {
		return err
	}
	return c.DecodeInto(b, obj)
}
Beispiel #3
0
// Object converts a watch.Event into an appropriately serializable JSON object
func Object(codec runtime.Codec, event *watch.Event) (interface{}, error) {
	obj, ok := event.Object.(runtime.Object)
	if !ok {
		return nil, fmt.Errorf("the event object cannot be safely converted to JSON: %v", reflect.TypeOf(event.Object).Name())
	}
	data, err := codec.Encode(obj)
	if err != nil {
		return nil, err
	}
	return &WatchEvent{event.Type, runtime.RawExtension{RawJSON: json.RawMessage(data)}}, nil
}