Skip to content

Commit cea9170

Browse files
committed
allow multiple single connections
1 parent 1c85697 commit cea9170

File tree

4 files changed

+26
-45
lines changed

4 files changed

+26
-45
lines changed

KubeConnect/Args.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class Args
2525

2626
List<string> optionsWithArguments = new List<string>()
2727
{
28+
"port",
2829
"service",
2930
"namespace",
3031
"elevated-command",
@@ -72,6 +73,9 @@ public Args(string[] args)
7273
case "insecure-skip-tls-verify":
7374
KubeSkipSsl = bool.Parse(argNext);
7475
break;
76+
case "port":
77+
MainPort = int.Parse(argNext);
78+
break;
7579
case "skip-hosts":
7680
UpdateHosts = false;
7781
break;
@@ -186,7 +190,8 @@ private void ProcessArgs(string[] args, Func<string, string, string, bool> proce
186190

187191
}
188192
}
189-
193+
194+
public int MainPort { get; set; } = 10401;
190195
public bool EnableTraceLogs { get; set; } = false;
191196
public string? Namespace { get; set; }
192197
public string? KubeconfigFile { get; private set; }

KubeConnect/PortForwarding/PortForwarderHandlerSetup.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public PortForwarderHandlerSetup(ServiceManager manager, ILogger<PortForwarderHa
3434
public void Configure(KestrelServerOptions options)
3535
{
3636
options.ApplicationServices = serviceProvider;
37-
options.Listen(IPAddress.Loopback, Program.MainPort);
37+
options.Listen(IPAddress.Loopback, args.MainPort);
3838

3939
if (manager.IngressConfig.Enabled)
4040
{

KubeConnect/Program.cs

+2-26
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace KubeConnect
2222
{
2323
class Program
2424
{
25-
public static int MainPort = 10401;
2625
public static string CurrentVersion
2726
{
2827
get
@@ -97,35 +96,12 @@ _ __ _ ____ _
9796
const string semaphoreName = $"KubeConnect:FEC9031C-3BFD-4F5D-91D9-AC7B93074499";
9897
if (parseArgs.Action == Args.KubeConnectMode.Connect)
9998
{
100-
if (!CheckAvailableServerPort(MainPort))
99+
if (!CheckAvailableServerPort(parseArgs.MainPort))
101100
{
102101
console.WriteErrorLine("There is another instance of KubeConnect running exposing the cluster to your machine. Only once instance in 'connect' mode is allows at once.");
103102
return -1;
104103
}
105-
106-
//// skip the check if elivated as the host exe has already done
107-
//if (!parseArgs.Elevated)
108-
//{
109-
// var locker = new ProcessLock(semaphoreName);
110-
// if (!locker.Locked)
111-
// {
112-
// console.WriteErrorLine("There is another instance of KubeConnect running exposing the cluster to your machine. Only once instance in 'connect' mode is allows at once.");
113-
// return -1;
114-
// }
115-
//}
116104
}
117-
//else if (parseArgs.Action == Args.KubeConnectMode.Bridge)
118-
//{
119-
// // should we not auto elevate and launch connect as required???
120-
// using var locker = new ProcessLock(semaphoreName);
121-
122-
// if (locker.Locked)
123-
// {
124-
// console.WriteErrorLine("You must also be running a separate KubeConnect session in 'connect' mode to enable bridging across a service.");
125-
// return -1;
126-
// }
127-
//}
128-
129105

130106
if (parseArgs.Action == Args.KubeConnectMode.Connect)
131107
{
@@ -248,7 +224,7 @@ _ __ _ ____ _
248224
// lets call home first to see if the conenct server is running
249225

250226
var response = await new HttpClient()
251-
.GetAsync($"http://localhost:{MainPort}/status");
227+
.GetAsync($"http://localhost:{parseArgs.MainPort}/status");
252228

253229
if (!response.IsSuccessStatusCode)
254230
{
+17-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"profiles": {
3-
"KubeConnect": {
4-
"commandName": "Project",
5-
"commandLineArgs": "-x minikube"
6-
},
7-
"KubeConnect - bridge": {
8-
"commandName": "Project",
9-
"commandLineArgs": "bridge -service apphost"
10-
},
11-
"KubeConnect - run": {
12-
"commandName": "Project",
13-
"commandLineArgs": "bridge -service apphost -env IdentityServer__Certificate__Path=certificates/certificate.pfx -env IdentityServer__Certificate__Password=password -working-directory \"C:\\Source\\Work\\Hubl.AppHost\\src\\Hubl.AppHost\" -- dotnet run -- --ASPNETCORE_URLS=http://+:5562"
14-
},
15-
"KubeConnect-reduced": {
16-
"commandName": "Project",
17-
"commandLineArgs": "-x minikube -skip-hosts -http-only "
18-
}
2+
"profiles": {
3+
"KubeConnect": {
4+
"commandName": "Project",
5+
"commandLineArgs": "--insecure-skip-tls-verify=true --namespace=localdev"
6+
},
7+
"KubeConnect - bridge": {
8+
"commandName": "Project",
9+
"commandLineArgs": "bridge -service apphost"
10+
},
11+
"KubeConnect - run": {
12+
"commandName": "Project",
13+
"commandLineArgs": "bridge -service apphost -env IdentityServer__Certificate__Path=certificates/certificate.pfx -env IdentityServer__Certificate__Password=password -working-directory \"C:\\Source\\Work\\Hubl.AppHost\\src\\Hubl.AppHost\" -- dotnet run -- --ASPNETCORE_URLS=http://+:5562"
14+
},
15+
"KubeConnect-reduced": {
16+
"commandName": "Project",
17+
"commandLineArgs": "-x minikube -skip-hosts -http-only "
1918
}
19+
}
2020
}

0 commit comments

Comments
 (0)