Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #945 from StrongMonkey/fix-image-client
Browse files Browse the repository at this point in the history
Fix port-forward use wrong client loader
  • Loading branch information
StrongMonkey authored Dec 18, 2019
2 parents 91e1c3c + 8b6e755 commit ff194c1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/images/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (i *Images) Run(ctx *clicontext.CLIContext) error {
if strings.HasPrefix(pod.Name, constants.BuildkitdService) {
readyChan := make(chan struct{})
go func() {
if err := localbuilder.PortForward(ctx.K8s, portForward, registryPort, pod, false, readyChan, localbuilder.ChanWrapper(ctx.Ctx.Done())); err != nil {
if err := localbuilder.PortForward(ctx.RestConfig, ctx.K8s, portForward, registryPort, pod, false, readyChan, localbuilder.ChanWrapper(ctx.Ctx.Done())); err != nil {
logrus.Fatal(err)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/linkerd/linkerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (l *Linkerd) Run(ctx *clicontext.CLIContext) error {
if err != nil {
return err
}
if err := localbuilder.PortForward(ctx.K8s, l.Port, webPort, pod, true, make(chan struct{}), localbuilder.ChanWrapper(ctx.Ctx.Done())); err != nil {
if err := localbuilder.PortForward(ctx.RestConfig, ctx.K8s, l.Port, webPort, pod, true, make(chan struct{}), localbuilder.ChanWrapper(ctx.Ctx.Done())); err != nil {
logrus.Fatal(err)
}
return err
Expand Down
7 changes: 5 additions & 2 deletions cli/pkg/localbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

var (
Expand All @@ -38,8 +39,9 @@ type RuntimeBuilder interface {
Build(ctx context.Context, spec riov1.ImageBuildSpec) (string, error)
}

func NewLocalBuilder(ctx context.Context, systemNamespace string, apply apply.Apply, k8s *kubernetes.Clientset) (LocalBuilder, error) {
func NewLocalBuilder(ctx context.Context, restConfig *rest.Config, systemNamespace string, apply apply.Apply, k8s *kubernetes.Clientset) (LocalBuilder, error) {
builder := &localBuilder{
restConfig: restConfig,
k8s: k8s,
apply: apply,
buildkitPort: generateRandomPort(),
Expand All @@ -52,6 +54,7 @@ func NewLocalBuilder(ctx context.Context, systemNamespace string, apply apply.Ap
}

type localBuilder struct {
restConfig *rest.Config
apply apply.Apply
k8s *kubernetes.Clientset
runtimeBuilder RuntimeBuilder
Expand Down Expand Up @@ -118,7 +121,7 @@ func (l localBuilder) setupPortforwarding(ctx context.Context) error {
break
}
}
if err := PortForward(l.k8s, l.buildkitPort, "8080", pod, false, readyChan, ChanWrapper(ctx.Done())); err != nil {
if err := PortForward(l.restConfig, l.k8s, l.buildkitPort, "8080", pod, false, readyChan, ChanWrapper(ctx.Done())); err != nil {
logrus.Fatal(err)
}
}()
Expand Down
8 changes: 1 addition & 7 deletions cli/pkg/localbuilder/port-forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"

"github.com/rancher/rio/pkg/generated/clientset/versioned/scheme"
"github.com/rancher/wrangler/pkg/kubeconfig"
appv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -20,12 +19,7 @@ import (
"k8s.io/kubectl/pkg/cmd/portforward"
)

func PortForward(k8s *kubernetes.Clientset, port, targetPort string, pod v1.Pod, stdOutAndErr bool, readyChan, stopChan chan struct{}) error {
loader := kubeconfig.GetInteractiveClientConfig(os.Getenv("KUBECONFIG"))
restConfig, err := loader.ClientConfig()
if err != nil {
return err
}
func PortForward(restConfig *rest.Config, k8s *kubernetes.Clientset, port, targetPort string, pod v1.Pod, stdOutAndErr bool, readyChan, stopChan chan struct{}) error {
if err := setConfigDefaults(restConfig); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/pkg/up/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Build(builds map[stack.ContainerBuildKey]riov1.ImageBuildSpec, c *clicontex
logrus.Warn(err)
}

localBuilder, err := localbuilder.NewLocalBuilder(c.Ctx, c.SystemNamespace, c.Apply, c.K8s)
localBuilder, err := localbuilder.NewLocalBuilder(c.Ctx, c.RestConfig, c.SystemNamespace, c.Apply, c.K8s)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ff194c1

Please sign in to comment.