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

Zhangl/cp4072 #4127

Merged
merged 2 commits into from
Aug 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion agent-install/agent-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ function get_kubernetes_version() {
major_version=$($KUBECTL version -o json | jq '.serverVersion.major' | sed s/\"//g)
minor_version=$($KUBECTL version -o json | jq '.serverVersion.minor' | sed s/\"//g)
if [ "${minor_version:0-1}" == "+" ]; then
minor_version=${minor_version::-1}
minor_version=${minor_version::$((${#minor_version} - 1))}
fi

full_version="$major_version.$minor_version"
Expand Down
14 changes: 8 additions & 6 deletions agreementbot/persistence/postgresql/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ func (db *AgbotPostgresqlDB) Initialize(cfg *config.HorizonConfig) error {
for si := 0; si < len(migrationSQL[v].sql); si++ {
if _, err := db.db.Exec(migrationSQL[v].sql[si]); err != nil {
return errors.New(fmt.Sprintf("unable to run SQL migration statement version %v, index %v, statement %v, error: %v", v, si, migrationSQL[v].sql[si], err))
} else if _, err := db.db.Exec(VERSION_UPDATE, HIGHEST_DATABASE_VERSION, migrationSQL[v].description); err != nil {
return errors.New(fmt.Sprintf("unable to create version table, error: %v", err))
} else {
glog.V(3).Infof("Postgresql database tables upgraded to version %v, %v", v, migrationSQL[v].description)
}
}
}
glog.V(3).Infof("Postgresql database tables upgraded for version %v, %v", v, migrationSQL[v].description)

glog.V(3).Infof("Postgresql database tables upgraded to version %v", HIGHEST_DATABASE_VERSION)
if _, err := db.db.Exec(VERSION_UPDATE, v, migrationSQL[v].description); err != nil {
return errors.New(fmt.Sprintf("unable to create version table, error: %v", err))
} else {
glog.V(3).Infof("Postgresql database tables upgraded to version %v, %v", v, migrationSQL[v].description)
}
}
glog.V(3).Infof("Finished upgrading postgresql database tables. The version is now %v", HIGHEST_DATABASE_VERSION)
}

glog.V(3).Infof("Postgresql database tables initialized.")
Expand Down
7 changes: 5 additions & 2 deletions agreementbot/persistence/postgresql/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ END $$`

const VERSION_UPDATE = `UPDATE version SET ver = $1, description = $2, updated = current_timestamp WHERE id = 1;`

const HIGHEST_DATABASE_VERSION = v1
const HIGHEST_DATABASE_VERSION = v2
const v2 = 1
const v1 = 0

type SchemaUpdate struct {
sql []string // The SQL statements to run for an update to the schema.
description string // A description of the schema change.
}

var migrationSQL = map[int]SchemaUpdate{}
var v2SchemaUpdate = SchemaUpdate{sql: []string{"ALTER TABLE secrets_policy ADD COLUMN IF NOT EXISTS \"secret_exists\" BOOLEAN NOT NULL DEFAULT true;", "ALTER TABLE secrets_pattern ADD COLUMN IF NOT EXISTS \"secret_exists\" BOOLEAN NOT NULL DEFAULT true;"}, description: "Add a column to the secrets table to indicate if the secret exists or not. This is necessary to support node-specific secrets."}

var migrationSQL = map[int]SchemaUpdate{v2: v2SchemaUpdate}
38 changes: 19 additions & 19 deletions cli/cliutils/cliutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,29 +1098,29 @@ func GetIcpCertPath() string {

// TrustIcpCert adds the icp cert file to be trusted in calls made by the given http client
func TrustIcpCert(httpClient *http.Client) error {
icpCertPath := GetIcpCertPath()
icpCertPath := GetIcpCertPath()

var caCertPool *x509.CertPool
var err error
var caCertPool *x509.CertPool
var err error

// Trust the system certs like the anax agent code can
caCertPool, err = x509.SystemCertPool()
if err != nil {
// Trust the system certs like the anax agent code can
caCertPool, err = x509.SystemCertPool()
if err != nil {
// Decided not to fail and return here but just create a new pool
caCertPool = x509.NewCertPool()
}

if icpCertPath != "" {
icpCert, err := ioutil.ReadFile(icpCertPath)
if err != nil {
return fmt.Errorf(i18n.GetMessagePrinter().Sprintf("Encountered error reading ICP cert file %v: %v", icpCertPath, err))
}
caCertPool.AppendCertsFromPEM(icpCert)
}

transport := httpClient.Transport.(*http.Transport)
transport.TLSClientConfig.RootCAs = caCertPool
return nil
}

if icpCertPath != "" {
icpCert, err := ioutil.ReadFile(icpCertPath)
if err != nil {
return fmt.Errorf(i18n.GetMessagePrinter().Sprintf("Encountered error reading ICP cert file %v: %v", icpCertPath, err))
}
caCertPool.AppendCertsFromPEM(icpCert)
}

transport := httpClient.Transport.(*http.Transport)
transport.TLSClientConfig.RootCAs = caCertPool
return nil
}

// Get exchange url from /etc/default/horizon file. if not set, check /etc/horizon/anax.json file
Expand Down
Loading