ref(kube): Renames `Result` type to `ResourceList`

`Result` is a misnomer and is going to be repurposed in a future commit for a
common result type for the different kube `Interface` methods

Signed-off-by: Taylor Thomas <taylor.thomas@microsoft.com>
pull/6085/head
Taylor Thomas 6 years ago
parent 3cf6f0c8ef
commit 1dac8421ef

@ -126,7 +126,7 @@ func (c *Client) validator() resource.ContentValidator {
}
// BuildUnstructured validates for Kubernetes objects and returns unstructured infos.
func (c *Client) BuildUnstructured(reader io.Reader) (Result, error) {
func (c *Client) BuildUnstructured(reader io.Reader) (ResourceList, error) {
result, err := c.newBuilder().
Unstructured().
Stream(reader, "").
@ -135,7 +135,7 @@ func (c *Client) BuildUnstructured(reader io.Reader) (Result, error) {
}
// Build validates for Kubernetes objects and returns resource Infos from a io.Reader.
func (c *Client) Build(reader io.Reader) (Result, error) {
func (c *Client) Build(reader io.Reader) (ResourceList, error) {
result, err := c.newBuilder().
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
Schema(c.validator()).
@ -268,7 +268,7 @@ func (c *Client) WatchUntilReady(reader io.Reader, timeout time.Duration) error
return perform(infos, c.watchTimeout(timeout))
}
func perform(infos Result, fn func(*resource.Info) error) error {
func perform(infos ResourceList, fn func(*resource.Info) error) error {
if len(infos) == 0 {
return ErrNoObjectsVisited
}

@ -92,7 +92,7 @@ func (f *FailingKubeClient) Update(r, modifiedReader io.Reader, not, needed bool
}
// Build returns the configured error if set or prints
func (f *FailingKubeClient) Build(r io.Reader) (kube.Result, error) {
func (f *FailingKubeClient) Build(r io.Reader) (kube.ResourceList, error) {
if f.BuildError != nil {
return []*resource.Info{}, f.BuildError
}
@ -100,7 +100,7 @@ func (f *FailingKubeClient) Build(r io.Reader) (kube.Result, error) {
}
// BuildUnstructured returns the configured error if set or prints
func (f *FailingKubeClient) BuildUnstructured(r io.Reader) (kube.Result, error) {
func (f *FailingKubeClient) BuildUnstructured(r io.Reader) (kube.ResourceList, error) {
if f.BuildUnstructuredError != nil {
return []*resource.Info{}, f.BuildUnstructuredError
}

@ -70,11 +70,11 @@ func (p *PrintingKubeClient) Update(_, modifiedReader io.Reader, _, _ bool) erro
}
// Build implements KubeClient Build.
func (p *PrintingKubeClient) Build(_ io.Reader) (kube.Result, error) {
func (p *PrintingKubeClient) Build(_ io.Reader) (kube.ResourceList, error) {
return []*resource.Info{}, nil
}
func (p *PrintingKubeClient) BuildUnstructured(_ io.Reader) (kube.Result, error) {
func (p *PrintingKubeClient) BuildUnstructured(_ io.Reader) (kube.ResourceList, error) {
return p.Build(nil)
}

@ -55,8 +55,8 @@ type Interface interface {
// by "\n---\n").
Update(originalReader, modifiedReader io.Reader, force bool, recreate bool) error
Build(reader io.Reader) (Result, error)
BuildUnstructured(reader io.Reader) (Result, error)
Build(reader io.Reader) (ResourceList, error)
BuildUnstructured(reader io.Reader) (ResourceList, error)
// WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase
// and returns said phase (PodSucceeded or PodFailed qualify).

@ -18,16 +18,16 @@ package kube // import "helm.sh/helm/pkg/kube"
import "k8s.io/cli-runtime/pkg/resource"
// Result provides convenience methods for comparing collections of Infos.
type Result []*resource.Info
// ResourceList provides convenience methods for comparing collections of Infos.
type ResourceList []*resource.Info
// Append adds an Info to the Result.
func (r *Result) Append(val *resource.Info) {
func (r *ResourceList) Append(val *resource.Info) {
*r = append(*r, val)
}
// Visit implements resource.Visitor.
func (r Result) Visit(fn resource.VisitorFunc) error {
func (r ResourceList) Visit(fn resource.VisitorFunc) error {
for _, i := range r {
if err := fn(i, nil); err != nil {
return err
@ -37,8 +37,8 @@ func (r Result) Visit(fn resource.VisitorFunc) error {
}
// Filter returns a new Result with Infos that satisfy the predicate fn.
func (r Result) Filter(fn func(*resource.Info) bool) Result {
var result Result
func (r ResourceList) Filter(fn func(*resource.Info) bool) ResourceList {
var result ResourceList
for _, i := range r {
if fn(i) {
result.Append(i)
@ -48,7 +48,7 @@ func (r Result) Filter(fn func(*resource.Info) bool) Result {
}
// Get returns the Info from the result that matches the name and kind.
func (r Result) Get(info *resource.Info) *resource.Info {
func (r ResourceList) Get(info *resource.Info) *resource.Info {
for _, i := range r {
if isMatchingInfo(i, info) {
return i
@ -58,7 +58,7 @@ func (r Result) Get(info *resource.Info) *resource.Info {
}
// Contains checks to see if an object exists.
func (r Result) Contains(info *resource.Info) bool {
func (r ResourceList) Contains(info *resource.Info) bool {
for _, i := range r {
if isMatchingInfo(i, info) {
return true
@ -68,14 +68,14 @@ func (r Result) Contains(info *resource.Info) bool {
}
// Difference will return a new Result with objects not contained in rs.
func (r Result) Difference(rs Result) Result {
func (r ResourceList) Difference(rs ResourceList) ResourceList {
return r.Filter(func(info *resource.Info) bool {
return !rs.Contains(info)
})
}
// Intersect will return a new Result with objects contained in both Results.
func (r Result) Intersect(rs Result) Result {
func (r ResourceList) Intersect(rs ResourceList) ResourceList {
return r.Filter(rs.Contains)
}

@ -24,7 +24,7 @@ import (
"k8s.io/cli-runtime/pkg/resource"
)
func TestResult(t *testing.T) {
func TestResourceList(t *testing.T) {
mapping := &meta.RESTMapping{
Resource: schema.GroupVersionResource{Group: "group", Version: "version", Resource: "pod"},
}
@ -33,7 +33,7 @@ func TestResult(t *testing.T) {
return &resource.Info{Name: name, Mapping: mapping}
}
var r1, r2 Result
var r1, r2 ResourceList
r1 = []*resource.Info{info("foo"), info("bar")}
r2 = []*resource.Info{info("bar")}

@ -44,7 +44,7 @@ type waiter struct {
// waitForResources polls to get the current status of all pods, PVCs, and Services
// until all are ready or a timeout is reached
func (w *waiter) waitForResources(created Result) error {
func (w *waiter) waitForResources(created ResourceList) error {
w.log("beginning wait for %d resources with timeout of %v", len(created), w.timeout)
return wait.Poll(2*time.Second, w.timeout, func() (bool, error) {

Loading…
Cancel
Save