Merge pull request #4679 from iawia002/cluster-name

Set the name of the current cluster into the kubesphere-config configmap
This commit is contained in:
KubeSphere CI Bot
2022-03-07 13:22:11 +08:00
committed by GitHub
7 changed files with 123 additions and 46 deletions

View File

@@ -22,17 +22,17 @@ import (
"strings"
"sync"
"k8s.io/klog"
"github.com/fsnotify/fsnotify"
"kubesphere.io/kubesphere/pkg/apiserver/authentication"
"kubesphere.io/kubesphere/pkg/apiserver/authorization"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/klog"
networkv1alpha1 "kubesphere.io/api/network/v1alpha1"
"kubesphere.io/kubesphere/pkg/apiserver/authentication"
"kubesphere.io/kubesphere/pkg/apiserver/authorization"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/models/terminal"
"kubesphere.io/kubesphere/pkg/simple/client/alerting"
"kubesphere.io/kubesphere/pkg/simple/client/auditing"
@@ -363,3 +363,17 @@ func (conf *Config) stripEmptyOptions() {
conf.GPUOptions = nil
}
}
// GetFromConfigMap returns KubeSphere ruuning config by the given ConfigMap.
func GetFromConfigMap(cm *corev1.ConfigMap) (*Config, error) {
c := &Config{}
value, ok := cm.Data[constants.KubeSphereConfigMapDataKey]
if !ok {
return nil, fmt.Errorf("failed to get configmap kubesphere.yaml value")
}
if err := yaml.Unmarshal([]byte(value), c); err != nil {
return nil, fmt.Errorf("failed to unmarshal value from configmap. err: %s", err)
}
return c, nil
}