Add utility function to get port forwarded tiller hostname

I didn't change any binaries to use this to minimize possible conflicts.
Main purpose of adding this is to simplify external developers creating
a helm client.
pull/3580/head
Chad Ostler 8 years ago
parent 293a0b7a10
commit e01332404c

@ -17,6 +17,7 @@ limitations under the License.
package helm // import "k8s.io/helm/pkg/helm" package helm // import "k8s.io/helm/pkg/helm"
import ( import (
"fmt"
"io" "io"
"time" "time"
@ -25,9 +26,14 @@ import (
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive" "google.golang.org/grpc/keepalive"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/helm/portforwarder"
"k8s.io/helm/pkg/kube"
"k8s.io/helm/pkg/proto/hapi/chart" "k8s.io/helm/pkg/proto/hapi/chart"
rls "k8s.io/helm/pkg/proto/hapi/services" rls "k8s.io/helm/pkg/proto/hapi/services"
"k8s.io/helm/pkg/tiller/environment"
) )
// maxMsgSize use 20MB as the default message size limit. // maxMsgSize use 20MB as the default message size limit.
@ -39,6 +45,32 @@ type Client struct {
opts options opts options
} }
// TillerHost returns a port forwarded tiller hostname
func TillerHost(namespace, context string) (string, error) {
config, err := rest.InClusterConfig()
if err != nil {
config, err = kube.GetConfig(context).ClientConfig()
}
if err != nil {
return "", fmt.Errorf("could not get Kubernetes config for context %q: %s", context, err)
}
client, err := kubernetes.NewForConfig(config)
if err != nil {
return "", fmt.Errorf("could not get Kubernetes client: %s", err)
}
if namespace == "" {
namespace = environment.DefaultTillerNamespace
}
tunnel, err := portforwarder.New(namespace, client, config)
if err != nil {
return "", err
}
return fmt.Sprintf("127.0.0.1:%d", tunnel.Local), nil
}
// NewClient creates a new client. // NewClient creates a new client.
func NewClient(opts ...Option) *Client { func NewClient(opts ...Option) *Client {
var c Client var c Client

Loading…
Cancel
Save