37 Star 407 Fork 75

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
store.go 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
Daishan Peng 提交于 2018-07-16 15:15 . improvement for nodeconfig server
package clusterprovisioner
import (
"encoding/json"
"github.com/rancher/kontainer-engine/cluster"
"github.com/rancher/rancher/pkg/encryptedstore"
"github.com/rancher/types/apis/core/v1"
"github.com/sirupsen/logrus"
)
const (
dataKey = "cluster"
)
func NewPersistentStore(namespaces v1.NamespaceInterface, secretsGetter v1.SecretsGetter) cluster.PersistentStore {
store, err := encryptedstore.NewGenericEncrypedStore("c-", "", namespaces, secretsGetter)
if err != nil {
logrus.Fatal(err)
}
return &engineStore{
store: store,
}
}
type engineStore struct {
store *encryptedstore.GenericEncryptedStore
}
func (s *engineStore) GetStatus(name string) (string, error) {
cls, err := s.Get(name)
if err != nil {
return "", err
}
return cls.Status, nil
}
func (s *engineStore) Get(name string) (cluster.Cluster, error) {
cluster := cluster.Cluster{}
data, err := s.store.Get(name)
if err != nil {
return cluster, err
}
return cluster, json.Unmarshal([]byte(data[dataKey]), &cluster)
}
func (s *engineStore) Remove(name string) error {
return s.store.Remove(name)
}
func (s *engineStore) Store(cluster cluster.Cluster) error {
content, err := json.Marshal(cluster)
if err != nil {
return err
}
return s.store.Set(cluster.Name, map[string]string{
dataKey: string(content),
})
}
func (s *engineStore) PersistStatus(cluster cluster.Cluster, status string) error {
cluster.Status = status
return s.Store(cluster)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.0-rc6

搜索帮助