37 Star 404 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
temporarycredentials.go 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-06-12 13:38 . goimport linting changes
package clusterstatus
import (
"context"
"fmt"
"strconv"
"k8s.io/apimachinery/pkg/runtime"
v3 "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(ctx context.Context, management *config.ManagementContext) {
c := &clusterAnnotations{
clusters: management.Management.Clusters(""),
}
management.Management.Clusters("").AddHandler(ctx, "temporary-credentials", c.sync)
}
type clusterAnnotations struct {
clusters v3.ClusterInterface
}
func (cd *clusterAnnotations) sync(key string, cluster *v3.Cluster) (runtime.Object, error) {
if key == "" || cluster == nil || cluster.DeletionTimestamp != nil {
return nil, nil
}
if genericConfig := cluster.Spec.GenericEngineConfig; genericConfig != nil {
eksConfig := *genericConfig
if eksConfig["driverName"] != "amazonelasticcontainerservice" {
return nil, nil
}
newValue := strconv.FormatBool(eksConfig["sessionToken"] != "" && eksConfig["sessionToken"] != nil)
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 nil, fmt.Errorf("error updating temporary credentials annotation: %v", err)
}
}
return nil, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.7-rc5

搜索帮助