Repository: spidernet-io/spiderpool
Pull request #600 (2022-08-21 05:45:35)

CI: update chart readme
Signed-off-by: weizhou.lan@daocloud.io <weizhou.lan@daocloud.io>

---
name: Pull request
about: Tell us about your contribution
labels: ["pr/release/none-required"]
---

---
## Thanks for contributing !

Before submitting a pull request, make sure you read about our Contribution notice here: <https://spidernet-io.github.io/spiderpool/contributing/development/pullrequest/#need-review>

**What this PR does / why we need it**:

**Which issue(s) this PR fixes**:

**Special notes for your reviewer**:

**make sure your commit is signed off**


sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=spidernet-io_spiderpool&pullRequest=600)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=spidernet-io_spiderpool&pullRequest=600&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=spidernet-io_spiderpool&pullRequest=600) No Coverage information  
[![No Duplication information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/NoDuplicationInfo-16px.png 'No Duplication information')](https://sonarcloud.io/component_measures?id=spidernet-io_spiderpool&pullRequest=600&metric=duplicated_lines_density&view=list) No Duplication information



Patch:
diff --git a/.github/workflows/update-chart-readme.yml b/.github/workflows/update-chart-readme.yml
index 9e17c3e17..9f8932071 100644
--- a/.github/workflows/update-chart-readme.yml
+++ b/.github/workflows/update-chart-readme.yml
@@ -51,10 +51,11 @@ jobs:
           files_changed="$(echo $files_changed_data | jq -r '.[] | .filename')"
           echo "files_changed: $files_changed"
           # Adding || true to avoid "Process exited with code 1" errors
-          charts_changed="$(echo "$files_changed" | grep -E -o "([^/]*)/values.yaml" | xargs dirname | sort | uniq | awk -F'/' '{print $1}' | tr '\n' ' ' || true)"
+          charts_changed="$(echo "$files_changed" | grep -E -o "([^/]*)/values.yaml" | sort | uniq | awk -F'/' '{print $1}' | tr '\n' ' ' || true)"
+          echo "charts_changed: $charts_changed"
           #--------------------
           for ITEM in $charts_changed ; do
-            if [ -f "charts/${ITEM}/values.yaml" ] && grep "charts/${ITEM}/values.yaml" <<< "$files_changed" &>/dev/null ; then
+            if [ -f "thisPorject/charts/${ITEM}/values.yaml" ] && grep "charts/${ITEM}/values.yaml" <<< "$files_changed" &>/dev/null ; then
                 echo "------ Updating README.md for ${ITEM}"
                 readme-generator-for-helm/bin/index.js --values "thisPorject/charts/${ITEM}/values.yaml" --readme "thisPorject/charts/${ITEM}/README.md" --schema "/tmp/schema.json"
                 cat thisPorject/charts/${ITEM}/README.md
@@ -66,6 +67,7 @@ jobs:
           # Push all the changes
           cd thisPorject
           if git status -s | grep README.md; then
+            echo "creat pr"
             git config user.name  "weizhoublue"
             git config user.email "weizhoublue@daocloud.io"
             git add . && git commit -am "Update README.md with readme-generator-for-helm" --signoff && git push
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() {