37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
package pipeline
import (
"github.com/rancher/rancher/pkg/controllers/user/pipeline/remote"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/satori/uuid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
)
func refreshReposByCredential(sourceCodeRepositories v3.SourceCodeRepositoryInterface, sourceCodeRepositoryLister v3.SourceCodeRepositoryLister, credential *v3.SourceCodeCredential) ([]*v3.SourceCodeRepository, error) {
remoteType := credential.Spec.SourceCodeType
mockConfig := v3.ClusterPipeline{
Spec: v3.ClusterPipelineSpec{
GithubConfig: &v3.GithubClusterConfig{},
},
}
remote, err := remote.New(mockConfig, remoteType)
if err != nil {
return nil, err
}
repos, err := remote.Repos(credential)
if err != nil {
return nil, err
}
//remove old repos
repositories, err := sourceCodeRepositoryLister.List("", labels.Everything())
if err != nil {
return nil, err
}
for _, repo := range repositories {
if repo.Spec.SourceCodeCredentialName == credential.Name {
if err := sourceCodeRepositories.Delete(repo.Name, &metav1.DeleteOptions{}); err != nil {
return nil, err
}
}
}
//store new repos
for _, repo := range repos {
repo.Spec.SourceCodeCredentialName = credential.Name
repo.Spec.ClusterName = credential.Spec.ClusterName
repo.Spec.UserName = credential.Spec.UserName
repo.Name = uuid.NewV4().String()
if _, err := sourceCodeRepositories.Create(&repo); err != nil {
return nil, err
}
}
return repositories, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.0-alpha17

搜索帮助