From c80f11643de95c777d7be5acba4c0b72c887a1f6 Mon Sep 17 00:00:00 2001 From: yeka Date: Thu, 12 Sep 2024 11:31:15 +0800 Subject: [PATCH 1/5] feat: add env to pipelinerun event && support more configs of mysql Signed-off-by: yeka --- lib/orm/orm.go | 39 ++++++++++++++++----- pkg/eventhandler/wlgenerator/wlgenerator.go | 2 ++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/lib/orm/orm.go b/lib/orm/orm.go index e98b0cdd2..6c3b7a059 100644 --- a/lib/orm/orm.go +++ b/lib/orm/orm.go @@ -33,25 +33,41 @@ import ( // MySQL ... type MySQL struct { - Host string `json:"host"` - Port int `json:"port"` - Username string `json:"username"` - Password string `json:"password,omitempty"` - Database string `json:"database"` - PrometheusEnabled bool `json:"prometheusEnabled"` + Host string `json:"host"` + Port int `json:"port"` + Username string `json:"username"` + Password string `json:"password,omitempty"` + Database string `json:"database"` + PrometheusEnabled bool `json:"prometheusEnabled"` + SlowThreshold time.Duration `json:"slowThreshold"` + MaxIdleConns int `json:"maxIdleConns"` + MaxOpenConns int `json:"maxOpenConns"` } func NewMySQLDB(db *MySQL) (*gorm.DB, error) { conn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", db.Username, db.Password, db.Host, db.Port, db.Database) + // Set default value for SlowThreshold if not provided + if db.SlowThreshold == 0 { + db.SlowThreshold = 200 * time.Millisecond + } + // Set default value for MaxIdleConns if not provided + if db.MaxIdleConns == 0 { + db.MaxIdleConns = 10 + } + // Set default value for MaxOpenConns if not provided + if db.MaxOpenConns == 0 { + db.MaxOpenConns = 100 + } + sqlDB, err := sql.Open("mysql", conn) if err != nil { return nil, err } - sqlDB.SetMaxIdleConns(10) - sqlDB.SetMaxOpenConns(100) + sqlDB.SetMaxIdleConns(db.MaxIdleConns) + sqlDB.SetMaxOpenConns(db.MaxOpenConns) sqlDB.SetConnMaxLifetime(time.Hour) sqlDB.SetConnMaxIdleTime(time.Hour) @@ -62,6 +78,13 @@ func NewMySQLDB(db *MySQL) (*gorm.DB, error) { TablePrefix: "tb_", SingularTable: true, }, + Logger: logger.New(log.New(os.Stdout, "\r\n", log.LstdFlags), + logger.Config{ + SlowThreshold: db.SlowThreshold, + LogLevel: logger.Warn, + IgnoreRecordNotFoundError: false, + Colorful: true, + }), }) if db.PrometheusEnabled { diff --git a/pkg/eventhandler/wlgenerator/wlgenerator.go b/pkg/eventhandler/wlgenerator/wlgenerator.go index 9ca316797..74e533941 100644 --- a/pkg/eventhandler/wlgenerator/wlgenerator.go +++ b/pkg/eventhandler/wlgenerator/wlgenerator.go @@ -87,6 +87,7 @@ type PipelinerunInfo struct { ResourceCommonInfo ClusterID uint `json:"clusterID,omitempty"` ClusterName string `json:"clusterName,omitempty"` + ClusterEnv string `json:"clusterEnv,omitempty"` Action string `json:"action,omitempty"` Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` @@ -329,6 +330,7 @@ func (w *WebhookLogGenerator) makeRequestBody(ctx context.Context, dep *messageD } return "" }(), + ClusterEnv: dep.cluster.EnvironmentName, Action: dep.pipelinerun.Action, Title: dep.pipelinerun.Title, Description: dep.pipelinerun.Description, From 61f455a1673508af492176cc1da0dac72d747dc1 Mon Sep 17 00:00:00 2001 From: yeka Date: Thu, 12 Sep 2024 14:01:46 +0800 Subject: [PATCH 2/5] feat: push image to aliyun (#4) Signed-off-by: yeka --- .github/workflows/image.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 5f5a1b139..b147715f0 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -40,24 +40,18 @@ jobs: flavor: | latest=false images: | - ${{ secrets.DOCKERHUB_USERNAME }}/horizon-${{ matrix.components }} -# registry.cn-hangzhou.aliyuncs.com/${{ secrets.ALIREGISTRY_NAMESPACE }}/horizon-${{ matrix.components }} + registry.cn-hangzhou.aliyuncs.com/${{ secrets.ALIREGISTRY_NAMESPACE }}/horizon-${{ matrix.components }} tags: | type=ref,event=branch type=sha,prefix={{branch}}-,enable=${{ github.ref_type == 'branch' }} type=ref,event=tag - - name: Login to Docker Hub + + - name: Login to Ali Container Registry uses: docker/login-action@v2 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - -# - name: Login to Ali Container Registry -# uses: docker/login-action@v2 -# with: -# registry: registry.cn-hangzhou.aliyuncs.com -# username: ${{ secrets.ALIREGISTRY_USERNAME }} -# password: ${{ secrets.ALIREGISTRY_TOKEN }} + registry: registry.cn-hangzhou.aliyuncs.com + username: ${{ secrets.ALIREGISTRY_USERNAME }} + password: ${{ secrets.ALIREGISTRY_TOKEN }} - name: Condition id: condition From b8e4864d480c19de914132b3554f5b2da063ef72 Mon Sep 17 00:00:00 2001 From: yeka Date: Thu, 12 Sep 2024 14:24:36 +0800 Subject: [PATCH 3/5] feat: more configs of db (#6) Signed-off-by: yeka --- core/cmd/cmd.go | 2 ++ pkg/config/db/config.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core/cmd/cmd.go b/core/cmd/cmd.go index faa7a6a8e..e5f3399fa 100644 --- a/core/cmd/cmd.go +++ b/core/cmd/cmd.go @@ -297,6 +297,8 @@ func Init(ctx context.Context, flags *Flags, coreConfig *config.Config) { Password: coreConfig.DBConfig.Password, Database: coreConfig.DBConfig.Database, PrometheusEnabled: coreConfig.DBConfig.PrometheusEnabled, + MaxIdleConns: coreConfig.DBConfig.MaxIdleConns, + MaxOpenConns: coreConfig.DBConfig.MaxOpenConns, }) if err != nil { panic(err) diff --git a/pkg/config/db/config.go b/pkg/config/db/config.go index c8ed6fb1d..fe1bdfbb9 100644 --- a/pkg/config/db/config.go +++ b/pkg/config/db/config.go @@ -21,4 +21,6 @@ type Config struct { Password string `yaml:"password,omitempty"` Database string `yaml:"database"` PrometheusEnabled bool `yaml:"prometheusEnabled"` + MaxIdleConns int `json:"maxIdleConns"` + MaxOpenConns int `json:"maxOpenConns"` } From 62ec1d41e5490fdf8463392d3c6f249ac8fb53c5 Mon Sep 17 00:00:00 2001 From: yeka Date: Thu, 12 Sep 2024 14:38:11 +0800 Subject: [PATCH 4/5] feat: more configs of db Signed-off-by: yeka --- core/cmd/cmd.go | 11 +---------- lib/orm/orm.go | 16 ++-------------- pkg/config/db/config.go | 19 +++++++++++-------- 3 files changed, 14 insertions(+), 32 deletions(-) diff --git a/core/cmd/cmd.go b/core/cmd/cmd.go index e5f3399fa..c4c2e6c9d 100644 --- a/core/cmd/cmd.go +++ b/core/cmd/cmd.go @@ -290,16 +290,7 @@ func Init(ctx context.Context, flags *Flags, coreConfig *config.Config) { log.Printf("the roleConfig = %+v\n", roleConfig) // init db - mysqlDB, err := orm.NewMySQLDB(&orm.MySQL{ - Host: coreConfig.DBConfig.Host, - Port: coreConfig.DBConfig.Port, - Username: coreConfig.DBConfig.Username, - Password: coreConfig.DBConfig.Password, - Database: coreConfig.DBConfig.Database, - PrometheusEnabled: coreConfig.DBConfig.PrometheusEnabled, - MaxIdleConns: coreConfig.DBConfig.MaxIdleConns, - MaxOpenConns: coreConfig.DBConfig.MaxOpenConns, - }) + mysqlDB, err := orm.NewMySQLDB(coreConfig.DBConfig) if err != nil { panic(err) } diff --git a/lib/orm/orm.go b/lib/orm/orm.go index 6c3b7a059..aa0413e83 100644 --- a/lib/orm/orm.go +++ b/lib/orm/orm.go @@ -17,6 +17,7 @@ package orm import ( "database/sql" "fmt" + "github.com/horizoncd/horizon/pkg/config/db" "log" "os" "strings" @@ -31,20 +32,7 @@ import ( "gorm.io/plugin/prometheus" ) -// MySQL ... -type MySQL struct { - Host string `json:"host"` - Port int `json:"port"` - Username string `json:"username"` - Password string `json:"password,omitempty"` - Database string `json:"database"` - PrometheusEnabled bool `json:"prometheusEnabled"` - SlowThreshold time.Duration `json:"slowThreshold"` - MaxIdleConns int `json:"maxIdleConns"` - MaxOpenConns int `json:"maxOpenConns"` -} - -func NewMySQLDB(db *MySQL) (*gorm.DB, error) { +func NewMySQLDB(db db.Config) (*gorm.DB, error) { conn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", db.Username, db.Password, db.Host, db.Port, db.Database) diff --git a/pkg/config/db/config.go b/pkg/config/db/config.go index fe1bdfbb9..4d4cdc736 100644 --- a/pkg/config/db/config.go +++ b/pkg/config/db/config.go @@ -14,13 +14,16 @@ package db +import "time" + type Config struct { - Host string `yaml:"host"` - Port int `yaml:"port"` - Username string `yaml:"username"` - Password string `yaml:"password,omitempty"` - Database string `yaml:"database"` - PrometheusEnabled bool `yaml:"prometheusEnabled"` - MaxIdleConns int `json:"maxIdleConns"` - MaxOpenConns int `json:"maxOpenConns"` + Host string `yaml:"host"` + Port int `yaml:"port"` + Username string `yaml:"username"` + Password string `yaml:"password,omitempty"` + Database string `yaml:"database"` + PrometheusEnabled bool `yaml:"prometheusEnabled"` + SlowThreshold time.Duration `yaml:"slowThreshold"` + MaxIdleConns int `yaml:"maxIdleConns"` + MaxOpenConns int `yaml:"maxOpenConns"` } From 6f3fc63574c1a7fb5ae67b4cef3f491ec93bbcae Mon Sep 17 00:00:00 2001 From: hzyuzhuoer Date: Sat, 14 Sep 2024 11:17:19 +0800 Subject: [PATCH 5/5] remove container env check from rollout healthy Signed-off-by: hzyuzhuoer --- pkg/workload/rollout/util.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/workload/rollout/util.go b/pkg/workload/rollout/util.go index 19290a53f..2aef3246a 100644 --- a/pkg/workload/rollout/util.go +++ b/pkg/workload/rollout/util.go @@ -60,12 +60,6 @@ func assignContainers(containers []corev1.Container) []corev1.Container { Args: container.Args, WorkingDir: container.WorkingDir, } - for _, env := range container.Env { - ctr.Env = append(ctr.Env, corev1.EnvVar{ - Name: env.Name, - Value: env.Value, - }) - } ctrs = append(ctrs, ctr) } return ctrs