diff --git a/apply/processor/create.go b/apply/processor/create.go index 1c8f1f0f1f9..fb080dc2038 100644 --- a/apply/processor/create.go +++ b/apply/processor/create.go @@ -47,9 +47,9 @@ type CreateProcessor struct { func (c *CreateProcessor) GetPipeLine() ([]func(cluster *v2.Cluster) error, error) { var todoList []func(cluster *v2.Cluster) error todoList = append(todoList, + c.MountImage, c.PreProcess, c.GetPhasePluginFunc(plugin.PhaseOriginally), - c.MountImage, c.RunConfig, c.MountRootfs, c.GetPhasePluginFunc(plugin.PhasePreInit), diff --git a/logger/log.go b/logger/log.go index c94f482a07b..1ed1e8323f9 100755 --- a/logger/log.go +++ b/logger/log.go @@ -73,7 +73,7 @@ var levelPrefix = [LevelTrace + 1]string{ } const ( - logTimeDefaultFormat = "2006-01-02 15:04:05" // 日志输出默认格式 + LogTimeDefaultFormat = "2006-01-02 15:04:05" // 日志输出默认格式 AdapterConsole = "console" // 控制台输出配置项 AdapterFile = "file" // 文件输出配置项 AdapterConn = "conn" // 网络输出配置项 @@ -136,7 +136,7 @@ func NewLogger(depth ...int) *LocalLogger { l.callDepth = dep l.usePath = true //l.SetLogger(AdapterConsole) - l.timeFormat = logTimeDefaultFormat + //l.timeFormat = logTimeDefaultFormat return l } @@ -168,14 +168,12 @@ func Cfg(debugMod bool) { cfg, err := json.Marshal(&logCfg) if err == nil { SetLogger(string(cfg)) - SetLogPath(true) return } } } SetLogger(fmt.Sprintf(`{ - "TimeFormat": "2006-01-02 15:04:05", "Console": { "level": "", "color": true, @@ -194,8 +192,6 @@ func Cfg(debugMod bool) { }}`, logLev, common.DefaultLogDir, time.Now().Format("2006-01-02"), )) - - SetLogPath(true) } func (localLog *LocalLogger) SetLogger(adapterName string, configs ...string) { @@ -260,6 +256,10 @@ func (localLog *LocalLogger) SetLogPath(bPath bool) { localLog.usePath = bPath } +func (localLog *LocalLogger) SetTimeFormat(format string) { + localLog.timeFormat = format +} + func (localLog *LocalLogger) writeToLoggers(when time.Time, msg *loginfo, level logLevel) { for _, l := range localLog.outputs { if l.name == AdapterConn { @@ -403,6 +403,10 @@ func SetLogPath(show bool) { defaultLogger.SetLogPath(show) } +func SetTimeFormat(format string) { + defaultLogger.SetTimeFormat(format) +} + // param 可以是log配置文件名,也可以是log配置内容,默认DEBUG输出到控制台 func SetLogger(param ...string) { if len(param) == 0 { diff --git a/pkg/plugin/hostname_plugin.go b/pkg/plugin/hostname_plugin.go index 2aeed99f57f..966dcd86e7f 100644 --- a/pkg/plugin/hostname_plugin.go +++ b/pkg/plugin/hostname_plugin.go @@ -86,5 +86,6 @@ func (h HostnamePlugin) changeNodeName(hostname, ip string, SSH ssh.Interface) e if err := SSH.CmdAsync(ip, tmpCMD, perCMD); err != nil { return fmt.Errorf("failed to change the node %v hostname,%v", ip, err) } + logger.Info("successfully changed node %s hostname to %s.", ip, hostname) return nil } diff --git a/pkg/plugin/labels.go b/pkg/plugin/labels.go index 273f0121042..78ed46177a8 100644 --- a/pkg/plugin/labels.go +++ b/pkg/plugin/labels.go @@ -74,6 +74,7 @@ func (l LabelsNodes) Run(context Context, phase Phase) error { if _, err := l.client.UpdateNode(v); err != nil { return fmt.Errorf("current cluster nodes label failed, %v", err) } + logger.Info("successfully added node %s labels %v.", internalIP, labels) } } return nil diff --git a/pkg/plugin/taint_plugin.go b/pkg/plugin/taint_plugin.go index 8f340f4e5f5..f30bb15c893 100644 --- a/pkg/plugin/taint_plugin.go +++ b/pkg/plugin/taint_plugin.go @@ -98,6 +98,7 @@ func (l *Taint) Run(context Context, phase Phase) (err error) { if err != nil { return err } + logger.Info("successfully updated node %s taints to %v.", v.Address, updateTaints) } break } diff --git a/sealer/cmd/root.go b/sealer/cmd/root.go index 171d534ea60..5f7dafe4a8b 100644 --- a/sealer/cmd/root.go +++ b/sealer/cmd/root.go @@ -29,6 +29,8 @@ import ( type rootOpts struct { cfgFile string debugModeOn bool + hideLogTime bool + hideLogPath bool } var rootOpt rootOpts @@ -53,6 +55,8 @@ func init() { cobra.OnInitialize(initConfig) rootCmd.PersistentFlags().StringVar(&rootOpt.cfgFile, "config", "", "config file (default is $HOME/.sealer.json)") rootCmd.PersistentFlags().BoolVarP(&rootOpt.debugModeOn, "debug", "d", false, "turn on debug mode") + rootCmd.PersistentFlags().BoolVar(&rootOpt.hideLogTime, "hide-time", false, "hide the log time") + rootCmd.PersistentFlags().BoolVar(&rootOpt.hideLogPath, "hide-path", false, "hide the log path") rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") rootCmd.DisableAutoGenTag = true } @@ -70,9 +74,12 @@ func initConfig() { viper.AutomaticEnv() // read in environment variables that match - logger.InitLogger(logger.Config{ - DebugMode: rootOpt.debugModeOn, - }) + logger.InitLogger(logger.Config{DebugMode: rootOpt.debugModeOn}) + logger.SetLogPath(!rootOpt.hideLogPath) + + if !rootOpt.hideLogTime { + logger.SetTimeFormat(logger.LogTimeDefaultFormat) + } logger.Cfg(rootOpt.debugModeOn) } diff --git a/test/sealer_images_test.go b/test/sealer_images_test.go index 4bc2153eef5..293f62fc927 100644 --- a/test/sealer_images_test.go +++ b/test/sealer_images_test.go @@ -49,13 +49,12 @@ var _ = Describe("sealer image", func() { image.RemoveImageList(tagImageNames) }) - /* //not support - By("tag by image id", func() { - imageID := image.GetImageID(settings.TestImageName) - image.TagImageList(imageID, tagImageNames) - image.DoImageOps(settings.SubCmdListOfSealer, "") - image.RemoveImageList(tagImageNames) - })*/ + By("tag by image id", func() { + imageID := image.GetImageID(settings.TestImageName) + image.TagImageList(imageID, tagImageNames) + image.DoImageOps(settings.SubCmdListOfSealer, "") + image.RemoveImageList(tagImageNames) + }) By("remove tag image", func() { tagImageName := "e2e_images_test:v0.3" @@ -118,18 +117,10 @@ var _ = Describe("sealer image", func() { AfterEach(func() { registry.Logout() }) - pushImageNames := []string{ - "registry.cn-qingdao.aliyuncs.com/sealer-io/e2e_image_test:v0.01", - "sealer-io/e2e_image_test:v0.01", - "e2e_image_test:v0.01", - } - - for _, pushImage := range pushImageNames { - pushImage := pushImage - It(fmt.Sprintf("push image %s", pushImage), func() { - image.TagImages(settings.TestImageName, pushImage) - image.DoImageOps(settings.SubCmdPushOfSealer, pushImage) - }) - } + It("push image", func() { + pushImageName := "registry.cn-qingdao.aliyuncs.com/sealer-io/e2e_image_test:v0.01" + image.TagImages(settings.TestImageName, pushImageName) + image.DoImageOps(settings.SubCmdPushOfSealer, pushImageName) + }) }) }) diff --git a/test/suites/build/build.go b/test/suites/build/build.go index 9f0dde97773..dd91f499f56 100644 --- a/test/suites/build/build.go +++ b/test/suites/build/build.go @@ -20,8 +20,6 @@ import ( "io/ioutil" "os" "path/filepath" - "strconv" - "strings" "github.com/onsi/gomega" @@ -47,7 +45,7 @@ func GetContainerBuildDir() string { // GetTestImageName return specific image name that will be push to registry func GetTestImageName() string { - return fmt.Sprintf("sealer-io/%s%d:%s", settings.ImageName, 719, "v1") + return fmt.Sprintf("registry.cn-qingdao.aliyuncs.com/sealer-io/%s%d:%s", settings.ImageName, 719, "v1") } type ArgsOfBuild struct { @@ -94,12 +92,9 @@ func NewArgsOfBuild() *ArgsOfBuild { } func CheckIsImageExist(imageName string) bool { - cmd := fmt.Sprintf("%s images | grep %s | wc -l", settings.DefaultSealerBin, imageName) - result, err := utils.RunSimpleCmd(cmd) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - num, err := strconv.Atoi(strings.Replace(result, "\n", "", -1)) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - return num == 1 + cmd := fmt.Sprintf("%s inspect %s", settings.DefaultSealerBin, imageName) + _, err := utils.RunSimpleCmd(cmd) + return err == nil } func UpdateKubeFromImage(imageName string, KubefilePath string) {