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 5 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. // 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(). result, err := c.newBuilder().
Unstructured(). Unstructured().
Stream(reader, ""). 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. // 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(). result, err := c.newBuilder().
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...). WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
Schema(c.validator()). Schema(c.validator()).
@ -268,7 +268,7 @@ func (c *Client) WatchUntilReady(reader io.Reader, timeout time.Duration) error
return perform(infos, c.watchTimeout(timeout)) 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 { if len(infos) == 0 {
return ErrNoObjectsVisited 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 // 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 { if f.BuildError != nil {
return []*resource.Info{}, f.BuildError 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 // 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 { if f.BuildUnstructuredError != nil {
return []*resource.Info{}, f.BuildUnstructuredError return []*resource.Info{}, f.BuildUnstructuredError
} }

@ -70,11 +70,11 @@ func (p *PrintingKubeClient) Update(_, modifiedReader io.Reader, _, _ bool) erro
} }
// Build implements KubeClient Build. // 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 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) return p.Build(nil)
} }

@ -55,8 +55,8 @@ type Interface interface {
// by "\n---\n"). // by "\n---\n").
Update(originalReader, modifiedReader io.Reader, force bool, recreate bool) error Update(originalReader, modifiedReader io.Reader, force bool, recreate bool) error
Build(reader io.Reader) (Result, error) Build(reader io.Reader) (ResourceList, error)
BuildUnstructured(reader io.Reader) (Result, error) BuildUnstructured(reader io.Reader) (ResourceList, error)
// WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase // WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase
// and returns said phase (PodSucceeded or PodFailed qualify). // 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" import "k8s.io/cli-runtime/pkg/resource"
// Result provides convenience methods for comparing collections of Infos. // ResourceList provides convenience methods for comparing collections of Infos.
type Result []*resource.Info type ResourceList []*resource.Info
// Append adds an Info to the Result. // 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) *r = append(*r, val)
} }
// Visit implements resource.Visitor. // Visit implements resource.Visitor.
func (r Result) Visit(fn resource.VisitorFunc) error { func (r ResourceList) Visit(fn resource.VisitorFunc) error {
for _, i := range r { for _, i := range r {
if err := fn(i, nil); err != nil { if err := fn(i, nil); err != nil {
return err 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. // Filter returns a new Result with Infos that satisfy the predicate fn.
func (r Result) Filter(fn func(*resource.Info) bool) Result { func (r ResourceList) Filter(fn func(*resource.Info) bool) ResourceList {
var result Result var result ResourceList
for _, i := range r { for _, i := range r {
if fn(i) { if fn(i) {
result.Append(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. // 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 { for _, i := range r {
if isMatchingInfo(i, info) { if isMatchingInfo(i, info) {
return i return i
@ -58,7 +58,7 @@ func (r Result) Get(info *resource.Info) *resource.Info {
} }
// Contains checks to see if an object exists. // 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 { for _, i := range r {
if isMatchingInfo(i, info) { if isMatchingInfo(i, info) {
return true 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. // 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 r.Filter(func(info *resource.Info) bool {
return !rs.Contains(info) return !rs.Contains(info)
}) })
} }
// Intersect will return a new Result with objects contained in both Results. // 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) return r.Filter(rs.Contains)
} }

@ -24,7 +24,7 @@ import (
"k8s.io/cli-runtime/pkg/resource" "k8s.io/cli-runtime/pkg/resource"
) )
func TestResult(t *testing.T) { func TestResourceList(t *testing.T) {
mapping := &meta.RESTMapping{ mapping := &meta.RESTMapping{
Resource: schema.GroupVersionResource{Group: "group", Version: "version", Resource: "pod"}, 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} return &resource.Info{Name: name, Mapping: mapping}
} }
var r1, r2 Result var r1, r2 ResourceList
r1 = []*resource.Info{info("foo"), info("bar")} r1 = []*resource.Info{info("foo"), info("bar")}
r2 = []*resource.Info{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 // waitForResources polls to get the current status of all pods, PVCs, and Services
// until all are ready or a timeout is reached // 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) 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) { return wait.Poll(2*time.Second, w.timeout, func() (bool, error) {

Loading…
Cancel
Save