Skip to content

Commit

Permalink
Merge pull request #6 from lzambarda/develop
Browse files Browse the repository at this point in the history
feat: add support for k8s context
  • Loading branch information
lzambarda authored Aug 2, 2022
2 parents b340e8c + caf02d2 commit 922818d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BUILDFLAGS:="-s -w -X github.com/lzambarda/$(NAME)/internal.Version=$(build_tag)

.PHONY: dependencies
dependencies: ## Install test and build dependencies
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.0
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

.PHONY: lint
lint: ## Hmmm, lint?
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/lzambarda/tmancer

go 1.17
go 1.18

require (
github.com/ahmetb/go-cursor v0.0.0-20131010032410-8136607ea412
Expand Down
8 changes: 7 additions & 1 deletion internal/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var signalRegex = regexp.MustCompile(`signal: ([a-z ]+)$`)

// K8sInfo contains all information required to use a kubectl port forward command.
type K8sInfo struct {
Context string `json:"context"`
Namespace string `json:"namespace"`
Service string `json:"service"`
Port int `json:"port"`
Expand Down Expand Up @@ -48,7 +49,12 @@ func (c *TunnelConfig) GetType() string {
//nolint:gosec // I'm happy for now.
func (c *TunnelConfig) getCommand(ctx context.Context) (*exec.Cmd, error) {
if c.K8s != nil {
return exec.CommandContext(ctx, "kubectl", "port-forward", "-n", c.K8s.Namespace, c.K8s.Service, fmt.Sprintf("%d:%d", c.LocalPort, c.K8s.Port)), nil
args := []string{"port-forward", "-n", c.K8s.Namespace}
if c.K8s.Context != "" {
args = append(args, "--context", c.K8s.Context)
}
args = append(args, c.K8s.Service, fmt.Sprintf("%d:%d", c.LocalPort, c.K8s.Port))
return exec.CommandContext(ctx, "kubectl", args...), nil
}
if c.Custom != "" {
parts := strings.Split(c.Custom, " ")
Expand Down

0 comments on commit 922818d

Please sign in to comment.