Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove container env check from rollout healthy #252

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions core/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +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,
})
mysqlDB, err := orm.NewMySQLDB(coreConfig.DBConfig)
if err != nil {
panic(err)
}
Expand Down
37 changes: 24 additions & 13 deletions lib/orm/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package orm
import (
"database/sql"
"fmt"
"github.com/horizoncd/horizon/pkg/config/db"
"log"
"os"
"strings"
Expand All @@ -31,27 +32,30 @@ 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"`
}

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)

// 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)

Expand All @@ -62,6 +66,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 {
Expand Down
17 changes: 11 additions & 6 deletions pkg/config/db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +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"`
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"`
}
2 changes: 2 additions & 0 deletions pkg/eventhandler/wlgenerator/wlgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions pkg/workload/rollout/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading