Repository: spidernet-io/spiderpool
Pull request #597 (2022-08-19 12:09:34)

workflow typo
Signed-off-by: weizhou.lan@daocloud.io <weizhou.lan@daocloud.io>



Patch:
diff --git a/.github/workflows/lint-codeowners.yaml b/.github/workflows/lint-codeowners.yaml
index 5e2d0bc61..1e44d1f4c 100644
--- a/.github/workflows/lint-codeowners.yaml
+++ b/.github/workflows/lint-codeowners.yaml
@@ -10,6 +10,7 @@ on:
 permissions: read-all
 
 env:
+  # Hard-code the path instead of using ${{ github.repository }}
   REPOSITY_NAME: github.com/spidernet-io/spiderpool
 
 # for each pr, queue all workflows
@@ -61,7 +62,7 @@ jobs:
           # To check if all files are covered by patterns other than the
           # catch-all '*', we turn the file into a .gitignore and list
           # unmatched files.
-          cd src/${REPOSITY_NAME}
+          cd src/${{ env.REPOSITY_NAME }}
           # Copy all patterns from CODEOWNERS, but skipping the comments
           # ('^[^#]') and the catch-all '*' rule (the only one with a single
           # character, we skip it with '^.[^ ]').
@@ -80,7 +81,7 @@ jobs:
       - name: Check if CODEOWNERS has stale entries
         if: ${{ needs.check_changes.outputs.deleted-files == 'true' }}
         run: |
-          cd src/${REPOSITY_NAME}
+          cd src/${{ env.REPOSITY_NAME }}
           EXIT_STATUS=0
           # We go through the patterns in CODEOWNERS, and for each of them we
           # search for corresponding files in the repo.
diff --git a/.github/workflows/lint-markdown.yaml b/.github/workflows/lint-markdown.yaml
index 21e694807..684e3bc85 100644
--- a/.github/workflows/lint-markdown.yaml
+++ b/.github/workflows/lint-markdown.yaml
@@ -32,7 +32,7 @@ jobs:
         if: ${{ github.event_name == 'workflow_dispatch' }}
         uses: actions/checkout@v3
         with:
-          ref: ${{ github.event.inputs.tag }}
+          ref: ${{ github.event.inputs.ref }}
 
       - name: Checkout
         if: ${{ github.event_name != 'workflow_dispatch' }}
diff --git a/cmd/spiderpool/cmd/cni_types.go b/cmd/spiderpool/cmd/cni_types.go
index f2a1427e3..25e1bd8ab 100644
--- a/cmd/spiderpool/cmd/cni_types.go
+++ b/cmd/spiderpool/cmd/cni_types.go
@@ -1,5 +1,5 @@
-// Copyright 2022 Authors of spidernet-io
 // SPDX-License-Identifier: Apache-2.0
+// Copyright Authors of Cilium
 
 package cmd
 
diff --git a/cmd/spiderpool/cmd/command_add.go b/cmd/spiderpool/cmd/command_add.go
index 047abdfc7..b13e34446 100644
--- a/cmd/spiderpool/cmd/command_add.go
+++ b/cmd/spiderpool/cmd/command_add.go
@@ -21,6 +21,7 @@ import (
 	"github.com/spidernet-io/spiderpool/cmd/spiderpool-agent/cmd"
 	"github.com/spidernet-io/spiderpool/pkg/constant"
 	spiderpoolip "github.com/spidernet-io/spiderpool/pkg/ip"
+	"github.com/spidernet-io/spiderpool/pkg/logutils"
 )
 
 var (
@@ -56,13 +57,13 @@ func CmdAdd(args *skel.CmdArgs) (err error) {
 		return fmt.Errorf("Load network config failed: %v", err)
 	}
 
-	logger, err = setupFileLogging(conf)
+	err = setupFileLogging(conf)
 	if nil != err {
 		return fmt.Errorf("Unable to setup logging: %w", err)
 	}
 
 	// new cmdAdd logger
-	logger = logger.Named(BinNamePlugin)
+	logger = logutils.LoggerFile.Named(BinNamePlugin)
 	logger.Sugar().Debugf("Processing CNI ADD request %#v", args)
 	logger.Sugar().Debugf("CNI ADD NetConf: %#v", conf)
 
diff --git a/cmd/spiderpool/cmd/command_delete.go b/cmd/spiderpool/cmd/command_delete.go
index 27695e346..d74fd06c1 100644
--- a/cmd/spiderpool/cmd/command_delete.go
+++ b/cmd/spiderpool/cmd/command_delete.go
@@ -12,6 +12,7 @@ import (
 	"github.com/spidernet-io/spiderpool/api/v1/agent/client/daemonset"
 	"github.com/spidernet-io/spiderpool/api/v1/agent/models"
 	"github.com/spidernet-io/spiderpool/cmd/spiderpool-agent/cmd"
+	"github.com/spidernet-io/spiderpool/pkg/logutils"
 	"go.uber.org/zap"
 )
 
@@ -44,13 +45,13 @@ func CmdDel(args *skel.CmdArgs) (err error) {
 		return fmt.Errorf("Load network config failed: %v", err)
 	}
 
-	logger, err = setupFileLogging(conf)
+	err = setupFileLogging(conf)
 	if nil != err {
 		return fmt.Errorf("Unable to setup logging: %w", err)
 	}
 
 	// new cmdDel logger
-	logger = logger.Named(BinNamePlugin)
+	logger = logutils.LoggerFile.Named(BinNamePlugin)
 	logger.Sugar().Debugf("Processing CNI DEL request %#v", args)
 	logger.Sugar().Debugf("CNI DEL NetConf: %#v", conf)
 
diff --git a/cmd/spiderpool/cmd/utils.go b/cmd/spiderpool/cmd/utils.go
index 7055f2917..f128b886e 100644
--- a/cmd/spiderpool/cmd/utils.go
+++ b/cmd/spiderpool/cmd/utils.go
@@ -6,16 +6,21 @@ package cmd
 import (
 	"fmt"
 	"github.com/spidernet-io/spiderpool/pkg/logutils"
-	"go.uber.org/zap"
 )
 
 // Set up logging for spiderpool plugin
-func setupFileLogging(conf *NetConf) (*zap.Logger, error) {
+func setupFileLogging(conf *NetConf) error {
+
 	v := logutils.ConvertLogLevel(conf.IPAM.LogLevel)
 	if v == nil {
-		return nil, fmt.Errorf("wrong log level %s ", conf.IPAM.LogLevel)
+		return fmt.Errorf("wrong log level %s ", conf.IPAM.LogLevel)
 	}
 
-	return logutils.InitFileLogger(*v, conf.IPAM.LogFilePath,
+	err := logutils.InitFileLogger(*v, conf.IPAM.LogFilePath,
 		conf.IPAM.LogFileMaxSize, conf.IPAM.LogFileMaxAge, conf.IPAM.LogFileMaxCount)
+	if nil != err {
+		return err
+	}
+
+	return nil
 }
diff --git a/docs/concepts/config.md b/docs/concepts/config.md
index cc7188406..01fb2b445 100644
--- a/docs/concepts/config.md
+++ b/docs/concepts/config.md
@@ -19,7 +19,7 @@ There is an example of IPAM configuration.
             "mtu":1500,
             "ipam":{
                 "type":"spiderpool",
-                "log_file_path":"/var/log/spidernet/spiderpool.log",
+                "log_file_path":"/var/run/spidernet/spiderpool.log",
                 "log_file_max_size":"100M",
                 "log_file_max_age":"30d",
                 "log_file_max_count":7,
@@ -30,7 +30,7 @@ There is an example of IPAM configuration.
 }
 ```
 
-- `log_file_path` (string, optional): Path to log file  of IPAM plugin, default to `"/var/log/spidernet/spiderpool.log"`.
+- `log_file_path` (string, optional): Path to log file  of IPAM plugin, default to `"/var/run/spidernet/spiderpool.log"`.
 - `log_file_max_size` (string, optional): Max size of each rotated file, default to `"100M"`.
 - `log_file_max_age` (string, optional): Max age of each rotated file, default to `"30d"`.
 - `log_file_max_count` (string, optional): Max number of rotated file, default to `"7"`.
diff --git a/pkg/logutils/log.go b/pkg/logutils/log.go
index bb70c4655..301743a2a 100644
--- a/pkg/logutils/log.go
+++ b/pkg/logutils/log.go
@@ -8,19 +8,20 @@ import (
 	"fmt"
 	"os"
 	"path/filepath"
+
 	"strings"
 
+	"github.com/spidernet-io/spiderpool/pkg/constant"
 	"go.uber.org/zap"
 	"go.uber.org/zap/zapcore"
 	"gopkg.in/natefinch/lumberjack.v2"
-
-	"github.com/spidernet-io/spiderpool/pkg/constant"
 )
 
 // Pre-define log instance with default info level.
 var (
 	Logger       *zap.Logger
 	LoggerStderr *zap.Logger
+	LoggerFile   *zap.Logger
 )
 
 // LogFormat is a type help you choose the log output format, which supports "json" and "console".
@@ -40,7 +41,7 @@ type FileOutputOption struct {
 }
 
 const (
-	DefaultIPAMPluginLogFilePath = "/var/log/spidernet/spiderpool.log"
+	DefaultLogFilePath = "/tmp/cni.log"
 	// MaxSize    = 100 // MB
 	DefaultLogFileMaxSize int = 100
 	// MaxAge     = 30 // days (no limit)
@@ -100,6 +101,12 @@ func init() {
 	if nil != err {
 		panic(err)
 	}
+
+	err = InitFileLogger(InfoLevel, DefaultLogFilePath, DefaultLogFileMaxSize, DefaultLogFileMaxAge, DefaultLogFileMaxBackups)
+	if nil != err {
+		panic(err)
+	}
+
 }
 
 // NewLoggerWithOption provides the ability to custom log with options.
@@ -125,7 +132,7 @@ func NewLoggerWithOption(format LogFormat, outputMode LogMode, fileOutputOption
 		fileLoggerConf.MaxBackups = fileOutputOption.MaxBackups
 
 		if fileOutputOption.Filename == "" {
-			fileLoggerConf.Filename = DefaultIPAMPluginLogFilePath
+			fileLoggerConf.Filename = DefaultLogFilePath
 		}
 		if fileOutputOption.MaxSize < 0 {
 			fileLoggerConf.MaxSize = DefaultLogFileMaxSize
@@ -156,7 +163,7 @@ func NewLoggerWithOption(format LogFormat, outputMode LogMode, fileOutputOption
 	case OUTPUT_STDERR | OUTPUT_FILE:
 		ws = zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stderr), zapcore.AddSync(&fileLoggerConf))
 	case OUTPUT_STDOUT | OUTPUT_STDERR:
-		return nil, fmt.Errorf("log output mode can't set to stdout with stderr together")
+		return nil, fmt.Errorf("log output mode can't set to stdout with stderr together.")
 	default:
 		ws = zapcore.AddSync(os.Stdout)
 	}
@@ -221,19 +228,19 @@ func InitStderrLogger(logLevel LogLevel) error {
 
 // InitFileLogger sets LoggerFile configuration for 'file output' usage.
 // fileMaxSize unit MB, fileMaxAge unit days, fileMaxBackups unit counts.
-func InitFileLogger(logLevel LogLevel, filePath string, fileMaxSize, fileMaxAge, fileMaxBackups int) (*zap.Logger, error) {
+func InitFileLogger(logLevel LogLevel, filePath string, fileMaxSize, fileMaxAge, fileMaxBackups int) error {
 	fileLoggerConf := FileOutputOption{
 		Filename:   filePath,
 		MaxSize:    fileMaxSize,
 		MaxAge:     fileMaxAge,
 		MaxBackups: fileMaxBackups,
 	}
-	logFile, err := NewLoggerWithOption(JsonLogFormat, OUTPUT_FILE, &fileLoggerConf, true, true, true, logLevel)
+	l, err := NewLoggerWithOption(JsonLogFormat, OUTPUT_FILE, &fileLoggerConf, true, true, true, logLevel)
 	if nil != err {
-		return nil, fmt.Errorf("Failed to init logger for file: %v", err)
+		return fmt.Errorf("Failed to init logger for file: %v", err)
 	}
-
-	return logFile, nil
+	LoggerFile = l
+	return nil
 }
 
 // loggerKey is how we find Loggers in a context.Context.


Test patch:
diff --git a/pkg/logutils/log_test.go b/pkg/logutils/log_test.go
index dfad9a012..4be3d2fb9 100644
--- a/pkg/logutils/log_test.go
+++ b/pkg/logutils/log_test.go
@@ -13,10 +13,8 @@ import (
 	"go.uber.org/zap"
 )
 
-const tmpLogFilePath = "/tmp/cni.log"
-
 var _ = Describe("Log", Label("unitest", "log_test"), func() {
-	Context("check log with stdout/stderr/file", func() {
+	Context("When on a nice day", func() {
 		It("log with stdout", func() {
 			err := logutils.InitStdoutLogger(logutils.InfoLevel)
 			Expect(err).NotTo(HaveOccurred())
@@ -26,9 +24,9 @@ var _ = Describe("Log", Label("unitest", "log_test"), func() {
 		})
 
 		It("log for file output mode", func() {
-			loggerFile, err := logutils.InitFileLogger(logutils.InfoLevel, tmpLogFilePath, logutils.DefaultLogFileMaxSize, logutils.DefaultLogFileMaxAge, logutils.DefaultLogFileMaxBackups)
+			err := logutils.InitFileLogger(logutils.InfoLevel, logutils.DefaultLogFilePath, logutils.DefaultLogFileMaxSize, logutils.DefaultLogFileMaxAge, logutils.DefaultLogFileMaxBackups)
 			Expect(err).NotTo(HaveOccurred())
-			loggerFile.Info("This is log test.", zap.Int("log mode", 1))
+			logutils.LoggerFile.Info("This is log test.", zap.Int("log mode", 1))
 		})
 
 		It("log with stderr", func() {