Skip to content

Commit aafc69d

Browse files
authored
feat: set klog's verbosity & update help info (#62)
* feat: set klog's verbosity & update help info Signed-off-by: Jian Zeng <[email protected]> * chore: update go.mod Signed-off-by: Jian Zeng <[email protected]> --------- Signed-off-by: Jian Zeng <[email protected]>
1 parent ddbc982 commit aafc69d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

cmd/client/main.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import (
44
"context"
55
"encoding/json"
66
"errors"
7+
"flag"
78
"fmt"
89
"log/slog"
910
"os"
1011
"os/signal"
12+
"strconv"
1113
"strings"
1214
"time"
1315

@@ -21,6 +23,7 @@ import (
2123
"k8s.io/client-go/kubernetes/scheme"
2224
_ "k8s.io/client-go/plugin/pkg/client/auth"
2325
"k8s.io/client-go/rest"
26+
"k8s.io/klog/v2"
2427

2528
"github.com/knight42/krelay/pkg/constants"
2629
"github.com/knight42/krelay/pkg/ports"
@@ -296,11 +299,17 @@ func main() {
296299
}
297300
printVersion := false
298301

302+
fs := flag.NewFlagSet("klog", flag.ExitOnError)
303+
klog.InitFlags(fs)
304+
299305
c := cobra.Command{
300306
Use: fmt.Sprintf(`%s TYPE/NAME [options] [LOCAL_PORT:]REMOTE_PORT[@PROTOCOL] [...[LOCAL_PORT_N:]REMOTE_PORT_N[@PROTOCOL_N]]`, getProgramName()),
301307
Example: example(),
302308
Long: `This command is similar to "kubectl port-forward", but it also supports UDP and could forward data to a
303-
service, ip and hostname rather than only pods.`,
309+
service, ip and hostname rather than only pods.
310+
311+
Starting from version v0.1.2, it attempts to tunnel SPDY through websocket, in line with how "kubectl port-forward" works.
312+
This behavior can be disabled by setting the environment variable "KUBECTL_PORT_FORWARD_WEBSOCKETS" to "false".`,
304313
RunE: func(cmd *cobra.Command, args []string) error {
305314
if printVersion {
306315
return json.NewEncoder(cmd.OutOrStdout()).Encode(struct {
@@ -314,6 +323,7 @@ service, ip and hostname rather than only pods.`,
314323
})
315324
}
316325

326+
_ = fs.Set("v", strconv.Itoa(o.verbosity))
317327
slog.SetLogLoggerLevel(slogutil.MapVerbosityToLogLevel(o.verbosity))
318328
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
319329
defer cancel()

cmd/client/template.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99
)
1010

1111
func getProgramName() string {
12-
if strings.HasPrefix(filepath.Base(os.Args[0]), "kubectl-") {
12+
name := filepath.Base(os.Args[0])
13+
if strings.HasPrefix(name, "kubectl-") {
1314
return "kubectl relay"
1415
}
15-
return "krelay"
16+
return name
1617
}
1718

1819
func example() string {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
k8s.io/apimachinery v0.31.0
1111
k8s.io/cli-runtime v0.31.0
1212
k8s.io/client-go v0.31.0
13+
k8s.io/klog/v2 v2.130.1
1314
)
1415

1516
require (
@@ -65,7 +66,6 @@ require (
6566
gopkg.in/inf.v0 v0.9.1 // indirect
6667
gopkg.in/yaml.v2 v2.4.0 // indirect
6768
gopkg.in/yaml.v3 v3.0.1 // indirect
68-
k8s.io/klog/v2 v2.130.1 // indirect
6969
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
7070
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
7171
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect

0 commit comments

Comments
 (0)