diff --git a/go.mod b/go.mod index 6d07231..89785a9 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/tohjustin/kube-lineage go 1.16 require ( + github.com/hashicorp/go-multierror v1.1.1 github.com/spf13/cobra v1.1.3 github.com/spf13/pflag v1.0.5 k8s.io/apimachinery v0.22.1 diff --git a/go.sum b/go.sum index 22d1832..108192e 100644 --- a/go.sum +++ b/go.sum @@ -214,11 +214,14 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= diff --git a/pkg/cmd/lineage/lineage.go b/pkg/cmd/lineage/lineage.go index 775320e..69a68fe 100644 --- a/pkg/cmd/lineage/lineage.go +++ b/pkg/cmd/lineage/lineage.go @@ -7,6 +7,7 @@ import ( "strings" "sync" + multierror "github.com/hashicorp/go-multierror" "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -265,8 +266,9 @@ func (o *CmdOptions) getObjectsByResources(apis []Resource) ([]unstructuredv1.Un var mu sync.Mutex var wg sync.WaitGroup var result []unstructuredv1.Unstructured + var errResult *multierror.Error - var errResult error + errors := make(chan error, len(apis)) for _, api := range apis { // Avoid getting cluster-scoped objects if the root object is a namespaced // resource since cluster-scoped objects cannot have namespaced resources as @@ -280,7 +282,7 @@ func (o *CmdOptions) getObjectsByResources(apis []Resource) ([]unstructuredv1.Un defer wg.Done() objects, err := o.getObjectsByResource(r) if err != nil { - errResult = err + errors <- err return } mu.Lock() @@ -289,8 +291,13 @@ func (o *CmdOptions) getObjectsByResources(apis []Resource) ([]unstructuredv1.Un }(api) } wg.Wait() + close(errors) - return result, errResult + for err := range errors { + errResult = multierror.Append(errResult, err) + } + + return result, errResult.ErrorOrNil() } func (o *CmdOptions) getObjectsByResource(api Resource) ([]unstructuredv1.Unstructured, error) {