Skip to content

Commit

Permalink
allow multiple instances of k.logcli running locally
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Hros committed Mar 24, 2021
1 parent 92addee commit beac6fc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions k.logcli
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import os
import atexit
import time
import socket
import random

random.seed()
port = random.randint(30000, 31767)

def sigint_handler(signal, frame):
#print("Interrupted")
Expand All @@ -32,10 +36,10 @@ def check_port(port):
def setup_port_forwarding():
global portfw_pid

proc = subprocess.Popen(["kubectl","port-forward", "svc/loki", "-n", "monitoring", "3100:3100"])
proc = subprocess.Popen(["kubectl","port-forward", "svc/loki", "-n", "monitoring", str(port)+":3100"])
portfw_pid = proc.pid

while not check_port(3100):
while not check_port(port):
time.sleep(1)

print("Port fowarding ready", file=sys.stderr)
Expand Down Expand Up @@ -63,7 +67,7 @@ else:
#include_labels.append("container_name")

# construct options
opts = ["--limit="+args.limit, "--since="+args.since]
opts = ["--addr=http://localhost:"+str(port), "--limit="+args.limit, "--since="+args.since]
for label in include_labels:
opts.append("--include-label="+label)

Expand Down

0 comments on commit beac6fc

Please sign in to comment.