Skip to content

Commit

Permalink
allow multiple single connections
Browse files Browse the repository at this point in the history
  • Loading branch information
tocsoft committed Nov 27, 2023
1 parent 1c85697 commit cea9170
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 45 deletions.
7 changes: 6 additions & 1 deletion KubeConnect/Args.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Args

List<string> optionsWithArguments = new List<string>()
{
"port",
"service",
"namespace",
"elevated-command",
Expand Down Expand Up @@ -72,6 +73,9 @@ public Args(string[] args)
case "insecure-skip-tls-verify":
KubeSkipSsl = bool.Parse(argNext);
break;
case "port":
MainPort = int.Parse(argNext);
break;
case "skip-hosts":
UpdateHosts = false;
break;
Expand Down Expand Up @@ -186,7 +190,8 @@ private void ProcessArgs(string[] args, Func<string, string, string, bool> proce

}
}


public int MainPort { get; set; } = 10401;
public bool EnableTraceLogs { get; set; } = false;
public string? Namespace { get; set; }
public string? KubeconfigFile { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion KubeConnect/PortForwarding/PortForwarderHandlerSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public PortForwarderHandlerSetup(ServiceManager manager, ILogger<PortForwarderHa
public void Configure(KestrelServerOptions options)
{
options.ApplicationServices = serviceProvider;
options.Listen(IPAddress.Loopback, Program.MainPort);
options.Listen(IPAddress.Loopback, args.MainPort);

if (manager.IngressConfig.Enabled)
{
Expand Down
28 changes: 2 additions & 26 deletions KubeConnect/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace KubeConnect
{
class Program
{
public static int MainPort = 10401;
public static string CurrentVersion
{
get
Expand Down Expand Up @@ -97,35 +96,12 @@ _ __ _ ____ _
const string semaphoreName = $"KubeConnect:FEC9031C-3BFD-4F5D-91D9-AC7B93074499";
if (parseArgs.Action == Args.KubeConnectMode.Connect)
{
if (!CheckAvailableServerPort(MainPort))
if (!CheckAvailableServerPort(parseArgs.MainPort))
{
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.");
return -1;
}

//// skip the check if elivated as the host exe has already done
//if (!parseArgs.Elevated)
//{
// var locker = new ProcessLock(semaphoreName);
// if (!locker.Locked)
// {
// 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.");
// return -1;
// }
//}
}
//else if (parseArgs.Action == Args.KubeConnectMode.Bridge)
//{
// // should we not auto elevate and launch connect as required???
// using var locker = new ProcessLock(semaphoreName);

// if (locker.Locked)
// {
// console.WriteErrorLine("You must also be running a separate KubeConnect session in 'connect' mode to enable bridging across a service.");
// return -1;
// }
//}


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

var response = await new HttpClient()
.GetAsync($"http://localhost:{MainPort}/status");
.GetAsync($"http://localhost:{parseArgs.MainPort}/status");

if (!response.IsSuccessStatusCode)
{
Expand Down
34 changes: 17 additions & 17 deletions KubeConnect/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"profiles": {
"KubeConnect": {
"commandName": "Project",
"commandLineArgs": "-x minikube"
},
"KubeConnect - bridge": {
"commandName": "Project",
"commandLineArgs": "bridge -service apphost"
},
"KubeConnect - run": {
"commandName": "Project",
"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"
},
"KubeConnect-reduced": {
"commandName": "Project",
"commandLineArgs": "-x minikube -skip-hosts -http-only "
}
"profiles": {
"KubeConnect": {
"commandName": "Project",
"commandLineArgs": "--insecure-skip-tls-verify=true --namespace=localdev"
},
"KubeConnect - bridge": {
"commandName": "Project",
"commandLineArgs": "bridge -service apphost"
},
"KubeConnect - run": {
"commandName": "Project",
"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"
},
"KubeConnect-reduced": {
"commandName": "Project",
"commandLineArgs": "-x minikube -skip-hosts -http-only "
}
}
}

0 comments on commit cea9170

Please sign in to comment.