Skip to content

Commit

Permalink
Use user's kubeconfig for cached auth tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipleblanc committed Sep 1, 2023
1 parent e266416 commit 6633162
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import bundledKubectlInjectable from "../../../kubectl/bundled-kubectl.injectabl
import getPortFromStreamInjectable from "../../../utils/get-port-from-stream.injectable";
import { loggerInjectionToken } from "@k8slens/logger";

export type CreatePortForward = (pathToKubeConfig: string, args: PortForwardArgs) => PortForward;
export type CreatePortForward = (pathToKubeConfig: string, kubeContext:string, args: PortForwardArgs) => PortForward;

const createPortForwardInjectable = getInjectable({
id: "create-port-forward",
Expand All @@ -21,7 +21,7 @@ const createPortForwardInjectable = getInjectable({
logger: di.inject(loggerInjectionToken),
};

return (pathToKubeConfig, args) => new PortForward(dependencies, pathToKubeConfig, args);
return (pathToKubeConfig, kubeContext, args) => new PortForward(dependencies, pathToKubeConfig, kubeContext, args);
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class PortForward {
public forwardPort: number;
public httpsProxy?: string;

constructor(private dependencies: PortForwardDependencies, public pathToKubeConfig: string, args: PortForwardArgs) {
constructor(private dependencies: PortForwardDependencies, public pathToKubeConfig: string, public kubeContext: string, args: PortForwardArgs) {
this.clusterId = args.clusterId;
this.kind = args.kind;
this.namespace = args.namespace;
Expand All @@ -66,6 +66,7 @@ export class PortForward {
const kubectlBin = await this.dependencies.getKubectlBinPath(true);
const args = [
"--kubeconfig", this.pathToKubeConfig,
"--context", this.kubeContext,
"port-forward",
"-n", this.namespace,
`${this.kind}/${this.name}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { PortForward } from "./functionality/port-forward";
import createPortForwardInjectable from "./functionality/create-port-forward.injectable";
import { clusterRoute } from "../../router/route";
import { loggerInjectionToken } from "@k8slens/logger";
import kubeconfigManagerInjectable from "../../kubeconfig-manager/kubeconfig-manager.injectable";

const startPortForwardRouteInjectable = getRouteInjectable({
id: "start-current-port-forward-route",
Expand All @@ -25,8 +24,6 @@ const startPortForwardRouteInjectable = getRouteInjectable({
const port = Number(query.get("port"));
const forwardPort = Number(query.get("forwardPort"));

const proxyKubeconfigManager = di.inject(kubeconfigManagerInjectable, cluster);

try {
let portForward = PortForward.getPortforward({
clusterId: cluster.id,
Expand All @@ -46,9 +43,7 @@ const startPortForwardRouteInjectable = getRouteInjectable({
const thePort = 0 < forwardPort && forwardPort < 65536
? forwardPort
: 0;
const proxyKubeconfigPath = await proxyKubeconfigManager.ensurePath();

portForward = createPortForward(proxyKubeconfigPath, {
portForward = createPortForward(cluster.kubeConfigPath.get(), cluster.contextName.get(),{
clusterId: cluster.id,
kind: resourceType,
namespace,
Expand Down

0 comments on commit 6633162

Please sign in to comment.