Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Separate Find in clients, fix metadata loading temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
twelho committed Jul 6, 2019
1 parent 9273c75 commit 96fcd1f
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 49 deletions.
19 changes: 13 additions & 6 deletions pkg/client/client_dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (

// DynamicClient is an interface for accessing API types generically
type DynamicClient interface {
// Get returns an Object based on the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Get(filter filterer.BaseFilter) (meta.Object, error)
// Get returns an Object matching the UID from the storage
Get(meta.UID) (meta.Object, error)
// Set saves an Object into the persistent storage
Set(meta.Object) error
// Find returns an Object based on the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Find(filter filterer.BaseFilter) (meta.Object, error)
// Delete deletes an Object from the storage
Delete(uid meta.UID) error
// List returns a list of all Objects available
Expand Down Expand Up @@ -52,16 +54,21 @@ func newDynamicClient(s storage.Storage, kind meta.Kind) DynamicClient {
}
}

// Get returns an Object based on a given Filter
func (c *dynamicClient) Get(filter filterer.BaseFilter) (meta.Object, error) {
return c.filterer.Find(c.kind, filter)
// Get returns an Object based the given UID
func (c *dynamicClient) Get(uid meta.UID) (meta.Object, error) {
return c.storage.GetByID(c.kind, uid)
}

// Set saves an Object into the persistent storage
func (c *dynamicClient) Set(resource meta.Object) error {
return c.storage.Set(resource)
}

// Find returns an Object based on a given Filter
func (c *dynamicClient) Find(filter filterer.BaseFilter) (meta.Object, error) {
return c.filterer.Find(c.kind, filter)
}

// Delete deletes the Object from the storage
func (c *dynamicClient) Delete(uid meta.UID) error {
return c.storage.Delete(c.kind, uid)
Expand Down
27 changes: 17 additions & 10 deletions pkg/client/client_resource_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import (

// ResourceClient is an interface for accessing Resource-specific API objects
type ResourceClient interface {
// Get returns an Object based on the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Get(filter filterer.BaseFilter) (*api.Resource, error)
// Set saves an Object into the persistent storage
// Get returns the Resource matching given UID from the storage
Get(meta.UID) (*api.Resource, error)
// Set saves the given Resource into persistent storage
Set(*api.Resource) error
// Delete deletes an Object from the storage
// Find returns the Resource matching the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Find(filter filterer.BaseFilter) (*api.Resource, error)
// Delete deletes the Resource with the given UID from the storage
Delete(uid meta.UID) error
// List returns a list of all Objects available
// List returns a list of all Resources available
List() ([]*api.Resource, error)
}

Expand Down Expand Up @@ -57,11 +59,16 @@ func newResourceClient(s storage.Storage) ResourceClient {
}
}

// Get returns a single Resource based on a given Filter
func (c *resourceClient) Get(filter filterer.BaseFilter) (resource *api.Resource, err error) {
// Find returns a single Resource based on a given Filter
func (c *resourceClient) Find(filter filterer.BaseFilter) (*api.Resource, error) {
object, err := c.filterer.Find(api.ResourceKind, filter)
resource = object.(*api.Resource)
return
return object.(*api.Resource), err
}

// Get returns the Resource matching given UID from the storage
func (c *resourceClient) Get(uid meta.UID) (*api.Resource, error) {
object, err := c.storage.GetByID(meta.KindResource, uid)
return object.(*api.Resource), err
}

// Set saves the given Resource into the persistent storage
Expand Down
27 changes: 17 additions & 10 deletions pkg/client/zz_generated.client_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ import (

// ImageClient is an interface for accessing Image-specific API objects
type ImageClient interface {
// Get returns an Object based on the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Get(filter filterer.BaseFilter) (*api.Image, error)
// Set saves an Object into the persistent storage
// Get returns the Image matching given UID from the storage
Get(meta.UID) (*api.Image, error)
// Set saves the given Image into persistent storage
Set(*api.Image) error
// Delete deletes an Object from the storage
// Find returns the Image matching the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Find(filter filterer.BaseFilter) (*api.Image, error)
// Delete deletes the Image with the given UID from the storage
Delete(uid meta.UID) error
// List returns a list of all Objects available
// List returns a list of all Images available
List() ([]*api.Image, error)
}

Expand Down Expand Up @@ -55,11 +57,16 @@ func newImageClient(s storage.Storage) ImageClient {
}
}

// Get returns a single Image based on a given Filter
func (c *imageClient) Get(filter filterer.BaseFilter) (image *api.Image, err error) {
// Find returns a single Image based on a given Filter
func (c *imageClient) Find(filter filterer.BaseFilter) (*api.Image, error) {
object, err := c.filterer.Find(api.ImageKind, filter)
image = object.(*api.Image)
return
return object.(*api.Image), err
}

// Get returns the Image matching given UID from the storage
func (c *imageClient) Get(uid meta.UID) (*api.Image, error) {
object, err := c.storage.GetByID(meta.KindImage, uid)
return object.(*api.Image), err
}

// Set saves the given Image into the persistent storage
Expand Down
27 changes: 17 additions & 10 deletions pkg/client/zz_generated.client_kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ import (

// KernelClient is an interface for accessing Kernel-specific API objects
type KernelClient interface {
// Get returns an Object based on the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Get(filter filterer.BaseFilter) (*api.Kernel, error)
// Set saves an Object into the persistent storage
// Get returns the Kernel matching given UID from the storage
Get(meta.UID) (*api.Kernel, error)
// Set saves the given Kernel into persistent storage
Set(*api.Kernel) error
// Delete deletes an Object from the storage
// Find returns the Kernel matching the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Find(filter filterer.BaseFilter) (*api.Kernel, error)
// Delete deletes the Kernel with the given UID from the storage
Delete(uid meta.UID) error
// List returns a list of all Objects available
// List returns a list of all Kernels available
List() ([]*api.Kernel, error)
}

Expand Down Expand Up @@ -55,11 +57,16 @@ func newKernelClient(s storage.Storage) KernelClient {
}
}

// Get returns a single Kernel based on a given Filter
func (c *kernelClient) Get(filter filterer.BaseFilter) (kernel *api.Kernel, err error) {
// Find returns a single Kernel based on a given Filter
func (c *kernelClient) Find(filter filterer.BaseFilter) (*api.Kernel, error) {
object, err := c.filterer.Find(api.KernelKind, filter)
kernel = object.(*api.Kernel)
return
return object.(*api.Kernel), err
}

// Get returns the Kernel matching given UID from the storage
func (c *kernelClient) Get(uid meta.UID) (*api.Kernel, error) {
object, err := c.storage.GetByID(meta.KindKernel, uid)
return object.(*api.Kernel), err
}

// Set saves the given Kernel into the persistent storage
Expand Down
27 changes: 17 additions & 10 deletions pkg/client/zz_generated.client_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ import (

// VMClient is an interface for accessing VM-specific API objects
type VMClient interface {
// Get returns an Object based on the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Get(filter filterer.BaseFilter) (*api.VM, error)
// Set saves an Object into the persistent storage
// Get returns the VM matching given UID from the storage
Get(meta.UID) (*api.VM, error)
// Set saves the given VM into persistent storage
Set(*api.VM) error
// Delete deletes an Object from the storage
// Find returns the VM matching the given filter, filters can
// match e.g. the Object's Name, UID or a specific property
Find(filter filterer.BaseFilter) (*api.VM, error)
// Delete deletes the VM with the given UID from the storage
Delete(uid meta.UID) error
// List returns a list of all Objects available
// List returns a list of all VMs available
List() ([]*api.VM, error)
}

Expand Down Expand Up @@ -55,11 +57,16 @@ func newVMClient(s storage.Storage) VMClient {
}
}

// Get returns a single VM based on a given Filter
func (c *vmClient) Get(filter filterer.BaseFilter) (vm *api.VM, err error) {
// Find returns a single VM based on a given Filter
func (c *vmClient) Find(filter filterer.BaseFilter) (*api.VM, error) {
object, err := c.filterer.Find(api.VMKind, filter)
vm = object.(*api.VM)
return
return object.(*api.VM), err
}

// Get returns the VM matching given UID from the storage
func (c *vmClient) Get(uid meta.UID) (*api.VM, error) {
object, err := c.storage.GetByID(meta.KindVM, uid)
return object.(*api.VM), err
}

// Set saves the given VM into the persistent storage
Expand Down
2 changes: 1 addition & 1 deletion pkg/metadata/imgmd/imgmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (md *Image) ObjectPath() string {
}

func (md *Image) Load() (err error) {
md.Image, err = client.Images().Get(md.GetUID().String())
md.Image, err = client.Images().Get(md.GetUID())
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/metadata/kernmd/kernmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (md *Kernel) ObjectPath() string {
}

func (md *Kernel) Load() (err error) {
md.Kernel, err = client.Kernels().Get(md.GetUID().String())
md.Kernel, err = client.Kernels().Get(md.GetUID())
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/metadata/vmmd/vmmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (md *VM) ObjectPath() string {
}

func (md *VM) Load() (err error) {
md.VM, err = client.VMs().Get(md.GetUID().String())
md.VM, err = client.VMs().Get(md.GetUID())
return
}

Expand Down

0 comments on commit 96fcd1f

Please sign in to comment.