Use name from server when displaying create/update

Allows generated names from files to be displayed so users can
interact with them.
This commit is contained in:
Clayton Coleman
2015-02-06 11:57:52 -05:00
parent bb6b332a8b
commit 52c6c60b15
8 changed files with 82 additions and 42 deletions

View File

@@ -87,6 +87,7 @@ func (i *Info) Visit(fn VisitorFunc) error {
return fn(i)
}
// Get retrieves the object from the Namespace and Name fields
func (i *Info) Get() error {
obj, err := NewHelper(i.Client, i.Mapping).Get(i.Namespace, i.Name)
if err != nil {
@@ -97,6 +98,38 @@ func (i *Info) Get() error {
return nil
}
// Refresh updates the object with another object. If ignoreError is set
// the Object will be updated even if name, namespace, or resourceVersion
// attributes cannot be loaded from the object.
func (i *Info) Refresh(obj runtime.Object, ignoreError bool) error {
name, err := i.Mapping.MetadataAccessor.Name(obj)
if err != nil {
if !ignoreError {
return err
}
} else {
i.Name = name
}
namespace, err := i.Mapping.MetadataAccessor.Namespace(obj)
if err != nil {
if !ignoreError {
return err
}
} else {
i.Namespace = namespace
}
version, err := i.Mapping.MetadataAccessor.ResourceVersion(obj)
if err != nil {
if !ignoreError {
return err
}
} else {
i.ResourceVersion = version
}
i.Object = obj
return nil
}
// Watch returns server changes to this object after it was retrieved.
func (i *Info) Watch(resourceVersion string) (watch.Interface, error) {
return NewHelper(i.Client, i.Mapping).WatchSingle(i.Namespace, i.Name, resourceVersion)