From 8175eeecf4798357850f680c324dd040614b3da1 Mon Sep 17 00:00:00 2001 From: Fabian Ruff Date: Tue, 21 Aug 2018 11:12:47 +0200 Subject: [PATCH] Avoid importing k8s.io/kubernetes from pkg/helm When writing a helm client (e.g. a helm plugin) that talks to tiller importing k8s.io/helm/pkg/helm to get the grpc client is key. This pkg should not have a dependency to the k8s.io/kubernetes to avoid pulling in a lot of code that is only used within tiller and blow up binary sizes. Signed-off-by: Fabian Ruff --- pkg/helm/fake.go | 8 ++++---- pkg/helm/helm_test.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/helm/fake.go b/pkg/helm/fake.go index ffb5b40c9..ca0c3c8c1 100644 --- a/pkg/helm/fake.go +++ b/pkg/helm/fake.go @@ -19,6 +19,7 @@ package helm // import "k8s.io/helm/pkg/helm" import ( "bytes" "errors" + "fmt" "math/rand" "strings" "sync" @@ -31,7 +32,6 @@ import ( rls "k8s.io/helm/pkg/proto/hapi/services" "k8s.io/helm/pkg/proto/hapi/version" "k8s.io/helm/pkg/renderutil" - storage "k8s.io/helm/pkg/storage/driver" ) // FakeClient implements Interface @@ -138,7 +138,7 @@ func (c *FakeClient) DeleteRelease(rlsName string, opts ...DeleteOption) (*rls.U } } - return nil, storage.ErrReleaseNotFound(rlsName) + return nil, fmt.Errorf("release: %q not found", rlsName) } // GetVersion returns a fake version @@ -212,7 +212,7 @@ func (c *FakeClient) ReleaseStatus(rlsName string, opts ...StatusOption) (*rls.G }, nil } } - return nil, storage.ErrReleaseNotFound(rlsName) + return nil, fmt.Errorf("release: %q not found", rlsName) } // ReleaseContent returns the configuration for the matching release name in the fake release client. @@ -224,7 +224,7 @@ func (c *FakeClient) ReleaseContent(rlsName string, opts ...ContentOption) (resp }, nil } } - return resp, storage.ErrReleaseNotFound(rlsName) + return resp, fmt.Errorf("release: %q not found", rlsName) } // ReleaseHistory returns a release's revision history. diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go index fe7150cc0..93d4256a5 100644 --- a/pkg/helm/helm_test.go +++ b/pkg/helm/helm_test.go @@ -18,8 +18,10 @@ package helm // import "k8s.io/helm/pkg/helm" import ( "errors" + "os/exec" "path/filepath" "reflect" + "strings" "testing" "github.com/golang/protobuf/proto" @@ -361,3 +363,15 @@ func loadChart(t *testing.T, name string) *cpb.Chart { } return c } + +func TestDoesNotImportKubernetes(t *testing.T) { + cmd := exec.Command("go", "list", "-f", "{{.Deps}}", ".") + output, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("Failed to execute %s %s: %s", cmd.Path, strings.Join(cmd.Args, " "), err) + } + + if strings.Contains(string(output), "k8s.io/kubernetes") { + t.Fatal("k8s.io/helm/pkg/helm contains a dependency on k8s.io/kubernetes") + } +}