37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
kontainerdriver_data.go 4.22 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-06-12 13:38 . goimport linting changes
package app
import (
"fmt"
"os"
"strings"
"github.com/rancher/rancher/pkg/controllers/management/drivers/kontainerdriver"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func addKontainerDrivers(management *config.ManagementContext) error {
// create binary drop location if not exists
err := os.MkdirAll(kontainerdriver.DriverDir, 0777)
if err != nil {
return fmt.Errorf("error creating binary drop folder: %v", err)
}
creator := driverCreator{
driversLister: management.Management.KontainerDrivers("").Controller().Lister(),
drivers: management.Management.KontainerDrivers(""),
}
if err := cleanupImportDriver(creator); err != nil {
return err
}
if err := creator.add("rancherKubernetesEngine"); err != nil {
return err
}
if err := creator.add("googleKubernetesEngine"); err != nil {
return err
}
if err := creator.add("azureKubernetesService"); err != nil {
return err
}
if err := creator.add("amazonElasticContainerService"); err != nil {
return err
}
if err := creator.addCustomDriver(
"aliyunkubernetescontainerservice",
"https://github.com/rancher/kontainer-engine-driver-aliyun/releases/download/v0.2.5/kontainer-engine-driver-aliyun-linux",
"31aa0a44450c5a5eb128dd0956292dfd91aab726d1a548f6d527a9212a27db9b",
"",
false,
"*.aliyuncs.com",
); err != nil {
return err
}
if err := creator.addCustomDriver(
"tencentkubernetesengine",
"https://github.com/rancher/kontainer-engine-driver-tencent/releases/download/v0.2.3/kontainer-engine-driver-tencent-linux",
"144f785473290ee2f63cf35da0c6bde12bc307878078500a47a0a8d04422ae53",
"",
false,
"*.tencentcloudapi.com", "*.qcloud.com",
); err != nil {
return err
}
if err := creator.addCustomDriver(
"huaweicontainercloudengine",
"https://github.com/rancher/kontainer-engine-driver-huawei/releases/download/v0.1.2/kontainer-engine-driver-huawei-linux",
"0b6c1dfaa477a60a3bd9f8a60a55fcafd883866c2c5c387aec75b95d6ba81d45",
"",
false,
"*.myhuaweicloud.com",
); err != nil {
return err
}
return nil
}
func cleanupImportDriver(creator driverCreator) error {
var err error
if _, err = creator.driversLister.Get("", "import"); err == nil {
err = creator.drivers.Delete("import", &v1.DeleteOptions{})
}
if !errors.IsNotFound(err) {
return err
}
return nil
}
type driverCreator struct {
driversLister v3.KontainerDriverLister
drivers v3.KontainerDriverInterface
}
func (c *driverCreator) add(name string) error {
logrus.Infof("adding kontainer driver %v", name)
driver, err := c.driversLister.Get("", name)
if err != nil {
if errors.IsNotFound(err) {
_, err = c.drivers.Create(&v3.KontainerDriver{
ObjectMeta: v1.ObjectMeta{
Name: strings.ToLower(name),
Namespace: "",
},
Spec: v3.KontainerDriverSpec{
URL: "",
BuiltIn: true,
Active: true,
},
Status: v3.KontainerDriverStatus{
DisplayName: name,
},
})
if err != nil && !errors.IsAlreadyExists(err) {
return fmt.Errorf("error creating driver: %v", err)
}
} else {
return fmt.Errorf("error getting driver: %v", err)
}
} else {
driver.Spec.URL = ""
_, err = c.drivers.Update(driver)
if err != nil {
return fmt.Errorf("error updating driver: %v", err)
}
}
return nil
}
func (c *driverCreator) addCustomDriver(name, url, checksum, uiURL string, active bool, domains ...string) error {
logrus.Infof("adding kontainer driver %v", name)
_, err := c.driversLister.Get("", name)
if err != nil {
if errors.IsNotFound(err) {
_, err = c.drivers.Create(&v3.KontainerDriver{
ObjectMeta: v1.ObjectMeta{
Name: strings.ToLower(name),
},
Spec: v3.KontainerDriverSpec{
URL: url,
BuiltIn: false,
Active: active,
Checksum: checksum,
UIURL: uiURL,
WhitelistDomains: domains,
},
Status: v3.KontainerDriverStatus{
DisplayName: name,
},
})
if err != nil && !errors.IsAlreadyExists(err) {
return fmt.Errorf("error creating driver: %v", err)
}
} else {
return fmt.Errorf("error getting driver: %v", err)
}
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.5-rc4

搜索帮助

0d507c66 1850385 C8b1a773 1850385