ref(kube): refactor kubeclient to a struct

pull/635/head
Adam Reese 9 years ago
parent c44f0b0b01
commit 0b6309be02

@ -43,7 +43,7 @@ func (i *Installer) Install() error {
return err return err
} }
return kube.Create("helm", &b, nil) return kube.New(nil).Create("helm", &b)
} }
// InstallYAML is the installation YAML for DM. // InstallYAML is the installation YAML for DM.

@ -9,7 +9,17 @@ import (
"k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/kubectl/resource"
) )
const includeThirdPartyAPIs = false // Client represents a client capable of communicating with the Kubernetes API.
type Client struct {
config clientcmd.ClientConfig
}
// New create a new Client
func New(config clientcmd.ClientConfig) *Client {
return &Client{
config: config,
}
}
// ResourceActorFunc performs an action on a signle resource. // ResourceActorFunc performs an action on a signle resource.
type ResourceActorFunc func(*resource.Info) error type ResourceActorFunc func(*resource.Info) error
@ -17,12 +27,13 @@ type ResourceActorFunc func(*resource.Info) error
// Create creates kubernetes resources from an io.reader // Create creates kubernetes resources from an io.reader
// //
// Namespace will set the namespace // Namespace will set the namespace
// Config allows for overiding values from kubectl func (c *Client) Create(namespace string, reader io.Reader) error {
func Create(namespace string, reader io.Reader, config clientcmd.ClientConfig) error { f := cmdutil.NewFactory(c.config)
f := cmdutil.NewFactory(config)
return perform(f, namespace, reader, createResource) return perform(f, namespace, reader, createResource)
} }
const includeThirdPartyAPIs = false
func perform(f *cmdutil.Factory, namespace string, reader io.Reader, fn ResourceActorFunc) error { func perform(f *cmdutil.Factory, namespace string, reader io.Reader, fn ResourceActorFunc) error {
r := f.NewBuilder(includeThirdPartyAPIs). r := f.NewBuilder(includeThirdPartyAPIs).
ContinueOnError(). ContinueOnError().

Loading…
Cancel
Save