ref(*): remove pkg/kubernetes from tiller and storage

pull/3945/head
Adam Reese 7 years ago
parent 496ca54183
commit fc4c095cf0
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -169,15 +169,16 @@ func ensureHelmClient(h helm.Interface) helm.Interface {
}
func newClient() helm.Interface {
clientset, err := kube.New(nil).ClientSet()
_, clientset, err := getKubeClient(settings.KubeContext)
if err != nil {
// TODO return error
panic(err)
}
// TODO add other backends
cfgmaps := driver.NewConfigMaps(clientset.Core().ConfigMaps(settings.TillerNamespace))
return helm.NewClient(
helm.Driver(cfgmaps),
helm.ClientSet(clientset),
helm.Discovery(clientset.Discovery()),
)
}

@ -26,7 +26,6 @@ import (
"github.com/spf13/cobra"
"k8s.io/helm/pkg/chartutil"
"k8s.io/kubernetes/pkg/util/slice"
)
const inspectDesc = `
@ -256,9 +255,11 @@ func (i *inspectCmd) run() error {
func findReadme(files []*any.Any) (file *any.Any) {
for _, file := range files {
if slice.ContainsString(readmeFileNames, strings.ToLower(file.TypeUrl), nil) {
for _, n := range readmeFileNames {
if strings.EqualFold(file.TypeUrl, n) {
return file
}
}
}
return nil
}

@ -57,7 +57,7 @@ func (c *Client) init() *Client {
// TODO
env.KubeClient = kube.New(nil)
c.tiller = tiller.NewReleaseServer(env, c.opts.clientset)
c.tiller = tiller.NewReleaseServer(env, c.opts.discovery)
return c
}

@ -18,7 +18,7 @@ package helm
import (
"github.com/golang/protobuf/proto"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/client-go/discovery"
cpb "k8s.io/helm/pkg/proto/hapi/chart"
"k8s.io/helm/pkg/proto/hapi/release"
@ -71,7 +71,7 @@ type options struct {
testReq rls.TestReleaseRequest
driver driver.Driver
clientset internalclientset.Interface
discovery discovery.DiscoveryInterface
}
func (opts *options) runBefore(msg proto.Message) error {
@ -380,8 +380,8 @@ func Driver(d driver.Driver) Option {
}
}
func ClientSet(cs internalclientset.Interface) Option {
func Discovery(dc discovery.DiscoveryInterface) Option {
return func(opts *options) {
opts.clientset = cs
opts.discovery = dc
}
}

@ -22,12 +22,12 @@ import (
"strings"
"time"
"k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kblabels "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
rspb "k8s.io/helm/pkg/proto/hapi/release"
)
@ -40,13 +40,13 @@ const ConfigMapsDriverName = "ConfigMap"
// ConfigMaps is a wrapper around an implementation of a kubernetes
// ConfigMapsInterface.
type ConfigMaps struct {
impl internalversion.ConfigMapInterface
impl corev1.ConfigMapInterface
Log func(string, ...interface{})
}
// NewConfigMaps initializes a new ConfigMaps wrapping an implementation of
// the kubernetes ConfigMapsInterface.
func NewConfigMaps(impl internalversion.ConfigMapInterface) *ConfigMaps {
func NewConfigMaps(impl corev1.ConfigMapInterface) *ConfigMaps {
return &ConfigMaps{
impl: impl,
Log: func(_ string, _ ...interface{}) {},
@ -228,7 +228,7 @@ func (cfgmaps *ConfigMaps) Delete(key string) (rls *rspb.Release, err error) {
// "OWNER" - owner of the configmap, currently "TILLER".
// "NAME" - name of the release.
//
func newConfigMapsObject(key string, rls *rspb.Release, lbs labels) (*core.ConfigMap, error) {
func newConfigMapsObject(key string, rls *rspb.Release, lbs labels) (*v1.ConfigMap, error) {
const owner = "TILLER"
// encode the release
@ -248,7 +248,7 @@ func newConfigMapsObject(key string, rls *rspb.Release, lbs labels) (*core.Confi
lbs.set("VERSION", strconv.Itoa(int(rls.Version)))
// create and return configmap object
return &core.ConfigMap{
return &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: key,
Labels: lbs.toMap(),

@ -19,7 +19,8 @@ import (
"testing"
"github.com/gogo/protobuf/proto"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/api/core/v1"
rspb "k8s.io/helm/pkg/proto/hapi/release"
)
@ -69,7 +70,7 @@ func TestUNcompressedConfigMapGet(t *testing.T) {
}
cfgmap.Data["release"] = base64.StdEncoding.EncodeToString(b)
var mock MockConfigMapsInterface
mock.objects = map[string]*core.ConfigMap{key: cfgmap}
mock.objects = map[string]*v1.ConfigMap{key: cfgmap}
cfgmaps := NewConfigMaps(&mock)
// get release with key

@ -20,10 +20,10 @@ import (
"fmt"
"testing"
"k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
rspb "k8s.io/helm/pkg/proto/hapi/release"
)
@ -76,14 +76,14 @@ func newTestFixtureCfgMaps(t *testing.T, releases ...*rspb.Release) *ConfigMaps
// MockConfigMapsInterface mocks a kubernetes ConfigMapsInterface
type MockConfigMapsInterface struct {
internalversion.ConfigMapInterface
corev1.ConfigMapInterface
objects map[string]*core.ConfigMap
objects map[string]*v1.ConfigMap
}
// Init initializes the MockConfigMapsInterface with the set of releases.
func (mock *MockConfigMapsInterface) Init(t *testing.T, releases ...*rspb.Release) {
mock.objects = map[string]*core.ConfigMap{}
mock.objects = map[string]*v1.ConfigMap{}
for _, rls := range releases {
objkey := testKey(rls.Name, rls.Version)
@ -97,17 +97,17 @@ func (mock *MockConfigMapsInterface) Init(t *testing.T, releases ...*rspb.Releas
}
// Get returns the ConfigMap by name.
func (mock *MockConfigMapsInterface) Get(name string, options metav1.GetOptions) (*core.ConfigMap, error) {
func (mock *MockConfigMapsInterface) Get(name string, options metav1.GetOptions) (*v1.ConfigMap, error) {
object, ok := mock.objects[name]
if !ok {
return nil, apierrors.NewNotFound(core.Resource("tests"), name)
return nil, apierrors.NewNotFound(v1.Resource("tests"), name)
}
return object, nil
}
// List returns the a of ConfigMaps.
func (mock *MockConfigMapsInterface) List(opts metav1.ListOptions) (*core.ConfigMapList, error) {
var list core.ConfigMapList
func (mock *MockConfigMapsInterface) List(opts metav1.ListOptions) (*v1.ConfigMapList, error) {
var list v1.ConfigMapList
for _, cfgmap := range mock.objects {
list.Items = append(list.Items, *cfgmap)
}
@ -115,20 +115,20 @@ func (mock *MockConfigMapsInterface) List(opts metav1.ListOptions) (*core.Config
}
// Create creates a new ConfigMap.
func (mock *MockConfigMapsInterface) Create(cfgmap *core.ConfigMap) (*core.ConfigMap, error) {
func (mock *MockConfigMapsInterface) Create(cfgmap *v1.ConfigMap) (*v1.ConfigMap, error) {
name := cfgmap.ObjectMeta.Name
if object, ok := mock.objects[name]; ok {
return object, apierrors.NewAlreadyExists(core.Resource("tests"), name)
return object, apierrors.NewAlreadyExists(v1.Resource("tests"), name)
}
mock.objects[name] = cfgmap
return cfgmap, nil
}
// Update updates a ConfigMap.
func (mock *MockConfigMapsInterface) Update(cfgmap *core.ConfigMap) (*core.ConfigMap, error) {
func (mock *MockConfigMapsInterface) Update(cfgmap *v1.ConfigMap) (*v1.ConfigMap, error) {
name := cfgmap.ObjectMeta.Name
if _, ok := mock.objects[name]; !ok {
return nil, apierrors.NewNotFound(core.Resource("tests"), name)
return nil, apierrors.NewNotFound(v1.Resource("tests"), name)
}
mock.objects[name] = cfgmap
return cfgmap, nil
@ -137,7 +137,7 @@ func (mock *MockConfigMapsInterface) Update(cfgmap *core.ConfigMap) (*core.Confi
// Delete deletes a ConfigMap by name.
func (mock *MockConfigMapsInterface) Delete(name string, opts *metav1.DeleteOptions) error {
if _, ok := mock.objects[name]; !ok {
return apierrors.NewNotFound(core.Resource("tests"), name)
return apierrors.NewNotFound(v1.Resource("tests"), name)
}
delete(mock.objects, name)
return nil
@ -154,14 +154,14 @@ func newTestFixtureSecrets(t *testing.T, releases ...*rspb.Release) *Secrets {
// MockSecretsInterface mocks a kubernetes SecretsInterface
type MockSecretsInterface struct {
internalversion.SecretInterface
corev1.SecretInterface
objects map[string]*core.Secret
objects map[string]*v1.Secret
}
// Init initializes the MockSecretsInterface with the set of releases.
func (mock *MockSecretsInterface) Init(t *testing.T, releases ...*rspb.Release) {
mock.objects = map[string]*core.Secret{}
mock.objects = map[string]*v1.Secret{}
for _, rls := range releases {
objkey := testKey(rls.Name, rls.Version)
@ -175,17 +175,17 @@ func (mock *MockSecretsInterface) Init(t *testing.T, releases ...*rspb.Release)
}
// Get returns the Secret by name.
func (mock *MockSecretsInterface) Get(name string, options metav1.GetOptions) (*core.Secret, error) {
func (mock *MockSecretsInterface) Get(name string, options metav1.GetOptions) (*v1.Secret, error) {
object, ok := mock.objects[name]
if !ok {
return nil, apierrors.NewNotFound(core.Resource("tests"), name)
return nil, apierrors.NewNotFound(v1.Resource("tests"), name)
}
return object, nil
}
// List returns the a of Secret.
func (mock *MockSecretsInterface) List(opts metav1.ListOptions) (*core.SecretList, error) {
var list core.SecretList
func (mock *MockSecretsInterface) List(opts metav1.ListOptions) (*v1.SecretList, error) {
var list v1.SecretList
for _, secret := range mock.objects {
list.Items = append(list.Items, *secret)
}
@ -193,20 +193,20 @@ func (mock *MockSecretsInterface) List(opts metav1.ListOptions) (*core.SecretLis
}
// Create creates a new Secret.
func (mock *MockSecretsInterface) Create(secret *core.Secret) (*core.Secret, error) {
func (mock *MockSecretsInterface) Create(secret *v1.Secret) (*v1.Secret, error) {
name := secret.ObjectMeta.Name
if object, ok := mock.objects[name]; ok {
return object, apierrors.NewAlreadyExists(core.Resource("tests"), name)
return object, apierrors.NewAlreadyExists(v1.Resource("tests"), name)
}
mock.objects[name] = secret
return secret, nil
}
// Update updates a Secret.
func (mock *MockSecretsInterface) Update(secret *core.Secret) (*core.Secret, error) {
func (mock *MockSecretsInterface) Update(secret *v1.Secret) (*v1.Secret, error) {
name := secret.ObjectMeta.Name
if _, ok := mock.objects[name]; !ok {
return nil, apierrors.NewNotFound(core.Resource("tests"), name)
return nil, apierrors.NewNotFound(v1.Resource("tests"), name)
}
mock.objects[name] = secret
return secret, nil
@ -215,7 +215,7 @@ func (mock *MockSecretsInterface) Update(secret *core.Secret) (*core.Secret, err
// Delete deletes a Secret by name.
func (mock *MockSecretsInterface) Delete(name string, opts *metav1.DeleteOptions) error {
if _, ok := mock.objects[name]; !ok {
return apierrors.NewNotFound(core.Resource("tests"), name)
return apierrors.NewNotFound(v1.Resource("tests"), name)
}
delete(mock.objects, name)
return nil

@ -22,12 +22,12 @@ import (
"strings"
"time"
"k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kblabels "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
rspb "k8s.io/helm/pkg/proto/hapi/release"
)
@ -40,13 +40,13 @@ const SecretsDriverName = "Secret"
// Secrets is a wrapper around an implementation of a kubernetes
// SecretsInterface.
type Secrets struct {
impl internalversion.SecretInterface
impl corev1.SecretInterface
Log func(string, ...interface{})
}
// NewSecrets initializes a new Secrets wrapping an implmenetation of
// the kubernetes SecretsInterface.
func NewSecrets(impl internalversion.SecretInterface) *Secrets {
func NewSecrets(impl corev1.SecretInterface) *Secrets {
return &Secrets{
impl: impl,
Log: func(_ string, _ ...interface{}) {},
@ -228,7 +228,7 @@ func (secrets *Secrets) Delete(key string) (rls *rspb.Release, err error) {
// "OWNER" - owner of the secret, currently "TILLER".
// "NAME" - name of the release.
//
func newSecretsObject(key string, rls *rspb.Release, lbs labels) (*core.Secret, error) {
func newSecretsObject(key string, rls *rspb.Release, lbs labels) (*v1.Secret, error) {
const owner = "TILLER"
// encode the release
@ -248,7 +248,7 @@ func newSecretsObject(key string, rls *rspb.Release, lbs labels) (*core.Secret,
lbs.set("VERSION", strconv.Itoa(int(rls.Version)))
// create and return secret object
return &core.Secret{
return &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: key,
Labels: lbs.toMap(),

@ -19,7 +19,8 @@ import (
"testing"
"github.com/gogo/protobuf/proto"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/api/core/v1"
rspb "k8s.io/helm/pkg/proto/hapi/release"
)
@ -69,7 +70,7 @@ func TestUNcompressedSecretGet(t *testing.T) {
}
secret.Data["release"] = []byte(base64.StdEncoding.EncodeToString(b))
var mock MockSecretsInterface
mock.objects = map[string]*core.Secret{key: secret}
mock.objects = map[string]*v1.Secret{key: secret}
secrets := NewSecrets(&mock)
// get release with key

@ -62,7 +62,7 @@ func (s *ReleaseServer) prepareRelease(req *services.InstallReleaseRequest) (*re
return nil, err
}
caps, err := capabilities(s.clientset.Discovery())
caps, err := capabilities(s.discovery)
if err != nil {
return nil, err
}

@ -29,7 +29,6 @@ import (
"gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/discovery"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/hooks"
@ -85,15 +84,15 @@ var ValidName = regexp.MustCompile("^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])+
// ReleaseServer implements the server-side gRPC endpoint for the HAPI services.
type ReleaseServer struct {
env *environment.Environment
clientset internalclientset.Interface
discovery discovery.DiscoveryInterface
Log func(string, ...interface{})
}
// NewReleaseServer creates a new release server.
func NewReleaseServer(env *environment.Environment, clientset internalclientset.Interface) *ReleaseServer {
func NewReleaseServer(env *environment.Environment, discovery discovery.DiscoveryInterface) *ReleaseServer {
return &ReleaseServer{
env: env,
clientset: clientset,
discovery: discovery,
Log: func(_ string, _ ...interface{}) {},
}
}
@ -466,7 +465,7 @@ func (m *ReleaseServer) Status(r *release.Release, req *services.GetReleaseStatu
// Delete deletes the release and returns manifests that were kept in the deletion process
func (m *ReleaseServer) Delete(rel *release.Release, req *services.UninstallReleaseRequest, env *environment.Environment) (kept string, errs []error) {
vs, err := GetVersionSet(m.clientset.Discovery())
vs, err := GetVersionSet(m.discovery)
if err != nil {
return rel.Manifest, []error{fmt.Errorf("Could not get apiVersions from Kubernetes: %v", err)}
}

@ -30,8 +30,8 @@ import (
"github.com/golang/protobuf/ptypes/timestamp"
"golang.org/x/net/context"
"google.golang.org/grpc/metadata"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/helm/pkg/hooks"
@ -93,10 +93,10 @@ data:
`
func rsFixture() *ReleaseServer {
clientset := fake.NewSimpleClientset()
dc := fake.NewSimpleClientset().Discovery()
return &ReleaseServer{
env: MockEnvironment(),
clientset: clientset,
discovery: dc,
Log: func(_ string, _ ...interface{}) {},
}
}
@ -309,7 +309,7 @@ func TestValidName(t *testing.T) {
func TestGetVersionSet(t *testing.T) {
rs := rsFixture()
vs, err := GetVersionSet(rs.clientset.Discovery())
vs, err := GetVersionSet(rs.discovery)
if err != nil {
t.Error(err)
}
@ -524,10 +524,10 @@ func deletePolicyStub(kubeClient *mockHooksKubeClient) *ReleaseServer {
e.Releases = storage.Init(driver.NewMemory())
e.KubeClient = kubeClient
clientset := fake.NewSimpleClientset()
dc := fake.NewSimpleClientset().Discovery()
return &ReleaseServer{
env: e,
clientset: clientset,
discovery: dc,
Log: func(_ string, _ ...interface{}) {},
}
}

@ -102,7 +102,7 @@ func (s *ReleaseServer) prepareUpdate(req *services.UpdateReleaseRequest) (*rele
Revision: int(revision),
}
caps, err := capabilities(s.clientset.Discovery())
caps, err := capabilities(s.discovery)
if err != nil {
return nil, nil, err
}

Loading…
Cancel
Save