K-EXPLORER: format cluster name with kube context

This commit is contained in:
niusmallnan 2022-02-09 13:48:33 +08:00
parent 18f619f9df
commit 28259927a9
2 changed files with 18 additions and 1 deletions

View File

@ -2,7 +2,9 @@ package cluster
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"strings"
"time" "time"
"github.com/rancher/apiserver/pkg/store/empty" "github.com/rancher/apiserver/pkg/store/empty"
@ -21,6 +23,10 @@ import (
"k8s.io/client-go/discovery" "k8s.io/client-go/discovery"
) )
var (
CurrentKubeContext string
)
const ( const (
shellPodImage = "rancher/shell:v0.1.6" shellPodImage = "rancher/shell:v0.1.6"
shellPodNS = "kube-system" shellPodNS = "kube-system"
@ -160,7 +166,7 @@ func (s *Store) getLocal() types.APIObject {
Name: "local", Name: "local",
}, },
Spec: Spec{ Spec: Spec{
DisplayName: "Local Cluster", DisplayName: getDisplayNameWithContext(),
Internal: true, Internal: true,
}, },
Status: Status{ Status: Status{
@ -207,3 +213,10 @@ func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.
return result, nil return result, nil
} }
func getDisplayNameWithContext() string {
if CurrentKubeContext != "" {
return fmt.Sprintf("%s Cluster", strings.Title(CurrentKubeContext))
}
return "Local Cluster"
}

View File

@ -5,6 +5,7 @@ import (
steveauth "github.com/rancher/steve/pkg/auth" steveauth "github.com/rancher/steve/pkg/auth"
authcli "github.com/rancher/steve/pkg/auth/cli" authcli "github.com/rancher/steve/pkg/auth/cli"
"github.com/rancher/steve/pkg/resources/cluster"
"github.com/rancher/steve/pkg/server" "github.com/rancher/steve/pkg/server"
"github.com/rancher/steve/pkg/ui" "github.com/rancher/steve/pkg/ui"
"github.com/rancher/wrangler/pkg/kubeconfig" "github.com/rancher/wrangler/pkg/kubeconfig"
@ -48,6 +49,9 @@ func (c *Config) ToServer(ctx context.Context) (*server.Server, error) {
} }
} }
// K-EXPLORER
cluster.CurrentKubeContext = c.Context
return server.New(ctx, restConfig, &server.Options{ return server.New(ctx, restConfig, &server.Options{
AuthMiddleware: auth, AuthMiddleware: auth,
Next: ui.New(c.UIPath), Next: ui.New(c.UIPath),