From 449641b8d1867a115e3a933900336b330c08b4fd Mon Sep 17 00:00:00 2001 From: Shaodong Ma <1289490664@qq.com> Date: Mon, 8 Apr 2024 21:53:15 +0800 Subject: [PATCH 01/33] fix: onex.sh .bashrc name --- scripts/installation/onex.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/installation/onex.sh b/scripts/installation/onex.sh index e7828790b4e..dd79026b818 100755 --- a/scripts/installation/onex.sh +++ b/scripts/installation/onex.sh @@ -250,7 +250,7 @@ onex::onex::prepare() # 2. 配置 $HOME/.bashrc 添加一些便捷入口 if ! grep -q 'Alias for onex quick access' $HOME/.bashrc; then - cat << 'EOF' >> $HOME/.bashr + cat << 'EOF' >> $HOME/.bashrc # Alias and environments for onex quick access export GOSRC="$WORKSPACE/golang/src" # OneX project root directory, used in many places. From e669d7edd8abf7938949e11e9b5fe5ea93d32143 Mon Sep 17 00:00:00 2001 From: feyoung Date: Mon, 8 Apr 2024 23:57:09 +0800 Subject: [PATCH 02/33] fix: fix missing mongo apt signing_key when install mongodb-mongosh --- scripts/installation/mongo.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/installation/mongo.sh b/scripts/installation/mongo.sh index af6b8e4fc66..924908de668 100755 --- a/scripts/installation/mongo.sh +++ b/scripts/installation/mongo.sh @@ -44,6 +44,9 @@ onex::mongo::docker::install() onex::mongo::pre_install() { + # 获取 MongoDB 公钥 + echo ${LINUX_PASSWORD} | sudo -S wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add - + # 添加 MongoDB APT 源 echo ${LINUX_PASSWORD} | sudo -S echo "deb [arch=amd64,arm64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list @@ -74,9 +77,6 @@ onex::mongo::sbs::install() echo ${LINUX_PASSWORD} | sudo -S apt install -y gnupg - # 获取 MongoDB 公钥 - echo ${LINUX_PASSWORD} | sudo -S wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add - - # 安装 MongoDB 服务端 # 以为我们uninstall时会删除配置文件,所以要使用--force-confmiss 重新安装配置文件 onex::util::sudo "apt -y -o Dpkg::Options::="--force-confmiss" --reinstall install mongodb-org mongodb-org-server" From 7d45f9f55dc74ea94035f28ad57a10caf594ddbd Mon Sep 17 00:00:00 2001 From: feyoung Date: Tue, 9 Apr 2024 10:24:31 +0800 Subject: [PATCH 03/33] fix: fix missing add MongoDB APT sources for different system versions when install mongodb-mongosh --- scripts/installation/mongo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/installation/mongo.sh b/scripts/installation/mongo.sh index 924908de668..be968fbd661 100755 --- a/scripts/installation/mongo.sh +++ b/scripts/installation/mongo.sh @@ -48,7 +48,7 @@ onex::mongo::pre_install() echo ${LINUX_PASSWORD} | sudo -S wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add - # 添加 MongoDB APT 源 - echo ${LINUX_PASSWORD} | sudo -S echo "deb [arch=amd64,arm64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list + echo ${LINUX_PASSWORD} | sudo -S echo "deb [arch=amd64,arm64] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list # 安装libssl1.1,否则安装 mongo 时会报以下错误: # mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.1) but it is not installable From 619894a70004b5d2573df4ed62c375b9a8fd73b9 Mon Sep 17 00:00:00 2001 From: tsukiyo Date: Tue, 9 Apr 2024 19:35:53 +0800 Subject: [PATCH 04/33] docs: fix UserBiz annotation --- internal/usercenter/biz/user/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/usercenter/biz/user/user.go b/internal/usercenter/biz/user/user.go index 883402f0aaf..7c772f0b981 100644 --- a/internal/usercenter/biz/user/user.go +++ b/internal/usercenter/biz/user/user.go @@ -15,7 +15,7 @@ import ( v1 "github.com/superproj/onex/pkg/api/usercenter/v1" ) -// UserBiz defines methods used to handle user rquest. +// UserBiz defines methods used to handle user request. type UserBiz interface { Create(ctx context.Context, rq *v1.CreateUserRequest) (*v1.UserReply, error) List(ctx context.Context, rq *v1.ListUserRequest) (*v1.ListUserResponse, error) From 4a8c5b3842d23f0e700618bcd5ac377ab4837dec Mon Sep 17 00:00:00 2001 From: Shaodong Ma <1289490664@qq.com> Date: Tue, 9 Apr 2024 22:39:32 +0800 Subject: [PATCH 05/33] fix: onex.sh grep pattern string matching error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复grep 模式匹配与文件中关键字不一致导致的重复设置问题 --- scripts/installation/onex.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/installation/onex.sh b/scripts/installation/onex.sh index dd79026b818..2238c2a5ffc 100755 --- a/scripts/installation/onex.sh +++ b/scripts/installation/onex.sh @@ -251,7 +251,7 @@ onex::onex::prepare() # 2. 配置 $HOME/.bashrc 添加一些便捷入口 if ! grep -q 'Alias for onex quick access' $HOME/.bashrc; then cat << 'EOF' >> $HOME/.bashrc -# Alias and environments for onex quick access +# Alias for onex quick access export GOSRC="$WORKSPACE/golang/src" # OneX project root directory, used in many places. export ONEX_ROOT="$GOSRC/github.com/superproj/onex" From af147fc6f2725b85f7355d8b8a0aa3cbde552a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Wed, 10 Apr 2024 19:48:02 +0800 Subject: [PATCH 06/33] chore: auto detects the CPU arch when install kubectl --- scripts/make-rules/tools.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/make-rules/tools.mk b/scripts/make-rules/tools.mk index aba92d2b26a..3d5c4279c51 100644 --- a/scripts/make-rules/tools.mk +++ b/scripts/make-rules/tools.mk @@ -173,7 +173,7 @@ _install.kubeconform: ## Install kubeconform command line tool. .PHONY: _install.kubectl _install.kubectl: ## Install kubectl command line tool. - @curl --create-dirs -L -o $$HOME/bin/kubectl "https://dl.k8s.io/release/$(shell curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + @curl --create-dirs -L -o $$HOME/bin/kubectl "https://dl.k8s.io/release/$(shell curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/$(shell $(GO) env GOHOSTARCH)/kubectl" @chmod +x $$HOME/bin/kubectl @$(SCRIPTS_DIR)/add-completion.sh kubectl bash From d2ffddfe0916cd973f215ccb294cb05b94963d42 Mon Sep 17 00:00:00 2001 From: goooogoooo Date: Wed, 10 Apr 2024 21:32:18 +0800 Subject: [PATCH 07/33] fix:selector is required --- manifests/sample/onex/minerset.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/manifests/sample/onex/minerset.yaml b/manifests/sample/onex/minerset.yaml index 28b4d225f17..459e4cf5332 100644 --- a/manifests/sample/onex/minerset.yaml +++ b/manifests/sample/onex/minerset.yaml @@ -17,3 +17,6 @@ spec: spec: chainName: genesis minerType: M1.MEDIUM2 + selector: + matchLabels: + app: testminerset From dae366aa9966ac55c279a354f2d5cca3e2db26f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Wed, 10 Apr 2024 22:48:46 +0800 Subject: [PATCH 08/33] fix: change mongodb apt source from ubuntu to debian --- scripts/installation/mongo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/installation/mongo.sh b/scripts/installation/mongo.sh index be968fbd661..4490127545d 100755 --- a/scripts/installation/mongo.sh +++ b/scripts/installation/mongo.sh @@ -48,7 +48,7 @@ onex::mongo::pre_install() echo ${LINUX_PASSWORD} | sudo -S wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add - # 添加 MongoDB APT 源 - echo ${LINUX_PASSWORD} | sudo -S echo "deb [arch=amd64,arm64] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list + echo ${LINUX_PASSWORD} | sudo -S echo "deb [arch=amd64,arm64] https://repo.mongodb.org/apt/debian $(lsb_release -cs)/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list # 安装libssl1.1,否则安装 mongo 时会报以下错误: # mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.1) but it is not installable From 131c0dacd9d67a5af3d8d1a61ecab6fd202e1193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Thu, 11 Apr 2024 21:31:25 +0800 Subject: [PATCH 09/33] fix: fix the wrong component name for mongodb apt source --- scripts/installation/mongo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/installation/mongo.sh b/scripts/installation/mongo.sh index 4490127545d..26ab1876264 100755 --- a/scripts/installation/mongo.sh +++ b/scripts/installation/mongo.sh @@ -48,7 +48,7 @@ onex::mongo::pre_install() echo ${LINUX_PASSWORD} | sudo -S wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add - # 添加 MongoDB APT 源 - echo ${LINUX_PASSWORD} | sudo -S echo "deb [arch=amd64,arm64] https://repo.mongodb.org/apt/debian $(lsb_release -cs)/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list + echo ${LINUX_PASSWORD} | sudo -S echo "deb [arch=amd64,arm64] https://repo.mongodb.org/apt/debian $(lsb_release -cs)/mongodb-org/7.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list # 安装libssl1.1,否则安装 mongo 时会报以下错误: # mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.1) but it is not installable From ed1abcbf9fc4aabc68f384503f94e87e120c0b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Fri, 12 Apr 2024 14:46:05 +0800 Subject: [PATCH 10/33] chore: change mysql default port from 6379 to 3306 --- scripts/installation/mariadb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/installation/mariadb.sh b/scripts/installation/mariadb.sh index ac5ed841a93..ce08c82cf7a 100755 --- a/scripts/installation/mariadb.sh +++ b/scripts/installation/mariadb.sh @@ -12,7 +12,7 @@ ONEX_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. [[ -z ${COMMON_SOURCED} ]] && source ${ONEX_ROOT}/scripts/installation/common.sh # Set some environment variables. ONEX_MYSQL_HOST=${ONEX_MYSQL_HOST:-127.0.0.1} -ONEX_MYSQL_PORT=${ONEX_MYSQL_PORT:-6379} +ONEX_MYSQL_PORT=${ONEX_MYSQL_PORT:-3306} ONEX_PASSWORD=${ONEX_PASSWORD:-onex(#)666} # Install mariadb using containerization. From 09318f9d07be9c86a6b454e18514d21e6544cbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sun, 14 Apr 2024 15:50:46 +0800 Subject: [PATCH 11/33] chore: show an error message if curl fails --- scripts/installation/test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/installation/test.sh b/scripts/installation/test.sh index 760163204cb..59b81510c38 100755 --- a/scripts/installation/test.sh +++ b/scripts/installation/test.sh @@ -17,8 +17,7 @@ ONEX_PUMP_ADDR=${ONEX_ACCESS_HOST}:${ONEX_PUMP_HEALTH_CHECK_PORT} ONEX_TOYBLC_ADDR=${ONEX_ACCESS_HOST}:${ONEX_TOYBLC_HTTP_PORT} Header="-HContent-Type:application/json" -CURLARGS="-f -s" -#CURLARGS="" +CURLARGS="-S" CCURL="curl ${CURLARGS} -XPOST ${Header}" # Create UCURL="curl ${CURLARGS} -XPUT ${Header}" # Update RCURL="curl ${CURLARGS} -XGET" # Retrieve From d3717bad97b22612293ce66b0f8729073166e626 Mon Sep 17 00:00:00 2001 From: goooogoooo Date: Mon, 15 Apr 2024 16:52:50 +0800 Subject: [PATCH 12/33] docs: fix db annotation --- pkg/db/mysql.go | 2 +- pkg/db/redis.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/db/mysql.go b/pkg/db/mysql.go index 76650b20495..58ecd61dfc5 100644 --- a/pkg/db/mysql.go +++ b/pkg/db/mysql.go @@ -15,7 +15,7 @@ import ( "gorm.io/gorm/logger" ) -// MySQLOptions defines optsions for mysql database. +// MySQLOptions defines options for mysql database. type MySQLOptions struct { Host string Username string diff --git a/pkg/db/redis.go b/pkg/db/redis.go index daeb9447639..dcafcba2c09 100644 --- a/pkg/db/redis.go +++ b/pkg/db/redis.go @@ -13,7 +13,7 @@ import ( "github.com/redis/go-redis/v9" ) -// RedisOptions defines optsions for mysql database. +// RedisOptions defines options for redis database. type RedisOptions struct { Addr string Username string @@ -28,7 +28,7 @@ type RedisOptions struct { PoolSize int } -// NewRedis create a new gorm db instance with the given options. +// NewRedis create a new redis db instance with the given options. func NewRedis(opts *RedisOptions) (*redis.Client, error) { options := &redis.Options{ Addr: opts.Addr, From 3de90773af66fb8f3c03bd2a7ab40bb90a3948fd Mon Sep 17 00:00:00 2001 From: goooogoooo Date: Sun, 21 Apr 2024 18:30:14 +0800 Subject: [PATCH 13/33] fix: serviceName in StatefulSet is required --- manifests/installation/middleware/jaeger/statefulset.yaml | 1 + manifests/installation/middleware/kafka/statefulset.yaml | 1 + manifests/installation/storage/etcd/statefulset.yaml | 1 + manifests/installation/storage/mariadb/statefulset.yaml | 2 ++ manifests/installation/storage/mongo/statefulset.yaml | 1 + manifests/installation/storage/redis/statefulset.yaml | 1 + 6 files changed, 7 insertions(+) diff --git a/manifests/installation/middleware/jaeger/statefulset.yaml b/manifests/installation/middleware/jaeger/statefulset.yaml index e3d8569c85d..ce9fb14268b 100644 --- a/manifests/installation/middleware/jaeger/statefulset.yaml +++ b/manifests/installation/middleware/jaeger/statefulset.yaml @@ -7,6 +7,7 @@ spec: selector: matchLabels: app: jaeger + serviceName: jaeger template: metadata: labels: diff --git a/manifests/installation/middleware/kafka/statefulset.yaml b/manifests/installation/middleware/kafka/statefulset.yaml index cbf7ba0e8df..13f6dcea113 100644 --- a/manifests/installation/middleware/kafka/statefulset.yaml +++ b/manifests/installation/middleware/kafka/statefulset.yaml @@ -7,6 +7,7 @@ spec: selector: matchLabels: app: kafka + serviceName: onex-kafka template: metadata: labels: diff --git a/manifests/installation/storage/etcd/statefulset.yaml b/manifests/installation/storage/etcd/statefulset.yaml index 12d1017bdd7..5266a32c9e8 100644 --- a/manifests/installation/storage/etcd/statefulset.yaml +++ b/manifests/installation/storage/etcd/statefulset.yaml @@ -7,6 +7,7 @@ spec: selector: matchLabels: app: etcd + serviceName: etcd template: metadata: labels: diff --git a/manifests/installation/storage/mariadb/statefulset.yaml b/manifests/installation/storage/mariadb/statefulset.yaml index aabdf01ce08..292a8a20281 100644 --- a/manifests/installation/storage/mariadb/statefulset.yaml +++ b/manifests/installation/storage/mariadb/statefulset.yaml @@ -17,6 +17,8 @@ spec: selector: matchLabels: app: mariadb + # 指定了Pod关联的Service名称 + serviceName: mariadb # 指定了要创建的Pod的模板信息 template: # 指定了Pod的元数据信息,包括标签等 diff --git a/manifests/installation/storage/mongo/statefulset.yaml b/manifests/installation/storage/mongo/statefulset.yaml index e283457c32b..6a05d87773c 100644 --- a/manifests/installation/storage/mongo/statefulset.yaml +++ b/manifests/installation/storage/mongo/statefulset.yaml @@ -7,6 +7,7 @@ spec: selector: matchLabels: app: mongo + serviceName: mongo template: metadata: labels: diff --git a/manifests/installation/storage/redis/statefulset.yaml b/manifests/installation/storage/redis/statefulset.yaml index 3d1fda9592c..11ea1f7c2b3 100644 --- a/manifests/installation/storage/redis/statefulset.yaml +++ b/manifests/installation/storage/redis/statefulset.yaml @@ -7,6 +7,7 @@ spec: selector: matchLabels: app: redis + serviceName: redis template: metadata: labels: From 309923a723f871c4f7cfcb47dcc8f0abfa444a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sun, 21 Apr 2024 23:05:49 +0800 Subject: [PATCH 14/33] fix: remove -loglevel option for cfssl tool remove -loglevel option for cfssl tool because some cfssl version do not provide this option --- scripts/gen-certs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/gen-certs.sh b/scripts/gen-certs.sh index 2953d7b2bb5..5479fc10260 100755 --- a/scripts/gen-certs.sh +++ b/scripts/gen-certs.sh @@ -85,7 +85,7 @@ EOF fi if [[ ! -r "ca.pem" || ! -r "ca-key.pem" ]]; then - ${CFSSL_BIN} gencert -loglevel 2 -initca ca-csr.json | ${CFSSLJSON_BIN} -bare ca - + ${CFSSL_BIN} gencert -initca ca-csr.json | ${CFSSLJSON_BIN} -bare ca - fi if [[ -z "${prefix}" ]];then @@ -94,7 +94,7 @@ EOF #echo "Generate "${prefix}" certificates..." echo '{"CN":"'"${prefix}"'","hosts":[],"key":{"algo":"rsa","size":2048},"names":[{"C":"CN","ST":"Shenzhen","L":"Shenzhen","O":"tencent","OU":"'"${prefix}"'"}]}' \ - | ${CFSSL_BIN} gencert -loglevel 2 -hostname="${CERT_HOSTNAME},${prefix/-/.}.${ONEX_DOMAIN}" -ca=ca.pem -ca-key=ca-key.pem \ + | ${CFSSL_BIN} gencert -hostname="${CERT_HOSTNAME},${prefix/-/.}.${ONEX_DOMAIN}" -ca=ca.pem -ca-key=ca-key.pem \ -config=ca-config.json -profile=node - | ${CFSSLJSON_BIN} -bare "${prefix}" # the popd will access `directory stack`, no `real` parameters is actually needed From 4f026714adfe83e5540991803858696c97b40eab Mon Sep 17 00:00:00 2001 From: firefly Date: Thu, 25 Apr 2024 11:34:48 +0800 Subject: [PATCH 15/33] fix(etc): change go-version from "go1.22.2" to "1.22.2" I encountered the following error, when I manually installed onex: go: invalid GOTOOLCHAIN "gogo1.22.2" I don't have any idea what to do with 'go1.22.2'. (using download type 'auto') go: invalid GOTOOLCHAIN "gogo1.22.2" To fix this error, I removed "go" from "go1.22.2". --- .go-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.go-version b/.go-version index e817184225c..6fee2fedb0a 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -go1.22.2 +1.22.2 From 6db5a1dec8e85481b97ede405fa9c7009ba19420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sun, 28 Apr 2024 11:53:01 +0800 Subject: [PATCH 16/33] Revert "fix:selector is required" This reverts commit d2ffddfe0916cd973f215ccb294cb05b94963d42. --- manifests/sample/onex/minerset.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/manifests/sample/onex/minerset.yaml b/manifests/sample/onex/minerset.yaml index 459e4cf5332..28b4d225f17 100644 --- a/manifests/sample/onex/minerset.yaml +++ b/manifests/sample/onex/minerset.yaml @@ -17,6 +17,3 @@ spec: spec: chainName: genesis minerType: M1.MEDIUM2 - selector: - matchLabels: - app: testminerset From d284a0dd9cdf4e295073189c6f25b09444d0af51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=B9=96=E5=8D=81=E5=B9=B4?= Date: Tue, 30 Apr 2024 09:46:04 +0800 Subject: [PATCH 17/33] chore: prefixs to prefixes --- .../onexctl/util/options/server_options.go | 18 +++++++++--------- internal/pkg/client/usercenter/options.go | 2 +- pkg/options/authentication_options.go | 2 +- pkg/options/consul_options.go | 2 +- pkg/options/etcd_options.go | 2 +- pkg/options/grpc_options.go | 2 +- pkg/options/health_options.go | 2 +- pkg/options/helper.go | 4 ++-- pkg/options/http_options.go | 2 +- pkg/options/insecure_serving.go | 2 +- pkg/options/jaeger_options.go | 2 +- pkg/options/jwt_options.go | 2 +- pkg/options/kafka_options.go | 2 +- pkg/options/logs_options.go | 2 +- pkg/options/metrics_options.go | 2 +- pkg/options/mongo_options.go | 2 +- pkg/options/mysql_options.go | 18 +++++++++--------- pkg/options/options.go | 2 +- pkg/options/polaris_options.go | 2 +- pkg/options/redis_options.go | 2 +- pkg/options/secure_serving.go | 2 +- pkg/options/tls_options.go | 12 ++++++------ 22 files changed, 44 insertions(+), 44 deletions(-) diff --git a/internal/onexctl/util/options/server_options.go b/internal/onexctl/util/options/server_options.go index 793728b0b56..40c981f1ca1 100644 --- a/internal/onexctl/util/options/server_options.go +++ b/internal/onexctl/util/options/server_options.go @@ -36,19 +36,19 @@ func (o *ServerOptions) Validate() []error { } // AddFlags adds flags related to mysql storage for a specific APIServer to the specified FlagSet. -func (o *ServerOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { - fs.BoolVar(&o.Insecure, join(prefixs...)+"insecure-skip-tls-verify", o.Insecure, ""+ +func (o *ServerOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { + fs.BoolVar(&o.Insecure, join(prefixes...)+"insecure-skip-tls-verify", o.Insecure, ""+ "If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure") - fs.StringVar(&o.CAFile, join(prefixs...)+"certificate-authority", o.CAFile, "Path to a cert file for the certificate authority") - fs.StringVar(&o.Addr, join(prefixs...)+"address", o.Addr, "The address and port of the OneX API server") - fs.DurationVar(&o.Timeout, join(prefixs...)+"timeout", o.Timeout, "The length of time to wait before giving up on a single "+ + fs.StringVar(&o.CAFile, join(prefixes...)+"certificate-authority", o.CAFile, "Path to a cert file for the certificate authority") + fs.StringVar(&o.Addr, join(prefixes...)+"address", o.Addr, "The address and port of the OneX API server") + fs.DurationVar(&o.Timeout, join(prefixes...)+"timeout", o.Timeout, "The length of time to wait before giving up on a single "+ "server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests.") - fs.IntVar(&o.MaxRetries, join(prefixs...)+"max-retries", o.MaxRetries, "Maximum number of retries.") - fs.DurationVar(&o.RetryInterval, join(prefixs...)+"retry-interval", o.RetryInterval, "The interval time between each attempt.") + fs.IntVar(&o.MaxRetries, join(prefixes...)+"max-retries", o.MaxRetries, "Maximum number of retries.") + fs.DurationVar(&o.RetryInterval, join(prefixes...)+"retry-interval", o.RetryInterval, "The interval time between each attempt.") } -func join(prefixs ...string) string { - joined := strings.Join(prefixs, ".") +func join(prefixes ...string) string { + joined := strings.Join(prefixes, ".") if joined != "" { joined += "." } diff --git a/internal/pkg/client/usercenter/options.go b/internal/pkg/client/usercenter/options.go index eccb95588be..0d98400d320 100644 --- a/internal/pkg/client/usercenter/options.go +++ b/internal/pkg/client/usercenter/options.go @@ -43,7 +43,7 @@ func (o *UserCenterOptions) Validate() []error { } // AddFlags adds flags for a specific APIServer to the specified FlagSet. -func (o *UserCenterOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *UserCenterOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { if o == nil { return } diff --git a/pkg/options/authentication_options.go b/pkg/options/authentication_options.go index b03e1c8825d..c175565c9cf 100644 --- a/pkg/options/authentication_options.go +++ b/pkg/options/authentication_options.go @@ -33,7 +33,7 @@ func (o *ClientCertAuthenticationOptions) Validate() []error { // AddFlags adds flags related to ClientCertAuthenticationOptions for a specific server to the // specified FlagSet. -func (o *ClientCertAuthenticationOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *ClientCertAuthenticationOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.StringVar(&o.ClientCA, "client-ca-file", o.ClientCA, ""+ "If set, any request presenting a client certificate signed by one of "+ "the authorities in the client-ca-file is authenticated with an identity "+ diff --git a/pkg/options/consul_options.go b/pkg/options/consul_options.go index a198b691b2b..2db05e08903 100644 --- a/pkg/options/consul_options.go +++ b/pkg/options/consul_options.go @@ -37,7 +37,7 @@ func (o *ConsulOptions) Validate() []error { } // AddFlags adds flags related to mysql storage for a specific APIServer to the specified FlagSet. -func (o *ConsulOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *ConsulOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.StringVar(&o.Addr, "consul.addr", o.Addr, ""+ "Addr is the address of the consul server.") diff --git a/pkg/options/etcd_options.go b/pkg/options/etcd_options.go index def84afc9ea..257c546dd7e 100644 --- a/pkg/options/etcd_options.go +++ b/pkg/options/etcd_options.go @@ -51,7 +51,7 @@ func (o *EtcdOptions) Validate() []error { } // AddFlags adds flags related to redis storage for a specific APIServer to the specified FlagSet. -func (o *EtcdOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *EtcdOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { o.TLSOptions.AddFlags(fs, "etcd") fs.StringSliceVar(&o.Endpoints, "etcd.endpoints", o.Endpoints, "Endpoints of etcd cluster.") diff --git a/pkg/options/grpc_options.go b/pkg/options/grpc_options.go index a0913184750..11c8ef18188 100644 --- a/pkg/options/grpc_options.go +++ b/pkg/options/grpc_options.go @@ -51,7 +51,7 @@ func (o *GRPCOptions) Validate() []error { // AddFlags adds flags related to features for a specific api server to the // specified FlagSet. -func (o *GRPCOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *GRPCOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.StringVar(&o.Network, "grpc.network", o.Network, "Specify the network for the gRPC server.") fs.StringVar(&o.Addr, "grpc.addr", o.Addr, "Specify the gRPC server bind address and port.") fs.DurationVar(&o.Timeout, "grpc.timeout", o.Timeout, "Timeout for server connections.") diff --git a/pkg/options/health_options.go b/pkg/options/health_options.go index 291ad4fe2d0..9fa92d4195b 100644 --- a/pkg/options/health_options.go +++ b/pkg/options/health_options.go @@ -44,7 +44,7 @@ func (o *HealthOptions) Validate() []error { } // AddFlags adds flags related to redis storage for a specific APIServer to the specified FlagSet. -func (o *HealthOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *HealthOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.BoolVar(&o.HTTPProfile, "health.enable-http-profiler", o.HTTPProfile, "Expose runtime profiling data via HTTP.") fs.StringVar(&o.HealthCheckPath, "health.check-path", o.HealthCheckPath, "Specifies liveness health check request path.") fs.StringVar(&o.HealthCheckAddress, "health.check-address", o.HealthCheckAddress, "Specifies liveness health check bind address.") diff --git a/pkg/options/helper.go b/pkg/options/helper.go index f073ea55af4..69079aa9aa6 100644 --- a/pkg/options/helper.go +++ b/pkg/options/helper.go @@ -23,8 +23,8 @@ const ( TiB ) -func join(prefixs ...string) string { - joined := strings.Join(prefixs, ".") +func join(prefixes ...string) string { + joined := strings.Join(prefixes, ".") if joined != "" { joined += "." } diff --git a/pkg/options/http_options.go b/pkg/options/http_options.go index cf6c116c20a..fcfa87611fa 100644 --- a/pkg/options/http_options.go +++ b/pkg/options/http_options.go @@ -53,7 +53,7 @@ func (o *HTTPOptions) Validate() []error { // AddFlags adds flags related to HTTPS server for a specific APIServer to the // specified FlagSet. -func (o *HTTPOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *HTTPOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.StringVar(&o.Network, "http.network", o.Network, "Specify the network for the HTTP server.") fs.StringVar(&o.Addr, "http.addr", o.Addr, "Specify the HTTP server bind address and port.") fs.DurationVar(&o.Timeout, "http.timeout", o.Timeout, "Timeout for server connections.") diff --git a/pkg/options/insecure_serving.go b/pkg/options/insecure_serving.go index 86ebfafa543..579a3a99dea 100644 --- a/pkg/options/insecure_serving.go +++ b/pkg/options/insecure_serving.go @@ -36,6 +36,6 @@ func (s *InsecureServingOptions) Validate() []error { // AddFlags adds flags related to features for a specific api server to the // specified FlagSet. -func (s *InsecureServingOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (s *InsecureServingOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.StringVar(&s.Addr, "insecure.addr", s.Addr, "Specify the HTTP server bind address and port.") } diff --git a/pkg/options/jaeger_options.go b/pkg/options/jaeger_options.go index eb2f8212e78..d0c0f1cc140 100644 --- a/pkg/options/jaeger_options.go +++ b/pkg/options/jaeger_options.go @@ -44,7 +44,7 @@ func (o *JaegerOptions) Validate() []error { } // AddFlags adds flags related to mysql storage for a specific APIServer to the specified FlagSet. -func (o *JaegerOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *JaegerOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.StringVar(&o.Server, "jaeger.server", o.Server, ""+ "Server is the url of the Jaeger server.") fs.StringVar(&o.ServiceName, "jaeger.service-name", o.ServiceName, ""+ diff --git a/pkg/options/jwt_options.go b/pkg/options/jwt_options.go index a975f8e3be1..ae4a76acb88 100644 --- a/pkg/options/jwt_options.go +++ b/pkg/options/jwt_options.go @@ -49,7 +49,7 @@ func (s *JWTOptions) Validate() []error { // AddFlags adds flags related to features for a specific api server to the // specified FlagSet. -func (s *JWTOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (s *JWTOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { if fs == nil { return } diff --git a/pkg/options/kafka_options.go b/pkg/options/kafka_options.go index 2efe55a591c..83cfa1e3e69 100644 --- a/pkg/options/kafka_options.go +++ b/pkg/options/kafka_options.go @@ -245,7 +245,7 @@ func (o *KafkaOptions) Validate() []error { } // AddFlags adds flags related to redis storage for a specific APIServer to the specified FlagSet. -func (o *KafkaOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *KafkaOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { o.TLSOptions.AddFlags(fs, "kafka") fs.StringSliceVar(&o.Brokers, "kafka.brokers", o.Brokers, "The list of brokers used to discover the partitions available on the kafka cluster.") diff --git a/pkg/options/logs_options.go b/pkg/options/logs_options.go index 60ecaba325b..a9f38a9e562 100644 --- a/pkg/options/logs_options.go +++ b/pkg/options/logs_options.go @@ -58,7 +58,7 @@ func (o *LogsOptions) Validate() []error { } // AddFlags adds command line flags for the configuration. -func (o *LogsOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *LogsOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.StringVar(&o.Format, "logs.format", o.Format, "Sets the log format. Permitted formats: json, text.") fs.DurationVar(&o.FlushFrequency, "log.flush-frequency", o.FlushFrequency, "Maximum number of seconds between log flushes.") fs.VarP(logsapi.VerbosityLevelPflag(&o.Verbosity), "logs.verbosity", "", " Number for the log level verbosity.") diff --git a/pkg/options/metrics_options.go b/pkg/options/metrics_options.go index dbf3d8695cf..4d4a3a0c770 100644 --- a/pkg/options/metrics_options.go +++ b/pkg/options/metrics_options.go @@ -42,7 +42,7 @@ func (o *MetricsOptions) Validate() []error { } // AddFlags adds flags for exposing component metrics. -func (o *MetricsOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *MetricsOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { if o == nil { return } diff --git a/pkg/options/mongo_options.go b/pkg/options/mongo_options.go index 1587a3d5f11..0eac0b81c1f 100644 --- a/pkg/options/mongo_options.go +++ b/pkg/options/mongo_options.go @@ -63,7 +63,7 @@ func (o *MongoOptions) Validate() []error { } // AddFlags adds flags related to redis storage for a specific APIServer to the specified FlagSet. -func (o *MongoOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *MongoOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { o.TLSOptions.AddFlags(fs, "mongo") fs.DurationVar(&o.Timeout, "mongo.timeout", o.Timeout, "Timeout is the maximum amount of time a dial will wait for a connect to complete.") diff --git a/pkg/options/mysql_options.go b/pkg/options/mysql_options.go index d69533c0876..c8efea56c3a 100644 --- a/pkg/options/mysql_options.go +++ b/pkg/options/mysql_options.go @@ -53,21 +53,21 @@ func (o *MySQLOptions) Validate() []error { } // AddFlags adds flags related to mysql storage for a specific APIServer to the specified FlagSet. -func (o *MySQLOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { - fs.StringVar(&o.Host, join(prefixs...)+"db.host", o.Host, ""+ +func (o *MySQLOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { + fs.StringVar(&o.Host, join(prefixes...)+"db.host", o.Host, ""+ "MySQL service host address. If left blank, the following related mysql options will be ignored.") - fs.StringVar(&o.Username, join(prefixs...)+"db.username", o.Username, "Username for access to mysql service.") - fs.StringVar(&o.Password, join(prefixs...)+"db.password", o.Password, ""+ + fs.StringVar(&o.Username, join(prefixes...)+"db.username", o.Username, "Username for access to mysql service.") + fs.StringVar(&o.Password, join(prefixes...)+"db.password", o.Password, ""+ "Password for access to mysql, should be used pair with password.") - fs.StringVar(&o.Database, join(prefixs...)+"db.database", o.Database, ""+ + fs.StringVar(&o.Database, join(prefixes...)+"db.database", o.Database, ""+ "Database name for the server to use.") - fs.IntVar(&o.MaxIdleConnections, join(prefixs...)+"db.max-idle-connections", o.MaxOpenConnections, ""+ + fs.IntVar(&o.MaxIdleConnections, join(prefixes...)+"db.max-idle-connections", o.MaxOpenConnections, ""+ "Maximum idle connections allowed to connect to mysql.") - fs.IntVar(&o.MaxOpenConnections, join(prefixs...)+"db.max-open-connections", o.MaxOpenConnections, ""+ + fs.IntVar(&o.MaxOpenConnections, join(prefixes...)+"db.max-open-connections", o.MaxOpenConnections, ""+ "Maximum open connections allowed to connect to mysql.") - fs.DurationVar(&o.MaxConnectionLifeTime, join(prefixs...)+"db.max-connection-life-time", o.MaxConnectionLifeTime, ""+ + fs.DurationVar(&o.MaxConnectionLifeTime, join(prefixes...)+"db.max-connection-life-time", o.MaxConnectionLifeTime, ""+ "Maximum connection life time allowed to connect to mysql.") - fs.IntVar(&o.LogLevel, join(prefixs...)+"db.log-mode", o.LogLevel, ""+ + fs.IntVar(&o.LogLevel, join(prefixes...)+"db.log-mode", o.LogLevel, ""+ "Specify gorm log level.") } diff --git a/pkg/options/options.go b/pkg/options/options.go index 4f6fffc198f..fe45dc71cb8 100644 --- a/pkg/options/options.go +++ b/pkg/options/options.go @@ -14,5 +14,5 @@ type IOptions interface { Validate() []error // AddFlags adds flags related to given flagset. - AddFlags(fs *pflag.FlagSet, prefixs ...string) + AddFlags(fs *pflag.FlagSet, prefixes ...string) } diff --git a/pkg/options/polaris_options.go b/pkg/options/polaris_options.go index e218f0e8e0d..ed8df17d9f4 100644 --- a/pkg/options/polaris_options.go +++ b/pkg/options/polaris_options.go @@ -35,7 +35,7 @@ func (o *PolarisOptions) Validate() []error { } // AddFlags adds flags related to Polaris service to the specified FlagSet. -func (o *PolarisOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *PolarisOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.StringVar(&o.Addr, "polaris.addr", o.Addr, "Address of your Polaris service(ip:port).") fs.DurationVar(&o.ReadTimeout, "polaris.read-timeout", o.ReadTimeout, "Timeout for socket reads.") fs.DurationVar(&o.WriteTimeout, "polaris.write-timeout", o.WriteTimeout, "Timeout for socket writes.") diff --git a/pkg/options/redis_options.go b/pkg/options/redis_options.go index 08e54c0e261..ac124b2273a 100644 --- a/pkg/options/redis_options.go +++ b/pkg/options/redis_options.go @@ -68,7 +68,7 @@ func (o *RedisOptions) Validate() []error { } // AddFlags adds flags related to redis storage for a specific APIServer to the specified FlagSet. -func (o *RedisOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (o *RedisOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.StringVar(&o.Addr, "redis.addr", o.Addr, "Address of your Redis server(ip:port).") fs.StringVar(&o.Username, "redis.username", o.Username, "Username for access to redis service.") fs.StringVar(&o.Password, "redis.password", o.Password, "Optional auth password for redis db.") diff --git a/pkg/options/secure_serving.go b/pkg/options/secure_serving.go index 3506dee234f..e78de41d9c8 100644 --- a/pkg/options/secure_serving.go +++ b/pkg/options/secure_serving.go @@ -82,7 +82,7 @@ func (s *SecureServingOptions) Validate() []error { // AddFlags adds flags related to HTTPS server for a specific APIServer to the // specified FlagSet. -func (s *SecureServingOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { +func (s *SecureServingOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { fs.StringVar(&s.BindAddress, "secure.bind-address", s.BindAddress, ""+ "The IP address on which to listen for the --secure.bind-port port. The "+ "associated interface(s) must be reachable by the rest of the engine, and by CLI/web "+ diff --git a/pkg/options/tls_options.go b/pkg/options/tls_options.go index 7ecb9dc9638..ce8e6bb4fe0 100644 --- a/pkg/options/tls_options.go +++ b/pkg/options/tls_options.go @@ -49,13 +49,13 @@ func (o *TLSOptions) Validate() []error { } // AddFlags adds flags related to redis storage for a specific APIServer to the specified FlagSet. -func (o *TLSOptions) AddFlags(fs *pflag.FlagSet, prefixs ...string) { - fs.BoolVar(&o.UseTLS, join(prefixs...)+"tls.use-tls", o.UseTLS, "Use tls transport to connect the server.") - fs.BoolVar(&o.InsecureSkipVerify, join(prefixs...)+"tls.insecure-skip-verify", o.InsecureSkipVerify, ""+ +func (o *TLSOptions) AddFlags(fs *pflag.FlagSet, prefixes ...string) { + fs.BoolVar(&o.UseTLS, join(prefixes...)+"tls.use-tls", o.UseTLS, "Use tls transport to connect the server.") + fs.BoolVar(&o.InsecureSkipVerify, join(prefixes...)+"tls.insecure-skip-verify", o.InsecureSkipVerify, ""+ "Controls whether a client verifies the server's certificate chain and host name.") - fs.StringVar(&o.CaCert, join(prefixs...)+"tls.ca-cert", o.CaCert, "Path to ca cert for connecting to the server.") - fs.StringVar(&o.Cert, join(prefixs...)+"tls.cert", o.Cert, "Path to cert file for connecting to the server.") - fs.StringVar(&o.Key, join(prefixs...)+"tls.key", o.Key, "Path to key file for connecting to the server.") + fs.StringVar(&o.CaCert, join(prefixes...)+"tls.ca-cert", o.CaCert, "Path to ca cert for connecting to the server.") + fs.StringVar(&o.Cert, join(prefixes...)+"tls.cert", o.Cert, "Path to cert file for connecting to the server.") + fs.StringVar(&o.Key, join(prefixes...)+"tls.key", o.Key, "Path to key file for connecting to the server.") } func (o *TLSOptions) MustTLSConfig() *tls.Config { From ae61c75ce521526ef7080289fdacd5c683dfcf87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=B9=96=E5=8D=81=E5=B9=B4?= Date: Sun, 28 Apr 2024 20:45:50 +0800 Subject: [PATCH 18/33] chore: modify code comment --- cmd/onex-gateway/app/options/options.go | 4 ++-- cmd/onex-nightwatch/app/options/options.go | 2 +- cmd/onex-pump/app/options/options.go | 2 +- cmd/onex-toyblc/app/options/options.go | 4 ++-- cmd/onex-usercenter/app/options/options.go | 4 ++-- pkg/app/app.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/onex-gateway/app/options/options.go b/cmd/onex-gateway/app/options/options.go index c91a1fc436a..108493a9762 100644 --- a/cmd/onex-gateway/app/options/options.go +++ b/cmd/onex-gateway/app/options/options.go @@ -122,7 +122,7 @@ func (o *Options) Validate() error { return utilerrors.NewAggregate(errs) } -// ApplyTo fills up onex-nightwatch config with options. +// ApplyTo fills up onex-gateway config with options. func (o *Options) ApplyTo(c *gateway.Config) error { c.GRPCOptions = o.GRPCOptions c.HTTPOptions = o.HTTPOptions @@ -136,7 +136,7 @@ func (o *Options) ApplyTo(c *gateway.Config) error { return nil } -// Config return a onex-nightwatch config object. +// Config return an onex-gateway config object. func (o *Options) Config() (*gateway.Config, error) { kubeconfig, err := clientcmd.BuildConfigFromFlags("", o.Kubeconfig) if err != nil { diff --git a/cmd/onex-nightwatch/app/options/options.go b/cmd/onex-nightwatch/app/options/options.go index c986c0574b7..5fc54b446e4 100644 --- a/cmd/onex-nightwatch/app/options/options.go +++ b/cmd/onex-nightwatch/app/options/options.go @@ -101,7 +101,7 @@ func (o *Options) ApplyTo(c *nightwatch.Config) error { return nil } -// Config return a onex-nightwatch config object. +// Config return an onex-nightwatch config object. func (o *Options) Config() (*nightwatch.Config, error) { kubeconfig, err := clientcmd.BuildConfigFromFlags("", o.Kubeconfig) if err != nil { diff --git a/cmd/onex-pump/app/options/options.go b/cmd/onex-pump/app/options/options.go index 9d8419f6728..613a68f71f8 100644 --- a/cmd/onex-pump/app/options/options.go +++ b/cmd/onex-pump/app/options/options.go @@ -89,7 +89,7 @@ func (o *Options) ApplyTo(c *pump.Config) error { return nil } -// Config return a onex-nightwatch config object. +// Config return an onex-pump config object. func (o *Options) Config() (*pump.Config, error) { c := &pump.Config{} diff --git a/cmd/onex-toyblc/app/options/options.go b/cmd/onex-toyblc/app/options/options.go index cd4eb13be7d..bb78edeeb47 100644 --- a/cmd/onex-toyblc/app/options/options.go +++ b/cmd/onex-toyblc/app/options/options.go @@ -114,7 +114,7 @@ func (o *Options) Validate() error { return utilerrors.NewAggregate(errs) } -// ApplyTo fills up onex-nightwatch config with options. +// ApplyTo fills up onex-toyblc config with options. func (o *Options) ApplyTo(c *toyblc.Config) error { c.Miner = o.Miner c.MinMineInterval = o.MinMineInterval @@ -128,7 +128,7 @@ func (o *Options) ApplyTo(c *toyblc.Config) error { return nil } -// Config return a onex-nightwatch config object. +// Config return an onex-toyblc config object. func (o *Options) Config() (*toyblc.Config, error) { c := &toyblc.Config{} diff --git a/cmd/onex-usercenter/app/options/options.go b/cmd/onex-usercenter/app/options/options.go index 53844a80f5a..78615b1bd19 100644 --- a/cmd/onex-usercenter/app/options/options.go +++ b/cmd/onex-usercenter/app/options/options.go @@ -134,7 +134,7 @@ func (o *Options) Validate() error { return utilerrors.NewAggregate(errs) } -// ApplyTo fills up onex-nightwatch config with options. +// ApplyTo fills up onex-usercenter config with options. func (o *Options) ApplyTo(c *usercenter.Config) error { c.GRPCOptions = o.GRPCOptions c.HTTPOptions = o.HTTPOptions @@ -149,7 +149,7 @@ func (o *Options) ApplyTo(c *usercenter.Config) error { return nil } -// Config return a onex-nightwatch config object. +// Config return an onex-usercenter config object. func (o *Options) Config() (*usercenter.Config, error) { c := &usercenter.Config{} diff --git a/pkg/app/app.go b/pkg/app/app.go index d9482aae2f9..4d9fab4d527 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -83,7 +83,7 @@ func WithDescription(desc string) Option { } } -// WithHealthCheck is used to set the health check function for the application. +// WithHealthCheckFunc is used to set the health check function for the application. // The app framework will use the function to start a health check server. func WithHealthCheckFunc(fn HealthCheckFunc) Option { return func(a *App) { From 9dae1a04ed8c3ef36cce089417ca13a1cbeba867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Thu, 2 May 2024 20:26:41 +0800 Subject: [PATCH 19/33] chore: update release method --- scripts/make-rules/release.mk | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/make-rules/release.mk b/scripts/make-rules/release.mk index 2a81988d22f..160e3eee26b 100644 --- a/scripts/make-rules/release.mk +++ b/scripts/make-rules/release.mk @@ -8,13 +8,9 @@ .PHONY: release.run release.run: tools.verify.uplift release._check ## Generate and commit CHANGELOG, then tag the git repo. - @uplift release --fetch-all --skip-bumps + @uplift release --fetch-all release._check: - @if [[ "$(shell git symbolic-ref --short HEAD)" != "master" ]]; then \ - echo "Branch format is incorrect. Please switch to master branch"; \ - exit 1; \ - fi @if ! git diff --quiet; then \ echo "Git repository is not clean"; \ exit 1; \ From 9ed49084fb42f50499c5409fae7e055a74774983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Mon, 6 May 2024 07:31:11 +0800 Subject: [PATCH 20/33] chore: bump gsemver to v0.9.1 --- scripts/make-rules/common-versions.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/make-rules/common-versions.mk b/scripts/make-rules/common-versions.mk index 07a30581b1d..6ffc194653d 100644 --- a/scripts/make-rules/common-versions.mk +++ b/scripts/make-rules/common-versions.mk @@ -31,7 +31,7 @@ GO_JUNIT_REPORT_VERSION ?= v2.1.0 GO_TESTS_VERSION ?= v1.6.0 GO_IMPORTS_VERSION ?= v0.14.2 GO_GIT_LINT_VERSION ?= v1.1.1 -GSEMVER_VERSION ?= v0.9.0 +GSEMVER_VERSION ?= v0.9.1 GIT_CHGLOG_VERSION ?= v0.15.4 ADDLICENSE_VERSION ?= v0.0.2 KUSTOMIZE_VERSION ?= v5.3.0 From 265bfdeb65401e8277cb43a8863382ca47e8555b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Thu, 16 May 2024 10:18:51 +0800 Subject: [PATCH 21/33] fix: correct to the right viper env key format --- .todo.md | 2 +- internal/onexctl/cmd/helper.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.todo.md b/.todo.md index 850dc268394..6996e9e045d 100644 --- a/.todo.md +++ b/.todo.md @@ -34,7 +34,7 @@ [?] loft 调研 [?] onex-apiserver 后端对接 ES [?] 诊断平台 - +[?] GraphQL API --- [?] 创建一个项目开发者社区网站 + 群??? diff --git a/internal/onexctl/cmd/helper.go b/internal/onexctl/cmd/helper.go index 20086fa4845..4a56e4b0cda 100644 --- a/internal/onexctl/cmd/helper.go +++ b/internal/onexctl/cmd/helper.go @@ -54,7 +54,7 @@ func initConfig(cfgFile string) { viper.SetEnvPrefix("ONEX") // 以下 2 行,将 viper.Get(key) key 字符串中 '.' 和 '-' 替换为 '_' - replacer := strings.NewReplacer(".", "_") + replacer := strings.NewReplacer(".", "_", "-", "_") viper.SetEnvKeyReplacer(replacer) // 读取配置文件。如果指定了配置文件名,则使用指定的配置文件,否则在注册的搜索路径中搜索 From 76f83d1d4602a5b6d8535e64eaf8073289193230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Thu, 16 May 2024 19:37:55 +0800 Subject: [PATCH 22/33] fix: use the right uber maxprocs package --- cmd/onex-apiserver/apiserver.go | 2 +- cmd/onex-cacheserver/main.go | 2 +- cmd/onex-controller-manager/controller-manager.go | 2 +- cmd/onex-fakeserver/main.go | 2 +- cmd/onex-gateway/main.go | 2 +- cmd/onex-miner-controller/controller.go | 2 +- cmd/onex-minerset-controller/controller.go | 2 +- cmd/onex-nightwatch/main.go | 2 +- cmd/onex-toyblc/main.go | 2 +- cmd/onex-usercenter/main.go | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/onex-apiserver/apiserver.go b/cmd/onex-apiserver/apiserver.go index b426fe675ab..36145b737f0 100644 --- a/cmd/onex-apiserver/apiserver.go +++ b/cmd/onex-apiserver/apiserver.go @@ -11,7 +11,7 @@ package main import ( "os" - _ "go.uber.org/automaxprocs" + _ "go.uber.org/automaxprocs/maxprocs" "k8s.io/component-base/cli" _ "k8s.io/component-base/logs/json/register" // for JSON log format registration _ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugins diff --git a/cmd/onex-cacheserver/main.go b/cmd/onex-cacheserver/main.go index 2db56638a14..df818296e01 100644 --- a/cmd/onex-cacheserver/main.go +++ b/cmd/onex-cacheserver/main.go @@ -9,7 +9,7 @@ package main import ( - _ "go.uber.org/automaxprocs" + _ "go.uber.org/automaxprocs/maxprocs" "github.com/superproj/onex/cmd/onex-cacheserver/app" ) diff --git a/cmd/onex-controller-manager/controller-manager.go b/cmd/onex-controller-manager/controller-manager.go index 666d7282bed..ff5a6bb61c5 100644 --- a/cmd/onex-controller-manager/controller-manager.go +++ b/cmd/onex-controller-manager/controller-manager.go @@ -11,7 +11,7 @@ package main import ( "os" - _ "go.uber.org/automaxprocs" + _ "go.uber.org/automaxprocs/maxprocs" "k8s.io/component-base/cli" _ "k8s.io/component-base/logs/json/register" // for JSON log format registration _ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugin diff --git a/cmd/onex-fakeserver/main.go b/cmd/onex-fakeserver/main.go index 4cf3043a3c5..7c3f72d3b9b 100644 --- a/cmd/onex-fakeserver/main.go +++ b/cmd/onex-fakeserver/main.go @@ -9,7 +9,7 @@ package main import ( - _ "go.uber.org/automaxprocs" + _ "go.uber.org/automaxprocs/maxprocs" "github.com/superproj/onex/cmd/onex-fakeserver/app" ) diff --git a/cmd/onex-gateway/main.go b/cmd/onex-gateway/main.go index 503bd1d1f57..0d12e01b348 100644 --- a/cmd/onex-gateway/main.go +++ b/cmd/onex-gateway/main.go @@ -8,7 +8,7 @@ package main import ( - _ "go.uber.org/automaxprocs" + _ "go.uber.org/automaxprocs/maxprocs" "github.com/superproj/onex/cmd/onex-gateway/app" ) diff --git a/cmd/onex-miner-controller/controller.go b/cmd/onex-miner-controller/controller.go index ee05eb90e4b..5a5032445f3 100644 --- a/cmd/onex-miner-controller/controller.go +++ b/cmd/onex-miner-controller/controller.go @@ -11,7 +11,7 @@ package main import ( "os" - _ "go.uber.org/automaxprocs" + _ "go.uber.org/automaxprocs/maxprocs" "k8s.io/component-base/cli" _ "k8s.io/component-base/logs/json/register" // for JSON log format registration _ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugin diff --git a/cmd/onex-minerset-controller/controller.go b/cmd/onex-minerset-controller/controller.go index 85f7fddcc9d..94bba81f070 100644 --- a/cmd/onex-minerset-controller/controller.go +++ b/cmd/onex-minerset-controller/controller.go @@ -10,7 +10,7 @@ package main import ( "os" - _ "go.uber.org/automaxprocs" + _ "go.uber.org/automaxprocs/maxprocs" "k8s.io/component-base/cli" _ "k8s.io/component-base/logs/json/register" // for JSON log format registration _ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugin diff --git a/cmd/onex-nightwatch/main.go b/cmd/onex-nightwatch/main.go index 4361aa7c4be..4f851147012 100644 --- a/cmd/onex-nightwatch/main.go +++ b/cmd/onex-nightwatch/main.go @@ -8,7 +8,7 @@ package main import ( - _ "go.uber.org/automaxprocs" + _ "go.uber.org/automaxprocs/maxprocs" "github.com/superproj/onex/cmd/onex-nightwatch/app" ) diff --git a/cmd/onex-toyblc/main.go b/cmd/onex-toyblc/main.go index 6ad1ca2e341..8afb7e569f4 100644 --- a/cmd/onex-toyblc/main.go +++ b/cmd/onex-toyblc/main.go @@ -8,7 +8,7 @@ package main import ( - _ "go.uber.org/automaxprocs" + _ "go.uber.org/automaxprocs/maxprocs" "github.com/superproj/onex/cmd/onex-toyblc/app" ) diff --git a/cmd/onex-usercenter/main.go b/cmd/onex-usercenter/main.go index e45a932a496..7de1bcb5e97 100644 --- a/cmd/onex-usercenter/main.go +++ b/cmd/onex-usercenter/main.go @@ -9,7 +9,7 @@ package main import ( // Importing the package to automatically set GOMAXPROCS. - _ "go.uber.org/automaxprocs" + _ "go.uber.org/automaxprocs/maxprocs" "github.com/superproj/onex/cmd/onex-usercenter/app" ) From 332fe3ca9c1f9af0becab305abf9d3dbc456270a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sat, 1 Jun 2024 17:38:24 +0800 Subject: [PATCH 23/33] refactor: code optimize --- internal/controller/minerset/controller.go | 2 +- internal/fakeserver/biz/order/order.go | 2 +- internal/usercenter/biz/user/list.go | 2 +- internal/usercenter/store/secret.go | 2 +- internal/usercenter/store/user.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/controller/minerset/controller.go b/internal/controller/minerset/controller.go index 8b7fc20eb21..a3cee37f140 100644 --- a/internal/controller/minerset/controller.go +++ b/internal/controller/minerset/controller.go @@ -775,7 +775,7 @@ func (r *Reconciler) createMiners(ctx context.Context, ms *v1beta1.MinerSet, con eg.Go(func() error { select { case <-ctx.Done(): - return nil + return ctx.Err() default: miner := r.computeDesiredMiner(ms, nil) diff --git a/internal/fakeserver/biz/order/order.go b/internal/fakeserver/biz/order/order.go index 52408c61263..0d067e97768 100644 --- a/internal/fakeserver/biz/order/order.go +++ b/internal/fakeserver/biz/order/order.go @@ -93,7 +93,7 @@ func (b *orderBiz) List(ctx context.Context, rq *v1.ListOrderRequest) (*v1.ListO eg.Go(func() error { select { case <-ctx.Done(): - return nil + return ctx.Err() default: var o v1.OrderReply _ = copier.Copy(&o, order) diff --git a/internal/usercenter/biz/user/list.go b/internal/usercenter/biz/user/list.go index c306ddb048d..b9f1886b9ba 100644 --- a/internal/usercenter/biz/user/list.go +++ b/internal/usercenter/biz/user/list.go @@ -34,7 +34,7 @@ func (b *userBiz) List(ctx context.Context, rq *v1.ListUserRequest) (*v1.ListUse eg.Go(func() error { select { case <-ctx.Done(): - return nil + return ctx.Err() default: count, _, err := b.ds.Secrets().List(ctx, user.UserID) if err != nil { diff --git a/internal/usercenter/store/secret.go b/internal/usercenter/store/secret.go index 95eb817eef3..f102fcaaa15 100644 --- a/internal/usercenter/store/secret.go +++ b/internal/usercenter/store/secret.go @@ -90,7 +90,7 @@ func (d *secretStore) List(ctx context.Context, userID string, opts ...meta.List Not("name", known.TemporaryKeyName). Where(o.Filters). Offset(o.Offset). - Limit(defaultLimit(o.Limit)). + Limit(o.Limit). Order("id desc"). Find(&ret). Offset(-1). diff --git a/internal/usercenter/store/user.go b/internal/usercenter/store/user.go index 7067fb5ff01..52f976a5ed8 100644 --- a/internal/usercenter/store/user.go +++ b/internal/usercenter/store/user.go @@ -65,7 +65,7 @@ func (d *userStore) List(ctx context.Context, opts ...meta.ListOption) (count in ans := d.db(ctx). Where(o.Filters). Offset(o.Offset). - Limit(defaultLimit(o.Limit)). + Limit(o.Limit). Order("id desc"). Find(&ret). Offset(-1). From 85c6a4a47e5a2f6d4cb7d5a86ef13611d2b336d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sat, 1 Jun 2024 17:38:35 +0800 Subject: [PATCH 24/33] chore: add k8s yaml sample --- .../k8s/busybox-deployment.yaml} | 11 +++--- .../{centos8.yaml => centos8-deployment.yaml} | 0 manifests/sample/k8s/debian12-deployment.yaml | 34 +++++++++++++++++ manifests/sample/k8s/dnsutils-ds.yml | 38 +++++++++++++++++++ ...{deployment.json => nginx-deployment.json} | 0 ...{deployment.yaml => nginx-deployment.yaml} | 0 manifests/sample/k8s/nginx-ds.yml | 35 +++++++++++++++++ .../sample/k8s/{pod.yaml => nginx-pod.yaml} | 0 .../sample/k8s/{job.yaml => pi-job.yaml} | 0 9 files changed, 113 insertions(+), 5 deletions(-) rename manifests/{template/command-demo.yaml => sample/k8s/busybox-deployment.yaml} (80%) rename manifests/sample/k8s/{centos8.yaml => centos8-deployment.yaml} (100%) create mode 100644 manifests/sample/k8s/debian12-deployment.yaml create mode 100644 manifests/sample/k8s/dnsutils-ds.yml rename manifests/sample/k8s/{deployment.json => nginx-deployment.json} (100%) rename manifests/sample/k8s/{deployment.yaml => nginx-deployment.yaml} (100%) create mode 100644 manifests/sample/k8s/nginx-ds.yml rename manifests/sample/k8s/{pod.yaml => nginx-pod.yaml} (100%) rename manifests/sample/k8s/{job.yaml => pi-job.yaml} (100%) diff --git a/manifests/template/command-demo.yaml b/manifests/sample/k8s/busybox-deployment.yaml similarity index 80% rename from manifests/template/command-demo.yaml rename to manifests/sample/k8s/busybox-deployment.yaml index b3bb5df7dce..6a98cf00826 100644 --- a/manifests/template/command-demo.yaml +++ b/manifests/sample/k8s/busybox-deployment.yaml @@ -4,25 +4,26 @@ # this file is https://github.com/superproj/onex. # +# 有:wget, telnet, ping apiVersion: apps/v1 kind: Deployment metadata: - name: command-demo + name: busybox spec: replicas: 1 selector: matchLabels: - app: command-demo + app: busybox template: metadata: labels: - app: command-demo + app: busybox spec: restartPolicy: Always containers: - - name: my-container + - name: busybox image: busybox - command: ["sh", "-c", "sleep 3000"] + command: ["sleep", "infinity"] readinessProbe: exec: command: ["false"] diff --git a/manifests/sample/k8s/centos8.yaml b/manifests/sample/k8s/centos8-deployment.yaml similarity index 100% rename from manifests/sample/k8s/centos8.yaml rename to manifests/sample/k8s/centos8-deployment.yaml diff --git a/manifests/sample/k8s/debian12-deployment.yaml b/manifests/sample/k8s/debian12-deployment.yaml new file mode 100644 index 00000000000..95ca6168ceb --- /dev/null +++ b/manifests/sample/k8s/debian12-deployment.yaml @@ -0,0 +1,34 @@ +# Copyright 2022 Lingfei Kong . All rights reserved. +# Use of this source code is governed by a MIT style +# license that can be found in the LICENSE file. The original repo for +# this file is https://github.com/superproj/onex. +# + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: debian12-deployment + labels: + app: debian12 +spec: + replicas: 1 + selector: + matchLabels: + app: debian12 + template: + metadata: + labels: + app: debian12 + spec: + containers: + - name: debian12 + image: debian:12 + command: ["sleep", "infinity"] + args: ["while true; do sleep 30; done;"] + resources: + limits: + memory: "256Mi" + cpu: "500m" + requests: + memory: "128Mi" + cpu: "250m" diff --git a/manifests/sample/k8s/dnsutils-ds.yml b/manifests/sample/k8s/dnsutils-ds.yml new file mode 100644 index 00000000000..054c943612b --- /dev/null +++ b/manifests/sample/k8s/dnsutils-ds.yml @@ -0,0 +1,38 @@ +apiVersion: v1 +kind: Service +metadata: + name: dnsutils-ds + labels: + app: dnsutils-ds +spec: + type: NodePort + selector: + app: dnsutils-ds + ports: + - name: http + port: 80 + targetPort: 80 +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: dnsutils-ds + labels: + addonmanager.kubernetes.io/mode: Reconcile +spec: + selector: + matchLabels: + app: dnsutils-ds + template: + metadata: + labels: + app: dnsutils-ds + spec: + containers: + - name: my-dnsutils + image: tutum/dnsutils:latest + command: + - sleep + - "3600" + ports: + - containerPort: 80 diff --git a/manifests/sample/k8s/deployment.json b/manifests/sample/k8s/nginx-deployment.json similarity index 100% rename from manifests/sample/k8s/deployment.json rename to manifests/sample/k8s/nginx-deployment.json diff --git a/manifests/sample/k8s/deployment.yaml b/manifests/sample/k8s/nginx-deployment.yaml similarity index 100% rename from manifests/sample/k8s/deployment.yaml rename to manifests/sample/k8s/nginx-deployment.yaml diff --git a/manifests/sample/k8s/nginx-ds.yml b/manifests/sample/k8s/nginx-ds.yml new file mode 100644 index 00000000000..a448a49eaf3 --- /dev/null +++ b/manifests/sample/k8s/nginx-ds.yml @@ -0,0 +1,35 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx-ds + labels: + app: nginx-ds +spec: + type: NodePort + selector: + app: nginx-ds + ports: + - name: http + port: 80 + targetPort: 80 +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: nginx-ds + labels: + addonmanager.kubernetes.io/mode: Reconcile +spec: + selector: + matchLabels: + app: nginx-ds + template: + metadata: + labels: + app: nginx-ds + spec: + containers: + - name: my-nginx + image: nginx + ports: + - containerPort: 80 diff --git a/manifests/sample/k8s/pod.yaml b/manifests/sample/k8s/nginx-pod.yaml similarity index 100% rename from manifests/sample/k8s/pod.yaml rename to manifests/sample/k8s/nginx-pod.yaml diff --git a/manifests/sample/k8s/job.yaml b/manifests/sample/k8s/pi-job.yaml similarity index 100% rename from manifests/sample/k8s/job.yaml rename to manifests/sample/k8s/pi-job.yaml From 04f1072020075553d2956bd414a37c3422ecb5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sat, 1 Jun 2024 17:46:59 +0800 Subject: [PATCH 25/33] chore: add `--restart always` for to automatic start container --- scripts/installation/etcd.sh | 1 + scripts/installation/jaeger.sh | 1 + scripts/installation/kafka.sh | 3 ++- scripts/installation/mariadb.sh | 1 + scripts/installation/mongo.sh | 1 + scripts/installation/onex.sh | 1 + scripts/installation/redis.sh | 1 + scripts/installation/template.sh | 2 +- 8 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/installation/etcd.sh b/scripts/installation/etcd.sh index 8cbe88ff84b..715a38aa1ad 100755 --- a/scripts/installation/etcd.sh +++ b/scripts/installation/etcd.sh @@ -22,6 +22,7 @@ onex::etcd::docker::install() { onex::common::network docker run -d --name onex-etcd \ + --restart always \ --network onex \ -v ${ONEX_ETCD_DIR}:/etcd-data \ -p ${ONEX_ACCESS_HOST}:${ONEX_ETCD_CLIENT_PORT}:2379 \ diff --git a/scripts/installation/jaeger.sh b/scripts/installation/jaeger.sh index 8372c41e6fb..365d7c2112f 100755 --- a/scripts/installation/jaeger.sh +++ b/scripts/installation/jaeger.sh @@ -19,6 +19,7 @@ onex::jaeger::docker::install() { onex::common::network docker run -d --name onex-jaeger \ + --restart always \ --network onex \ -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \ -p ${ONEX_ACCESS_HOST}:6831:6831/udp \ diff --git a/scripts/installation/kafka.sh b/scripts/installation/kafka.sh index 1834f435adc..0b29e394e54 100755 --- a/scripts/installation/kafka.sh +++ b/scripts/installation/kafka.sh @@ -19,8 +19,9 @@ ONEX_KAFKA_PORT=${ONEX_KAFKA_PORT:-4317} onex::kafka::docker::install() { onex::common::network - docker run -d --name onex-zookeeper --network onex -p 2181:2181 -t wurstmeister/zookeeper + docker run -d --restart always --name onex-zookeeper --network onex -p 2181:2181 -t wurstmeister/zookeeper docker run -d --name onex-kafka --link onex-zookeeper:zookeeper \ + --restart always \ --network onex \ --restart=always \ -v /etc/localtime:/etc/localtime \ diff --git a/scripts/installation/mariadb.sh b/scripts/installation/mariadb.sh index ce08c82cf7a..ac0a22e008a 100755 --- a/scripts/installation/mariadb.sh +++ b/scripts/installation/mariadb.sh @@ -23,6 +23,7 @@ onex::mariadb::docker::install() onex::common::network docker run -d --name onex-mariadb \ + --restart always \ --network onex \ -v ${ONEX_THIRDPARTY_INSTALL_DIR}/mariadb:/var/lib/mysql \ -p ${ONEX_ACCESS_HOST}:${ONEX_MYSQL_PORT}:3306 \ diff --git a/scripts/installation/mongo.sh b/scripts/installation/mongo.sh index 26ab1876264..ccf0361d6b6 100755 --- a/scripts/installation/mongo.sh +++ b/scripts/installation/mongo.sh @@ -28,6 +28,7 @@ onex::mongo::docker::install() onex::common::network docker run -d --name onex-mongo \ + --restart always \ --network onex \ -v ${ONEX_THIRDPARTY_INSTALL_DIR}/mongo:/data \ -p ${ONEX_ACCESS_HOST}:${ONEX_MONGO_PORT}:27017 \ diff --git a/scripts/installation/onex.sh b/scripts/installation/onex.sh index 44f27b76987..6f99ddd6e41 100755 --- a/scripts/installation/onex.sh +++ b/scripts/installation/onex.sh @@ -41,6 +41,7 @@ onex::onex::docker::install() # "Failed to get D-Bus connection: Operation not permitted" onex::common::network docker run -d --name onex \ + --restart always \ --network onex \ --privileged \ -v onex-volume:${ONEX_INSTALL_DIR}:rw \ diff --git a/scripts/installation/redis.sh b/scripts/installation/redis.sh index 3b807dcca6a..f497cd7eebe 100755 --- a/scripts/installation/redis.sh +++ b/scripts/installation/redis.sh @@ -22,6 +22,7 @@ onex::redis::docker::install() onex::common::network docker run -d --name onex-redis \ + --restart always \ --network onex \ -v ${ONEX_THIRDPARTY_INSTALL_DIR}/redis:/data \ -p ${ONEX_ACCESS_HOST}:${ONEX_REDIS_PORT}:6379 \ diff --git a/scripts/installation/template.sh b/scripts/installation/template.sh index b0138d4e2d1..2a34796c309 100755 --- a/scripts/installation/template.sh +++ b/scripts/installation/template.sh @@ -17,7 +17,7 @@ ONEX_TEMPLATE_PORT=${ONEX_TEMPLATE_PORT:-xxxx} # Install template using containerization. onex::template::docker::install() { - # docker run -d --name onex-xxx ... + # docker run -d --restart always --name onex-xxx ... onex::template::status || return 1 onex::template::info onex::log::info "install template successfully" From 03086a220669cbd84a40111661a6284cae68aa45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sat, 1 Jun 2024 21:10:23 +0800 Subject: [PATCH 26/33] feat: add code example of using workerpool and ants package --- go.mod | 3 + go.sum | 8 +++ internal/usercenter/biz/user/list.go | 95 ++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/go.mod b/go.mod index 2cdd83a5fca..e8b3efa78c4 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/distribution/reference v0.5.0 github.com/envoyproxy/protoc-gen-validate v1.0.2 github.com/fatih/color v1.15.0 + github.com/gammazero/workerpool v1.1.3 github.com/ghodss/yaml v1.0.0 github.com/gin-contrib/pprof v1.4.0 github.com/gin-gonic/gin v1.8.1 @@ -50,6 +51,7 @@ require ( github.com/olekukonko/tablewriter v0.0.5 github.com/onsi/ginkgo/v2 v2.13.0 github.com/onsi/gomega v1.29.0 + github.com/panjf2000/ants/v2 v2.9.1 github.com/parnurzeal/gorequest v0.2.16 github.com/prometheus/client_golang v1.17.0 github.com/redis/go-redis/extra/rediscensus/v9 v9.0.5 @@ -113,6 +115,7 @@ require ( github.com/elazarl/goproxy v0.0.0-20210110162100-a92cc753f88e // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.6.0 // indirect + github.com/gammazero/deque v0.2.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/glebarez/go-sqlite v1.19.1 // indirect github.com/glebarez/sqlite v1.5.0 // indirect diff --git a/go.sum b/go.sum index 74e3f6a4502..c829fb1cdec 100644 --- a/go.sum +++ b/go.sum @@ -789,6 +789,10 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/gammazero/deque v0.2.0 h1:SkieyNB4bg2/uZZLxvya0Pq6diUlwx7m2TeT7GAIWaA= +github.com/gammazero/deque v0.2.0/go.mod h1:LFroj8x4cMYCukHJDbxFCkT+r9AndaJnFMuZDV34tuU= +github.com/gammazero/workerpool v1.1.3 h1:WixN4xzukFoN0XSeXF6puqEqFTl2mECI9S6W44HWy9Q= +github.com/gammazero/workerpool v1.1.3/go.mod h1:wPjyBLDbyKnUn2XwwyD3EEwo9dHutia9/fwNmSHWACc= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/pprof v1.4.0 h1:XxiBSf5jWZ5i16lNOPbMTVdgHBdhfGRD5PZ1LWazzvg= @@ -1308,6 +1312,8 @@ github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/panjf2000/ants/v2 v2.9.1 h1:Q5vh5xohbsZXGcD6hhszzGqB7jSSc2/CRr3QKIga8Kw= +github.com/panjf2000/ants/v2 v2.9.1/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I= github.com/parnurzeal/gorequest v0.2.16 h1:T/5x+/4BT+nj+3eSknXmCTnEVGSzFzPGdpqmUVVZXHQ= github.com/parnurzeal/gorequest v0.2.16/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -1464,6 +1470,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= @@ -1781,6 +1788,7 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/internal/usercenter/biz/user/list.go b/internal/usercenter/biz/user/list.go index b9f1886b9ba..5dcd6bc4c16 100644 --- a/internal/usercenter/biz/user/list.go +++ b/internal/usercenter/biz/user/list.go @@ -10,7 +10,9 @@ import ( "context" "sync" + "github.com/gammazero/workerpool" "github.com/jinzhu/copier" + "github.com/panjf2000/ants/v2" "golang.org/x/sync/errgroup" "google.golang.org/protobuf/types/known/timestamppb" @@ -68,6 +70,99 @@ func (b *userBiz) List(ctx context.Context, rq *v1.ListUserRequest) (*v1.ListUse return &v1.ListUserResponse{TotalCount: count, Users: users}, nil } +// ListWithWorkerPool retrieves a list of all users from the database use workerpool package. +// Concurrency limits can effectively protect downstream services and control the resource +// consumption of components. +func (b *userBiz) ListWithWorkerPool(ctx context.Context, rq *v1.ListUserRequest) (*v1.ListUserResponse, error) { + count, list, err := b.ds.Users().List(ctx, meta.WithOffset(rq.Offset), meta.WithLimit(rq.Limit)) + if err != nil { + log.C(ctx).Errorw(err, "Failed to list users from storage") + return nil, err + } + + var m sync.Map + wp := workerpool.New(100) + + // Use goroutine to improve interface performance + for _, user := range list { + wp.Submit(func() { + count, _, err := b.ds.Secrets().List(ctx, user.UserID) + if err != nil { + log.C(ctx).Errorw(err, "Failed to list secrets") + return + } + + u := ModelToReply(user) + u.Secrets = count + m.Store(user.ID, u) + + return + }) + } + + wp.StopWait() + + // The following code block is used to maintain the consistency of query order. + users := make([]*v1.UserReply, 0, len(list)) + for _, item := range list { + user, _ := m.Load(item.ID) + users = append(users, user.(*v1.UserReply)) + } + + log.C(ctx).Debugw("Get users from backend storage", "count", len(users)) + + return &v1.ListUserResponse{TotalCount: count, Users: users}, nil +} + +// ListWithAnts retrieves a list of all users from the database use ants package. +// Concurrency limits can effectively protect downstream services and control the +// resource consumption of components. +func (b *userBiz) ListWithAnts(ctx context.Context, rq *v1.ListUserRequest) (*v1.ListUserResponse, error) { + count, list, err := b.ds.Users().List(ctx, meta.WithOffset(rq.Offset), meta.WithLimit(rq.Limit)) + if err != nil { + log.C(ctx).Errorw(err, "Failed to list users from storage") + return nil, err + } + + var m sync.Map + var wg sync.WaitGroup + pool, _ := ants.NewPool(100) + defer pool.Release() + + // Use goroutine to improve interface performance + for _, user := range list { + wg.Add(1) + _ = pool.Submit(func() { + defer wg.Done() + + count, _, err := b.ds.Secrets().List(ctx, user.UserID) + if err != nil { + log.C(ctx).Errorw(err, "Failed to list secrets") + return + } + + u := ModelToReply(user) + u.Secrets = count + m.Store(user.ID, u) + + return + }) + } + + wg.Wait() + + // The following code block is used to maintain the consistency of query order. + users := make([]*v1.UserReply, 0, len(list)) + for _, item := range list { + user, _ := m.Load(item.ID) + users = append(users, user.(*v1.UserReply)) + } + + log.C(ctx).Debugw("Get users from backend storage", "count", len(users)) + + return &v1.ListUserResponse{TotalCount: count, Users: users}, nil +} + // ListWithBadPerformance is a poor performance implementation of List. func (b *userBiz) ListWithBadPerformance(ctx context.Context, rq *v1.ListUserRequest) (*v1.ListUserResponse, error) { count, list, err := b.ds.Users().List(ctx, meta.WithOffset(rq.Offset), meta.WithLimit(rq.Limit)) From ce90e206e3b89651cb6fb5c4117cdd668b26c5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Thu, 6 Jun 2024 18:04:29 +0800 Subject: [PATCH 27/33] feat(pkg): add ptr package handle pointers --- .todo.md | 1 + pkg/ptr/README.md | 3 + pkg/ptr/doc.go | 3 + pkg/ptr/ptr.go | 146 +++++++++++++++++++++++++++++++++++ pkg/ptr/ptr_test.go | 184 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 337 insertions(+) create mode 100644 pkg/ptr/README.md create mode 100644 pkg/ptr/doc.go create mode 100644 pkg/ptr/ptr.go create mode 100644 pkg/ptr/ptr_test.go diff --git a/.todo.md b/.todo.md index 6996e9e045d..331319e1da8 100644 --- a/.todo.md +++ b/.todo.md @@ -35,6 +35,7 @@ [?] onex-apiserver 后端对接 ES [?] 诊断平台 [?] GraphQL API +[?] 添加状态机 --- [?] 创建一个项目开发者社区网站 + 群??? diff --git a/pkg/ptr/README.md b/pkg/ptr/README.md new file mode 100644 index 00000000000..2ca8073dc73 --- /dev/null +++ b/pkg/ptr/README.md @@ -0,0 +1,3 @@ +# Pointer + +This package provides some functions for pointer-based operations. diff --git a/pkg/ptr/doc.go b/pkg/ptr/doc.go new file mode 100644 index 00000000000..98eb6932c50 --- /dev/null +++ b/pkg/ptr/doc.go @@ -0,0 +1,3 @@ +// Package gptr provides generic operations for pointers. + +package ptr diff --git a/pkg/ptr/ptr.go b/pkg/ptr/ptr.go new file mode 100644 index 00000000000..cac299da42e --- /dev/null +++ b/pkg/ptr/ptr.go @@ -0,0 +1,146 @@ +/* +Copyright 2023 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package ptr + +import ( + "fmt" + "reflect" +) + +// AllPtrFieldsNil tests whether all pointer fields in a struct are nil. This is useful when, +// for example, an API struct is handled by plugins which need to distinguish +// "no plugin accepted this spec" from "this spec is empty". +// +// This function is only valid for structs and pointers to structs. Any other +// type will cause a panic. Passing a typed nil pointer will return true. +func AllPtrFieldsNil(obj interface{}) bool { + v := reflect.ValueOf(obj) + if !v.IsValid() { + panic(fmt.Sprintf("reflect.ValueOf() produced a non-valid Value for %#v", obj)) + } + if v.Kind() == reflect.Ptr { + if v.IsNil() { + return true + } + v = v.Elem() + } + for i := 0; i < v.NumField(); i++ { + if v.Field(i).Kind() == reflect.Ptr && !v.Field(i).IsNil() { + return false + } + } + return true +} + +// To returns a pointer to the given value. +func To[T any](v T) *T { + return &v +} + +// From returns the value pointed to by the pointer p. +// If the pointer is nil, returns the zero value of T instead. +func From[T any](v *T) T { + var zero T + if v != nil { + return *v + } + + return zero +} + +// FromOr dereferences ptr and returns the value it points to if no nil, or else +// returns def. +func FromOr[T any](ptr *T, def T) T { + if ptr != nil { + return *ptr + } + return def +} + +// IsNil returns whether the given pointer v is nil. +func IsNil[T any](p *T) bool { + return p == nil +} + +// IsNotNil is negation of [IsNil]. +func IsNotNil[T any](p *T) bool { + return p != nil +} + +// Clone returns a shallow copy of the slice. +// If the given pointer is nil, nil is returned. +// +// HINT: The element is copied using assignment (=), so this is a shallow clone. +// If you want to do a deep clone, use [CloneBy] with an appropriate element +// clone function. +// +// AKA: Copy +func Clone[T any](p *T) *T { + if p == nil { + return nil + } + clone := *p + return &clone +} + +// CloneBy is variant of [Clone], it returns a copy of the map. +// Element is copied using function f. +// If the given pointer is nil, nil is returned. +func CloneBy[T any](p *T, f func(T) T) *T { + return Map(p, f) +} + +// Equal returns true if both arguments are nil or both arguments +// dereference to the same value. +func Equal[T comparable](a, b *T) bool { + if (a == nil) != (b == nil) { + return false + } + if a == nil { + return true + } + return *a == *b +} + +// EqualTo returns whether the value of pointer p is equal to value v. +// It a shortcut of "x != nil && *x == y". +// +// EXAMPLE: +// +// x, y := 1, 2 +// Equal(&x, 1) ⏩ true +// Equal(&y, 1) ⏩n false +// Equal(nil, 1) ⏩ false +func EqualTo[T comparable](p *T, v T) bool { + return p != nil && *p == v +} + +// Map applies function f to element of pointer p. +// If p is nil, f will not be called and nil is returned, otherwise, +// result of f are returned as a new pointer. +// +// EXAMPLE: +// +// i := 1 +// Map(&i, strconv.Itoa) ⏩ (*string)("1") +// Map[int](nil, strconv.Itoa) ⏩ (*string)(nil) +func Map[F, T any](p *F, f func(F) T) *T { + if p == nil { + return nil + } + return To(f(*p)) +} diff --git a/pkg/ptr/ptr_test.go b/pkg/ptr/ptr_test.go new file mode 100644 index 00000000000..1e54dfec5b9 --- /dev/null +++ b/pkg/ptr/ptr_test.go @@ -0,0 +1,184 @@ +/* +Copyright 2023 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package ptr + +import ( + "fmt" + "strconv" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAllPtrFieldsNil(t *testing.T) { + testCases := []struct { + obj interface{} + expected bool + }{ + {struct{}{}, true}, + {struct{ Foo int }{12345}, true}, + {&struct{ Foo int }{12345}, true}, + {struct{ Foo *int }{nil}, true}, + {&struct{ Foo *int }{nil}, true}, + {struct { + Foo int + Bar *int + }{12345, nil}, true}, + {&struct { + Foo int + Bar *int + }{12345, nil}, true}, + {struct { + Foo *int + Bar *int + }{nil, nil}, true}, + {&struct { + Foo *int + Bar *int + }{nil, nil}, true}, + {struct{ Foo *int }{new(int)}, false}, + {&struct{ Foo *int }{new(int)}, false}, + {struct { + Foo *int + Bar *int + }{nil, new(int)}, false}, + {&struct { + Foo *int + Bar *int + }{nil, new(int)}, false}, + {(*struct{})(nil), true}, + } + for i, tc := range testCases { + name := fmt.Sprintf("case[%d]", i) + t.Run(name, func(t *testing.T) { + if actual := AllPtrFieldsNil(tc.obj); actual != tc.expected { + t.Errorf("%s: expected %t, got %t", name, tc.expected, actual) + } + }) + } +} + +func TestRef(t *testing.T) { + type T int + + val := T(0) + pointer := To(val) + if *pointer != val { + t.Errorf("expected %d, got %d", val, *pointer) + } + + val = T(1) + pointer = To(val) + if *pointer != val { + t.Errorf("expected %d, got %d", val, *pointer) + } +} + +func TestFrom(t *testing.T) { + assert.Equal(t, 543, From(To(543))) + assert.Equal(t, "Alice", From(To("Alice"))) + assert.Zero(t, From[int](nil)) + assert.Nil(t, From[interface{}](nil)) + assert.Nil(t, From(To[fmt.Stringer](nil))) +} + +func TestFromOr(t *testing.T) { + type T int + + var val, def T = 1, 0 + + out := FromOr(&val, def) + if out != val { + t.Errorf("expected %d, got %d", val, out) + } + + out = FromOr(nil, def) + if out != def { + t.Errorf("expected %d, got %d", def, out) + } +} + +func TestIsNil(t *testing.T) { + assert.False(t, IsNil(To(1))) + assert.True(t, IsNil[int](nil)) +} + +func TestClone(t *testing.T) { + assert.True(t, IsNil(Clone(((*int)(nil))))) + + v := 1 + assert.True(t, Clone(&v) != &v) + assert.True(t, Equal(Clone(&v), &v)) + + src := To(1) + dst := Clone(&src) + assert.Equal(t, &src, dst) + assert.True(t, src == *dst) +} + +func TestCloneBy(t *testing.T) { + assert.True(t, IsNil(CloneBy(((**int)(nil)), Clone[int]))) + + src := To(1) + dst := CloneBy(&src, Clone[int]) + assert.Equal(t, &src, dst) + assert.False(t, src == *dst) +} + +func TestEqual(t *testing.T) { + type T int + + if !Equal[T](nil, nil) { + t.Errorf("expected true (nil == nil)") + } + if !Equal(To(T(123)), To(T(123))) { + t.Errorf("expected true (val == val)") + } + if Equal(nil, To(T(123))) { + t.Errorf("expected false (nil != val)") + } + if Equal(To(T(123)), nil) { + t.Errorf("expected false (val != nil)") + } + if Equal(To(T(123)), To(T(456))) { + t.Errorf("expected false (val != val)") + } +} + +func TestEqualTo(t *testing.T) { + assert.True(t, EqualTo(To(1), 1)) + assert.False(t, EqualTo(To(2), 1)) + assert.False(t, EqualTo(nil, 0)) +} + +func TestMap(t *testing.T) { + i := 1 + assert.Equal(t, To("1"), Map(&i, strconv.Itoa)) + assert.True(t, Map(nil, strconv.Itoa) == nil) + + assert.NotPanics(t, func() { + _ = Map(nil, func(int) string { + panic("Q_Q") + }) + }) + + assert.Panics(t, func() { + _ = Map(&i, func(int) string { + panic("Q_Q") + }) + }) +} From f30cdbaf58a3f07dda5884930b8b2e0ba6fd1cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sat, 8 Jun 2024 13:26:38 +0800 Subject: [PATCH 28/33] chore: bump helm to v3.15.1 --- manifests/installation/storage/mariadb/statefulset.yaml | 3 +++ scripts/make-rules/common-versions.mk | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/manifests/installation/storage/mariadb/statefulset.yaml b/manifests/installation/storage/mariadb/statefulset.yaml index 292a8a20281..01346c3a0d5 100644 --- a/manifests/installation/storage/mariadb/statefulset.yaml +++ b/manifests/installation/storage/mariadb/statefulset.yaml @@ -58,6 +58,9 @@ spec: # 指定了存储卷的规格信息,包括访问模式和资源请求等 spec: # 指定了存储卷的访问模式为"ReadWriteOnce",表示可以被单个节点挂载为读写模式 + # ReadWriteOnce: PV 能以 read-write 模式 mount 到单个节点 + # ReadOnlyMany: PV 能以 read-only 模式 mount 到多个节点 + # ReadWriteMany: PV 能以 read-write 模式 mount 到多个节点 accessModes: [ "ReadWriteOnce" ] # 指定了存储卷的资源请求信息 resources: diff --git a/scripts/make-rules/common-versions.mk b/scripts/make-rules/common-versions.mk index 6ffc194653d..aeba388a67f 100644 --- a/scripts/make-rules/common-versions.mk +++ b/scripts/make-rules/common-versions.mk @@ -9,7 +9,7 @@ HADOLINT_VER ?= v2.10.0 CHART_VERSION ?= 1.0.0 #KIND_VERSION ?= v0.22.0 KIND_VERSION ?= v0.19.0 -HELM_VERSION ?= v3.8.1 +HELM_VERSION ?= v3.15.1 GO_TESTS_SUM_VERSION ?=v1.6.4 GOLANGCI_LINT_VERSION := v1.55.2 YQ_VERSION ?= v4.25.2 From c79511995646a1da7be53ee14b63a66293bf0fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sun, 9 Jun 2024 12:39:33 +0800 Subject: [PATCH 29/33] chore: filter out dirs without go file when compile and build images --- .todo.md | 1 + build/docker/gen-docs/Dockerfile | 4 +- build/docker/gen-docs/Dockerfile.multistage | 4 +- build/docker/gen-man/Dockerfile | 4 +- build/docker/gen-man/Dockerfile.multistage | 4 +- build/docker/gen-onex-docs/Dockerfile | 4 +- .../gen-onex-docs/Dockerfile.multistage | 4 +- build/docker/gen-onex-gorm-model/Dockerfile | 4 +- .../gen-onex-gorm-model/Dockerfile.multistage | 4 +- build/docker/gen-yaml/Dockerfile | 4 +- build/docker/gen-yaml/Dockerfile.multistage | 4 +- build/docker/onex-blc/Dockerfile | 27 -------- build/docker/onex-blc/Dockerfile.multistage | 68 ------------------- build/docker/onex-chatroom/Dockerfile | 4 +- .../onex-chatroom/Dockerfile.multistage | 4 +- build/docker/onex-fake-miner/Dockerfile | 4 +- .../onex-fake-miner/Dockerfile.multistage | 4 +- build/docker/onex-oss-center/Dockerfile | 4 +- .../onex-oss-center/Dockerfile.multistage | 4 +- build/docker/onex/Dockerfile | 4 +- build/docker/onex/Dockerfile.multistage | 4 +- scripts/make-rules/golang.mk | 4 +- scripts/make-rules/image.mk | 8 +-- 23 files changed, 44 insertions(+), 136 deletions(-) delete mode 100644 build/docker/onex-blc/Dockerfile delete mode 100644 build/docker/onex-blc/Dockerfile.multistage diff --git a/.todo.md b/.todo.md index 331319e1da8..4facd2db1ef 100644 --- a/.todo.md +++ b/.todo.md @@ -36,6 +36,7 @@ [?] 诊断平台 [?] GraphQL API [?] 添加状态机 +[?] 场景:Webhook 展示修改镜像地址?? --- [?] 创建一个项目开发者社区网站 + 群??? diff --git a/build/docker/gen-docs/Dockerfile b/build/docker/gen-docs/Dockerfile index 2be895544da..82dfa47de39 100644 --- a/build/docker/gen-docs/Dockerfile +++ b/build/docker/gen-docs/Dockerfile @@ -9,8 +9,8 @@ # Build the gen-docs binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie FROM ${prod_image} LABEL maintainer="" diff --git a/build/docker/gen-docs/Dockerfile.multistage b/build/docker/gen-docs/Dockerfile.multistage index 67a6bdf3eb1..ac46b532381 100644 --- a/build/docker/gen-docs/Dockerfile.multistage +++ b/build/docker/gen-docs/Dockerfile.multistage @@ -10,8 +10,8 @@ # Build the gen-docs binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie # Ignore Hadolint rule "Always tag the version of an image explicitly." # It's an invalid finding since the image is explicitly set in the Makefile. diff --git a/build/docker/gen-man/Dockerfile b/build/docker/gen-man/Dockerfile index b573c3ea826..6fe8df191fe 100644 --- a/build/docker/gen-man/Dockerfile +++ b/build/docker/gen-man/Dockerfile @@ -9,8 +9,8 @@ # Build the gen-man binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie FROM ${prod_image} LABEL maintainer="" diff --git a/build/docker/gen-man/Dockerfile.multistage b/build/docker/gen-man/Dockerfile.multistage index 08d7fab6576..5c475e45069 100644 --- a/build/docker/gen-man/Dockerfile.multistage +++ b/build/docker/gen-man/Dockerfile.multistage @@ -10,8 +10,8 @@ # Build the gen-man binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie # Ignore Hadolint rule "Always tag the version of an image explicitly." # It's an invalid finding since the image is explicitly set in the Makefile. diff --git a/build/docker/gen-onex-docs/Dockerfile b/build/docker/gen-onex-docs/Dockerfile index 51686e50add..f1c985504a4 100644 --- a/build/docker/gen-onex-docs/Dockerfile +++ b/build/docker/gen-onex-docs/Dockerfile @@ -9,8 +9,8 @@ # Build the gen-onex-docs binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie FROM ${prod_image} LABEL maintainer="" diff --git a/build/docker/gen-onex-docs/Dockerfile.multistage b/build/docker/gen-onex-docs/Dockerfile.multistage index 22fb010682f..9ce394af533 100644 --- a/build/docker/gen-onex-docs/Dockerfile.multistage +++ b/build/docker/gen-onex-docs/Dockerfile.multistage @@ -10,8 +10,8 @@ # Build the gen-onex-docs binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie # Ignore Hadolint rule "Always tag the version of an image explicitly." # It's an invalid finding since the image is explicitly set in the Makefile. diff --git a/build/docker/gen-onex-gorm-model/Dockerfile b/build/docker/gen-onex-gorm-model/Dockerfile index d1c1d12a8dd..b81e061dc13 100644 --- a/build/docker/gen-onex-gorm-model/Dockerfile +++ b/build/docker/gen-onex-gorm-model/Dockerfile @@ -9,8 +9,8 @@ # Build the gen-onex-gorm-model binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie FROM ${prod_image} LABEL maintainer="" diff --git a/build/docker/gen-onex-gorm-model/Dockerfile.multistage b/build/docker/gen-onex-gorm-model/Dockerfile.multistage index 1e9321b868d..ede8732c540 100644 --- a/build/docker/gen-onex-gorm-model/Dockerfile.multistage +++ b/build/docker/gen-onex-gorm-model/Dockerfile.multistage @@ -10,8 +10,8 @@ # Build the gen-onex-gorm-model binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie # Ignore Hadolint rule "Always tag the version of an image explicitly." # It's an invalid finding since the image is explicitly set in the Makefile. diff --git a/build/docker/gen-yaml/Dockerfile b/build/docker/gen-yaml/Dockerfile index 4497bbda376..c4d8ea9002f 100644 --- a/build/docker/gen-yaml/Dockerfile +++ b/build/docker/gen-yaml/Dockerfile @@ -9,8 +9,8 @@ # Build the gen-yaml binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie FROM ${prod_image} LABEL maintainer="" diff --git a/build/docker/gen-yaml/Dockerfile.multistage b/build/docker/gen-yaml/Dockerfile.multistage index f8eda96e81f..c94970229c6 100644 --- a/build/docker/gen-yaml/Dockerfile.multistage +++ b/build/docker/gen-yaml/Dockerfile.multistage @@ -10,8 +10,8 @@ # Build the gen-yaml binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie # Ignore Hadolint rule "Always tag the version of an image explicitly." # It's an invalid finding since the image is explicitly set in the Makefile. diff --git a/build/docker/onex-blc/Dockerfile b/build/docker/onex-blc/Dockerfile deleted file mode 100644 index 053b463fb24..00000000000 --- a/build/docker/onex-blc/Dockerfile +++ /dev/null @@ -1,27 +0,0 @@ -# syntax=docker/dockerfile:1.4 - -# Copyright 2022 Lingfei Kong . All rights reserved. -# Use of this source code is governed by a MIT style -# license that can be found in the LICENSE file. The original repo for -# this file is https://github.com/superproj/onex. - -# Dockerfile generated by scripts/gen-dockerfile.sh. DO NOT EDIT. - -# Build the onex-blc binary -# Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie - -FROM ${prod_image} -LABEL maintainer="" - -WORKDIR /opt/onex - -# Note: the is required to support -# setting timezone otherwise the build will fail -RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ - echo "Asia/Shanghai" > /etc/timezone - -COPY onex-blc /opt/onex/bin/ - -ENTRYPOINT ["/opt/onex/bin/onex-blc"] diff --git a/build/docker/onex-blc/Dockerfile.multistage b/build/docker/onex-blc/Dockerfile.multistage deleted file mode 100644 index 10234c4d20a..00000000000 --- a/build/docker/onex-blc/Dockerfile.multistage +++ /dev/null @@ -1,68 +0,0 @@ -# syntax=docker/dockerfile:1.4 - -# Copyright 2022 Lingfei Kong . All rights reserved. -# Use of this source code is governed by a MIT style -# license that can be found in the LICENSE file. The original repo for -# this file is https://github.com/superproj/onex. - -# Dockerfile generated by scripts/gen-dockerfile.sh. DO NOT EDIT. - -# Build the onex-blc binary - -# Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie - -# Ignore Hadolint rule "Always tag the version of an image explicitly." -# It's an invalid finding since the image is explicitly set in the Makefile. -# https://github.com/hadolint/hadolint/wiki/DL3006 -# hadolint ignore=DL3006 -FROM golang:1.20 as builder -WORKDIR /workspace - -# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy -ARG goproxy=https://proxy.golang.org -ARG OS -ARG ARCH - -# Run this with docker build. -ENV GOPROXY=$goproxy - -# Copy the Go Modules manifests -COPY go.mod go.mod -COPY go.sum go.sum - -# Cache deps before building and copying source so that we don't need to re-download as much -# and so that source changes don't invalidate our downloaded layer -RUN --mount=type=cache,target=/go/pkg/mod \ - go mod download - -# Copy the sources -COPY api/ api/ -COPY cmd/onex-blc cmd/onex-blc -COPY pkg/ pkg/ -COPY internal/ internal/ -COPY third_party/ third_party/ - -# Build -# the GOARCH has not a default value to allow the binary be built according to the host where the command -# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO -# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, -# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. -RUN CGO_ENABLED=0 GOOS=${OS:-linux} GOARCH=${ARCH} go build -a ./cmd/onex-blc - -# Production image -FROM ${prod_image} -LABEL maintainer="" - -WORKDIR /opt/onex - -# Note: the is required to support -# setting timezone otherwise the build will fail -RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ - echo "Asia/Shanghai" > /etc/timezone - -COPY --from=builder /workspace/onex-blc /opt/onex/bin/ -# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying pod security policies -USER 65532 -ENTRYPOINT ["/opt/onex/bin/onex-blc"] diff --git a/build/docker/onex-chatroom/Dockerfile b/build/docker/onex-chatroom/Dockerfile index 147977b3a42..5c0657a648c 100644 --- a/build/docker/onex-chatroom/Dockerfile +++ b/build/docker/onex-chatroom/Dockerfile @@ -9,8 +9,8 @@ # Build the onex-chatroom binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie FROM ${prod_image} LABEL maintainer="" diff --git a/build/docker/onex-chatroom/Dockerfile.multistage b/build/docker/onex-chatroom/Dockerfile.multistage index 10f1f7d23da..56d92d4b919 100644 --- a/build/docker/onex-chatroom/Dockerfile.multistage +++ b/build/docker/onex-chatroom/Dockerfile.multistage @@ -10,8 +10,8 @@ # Build the onex-chatroom binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie # Ignore Hadolint rule "Always tag the version of an image explicitly." # It's an invalid finding since the image is explicitly set in the Makefile. diff --git a/build/docker/onex-fake-miner/Dockerfile b/build/docker/onex-fake-miner/Dockerfile index 945bdaf0ae6..d4cb19a94b4 100644 --- a/build/docker/onex-fake-miner/Dockerfile +++ b/build/docker/onex-fake-miner/Dockerfile @@ -9,8 +9,8 @@ # Build the onex-fake-miner binary # Run this with docker build --build-arg prod_image= -# Default is alpine:3.17 -ARG prod_image=alpine:3.17 +# Default is debian:trixie +ARG prod_image=debian:trixie FROM ${prod_image} LABEL maintainer="" diff --git a/build/docker/onex-fake-miner/Dockerfile.multistage b/build/docker/onex-fake-miner/Dockerfile.multistage index bf72ffccd11..e5cdc68bab4 100644 --- a/build/docker/onex-fake-miner/Dockerfile.multistage +++ b/build/docker/onex-fake-miner/Dockerfile.multistage @@ -10,8 +10,8 @@ # Build the onex-fake-miner binary # Run this with docker build --build-arg prod_image= -# Default is alpine:3.17 -ARG prod_image=alpine:3.17 +# Default is debian:trixie +ARG prod_image=debian:trixie # Ignore Hadolint rule "Always tag the version of an image explicitly." # It's an invalid finding since the image is explicitly set in the Makefile. diff --git a/build/docker/onex-oss-center/Dockerfile b/build/docker/onex-oss-center/Dockerfile index d613e3630bc..1718329a60d 100644 --- a/build/docker/onex-oss-center/Dockerfile +++ b/build/docker/onex-oss-center/Dockerfile @@ -9,8 +9,8 @@ # Build the onex-oss-center binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie FROM ${prod_image} LABEL maintainer="" diff --git a/build/docker/onex-oss-center/Dockerfile.multistage b/build/docker/onex-oss-center/Dockerfile.multistage index 0ba2c12cb7a..df1fdd7eb38 100644 --- a/build/docker/onex-oss-center/Dockerfile.multistage +++ b/build/docker/onex-oss-center/Dockerfile.multistage @@ -10,8 +10,8 @@ # Build the onex-oss-center binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie # Ignore Hadolint rule "Always tag the version of an image explicitly." # It's an invalid finding since the image is explicitly set in the Makefile. diff --git a/build/docker/onex/Dockerfile b/build/docker/onex/Dockerfile index 640d27fc232..e6fd9940be1 100644 --- a/build/docker/onex/Dockerfile +++ b/build/docker/onex/Dockerfile @@ -9,8 +9,8 @@ # Build the onex binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie FROM ${prod_image} LABEL maintainer="" diff --git a/build/docker/onex/Dockerfile.multistage b/build/docker/onex/Dockerfile.multistage index fdd6c0ed4d2..f877f5ae63f 100644 --- a/build/docker/onex/Dockerfile.multistage +++ b/build/docker/onex/Dockerfile.multistage @@ -10,8 +10,8 @@ # Build the onex binary # Run this with docker build --build-arg prod_image= -# Default is debian:jessie -ARG prod_image=debian:jessie +# Default is debian:trixie +ARG prod_image=debian:trixie # Ignore Hadolint rule "Always tag the version of an image explicitly." # It's an invalid finding since the image is explicitly set in the Makefile. diff --git a/scripts/make-rules/golang.mk b/scripts/make-rules/golang.mk index 43720b3aaf1..a988f55ada4 100644 --- a/scripts/make-rules/golang.mk +++ b/scripts/make-rules/golang.mk @@ -11,7 +11,9 @@ ifeq ($(origin GOBIN), undefined) GOBIN := $(GOPATH)/bin endif -COMMANDS ?= $(filter-out %.md, $(wildcard ${ONEX_ROOT}/cmd/*)) +CMD_DIRS := $(wildcard $(ONEX_ROOT)/cmd/*) +# Filter out directories without Go files, as these directories cannot be compiled. +COMMANDS := $(filter-out $(wildcard %.md), $(foreach dir, $(CMD_DIRS), $(if $(wildcard $(dir)/*.go), $(dir),))) BINS ?= $(foreach cmd,${COMMANDS},$(notdir ${cmd})) ifeq (${COMMANDS},) diff --git a/scripts/make-rules/image.mk b/scripts/make-rules/image.mk index f19b49b1491..e8bddcb4bee 100644 --- a/scripts/make-rules/image.mk +++ b/scripts/make-rules/image.mk @@ -20,10 +20,10 @@ _DOCKER_BUILD_EXTRA_ARGS += $(EXTRA_ARGS) endif # Determine image files by looking into cmd/* -IMAGES_DIR ?= $(wildcard ${ONEX_ROOT}/cmd/*) -# Determine images names by stripping out the dir names -IMAGES ?= $(filter-out tools,$(foreach image,${IMAGES_DIR},$(notdir ${image}))) - +CMD_DIRS ?= $(wildcard ${ONEX_ROOT}/cmd/*) +# Determine images names by stripping out the dir names. +# Filter out directories without Go files, as these directories cannot be compiled to build a docker image. +IMAGES ?= $(filter-out tools, $(foreach dir, $(CMD_DIRS), $(notdir $(if $(wildcard $(dir)/*.go), $(dir),)))) ifeq (${IMAGES},) $(error Could not determine IMAGES, set ONEX_ROOT or run in source dir) endif From aa43279ab11108856dc38523282b125df1df6b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sun, 9 Jun 2024 20:32:53 +0800 Subject: [PATCH 30/33] feat: add support to cluster.local cluster domain --- manifests/env.k8s | 16 ++++++++++------ scripts/gen-certs.sh | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/manifests/env.k8s b/manifests/env.k8s index a134ad93f11..58f8b855bba 100644 --- a/manifests/env.k8s +++ b/manifests/env.k8s @@ -2,12 +2,16 @@ ONEX_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -export ONEX_MYSQL_HOST=mariadb.infra.svc.onex.io -export ONEX_REDIS_HOST=redis.infra.svc.onex.io -export ONEX_ETCD_HOST=etcd.infra.svc.onex.io -export ONEX_MONGO_HOST=mongo.infra.svc.onex.io -export ONEX_KAFKA_HOST=onex-kafka.infra.svc.onex.io -export ONEX_JAEGER_HOST=jaeger.infra.svc.onex.io +# If deployed in a kubernetes cluster with cluster domain as +# cluster.local, please set KUBERNETES_CLUSTER_DOMAIN to cluster.local. +export KUBERNETES_CLUSTER_DOMAIN=${KUBERNETES_CLUSTER_DOMAIN:-onex.io} + +export ONEX_MYSQL_HOST=mariadb.infra.svc.${KUBERNETES_CLUSTER_DOMAIN} +export ONEX_REDIS_HOST=redis.infra.svc.${KUBERNETES_CLUSTER_DOMAIN} +export ONEX_ETCD_HOST=etcd.infra.svc.${KUBERNETES_CLUSTER_DOMAIN} +export ONEX_MONGO_HOST=mongo.infra.svc.${KUBERNETES_CLUSTER_DOMAIN} +export ONEX_KAFKA_HOST=onex-kafka.infra.svc.${KUBERNETES_CLUSTER_DOMAIN} +export ONEX_JAEGER_HOST=jaeger.infra.svc.${KUBERNETES_CLUSTER_DOMAIN} # 将组件的访问地址改为 Kubernetes 服务名 export ONEX_USERCENTER_HOST=onex-usercenter diff --git a/scripts/gen-certs.sh b/scripts/gen-certs.sh index 5479fc10260..3cacbd7ebac 100755 --- a/scripts/gen-certs.sh +++ b/scripts/gen-certs.sh @@ -15,6 +15,8 @@ source "${ONEX_ROOT}/scripts/lib/init.sh" readonly LOCAL_OUTPUT_ROOT="${ONEX_ROOT}/${OUT_DIR:-_output}" readonly LOCAL_OUTPUT_CAPATH="${LOCAL_OUTPUT_ROOT}/cert" readonly ONEX_DOMAIN="onex.io" +# To ensure that access is available in the default k8s cluster (with cluster domain as cluster.local). +readonly DEFAULT_KUBERNETES_CLUSTER_DOMAIN="cluster.local" # Hostname for the cert #readonly CERT_HOSTNAME="${CERT_HOSTNAME:-onex-apiserver},127.0.0.1,localhost," @@ -94,7 +96,7 @@ EOF #echo "Generate "${prefix}" certificates..." echo '{"CN":"'"${prefix}"'","hosts":[],"key":{"algo":"rsa","size":2048},"names":[{"C":"CN","ST":"Shenzhen","L":"Shenzhen","O":"tencent","OU":"'"${prefix}"'"}]}' \ - | ${CFSSL_BIN} gencert -hostname="${CERT_HOSTNAME},${prefix/-/.}.${ONEX_DOMAIN}" -ca=ca.pem -ca-key=ca-key.pem \ + | ${CFSSL_BIN} gencert -hostname="${CERT_HOSTNAME},${prefix/-/.}.${DEFAULT_KUBERNETES_CLUSTER_DOMAIN},${prefix/-/.}.${ONEX_DOMAIN}" -ca=ca.pem -ca-key=ca-key.pem \ -config=ca-config.json -profile=node - | ${CFSSLJSON_BIN} -bare "${prefix}" # the popd will access `directory stack`, no `real` parameters is actually needed From debeb3db910ddc69b3cb2f0c17bab0ae27afccc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Sun, 9 Jun 2024 23:34:06 +0800 Subject: [PATCH 31/33] fix: fix onex installation in k8s --- .../appconfig/onex-miner-controller.config.tmpl.yaml | 1 + .../onex-minerset-controller.config.tmpl.yaml | 1 - .../installation/onex/onex-toyblc/installation.md | 2 +- internal/pkg/util/miner/miner.go | 2 +- manifests/env.k8s | 2 +- .../bare/onex/onex-apiserver/deployment.yaml | 2 +- .../bare/onex/onex-apiserver/ingressroute.yaml | 11 +++++++++++ manifests/installation/kubernetes/kind-onex.yaml | 2 +- manifests/installation/storage/values.yaml | 2 +- scripts/gen-certs.sh | 4 ++-- 10 files changed, 20 insertions(+), 9 deletions(-) diff --git a/configs/appconfig/onex-miner-controller.config.tmpl.yaml b/configs/appconfig/onex-miner-controller.config.tmpl.yaml index 01a1a9b7f60..c0f22dc3d39 100644 --- a/configs/appconfig/onex-miner-controller.config.tmpl.yaml +++ b/configs/appconfig/onex-miner-controller.config.tmpl.yaml @@ -11,6 +11,7 @@ leaderElection: leaderElect: false metricsBindAddress: 0.0.0.0:${ONEX_MINER_CONTROLLER_METRICS_PORT} healthzBindAddress: 0.0.0.0:${ONEX_MINER_CONTROLLER_HEALTHZ_PORT} +providerKubeconfig: /opt/onex/etc/config.kind dryRun: true redis: addr: ${ONEX_REDIS_ADDR} diff --git a/configs/appconfig/onex-minerset-controller.config.tmpl.yaml b/configs/appconfig/onex-minerset-controller.config.tmpl.yaml index 27486adeb32..9fb3d4477c0 100644 --- a/configs/appconfig/onex-minerset-controller.config.tmpl.yaml +++ b/configs/appconfig/onex-minerset-controller.config.tmpl.yaml @@ -4,7 +4,6 @@ # this file is https://github.com/superproj/onex. # - apiVersion: minersetcontroller.config.onex.io/v1beta1 kind: MinerSetControllerConfiguration leaderElection: diff --git a/docs/guide/zh-CN/installation/onex/onex-toyblc/installation.md b/docs/guide/zh-CN/installation/onex/onex-toyblc/installation.md index 4974f8eec3f..bb43c726d0e 100644 --- a/docs/guide/zh-CN/installation/onex/onex-toyblc/installation.md +++ b/docs/guide/zh-CN/installation/onex/onex-toyblc/installation.md @@ -35,7 +35,7 @@ $ curl -H "Host: onex.toyblc.superproj.com" http://127.0.0.1:18080/v1/peers $ curl -H "Host: onex.toyblc.superproj.com" http://127.0.0.1:18080/v1/blocks ``` -> curl http://genesis.kube-system.svc.onex.io:8080/v1/blocks +> curl http://genesis.kube-system.svc.superproj.com:8080/v1/blocks ### 3. 挖矿 diff --git a/internal/pkg/util/miner/miner.go b/internal/pkg/util/miner/miner.go index 7e220c488c5..9332f0ed9d0 100644 --- a/internal/pkg/util/miner/miner.go +++ b/internal/pkg/util/miner/miner.go @@ -91,7 +91,7 @@ func IsMinerReady(m *v1beta1.Miner) bool { } func ChainDNSServiceNameFromMiner(namespace, name string) string { - return fmt.Sprintf("%s.%s.svc.onex.io", name, namespace) + return fmt.Sprintf("%s.%s.svc.superproj.com", name, namespace) } func GenesisDNSServiceNameFromMiner(name string) string { diff --git a/manifests/env.k8s b/manifests/env.k8s index 58f8b855bba..acda63c4717 100644 --- a/manifests/env.k8s +++ b/manifests/env.k8s @@ -4,7 +4,7 @@ ONEX_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. # If deployed in a kubernetes cluster with cluster domain as # cluster.local, please set KUBERNETES_CLUSTER_DOMAIN to cluster.local. -export KUBERNETES_CLUSTER_DOMAIN=${KUBERNETES_CLUSTER_DOMAIN:-onex.io} +export KUBERNETES_CLUSTER_DOMAIN=${KUBERNETES_CLUSTER_DOMAIN:-superproj.com} export ONEX_MYSQL_HOST=mariadb.infra.svc.${KUBERNETES_CLUSTER_DOMAIN} export ONEX_REDIS_HOST=redis.infra.svc.${KUBERNETES_CLUSTER_DOMAIN} diff --git a/manifests/installation/bare/onex/onex-apiserver/deployment.yaml b/manifests/installation/bare/onex/onex-apiserver/deployment.yaml index e94aa227a11..1dc953e2e9d 100644 --- a/manifests/installation/bare/onex/onex-apiserver/deployment.yaml +++ b/manifests/installation/bare/onex/onex-apiserver/deployment.yaml @@ -41,7 +41,7 @@ spec: - args: - --secure-port=52443 - --bind-address=0.0.0.0 - - --etcd-servers=etcd.infra.svc.onex.io:2379 + - --etcd-servers=etcd.infra.svc.superproj.com:2379 - --client-ca-file=/opt/onex/etc/cert/ca.pem - --tls-cert-file=/opt/onex/etc/cert/onex-apiserver.pem - --tls-private-key-file=/opt/onex/etc/cert/onex-apiserver-key.pem diff --git a/manifests/installation/bare/onex/onex-apiserver/ingressroute.yaml b/manifests/installation/bare/onex/onex-apiserver/ingressroute.yaml index 3a0f7e4ac8b..165451f2cdf 100644 --- a/manifests/installation/bare/onex/onex-apiserver/ingressroute.yaml +++ b/manifests/installation/bare/onex/onex-apiserver/ingressroute.yaml @@ -4,6 +4,16 @@ # this file is https://github.com/superproj/onex. # +apiVersion: traefik.io/v1alpha1 +kind: ServersTransport +metadata: + name: onex-apiserver-transport +spec: + serverName: onex.apiserver.superproj.com + insecureSkipVerify: false + rootCAsSecrets: + - root-ca-secret +--- apiVersion: traefik.io/v1alpha1 kind: IngressRoute metadata: @@ -18,5 +28,6 @@ spec: - kind: Service name: onex-apiserver port: 52443 + serversTransport: onex-apiserver-transport tls: secretName: onex-apiserver diff --git a/manifests/installation/kubernetes/kind-onex.yaml b/manifests/installation/kubernetes/kind-onex.yaml index 356b9189e66..21576b65404 100644 --- a/manifests/installation/kubernetes/kind-onex.yaml +++ b/manifests/installation/kubernetes/kind-onex.yaml @@ -42,7 +42,7 @@ kubeadmConfigPatches: - | kind: ClusterConfiguration networking: - dnsDomain: "onex.io" + dnsDomain: "superproj.com" - | apiVersion: kubelet.config.k8s.io/v1beta1 kind: KubeletConfiguration diff --git a/manifests/installation/storage/values.yaml b/manifests/installation/storage/values.yaml index 708061bcf7e..c66008cb337 100644 --- a/manifests/installation/storage/values.yaml +++ b/manifests/installation/storage/values.yaml @@ -1,5 +1,5 @@ # 设置集群的域名 -clusterDomain: onex.io +clusterDomain: superproj.com # 镜像相关配置 image: # 镜像仓库的地址 diff --git a/scripts/gen-certs.sh b/scripts/gen-certs.sh index 3cacbd7ebac..e2fa178f6f9 100755 --- a/scripts/gen-certs.sh +++ b/scripts/gen-certs.sh @@ -14,7 +14,7 @@ source "${ONEX_ROOT}/scripts/lib/init.sh" # OUT_DIR can come in from the Makefile, so honor it. readonly LOCAL_OUTPUT_ROOT="${ONEX_ROOT}/${OUT_DIR:-_output}" readonly LOCAL_OUTPUT_CAPATH="${LOCAL_OUTPUT_ROOT}/cert" -readonly ONEX_DOMAIN="onex.io" +readonly PROJ_DOMAIN="superproj.com" # To ensure that access is available in the default k8s cluster (with cluster domain as cluster.local). readonly DEFAULT_KUBERNETES_CLUSTER_DOMAIN="cluster.local" @@ -96,7 +96,7 @@ EOF #echo "Generate "${prefix}" certificates..." echo '{"CN":"'"${prefix}"'","hosts":[],"key":{"algo":"rsa","size":2048},"names":[{"C":"CN","ST":"Shenzhen","L":"Shenzhen","O":"tencent","OU":"'"${prefix}"'"}]}' \ - | ${CFSSL_BIN} gencert -hostname="${CERT_HOSTNAME},${prefix/-/.}.${DEFAULT_KUBERNETES_CLUSTER_DOMAIN},${prefix/-/.}.${ONEX_DOMAIN}" -ca=ca.pem -ca-key=ca-key.pem \ + | ${CFSSL_BIN} gencert -hostname="${CERT_HOSTNAME},${prefix/-/.}.${DEFAULT_KUBERNETES_CLUSTER_DOMAIN},${prefix/-/.}.${PROJ_DOMAIN}" -ca=ca.pem -ca-key=ca-key.pem \ -config=ca-config.json -profile=node - | ${CFSSLJSON_BIN} -bare "${prefix}" # the popd will access `directory stack`, no `real` parameters is actually needed From d4e0d50347d02ac21ac1799f54eb46acaa1cb92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=94=E4=BB=A4=E9=A3=9E?= Date: Tue, 25 Jun 2024 17:47:34 +0800 Subject: [PATCH 32/33] feat: support finite state machine (fsm) --- cmd/onex-nightwatch/app/options/options.go | 34 +++++--- configs/onex.sql | 1 + go.mod | 1 + go.sum | 2 + internal/controller/miner/controller.go | 1 - internal/nightwatch/nightwatch.go | 24 ++++-- internal/nightwatch/watcher/all/all.go | 1 + internal/nightwatch/watcher/clean/watcher.go | 2 +- internal/nightwatch/watcher/config.go | 3 + .../watcher/secretsclean/watcher.go | 2 +- internal/nightwatch/watcher/user/event.go | 76 +++++++++++++++++ internal/nightwatch/watcher/user/fsm.go | 26 ++++++ internal/nightwatch/watcher/user/watcher.go | 83 +++++++++++++++++++ internal/nightwatch/watcher/watcher.go | 5 +- internal/pkg/known/usercenter/status.go | 23 +++++ internal/pkg/onexx/onexx.go | 14 ++++ internal/usercenter/biz/user/list.go | 7 +- internal/usercenter/model/hook.go | 9 +- internal/usercenter/model/uc_user.gen.go | 2 +- pkg/app/options.go | 1 + 20 files changed, 285 insertions(+), 32 deletions(-) create mode 100644 internal/nightwatch/watcher/user/event.go create mode 100644 internal/nightwatch/watcher/user/fsm.go create mode 100644 internal/nightwatch/watcher/user/watcher.go create mode 100644 internal/pkg/known/usercenter/status.go diff --git a/cmd/onex-nightwatch/app/options/options.go b/cmd/onex-nightwatch/app/options/options.go index 5fc54b446e4..319a7f03299 100644 --- a/cmd/onex-nightwatch/app/options/options.go +++ b/cmd/onex-nightwatch/app/options/options.go @@ -8,6 +8,8 @@ package options import ( + "math" + "github.com/spf13/viper" utilerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/client-go/tools/clientcmd" @@ -31,10 +33,12 @@ var _ app.CliOptions = (*Options)(nil) // Options contains everything necessary to create and run a nightwatch server. type Options struct { - HealthOptions *genericoptions.HealthOptions `json:"health" mapstructure:"health"` - MySQLOptions *genericoptions.MySQLOptions `json:"mysql" mapstructure:"mysql"` - RedisOptions *genericoptions.RedisOptions `json:"redis" mapstructure:"redis"` - Metrics *genericoptions.MetricsOptions `json:"metrics" mapstructure:"metrics"` + HealthOptions *genericoptions.HealthOptions `json:"health" mapstructure:"health"` + MySQLOptions *genericoptions.MySQLOptions `json:"db" mapstructure:"db"` + RedisOptions *genericoptions.RedisOptions `json:"redis" mapstructure:"redis"` + UserWatcherMaxWorkers int64 `json:"user-watcher-max-workers" mapstructure:"user-watcher-max-workers"` + DisableWatchers []string `json:"disable-watchers" mapstructure:"disable-watchers"` + Metrics *genericoptions.MetricsOptions `json:"metrics" mapstructure:"metrics"` // Path to kubeconfig file with authorization and master location information. Kubeconfig string `json:"kubeconfig" mapstructure:"kubeconfig"` FeatureGates map[string]bool `json:"feature-gates"` @@ -44,11 +48,13 @@ type Options struct { // NewOptions returns initialized Options. func NewOptions() *Options { o := &Options{ - HealthOptions: genericoptions.NewHealthOptions(), - MySQLOptions: genericoptions.NewMySQLOptions(), - RedisOptions: genericoptions.NewRedisOptions(), - Metrics: genericoptions.NewMetricsOptions(), - Log: log.NewOptions(), + HealthOptions: genericoptions.NewHealthOptions(), + MySQLOptions: genericoptions.NewMySQLOptions(), + RedisOptions: genericoptions.NewRedisOptions(), + UserWatcherMaxWorkers: math.MaxInt64, + DisableWatchers: []string{}, + Metrics: genericoptions.NewMetricsOptions(), + Log: log.NewOptions(), } return o @@ -57,7 +63,7 @@ func NewOptions() *Options { // Flags returns flags for a specific server by section name. func (o *Options) Flags() (fss cliflag.NamedFlagSets) { o.HealthOptions.AddFlags(fss.FlagSet("health")) - o.MySQLOptions.AddFlags(fss.FlagSet("mysql")) + o.MySQLOptions.AddFlags(fss.FlagSet("db")) o.RedisOptions.AddFlags(fss.FlagSet("redis")) o.Metrics.AddFlags(fss.FlagSet("metrics")) o.Log.AddFlags(fss.FlagSet("log")) @@ -66,6 +72,8 @@ func (o *Options) Flags() (fss cliflag.NamedFlagSets) { // arrange these text blocks sensibly. Grrr. fs := fss.FlagSet("misc") fs.StringVar(&o.Kubeconfig, "kubeconfig", o.Kubeconfig, "Path to kubeconfig file with authorization and master location information.") + fs.Int64Var(&o.UserWatcherMaxWorkers, "user-watcher-max-workers", o.UserWatcherMaxWorkers, "Specify the maximum concurrency event of user watcher.") + fs.StringSliceVar(&o.DisableWatchers, "disable-watchers", o.DisableWatchers, "The list of watchers that should be disabled.") feature.DefaultMutableFeatureGate.AddFlag(fs) return fss @@ -77,6 +85,10 @@ func (o *Options) Complete() error { return err } + if o.UserWatcherMaxWorkers < 1 { + o.UserWatcherMaxWorkers = math.MaxInt64 + } + _ = feature.DefaultMutableFeatureGate.SetFromMap(o.FeatureGates) return nil } @@ -98,6 +110,8 @@ func (o *Options) Validate() error { func (o *Options) ApplyTo(c *nightwatch.Config) error { c.MySQLOptions = o.MySQLOptions c.RedisOptions = o.RedisOptions + c.UserWatcherMaxWorkers = o.UserWatcherMaxWorkers + c.DisableWatchers = o.DisableWatchers return nil } diff --git a/configs/onex.sql b/configs/onex.sql index 072caeae3e2..9e1ed8f65d1 100644 --- a/configs/onex.sql +++ b/configs/onex.sql @@ -235,6 +235,7 @@ CREATE TABLE `uc_user` ( `user_id` varchar(253) NOT NULL DEFAULT '' COMMENT '用户 ID', `username` varchar(253) NOT NULL DEFAULT '' COMMENT '用户名称', `status` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT '用户状态,0-禁用;1-启用', + `status` varchar(64) NOT NULL DEFAULT '' COMMENT '用户状态:registered,active,disabled,blacklisted,locked,deleted', `nickname` varchar(253) NOT NULL DEFAULT '' COMMENT '用户昵称', `password` varchar(64) NOT NULL DEFAULT '' COMMENT '用户加密后的密码', `email` varchar(253) NOT NULL DEFAULT '' COMMENT '用户电子邮箱', diff --git a/go.mod b/go.mod index e8b3efa78c4..e2d93dffbad 100644 --- a/go.mod +++ b/go.mod @@ -46,6 +46,7 @@ require ( github.com/jinzhu/copier v0.3.5 github.com/kisielk/errcheck v1.5.0 github.com/likexian/host-stat-go v0.0.0-20190516151207-c9cf36dd6ce9 + github.com/looplab/fsm v1.0.2 github.com/mitchellh/go-wordwrap v1.0.1 github.com/nicksnyder/go-i18n/v2 v2.2.1 github.com/olekukonko/tablewriter v0.0.5 diff --git a/go.sum b/go.sum index c829fb1cdec..95518d55000 100644 --- a/go.sum +++ b/go.sum @@ -1228,6 +1228,8 @@ github.com/likexian/host-stat-go v0.0.0-20190516151207-c9cf36dd6ce9/go.mod h1:Hn github.com/likexian/simplejson-go v0.0.0-20190409170913-40473a74d76d/go.mod h1:Typ1BfnATYtZ/+/shXfFYLrovhFyuKvzwrdOnIDHlmg= github.com/likexian/simplejson-go v0.0.0-20190419151922-c1f9f0b4f084/go.mod h1:U4O1vIJvIKwbMZKUJ62lppfdvkCdVd2nfMimHK81eec= github.com/likexian/simplejson-go v0.0.0-20190502021454-d8787b4bfa0b/go.mod h1:3BWwtmKP9cXWwYCr5bkoVDEfLywacOv0s06OBEDpyt8= +github.com/looplab/fsm v1.0.2 h1:f0kdMzr4CRpXtaKKRUxwLYJ7PirTdwrtNumeLN+mDx8= +github.com/looplab/fsm v1.0.2/go.mod h1:PmD3fFvQEIsjMEfvZdrCDZ6y8VwKTwWNjlpEr6IKPO4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a h1:N9zuLhTvBSRt0gWSiJswwQ2HqDmtX/ZCDJURnKUt1Ik= github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE= diff --git a/internal/controller/miner/controller.go b/internal/controller/miner/controller.go index 7eeacaf63bf..8b33f37e525 100644 --- a/internal/controller/miner/controller.go +++ b/internal/controller/miner/controller.go @@ -26,7 +26,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/source" "github.com/superproj/onex/internal/controller/miner/apis/config" diff --git a/internal/nightwatch/nightwatch.go b/internal/nightwatch/nightwatch.go index ab71f2e260b..0beb8c81d7b 100644 --- a/internal/nightwatch/nightwatch.go +++ b/internal/nightwatch/nightwatch.go @@ -25,6 +25,7 @@ import ( // trigger init functions in `internal/nightwatch/watcher/all`. _ "github.com/superproj/onex/internal/nightwatch/watcher/all" genericoptions "github.com/superproj/onex/pkg/options" + stringsutil "github.com/superproj/onex/pkg/util/strings" ) var ( @@ -37,15 +38,20 @@ var ( type nightWatch struct { runner *cron.Cron // distributed lock - locker *redsync.Mutex - config *watcher.Config + locker *redsync.Mutex + config *watcher.Config + disableWatchers []string } // Config is the configuration for the nightwatch server. type Config struct { MySQLOptions *genericoptions.MySQLOptions RedisOptions *genericoptions.RedisOptions - Client clientset.Interface + // The maximum concurrency event of user watcher. + UserWatcherMaxWorkers int64 + // The list of watchers that should be disabled. + DisableWatchers []string + Client clientset.Interface } // CompletedConfig same as Config, just to swap private object. @@ -68,7 +74,11 @@ func (c *Config) CreateWatcherConfig() (*watcher.Config, error) { return nil, err } - return &watcher.Config{Store: storeClient, Client: c.Client}, nil + return &watcher.Config{ + Store: storeClient, + Client: c.Client, + UserWatcherMaxWorkers: c.UserWatcherMaxWorkers, + }, nil } // New creates an asynchronous task instance. @@ -104,7 +114,7 @@ func (c *Config) New() (*nightWatch, error) { return nil, err } - nw := &nightWatch{runner: runner, locker: locker, config: cfg} + nw := &nightWatch{runner: runner, locker: locker, config: cfg, disableWatchers: c.DisableWatchers} if err := nw.addWatchers(); err != nil { return nil, err } @@ -115,6 +125,10 @@ func (c *Config) New() (*nightWatch, error) { // addWatchers used to initialize all registered watchers and add the watchers as a Cron job. func (nw *nightWatch) addWatchers() error { for n, w := range watcher.ListWatchers() { + if stringsutil.StringIn(n, nw.disableWatchers) { + continue + } + if err := w.Init(context.Background(), nw.config); err != nil { log.Errorw(err, "Failed to construct watcher", "watcher", n) return err diff --git a/internal/nightwatch/watcher/all/all.go b/internal/nightwatch/watcher/all/all.go index 8b7577cfdf3..9d9f2cb7941 100644 --- a/internal/nightwatch/watcher/all/all.go +++ b/internal/nightwatch/watcher/all/all.go @@ -10,4 +10,5 @@ package all import ( _ "github.com/superproj/onex/internal/nightwatch/watcher/clean" _ "github.com/superproj/onex/internal/nightwatch/watcher/secretsclean" + _ "github.com/superproj/onex/internal/nightwatch/watcher/user" ) diff --git a/internal/nightwatch/watcher/clean/watcher.go b/internal/nightwatch/watcher/clean/watcher.go index 63778ee5709..603636fefa7 100644 --- a/internal/nightwatch/watcher/clean/watcher.go +++ b/internal/nightwatch/watcher/clean/watcher.go @@ -42,5 +42,5 @@ func (w *cleanWatcher) Init(ctx context.Context, config *watcher.Config) error { } func init() { - watcher.Register(&cleanWatcher{}) + watcher.Register("clean", &cleanWatcher{}) } diff --git a/internal/nightwatch/watcher/config.go b/internal/nightwatch/watcher/config.go index 40879cb6e1e..cfc67eefa6b 100644 --- a/internal/nightwatch/watcher/config.go +++ b/internal/nightwatch/watcher/config.go @@ -20,4 +20,7 @@ type Config struct { // Client is the client for onex-apiserver. Client clientset.Interface + + // Then maximum concurrency event of user watcher. + UserWatcherMaxWorkers int64 } diff --git a/internal/nightwatch/watcher/secretsclean/watcher.go b/internal/nightwatch/watcher/secretsclean/watcher.go index 3abfa8c0949..23dd89051a7 100644 --- a/internal/nightwatch/watcher/secretsclean/watcher.go +++ b/internal/nightwatch/watcher/secretsclean/watcher.go @@ -50,5 +50,5 @@ func (w *secretsCleanWatcher) Init(ctx context.Context, config *watcher.Config) } func init() { - watcher.Register(&secretsCleanWatcher{}) + watcher.Register("secretsclean", &secretsCleanWatcher{}) } diff --git a/internal/nightwatch/watcher/user/event.go b/internal/nightwatch/watcher/user/event.go new file mode 100644 index 00000000000..6632e9290eb --- /dev/null +++ b/internal/nightwatch/watcher/user/event.go @@ -0,0 +1,76 @@ +package user + +import ( + "context" + "time" + + "github.com/looplab/fsm" + + "github.com/superproj/onex/internal/pkg/client/store" + known "github.com/superproj/onex/internal/pkg/known/usercenter" + "github.com/superproj/onex/internal/pkg/onexx" + "github.com/superproj/onex/pkg/log" +) + +const ( + UserEventAfterEvent = "after_event" +) + +func NewActiveUserCallback(store store.Interface) fsm.Callback { + return func(ctx context.Context, event *fsm.Event) { + userM := onexx.FromUserM(ctx) + log.Infow("Now active user", "event", event.Event, "username", userM.Username) + // Fake active user operations. + time.Sleep(5 * time.Second) + log.Infow("Success to active user", "event", event.Event, "username", userM.Username) + } +} + +func NewDisableUserCallback(store store.Interface) fsm.Callback { + return func(ctx context.Context, event *fsm.Event) { + userM := onexx.FromUserM(ctx) + log.Infow("Now disable user", "event", event.Event, "username", userM.Username) + // Fake disable user operations. + time.Sleep(5 * time.Second) + log.Infow("Success to disable user", "event", event.Event, "username", userM.Username) + } +} + +func NewDeleteUserCallback(store store.Interface) fsm.Callback { + return func(ctx context.Context, event *fsm.Event) { + userM := onexx.FromUserM(ctx) + log.Infow("Now delete user", "event", event.Event, "username", userM.Username) + // Fake delete user operations. + time.Sleep(5 * time.Second) + log.Infow("Success to delete user", "event", event.Event, "username", userM.Username) + } +} + +func NewUserEventAfterEvent(store store.Interface) fsm.Callback { + return func(ctx context.Context, event *fsm.Event) { + alarmStatus := "success" + userM := onexx.FromUserM(ctx) + + defer func() { + log.Infow("This is a fake alarm message", "status", alarmStatus, "username", userM.Username) + }() + + if event.Err != nil { + alarmStatus = "failed" + log.Errorw(event.Err, "Failed to handle event", "event", event.Event) + // We can add some alerts here in the future. + return + } + + user := onexx.FromUserM(ctx) + user.Status = event.FSM.Current() + if err := store.UserCenter().Users().Update(ctx, user); err != nil { + log.Errorw(err, "Failed to update status into database", "event", event.Event) + } + + if user.Status == known.UserStatusDeleted { + // We can add some lark card here in the future. + log.Infow("Finish to handle user", "event", event.Event, "username", user.Username) + } + } +} diff --git a/internal/nightwatch/watcher/user/fsm.go b/internal/nightwatch/watcher/user/fsm.go new file mode 100644 index 00000000000..8dce4a2635a --- /dev/null +++ b/internal/nightwatch/watcher/user/fsm.go @@ -0,0 +1,26 @@ +package user + +import ( + "github.com/looplab/fsm" + + known "github.com/superproj/onex/internal/pkg/known/usercenter" +) + +func NewFSM(initial string, w *userWatcher) *fsm.FSM { + return fsm.NewFSM( + initial, + fsm.Events{ + {Name: known.UserStatusRegistered, Src: []string{known.UserStatusRegistered}, Dst: known.UserStatusActive}, + {Name: known.UserStatusBlacklisted, Src: []string{known.UserStatusBlacklisted}, Dst: known.UserStatusDisabled}, + {Name: known.UserStatusDisabled, Src: []string{known.UserStatusDisabled}, Dst: known.UserStatusDeleted}, + }, + fsm.Callbacks{ + known.UserStatusActive: NewActiveUserCallback(w.store), + known.UserStatusDisabled: NewDisableUserCallback(w.store), + known.UserStatusDeleted: NewDeleteUserCallback(w.store), + // log, alert, save to stoer, etc for all events. + // Alert the status of each step of the operation. + UserEventAfterEvent: NewUserEventAfterEvent(w.store), + }, + ) +} diff --git a/internal/nightwatch/watcher/user/watcher.go b/internal/nightwatch/watcher/user/watcher.go new file mode 100644 index 00000000000..54f8520b854 --- /dev/null +++ b/internal/nightwatch/watcher/user/watcher.go @@ -0,0 +1,83 @@ +// Copyright 2022 Lingfei Kong . All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. The original repo for +// this file is https://github.com/superproj/onex. +// + +// Package user is a watcher implement. +package user + +import ( + "context" + + "github.com/gammazero/workerpool" + "github.com/looplab/fsm" + + "github.com/superproj/onex/internal/nightwatch/watcher" + "github.com/superproj/onex/internal/pkg/client/store" + known "github.com/superproj/onex/internal/pkg/known/usercenter" + "github.com/superproj/onex/internal/pkg/onexx" + "github.com/superproj/onex/internal/usercenter/model" + "github.com/superproj/onex/pkg/log" + stringsutil "github.com/superproj/onex/pkg/util/strings" +) + +var _ watcher.Watcher = (*userWatcher)(nil) + +// watcher implement. +type userWatcher struct { + store store.Interface + maxWorkers int64 +} + +type User struct { + *model.UserM + *fsm.FSM +} + +// Run runs the watcher. +func (w *userWatcher) Run() { + _, users, err := w.store.UserCenter().Users().List(context.Background()) + if err != nil { + log.Errorw(err, "Failed to list users") + return + } + + allowOperations := []string{ + known.UserStatusRegistered, + known.UserStatusBlacklisted, + known.UserStatusDisabled, + } + + wp := workerpool.New(int(w.maxWorkers)) + for _, user := range users { + if !stringsutil.StringIn(user.Status, allowOperations) { + continue + } + + wp.Submit(func() { + ctx := onexx.NewUserM(context.Background(), user) + + u := &User{UserM: user, FSM: NewFSM(user.Status, w)} + if err := u.Event(ctx, user.Status); err != nil { + log.Errorw(err, "Failed to event user", "username", user.Username, "status", user.Status) + return + } + + return + }) + } + + wp.StopWait() +} + +// Init initializes the watcher for later execution. +func (w *userWatcher) Init(ctx context.Context, config *watcher.Config) error { + w.store = config.Store + w.maxWorkers = config.UserWatcherMaxWorkers + return nil +} + +func init() { + watcher.Register("user", &userWatcher{}) +} diff --git a/internal/nightwatch/watcher/watcher.go b/internal/nightwatch/watcher/watcher.go index 421b616d88f..8aafc1e5aa1 100644 --- a/internal/nightwatch/watcher/watcher.go +++ b/internal/nightwatch/watcher/watcher.go @@ -12,8 +12,6 @@ import ( "sync" "github.com/robfig/cron/v3" - - reflectutil "github.com/superproj/onex/pkg/util/reflect" ) const ( @@ -49,11 +47,10 @@ var ( ) // Register registers a watcher and save in global variable `registry`. -func Register(watcher Watcher) { +func Register(name string, watcher Watcher) { registryLock.Lock() defer registryLock.Unlock() - name := reflectutil.StructName(watcher) if _, ok := registry[name]; ok { panic("duplicate watcher entry: " + name) } diff --git a/internal/pkg/known/usercenter/status.go b/internal/pkg/known/usercenter/status.go new file mode 100644 index 00000000000..1928647d745 --- /dev/null +++ b/internal/pkg/known/usercenter/status.go @@ -0,0 +1,23 @@ +package usercenter + +const ( + // User has submitted registration information, the account is in a pending. + // The user needs to complete email/phone number verification steps to transition to an active state. + // The OneX project does not currently use this. + UserStatusRegistered = "registered" + // The user has registered and been verified, and can use the system normally. + // Most user operations are performed in this state. + UserStatusActive = "active" + // The user has entered the incorrect password too many times, and the account has been locked by the system. + // The user needs to recover the password or contact the administrator to unlock the account. + UserStatusLocked = "locked" + // The user has been added to the system blacklist due to serious misconduct. + // Blacklisted users cannot register new accounts or use the system. + UserStatusBlacklisted = "blacklisted" + // The administrator has manually disabled the user account, and the user cannot log in after being disabled. + // This may be due to user misconduct or other reasons. + UserStatusDisabled = "disabled" + // The user has actively deleted their own account, or the administrator has deleted the user account. + // The deleted account can be chosen to be soft-deleted (with some data retained) or completely deleted. + UserStatusDeleted = "deleted" +) diff --git a/internal/pkg/onexx/onexx.go b/internal/pkg/onexx/onexx.go index 8dd87bca7fd..5ac022f0456 100644 --- a/internal/pkg/onexx/onexx.go +++ b/internal/pkg/onexx/onexx.go @@ -11,6 +11,8 @@ import ( "context" "github.com/golang-jwt/jwt/v4" + + "github.com/superproj/onex/internal/usercenter/model" ) // 定义全局上下文中的键. @@ -25,6 +27,7 @@ type ( type ( authKey struct{} userKey struct{} + userMKey struct{} accessTokenKey struct{} ) @@ -60,3 +63,14 @@ func FromAccessToken(ctx context.Context) string { accessToken, _ := ctx.Value(accessTokenKey{}).(string) return accessToken } + +// NewUserM put *UserM into context. +func NewUserM(ctx context.Context, user *model.UserM) context.Context { + return context.WithValue(ctx, userMKey{}, user) +} + +// FromUserM extract *UserM from extract. +func FromUserM(ctx context.Context) *model.UserM { + user, _ := ctx.Value(userMKey{}).(*model.UserM) + return user +} diff --git a/internal/usercenter/biz/user/list.go b/internal/usercenter/biz/user/list.go index 5dcd6bc4c16..e487c2fb259 100644 --- a/internal/usercenter/biz/user/list.go +++ b/internal/usercenter/biz/user/list.go @@ -21,6 +21,10 @@ import ( "github.com/superproj/onex/pkg/log" ) +const ( + defaultMaxWorkers = 100 +) + // List retrieves a list of all users from the database. func (b *userBiz) List(ctx context.Context, rq *v1.ListUserRequest) (*v1.ListUserResponse, error) { count, list, err := b.ds.Users().List(ctx, meta.WithOffset(rq.Offset), meta.WithLimit(rq.Limit)) @@ -81,8 +85,7 @@ func (b *userBiz) ListWithWorkerPool(ctx context.Context, rq *v1.ListUserRequest } var m sync.Map - wp := workerpool.New(100) - + wp := workerpool.New(defaultMaxWorkers) // Use goroutine to improve interface performance for _, user := range list { wp.Submit(func() { diff --git a/internal/usercenter/model/hook.go b/internal/usercenter/model/hook.go index 4c2a36adb27..54d3c987c79 100644 --- a/internal/usercenter/model/hook.go +++ b/internal/usercenter/model/hook.go @@ -10,16 +10,11 @@ import ( "github.com/google/uuid" "gorm.io/gorm" + known "github.com/superproj/onex/internal/pkg/known/usercenter" "github.com/superproj/onex/internal/pkg/zid" "github.com/superproj/onex/pkg/authn" ) -// User status constants. -const ( - StatusUserDisabled = iota // Status used for disabling a user. - StatusUserNormal // Status used for enabling a user. -) - // Secret status constants. const ( StatusSecretDisabled = iota // Status used for disabling a secret. @@ -58,7 +53,7 @@ func (u *UserM) BeforeCreate(tx *gorm.DB) (err error) { return err // Return error if there's a problem with encryption. } - u.Status = StatusUserNormal // Set the default status for the user as normal. + u.Status = known.UserStatusActive // Set the default status for the user as active. return nil } diff --git a/internal/usercenter/model/uc_user.gen.go b/internal/usercenter/model/uc_user.gen.go index 4d17541ae02..25fda7aa5e0 100644 --- a/internal/usercenter/model/uc_user.gen.go +++ b/internal/usercenter/model/uc_user.gen.go @@ -21,7 +21,7 @@ type UserM struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true;comment:主键 ID" json:"id"` // 主键 ID UserID string `gorm:"column:user_id;type:varchar(253);not null;uniqueIndex:idx_user_id,priority:1;comment:用户 ID" json:"user_id"` // 用户 ID Username string `gorm:"column:username;type:varchar(253);not null;uniqueIndex:idx_username,priority:1;comment:用户名称" json:"username"` // 用户名称 - Status int32 `gorm:"column:status;type:tinyint(3) unsigned;not null;default:1;comment:用户状态,0-禁用;1-启用" json:"status"` // 用户状态,0-禁用;1-启用 + Status string `gorm:"column:status;type:tinyint(3) unsigned;not null;default:1;comment:用户状态,0-禁用;1-启用" json:"status"` // 用户状态,0-禁用;1-启用 Nickname string `gorm:"column:nickname;type:varchar(253);not null;comment:用户昵称" json:"nickname"` // 用户昵称 Password string `gorm:"column:password;type:varchar(64);not null;comment:用户加密后的密码" json:"password"` // 用户加密后的密码 Email string `gorm:"column:email;type:varchar(253);not null;comment:用户电子邮箱" json:"email"` // 用户电子邮箱 diff --git a/pkg/app/options.go b/pkg/app/options.go index e03229ee81d..e6c71e0e03c 100644 --- a/pkg/app/options.go +++ b/pkg/app/options.go @@ -73,6 +73,7 @@ func AddConfigFlag(fs *pflag.FlagSet, name string, watch bool) { if err := viper.ReadInConfig(); err != nil { log.Debugw("Failed to read configuration file", "file", cfgFile, "err", err) } + log.Debugw("Success to read configuration file", "file", viper.ConfigFileUsed()) if watch { viper.WatchConfig() From 3253e2a8f925e1d4453208ab18b157cf3dc07227 Mon Sep 17 00:00:00 2001 From: lazywoo Date: Fri, 2 Aug 2024 13:12:00 +0800 Subject: [PATCH 33/33] fix: invalid mariadb repo fixed to 11.2.4, remove old commands and fix here document --- scripts/installation/mariadb.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/installation/mariadb.sh b/scripts/installation/mariadb.sh index ac0a22e008a..e51133aa850 100755 --- a/scripts/installation/mariadb.sh +++ b/scripts/installation/mariadb.sh @@ -28,7 +28,7 @@ onex::mariadb::docker::install() -v ${ONEX_THIRDPARTY_INSTALL_DIR}/mariadb:/var/lib/mysql \ -p ${ONEX_ACCESS_HOST}:${ONEX_MYSQL_PORT}:3306 \ -e MYSQL_ROOT_PASSWORD=${ONEX_PASSWORD} \ - mariadb:11.2.2 + mariadb:11.2.4 echo "Sleeping to wait for all onex-mariadb container to complete startup ..." sleep 10 @@ -57,7 +57,7 @@ onex::mariadb::sbs::install() # 软件包的签名,确保软件包在下载和安装过程中的完整性和安全性 echo ${LINUX_PASSWORD} | sudo -S apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc' # 配置 MariaDB 11.2.2 apt 源(docker install 和 sbs install 版本都要保持一致) - echo ${LINUX_PASSWORD} | sudo -S echo "deb [arch=amd64,arm64] https://mirrors.aliyun.com/mariadb/repo/11.2.2/debian/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb-11.2.2.list + echo ${LINUX_PASSWORD} | sudo -S echo "deb [arch=amd64,arm64] https://mirrors.aliyun.com/mariadb/repo/11.2.4/debian/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/mariadb-11.2.4.list # 注意:一定要执行 `apt update`,否则可能安装的还是旧的软件包 onex::util::sudo "apt update" @@ -78,7 +78,7 @@ onex::mariadb::sbs::install() onex::util::sudo "systemctl restart mariadb" # 设置 root 初始密码 - onex::util::sudo "mysqladmin -u${ONEX_MYSQL_ADMIN_USERNAME} password ${ONEX_MYSQL_ADMIN_PASSWORD}" + onex::util::sudo "mariadb-admin -u${ONEX_MYSQL_ADMIN_USERNAME} password ${ONEX_MYSQL_ADMIN_PASSWORD}" onex::mariadb::status || return 1 onex::mariadb::info @@ -97,7 +97,7 @@ onex::mariadb::sbs::uninstall() onex::util::sudo "rm -rvf /var/lib/mysql" onex::util::sudo "rm -rvf /etc/mysql" onex::util::sudo "rm -rvf /usr/share/keyrings/mariadb.gpg" - onex::util::sudo "rm -vf /etc/apt/sources.list.d/mariadb-11.2.2.list" + onex::util::sudo "rm -vf /etc/apt/sources.list.d/mariadb-11.2.4.list" onex::log::info "uninstall mariadb successfully" } @@ -108,7 +108,7 @@ onex::mariadb::info() cat << EOF | sed 's/^/ /' MySQL access endpoint is: ${ONEX_MYSQL_HOST}:${ONEX_MYSQL_PORT} root password is: ${ONEX_PASSWORD} -# `mysql` will be deprecated in the future, so here use `mariadb` instead. +# mysql will be deprecated in the future, so here use mariadb instead. Access command: mariadb -h ${ONEX_MYSQL_HOST} -P ${ONEX_MYSQL_PORT} -u root -p'${ONEX_PASSWORD}' EOF }