代码拉取完成,页面将自动刷新
同步操作将从 openEuler/isula-transform 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* Copyright (c) 2020 Huawei Technologies Co., Ltd.
* isula-transform is licensed under the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Create: 2020-04-24
*/
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"gopkg.in/natefinch/lumberjack.v2"
"isula.org/isula-transform/pkg/isulad"
"isula.org/isula-transform/transform"
_ "isula.org/isula-transform/transform/register"
"isula.org/isula-transform/utils"
)
const (
exitNormal = iota
exitInitErr
exitTransformErr
maxConcurrentTransform = 128
maxPerLogFileSize = 10 // megabytes
isuladConfFIle = "/etc/isulad/daemon.json"
)
var (
version string
gitCommit string
)
func genVersion() string {
versions := []string{
"version:" + version,
"commit:" + gitCommit,
}
return strings.Join(versions, "\t")
}
func main() {
app := &cli.App{
Name: "isula-transform",
Usage: "transform specify docker container type configuration to iSulad type",
UsageText: "[global options] --all|container_id[ container_id...]",
Version: genVersion(),
Action: start,
}
for _, v := range transformFlags {
app.Flags = append(app.Flags, v...)
}
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(exitInitErr)
}
os.Exit(exitNormal)
}
func start(ctx *cli.Context) error {
logInit(ctx)
if err := transformInit(); err != nil {
return cli.NewExitError(err.Error(), exitInitErr)
}
return doTransform(ctx)
}
func logInit(ctx *cli.Context) {
logPath := ctx.GlobalString("log")
logRoot := filepath.Dir(logPath)
if err := os.MkdirAll(logRoot, 0660); err != nil {
logrus.SetOutput(os.Stdout)
logrus.Infof("create the log directory %s failed: %v, using STDOUT", logRoot, err)
} else {
logrus.SetOutput(&lumberjack.Logger{
Filename: logPath,
MaxSize: maxPerLogFileSize,
Compress: true,
})
}
logrus.SetLevel(transLogLevel(ctx.GlobalString("log-level")))
}
func transLogLevel(lvl string) logrus.Level {
switch strings.ToLower(lvl) {
case "error":
return logrus.ErrorLevel
case "warn":
return logrus.WarnLevel
case "debug":
return logrus.DebugLevel
default:
}
return logrus.InfoLevel
}
func transformInit() error {
var conf = isulad.DaemonConfig{}
if err := utils.CheckFileValid(isuladConfFIle); err != nil {
return errors.Wrapf(err, "check isulad daemon config failed")
}
confData, err := ioutil.ReadFile(isuladConfFIle)
if err != nil {
logrus.Errorf("read isulad daemon config failed: %v, file path: %s", err, isuladConfFIle)
return errors.Wrapf(err, "read isulad daemon config failed")
}
err = json.Unmarshal(confData, &conf)
if err != nil {
logrus.Errorf("unmarshal isulad daemon config failed: %v, file path: %s", err, isuladConfFIle)
return errors.Wrapf(err, "unmarshal isulad daemon config failed")
}
logrus.Debugf("isulad daemon config: %+v", conf)
err = isulad.InitIsuladTool(&conf)
if err != nil {
return errors.Wrapf(err, "transform init failed")
}
if conf.LogDriver != "file" {
logrus.Infof("isula daemon log driver is %s, can't redirect to file", conf.LogDriver)
} else {
isulad.LcrLogInit(conf.State, conf.Runtime, conf.LogLevel)
}
return nil
}
func doTransform(ctx *cli.Context) error {
e := transform.GetTransformer(ctx)
if e == nil {
return cli.NewExitError("get transform engine failed", exitInitErr)
}
if err := e.Init(); err != nil {
return cli.NewExitError("transform engine init failed", exitInitErr)
}
var ids []string
all := ctx.GlobalBool("all")
if !all {
if ctx.Args().Present() {
ids = append(ctx.Args().Tail(), ctx.Args().First())
} else {
exitMsg := "isula-transform requires at least one container id as an input or setting the --all flag"
return cli.NewExitError(exitMsg, exitInitErr)
}
}
exitCode := exitNormal
retCh := make(chan transform.Result, maxConcurrentTransform)
go e.Transform(ids, all, retCh)
for ret := range retCh {
if !ret.Ok {
exitCode = exitTransformErr
fmt.Fprintln(os.Stderr, ret.Msg)
} else {
fmt.Fprintln(os.Stdout, ret.Msg)
}
}
if exitCode != exitNormal {
return cli.NewExitError("The transformation has been completed, but at least one failed", exitTransformErr)
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。