Removes clientset method from interface in favor of the configuration struct

Signed-off-by: Taylor Thomas <taylor.thomas@microsoft.com>
pull/6085/head
Taylor Thomas 5 years ago
parent 189b5a1229
commit dd8222d7f2

@ -82,7 +82,7 @@ func initActionConfig(actionConfig *action.Configuration, allNamespaces bool) {
kc := kube.New(kubeConfig())
kc.Log = logf
clientset, err := kc.KubernetesClientSet()
clientset, err := kc.Factory.KubernetesClientSet()
if err != nil {
// TODO return error
log.Fatal(err)

@ -27,6 +27,7 @@ import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"helm.sh/helm/pkg/chartutil"
@ -114,6 +115,15 @@ func (c *Configuration) getCapabilities() (*chartutil.Capabilities, error) {
return c.Capabilities, nil
}
func (c *Configuration) KubernetesClientSet() (kubernetes.Interface, error) {
conf, err := c.RESTClientGetter.ToRESTConfig()
if err != nil {
return nil, errors.Wrap(err, "unable to generate config for kubernetes client")
}
return kubernetes.NewForConfig(conf)
}
// Now generates a timestamp
//
// If the configuration has a Timestamper on it, that will be used.

@ -172,7 +172,7 @@ func (r *Rollback) performRollback(currentRelease, targetRelease *release.Releas
// log if an error occurs and continue onward. If we ever introduce log
// levels, we should make these error level logs so users are notified
// that they'll need to go do the cleanup on their own
if err := recreate(r.cfg.KubeClient, results.Updated); err != nil {
if err := recreate(r.cfg, results.Updated); err != nil {
r.cfg.Log(err.Error())
}
}

@ -228,7 +228,7 @@ func (u *Upgrade) performUpgrade(originalRelease, upgradedRelease *release.Relea
// log if an error occurs and continue onward. If we ever introduce log
// levels, we should make these error level logs so users are notified
// that they'll need to go do the cleanup on their own
if err := recreate(u.cfg.KubeClient, results.Updated); err != nil {
if err := recreate(u.cfg, results.Updated); err != nil {
u.cfg.Log(err.Error())
}
}
@ -349,7 +349,7 @@ func validateManifest(c kube.Interface, manifest []byte) error {
// recreate captures all the logic for recreating pods for both upgrade and
// rollback. If we end up refactoring rollback to use upgrade, this can just be
// made an unexported method on the upgrade action.
func recreate(client kube.Interface, resources kube.ResourceList) error {
func recreate(cfg *Configuration, resources kube.ResourceList) error {
for _, res := range resources {
versioned := kube.AsVersioned(res)
selector, err := kube.SelectorsForObject(versioned)
@ -359,7 +359,7 @@ func recreate(client kube.Interface, resources kube.ResourceList) error {
continue
}
client, err := client.KubernetesClientSet()
client, err := cfg.KubernetesClientSet()
if err != nil {
return errors.Wrapf(err, "unable to recreate pods for object %s/%s because an error occurred", res.Namespace, res.Name)
}

@ -38,7 +38,6 @@ import (
"k8s.io/apimachinery/pkg/watch"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/kubernetes"
watchtools "k8s.io/client-go/tools/watch"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
@ -63,11 +62,6 @@ func New(getter genericclioptions.RESTClientGetter) *Client {
}
}
// KubernetesClientSet returns a client set from the client factory.
func (c *Client) KubernetesClientSet() (kubernetes.Interface, error) {
return c.Factory.KubernetesClientSet()
}
var nopLogger = func(_ string, _ ...interface{}) {}
// Create creates Kubernetes resources specified in the resource list.
@ -81,7 +75,7 @@ func (c *Client) Create(resources ResourceList) (*Result, error) {
// Wait up to the given timeout for the specified resources to be ready
func (c *Client) Wait(resources ResourceList, timeout time.Duration) error {
cs, err := c.KubernetesClientSet()
cs, err := c.Factory.KubernetesClientSet()
if err != nil {
return err
}
@ -109,14 +103,6 @@ func (c *Client) newBuilder() *resource.Builder {
Flatten()
}
func (c *Client) validator() resource.ContentValidator {
schema, err := c.Factory.Validator(true)
if err != nil {
c.Log("warning: failed to load schema: %s", err)
}
return schema
}
// Build validates for Kubernetes objects and returns unstructured infos.
func (c *Client) Build(reader io.Reader) (ResourceList, error) {
result, err := c.newBuilder().
@ -452,7 +438,7 @@ func scrubValidationError(err error) error {
// WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase
// and returns said phase (PodSucceeded or PodFailed qualify).
func (c *Client) WaitAndGetCompletedPodPhase(name string, timeout time.Duration) (v1.PodPhase, error) {
client, _ := c.KubernetesClientSet()
client, _ := c.Factory.KubernetesClientSet()
to := int64(timeout)
watcher, err := client.CoreV1().Pods(c.namespace()).Watch(metav1.ListOptions{
FieldSelector: fmt.Sprintf("metadata.name=%s", name),

@ -327,14 +327,6 @@ spec:
targetPort: 9376
`
const testInvalidServiceManifest = `
kind: Service
apiVersion: v1
spec:
ports:
- port: "80"
`
const testEndpointManifest = `
kind: Endpoints
apiVersion: v1

@ -23,7 +23,6 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/kubernetes"
"helm.sh/helm/pkg/kube"
)
@ -91,11 +90,6 @@ func (f *FailingKubeClient) Build(r io.Reader) (kube.ResourceList, error) {
return f.PrintingKubeClient.Build(r)
}
// KubernetesClientSet implements the KubeClient interface
func (f *FailingKubeClient) KubernetesClientSet() (kubernetes.Interface, error) {
return f.PrintingKubeClient.KubernetesClientSet()
}
// WaitAndGetCompletedPodPhase returns the configured error if set or prints
func (f *FailingKubeClient) WaitAndGetCompletedPodPhase(s string, d time.Duration) (v1.PodPhase, error) {
if f.WaitAndGetCompletedPodPhaseError != nil {

@ -23,8 +23,6 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
"helm.sh/helm/pkg/kube"
)
@ -88,11 +86,6 @@ func (p *PrintingKubeClient) WaitAndGetCompletedPodPhase(_ string, _ time.Durati
return v1.PodSucceeded, nil
}
// KubernetesClientSet implements the KubeClient interface
func (p *PrintingKubeClient) KubernetesClientSet() (kubernetes.Interface, error) {
return fake.NewSimpleClientset(), nil
}
func bufferize(resources kube.ResourceList) io.Reader {
var builder strings.Builder
for _, info := range resources {

@ -21,7 +21,6 @@ import (
"time"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
)
// KubernetesClient represents a client capable of communicating with the Kubernetes API.
@ -56,9 +55,6 @@ type Interface interface {
// WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase
// and returns said phase (PodSucceeded or PodFailed qualify).
WaitAndGetCompletedPodPhase(name string, timeout time.Duration) (v1.PodPhase, error)
// KubernetesClientSet returns the underlying kubernetes clientset
KubernetesClientSet() (kubernetes.Interface, error)
}
var _ Interface = (*Client)(nil)

Loading…
Cancel
Save