feat: Support specifying shell pod image and registry

This commit is contained in:
Yuxing Deng
2024-07-16 17:20:18 +08:00
parent faa83722a0
commit 2f3c1e6ab5
7 changed files with 46 additions and 29 deletions

7
go.mod
View File

@@ -2,12 +2,7 @@ module github.com/cnrancher/kube-explorer
go 1.22.0 go 1.22.0
replace ( replace k8s.io/client-go => k8s.io/client-go v0.30.1
github.com/knative/pkg => github.com/rancher/pkg v0.0.0-20190514055449-b30ab9de040e
github.com/matryer/moq => github.com/rancher/moq v0.0.0-20200712062324-13d1f37d2d77
github.com/rancher/steve => github.com/rancher/steve v0.0.0-20240709130809-47871606146c
k8s.io/client-go => k8s.io/client-go v0.30.1
)
require ( require (
github.com/gorilla/mux v1.8.1 github.com/gorilla/mux v1.8.1

28
internal/config/flags.go Normal file
View File

@@ -0,0 +1,28 @@
package config
import (
"github.com/urfave/cli"
)
var InsecureSkipTLSVerify bool
var SystemDefaultRegistry string
var ShellPodImage string
func Flags() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: "insecure-skip-tls-verify",
Destination: &InsecureSkipTLSVerify,
},
cli.StringFlag{
Name: "system-default-registry",
Destination: &SystemDefaultRegistry,
},
cli.StringFlag{
Name: "pod-image",
Destination: &ShellPodImage,
Value: "rancher/shell:v0.2.1-rc.7",
},
}
}

View File

@@ -20,7 +20,7 @@ func Register(_ context.Context, server *server.Server, displayName string) erro
shell := &shell{ shell := &shell{
cg: cg, cg: cg,
namespace: shellPodNS, namespace: shellPodNS,
impersonator: podimpersonation.New("shell", cg, time.Hour, func() string { return shellPodImage }), impersonator: podimpersonation.New("shell", cg, time.Hour, getShellPodImage),
} }
clusterSchema := server.BaseSchemas.LookupSchema("management.cattle.io.cluster") clusterSchema := server.BaseSchemas.LookupSchema("management.cattle.io.cluster")

View File

@@ -2,10 +2,12 @@ package cluster
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"time" "time"
"github.com/cnrancher/kube-explorer/internal/config"
"github.com/rancher/steve/pkg/podimpersonation" "github.com/rancher/steve/pkg/podimpersonation"
"github.com/rancher/steve/pkg/stores/proxy" "github.com/rancher/steve/pkg/stores/proxy"
"github.com/rancher/wrangler/v3/pkg/schemas/validation" "github.com/rancher/wrangler/v3/pkg/schemas/validation"
@@ -18,8 +20,7 @@ import (
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
) )
const ( var (
shellPodImage = "rancher/shell:v0.1.20"
shellPodNS = "kube-system" shellPodNS = "kube-system"
) )
@@ -145,10 +146,17 @@ func (s *shell) createPod() *v1.Pod {
Value: "/home/shell/.kube/config", Value: "/home/shell/.kube/config",
}, },
}, },
Image: shellPodImage, Image: getShellPodImage(),
ImagePullPolicy: v1.PullIfNotPresent, ImagePullPolicy: v1.PullIfNotPresent,
}, },
}, },
}, },
} }
} }
func getShellPodImage() string {
if config.SystemDefaultRegistry == "" {
return config.ShellPodImage
}
return fmt.Sprintf("%s/%s", config.SystemDefaultRegistry, config.ShellPodImage)
}

View File

@@ -14,6 +14,7 @@ import (
"github.com/rancher/wrangler/v3/pkg/kubeconfig" "github.com/rancher/wrangler/v3/pkg/kubeconfig"
"github.com/rancher/wrangler/v3/pkg/ratelimit" "github.com/rancher/wrangler/v3/pkg/ratelimit"
"github.com/cnrancher/kube-explorer/internal/config"
"github.com/cnrancher/kube-explorer/internal/resources/cluster" "github.com/cnrancher/kube-explorer/internal/resources/cluster"
"github.com/cnrancher/kube-explorer/internal/ui" "github.com/cnrancher/kube-explorer/internal/ui"
) )
@@ -29,7 +30,7 @@ func ToServer(ctx context.Context, c *cli.Config, sqlCache bool) (*server.Server
} }
restConfig.RateLimiter = ratelimit.None restConfig.RateLimiter = ratelimit.None
restConfig.Insecure = insecureSkipTLSVerify restConfig.Insecure = config.InsecureSkipTLSVerify
if restConfig.Insecure { if restConfig.Insecure {
restConfig.CAData = nil restConfig.CAData = nil
restConfig.CAFile = "" restConfig.CAFile = ""

View File

@@ -1,16 +0,0 @@
package server
import (
"github.com/urfave/cli"
)
var insecureSkipTLSVerify bool
func Flags() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: "insecure-skip-tls-verify",
Destination: &insecureSkipTLSVerify,
},
}
}

View File

@@ -10,6 +10,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
keconfig "github.com/cnrancher/kube-explorer/internal/config"
"github.com/cnrancher/kube-explorer/internal/server" "github.com/cnrancher/kube-explorer/internal/server"
) )
@@ -26,7 +27,7 @@ func main() {
app.Flags = joinFlags( app.Flags = joinFlags(
stevecli.Flags(&config), stevecli.Flags(&config),
debug.Flags(&debugconfig), debug.Flags(&debugconfig),
server.Flags(), keconfig.Flags(),
) )
app.Action = run app.Action = run