37 Star 403 Fork 75

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
temporarycredentials.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
package clusterstatus
import (
"fmt"
"strconv"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
)
const TemporaryCredentialsAnnotationKey = "clusterstatus.management.cattle.io/temporary-security-credentials"
func Register(management *config.ManagementContext) {
c := &clusterAnnotations{
clusters: management.Management.Clusters(""),
}
management.Management.Clusters("").AddHandler("temporary-credentials", c.sync)
}
type clusterAnnotations struct {
clusters v3.ClusterInterface
}
func (cd *clusterAnnotations) sync(key string, cluster *v3.Cluster) error {
if key == "" || cluster == nil || cluster.DeletionTimestamp != nil {
return nil
}
if eksConfig := cluster.Spec.AmazonElasticContainerServiceConfig; eksConfig != nil {
newValue := strconv.FormatBool(eksConfig.SessionToken != "")
if newValue != cluster.Annotations[TemporaryCredentialsAnnotationKey] {
original := cluster
cluster = original.DeepCopy()
if cluster.Annotations == nil {
cluster.Annotations = make(map[string]string)
}
cluster.Annotations[TemporaryCredentialsAnnotationKey] = newValue
_, err := cd.clusters.Update(cluster)
if err != nil {
return fmt.Errorf("error updating temporary credentials annotation: %v", err)
}
}
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.7-rc1

搜索帮助