mirror of
https://github.com/alibaba/higress.git
synced 2026-03-19 01:37:28 +08:00
feat: implement auto-get higress console credential from hgctl profile installation (#3060)
This commit is contained in:
@@ -27,6 +27,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/alibaba/higress/hgctl/pkg/helm"
|
||||
"github.com/alibaba/higress/hgctl/pkg/installer"
|
||||
"github.com/alibaba/higress/hgctl/pkg/kubernetes"
|
||||
"github.com/alibaba/higress/v2/pkg/cmd/options"
|
||||
"github.com/braydonk/yaml"
|
||||
"github.com/fatih/color"
|
||||
"github.com/higress-group/openapi-to-mcpserver/pkg/converter"
|
||||
@@ -41,6 +45,11 @@ import (
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
const (
|
||||
SecretConsoleUser = "adminUsername"
|
||||
SecretConsolePwd = "adminPassword"
|
||||
)
|
||||
|
||||
var binaryName = AgentBinaryName
|
||||
|
||||
// ------ cmd related ------
|
||||
@@ -453,3 +462,52 @@ func promptForServiceKubeSettingsAndRetry() (string, error) {
|
||||
color.Green("✅ Found Higress Gateway Service IP: %s (namespace: %s)", ip, namespace)
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
func getConsoleCredentials(profile *helm.Profile) (username, password string, err error) {
|
||||
cliClient, err := kubernetes.NewCLIClient(options.DefaultConfigFlags.ToRawKubeConfigLoader())
|
||||
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("failed to build kubernetes client: %w", err)
|
||||
}
|
||||
|
||||
secret, err := cliClient.KubernetesInterface().CoreV1().Secrets(profile.Global.Namespace).Get(context.Background(), "higress-console", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return string(secret.Data[SecretConsoleUser]), string(secret.Data[SecretConsolePwd]), nil
|
||||
}
|
||||
|
||||
// This function will do following things:
|
||||
// 1. read the profile from local-file
|
||||
// 2. read the profile from k8s' configMap
|
||||
// 3. combine the two type profiles together and return
|
||||
func getAllProfiles() ([]*installer.ProfileContext, error) {
|
||||
profileContexts := make([]*installer.ProfileContext, 0)
|
||||
profileInstalledPath, err := installer.GetProfileInstalledPath()
|
||||
if err != nil {
|
||||
return profileContexts, nil
|
||||
}
|
||||
fileProfileStore, err := installer.NewFileDirProfileStore(profileInstalledPath)
|
||||
if err != nil {
|
||||
return profileContexts, nil
|
||||
}
|
||||
fileProfileContexts, err := fileProfileStore.List()
|
||||
if err == nil {
|
||||
profileContexts = append(profileContexts, fileProfileContexts...)
|
||||
}
|
||||
|
||||
cliClient, err := kubernetes.NewCLIClient(options.DefaultConfigFlags.ToRawKubeConfigLoader())
|
||||
if err != nil {
|
||||
return profileContexts, nil
|
||||
}
|
||||
configmapProfileStore, err := installer.NewConfigmapProfileStore(cliClient)
|
||||
if err != nil {
|
||||
return profileContexts, nil
|
||||
}
|
||||
|
||||
configmapProfileContexts, err := configmapProfileStore.List()
|
||||
if err == nil {
|
||||
profileContexts = append(profileContexts, configmapProfileContexts...)
|
||||
}
|
||||
return profileContexts, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user