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 <fabian@progra.de>
pull/4499/head
Fabian Ruff 7 years ago
parent 2e9855b98b
commit 8175eeecf4

@ -19,6 +19,7 @@ package helm // import "k8s.io/helm/pkg/helm"
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"math/rand" "math/rand"
"strings" "strings"
"sync" "sync"
@ -31,7 +32,6 @@ import (
rls "k8s.io/helm/pkg/proto/hapi/services" rls "k8s.io/helm/pkg/proto/hapi/services"
"k8s.io/helm/pkg/proto/hapi/version" "k8s.io/helm/pkg/proto/hapi/version"
"k8s.io/helm/pkg/renderutil" "k8s.io/helm/pkg/renderutil"
storage "k8s.io/helm/pkg/storage/driver"
) )
// FakeClient implements Interface // 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 // GetVersion returns a fake version
@ -212,7 +212,7 @@ func (c *FakeClient) ReleaseStatus(rlsName string, opts ...StatusOption) (*rls.G
}, nil }, 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. // 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 }, nil
} }
} }
return resp, storage.ErrReleaseNotFound(rlsName) return resp, fmt.Errorf("release: %q not found", rlsName)
} }
// ReleaseHistory returns a release's revision history. // ReleaseHistory returns a release's revision history.

@ -18,8 +18,10 @@ package helm // import "k8s.io/helm/pkg/helm"
import ( import (
"errors" "errors"
"os/exec"
"path/filepath" "path/filepath"
"reflect" "reflect"
"strings"
"testing" "testing"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
@ -361,3 +363,15 @@ func loadChart(t *testing.T, name string) *cpb.Chart {
} }
return c 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")
}
}

Loading…
Cancel
Save