Add "Update Event" to Kubernetes API

This commit is contained in:
saadali
2015-02-05 00:05:36 -08:00
parent 5de2e916e5
commit a41f520bf0
12 changed files with 330 additions and 35 deletions

View File

@@ -281,22 +281,22 @@ func (h *EtcdHelper) Delete(key string, recursive bool) error {
return err
}
// SetObj marshals obj via json, and stores under key. Will do an
// atomic update if obj's ResourceVersion field is set.
func (h *EtcdHelper) SetObj(key string, obj runtime.Object) error {
// SetObj marshals obj via json, and stores under key. Will do an atomic update if obj's ResourceVersion
// field is set. 'ttl' is time-to-live in seconds, and 0 means forever.
func (h *EtcdHelper) SetObj(key string, obj runtime.Object, ttl uint64) error {
data, err := h.Codec.Encode(obj)
if err != nil {
return err
}
if h.ResourceVersioner != nil {
if version, err := h.ResourceVersioner.ResourceVersion(obj); err == nil && version != 0 {
_, err = h.Client.CompareAndSwap(key, string(data), 0, "", version)
_, err = h.Client.CompareAndSwap(key, string(data), ttl, "", version)
return err // err is shadowed!
}
}
// Create will fail if a key already exists.
_, err = h.Client.Create(key, string(data), 0)
_, err = h.Client.Create(key, string(data), ttl)
return err
}