37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
purge_daemon.go 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
Craig Jellick 提交于 2018-02-16 17:26 . Token expiration logic
package tokens
import (
"context"
"time"
"github.com/rancher/norman/clientbase"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"
)
const intervalSeconds int64 = 3600
func StartPurgeDaemon(ctx context.Context, mgmt *config.ManagementContext) {
p := &purger{
tokenLister: mgmt.Management.Tokens("").Controller().Lister(),
tokens: mgmt.Management.Tokens(""),
}
go wait.JitterUntil(p.purge, time.Duration(intervalSeconds)*time.Second, .1, true, ctx.Done())
}
type purger struct {
tokenLister v3.TokenLister
tokens v3.TokenInterface
}
func (p *purger) purge() {
allTokens, err := p.tokenLister.List("", labels.Everything())
if err != nil {
logrus.Errorf("Error listing tokens during purge: %v", err)
}
var count int
for _, token := range allTokens {
if IsExpired(*token) {
err = p.tokens.Delete(token.ObjectMeta.Name, &metav1.DeleteOptions{})
if err != nil && !clientbase.IsNotFound(err) {
logrus.Errorf("Error: while deleting expired token %v: %v", err, token.ObjectMeta.Name)
continue
}
count++
}
}
if count > 0 {
logrus.Infof("Purged %v expired tokens", count)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.2-rc2

搜索帮助

0d507c66 1850385 C8b1a773 1850385