Skip to content

Commit

Permalink
refactor pkg/kubernetes to mirror k8s.io/client-go/kubernetes symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
0xch4z committed Apr 28, 2020
1 parent e0f96e8 commit c9cf646
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
17 changes: 4 additions & 13 deletions internal/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package kubernetes

import (
"context"
"encoding/base64"
"fmt"

"k8s.io/client-go/kubernetes"
Expand All @@ -13,22 +11,15 @@ import (
// Clientset is an alias to k8s.io/client-go/kubernetes.Interface
type Clientset kubernetes.Interface

// buildClientsetFromConfigBytes builds a Clientset from a given Kubeconfig
// from the Linode API.
// NewClientsetFromBytes builds a Clientset from a given Kubeconfig.
//
// Takes an optional transport.WrapperFunc to add request/response middleware to
// api-server requests.
func BuildClientsetFromConfigBytes(
ctx context.Context,
kubeconfig string,
func BuildClientsetFromConfig(
kubeconfigBytes []byte,
transportWrapper transport.WrapperFunc,
) (Clientset, error) {
kubeConfigBytes, err := base64.StdEncoding.DecodeString(kubeconfig)
if err != nil {
return nil, fmt.Errorf("failed to decode kubeconfig: %s", err)
}

config, err := clientcmd.NewClientConfigFromBytes(kubeConfigBytes)
config, err := clientcmd.NewClientConfigFromBytes(kubeconfigBytes)
if err != nil {
return nil, fmt.Errorf("failed to parse LKE cluster kubeconfig: %s", err)
}
Expand Down
8 changes: 7 additions & 1 deletion waitfor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package linodego

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -228,7 +229,12 @@ func (client Client) WaitForLKEClusterConditions(
return false, fmt.Errorf("failed to get Kubeconfig for LKE cluster %d: %s", clusterID, err)
}

clientset, err = kubernetes.BuildClientsetFromConfigBytes(ctx, resp.KubeConfig, options.TransportWrapper)
kubeConfigBytes, err := base64.StdEncoding.DecodeString(resp.KubeConfig)
if err != nil {
return false, fmt.Errorf("failed to decode kubeconfig: %s", err)
}

clientset, err = kubernetes.BuildClientsetFromConfig(kubeConfigBytes, options.TransportWrapper)
if err != nil {
return false, fmt.Errorf("failed to build client for LKE cluster %d: %s", clusterID, err)
}
Expand Down

0 comments on commit c9cf646

Please sign in to comment.