Skip to content

Commit

Permalink
Merge branch 'main' into update-permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
vishal-chdhry authored Feb 1, 2024
2 parents 95ad387 + 61f0a02 commit c7cdcc1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Install Cosign
uses: sigstore/cosign-installer@9614fae9e5c5eddabb09f90a270fcb487c9f7149 # v3.3.0
- name: Install Syft
uses: anchore/sbom-action/download-syft@24b0d5238516480139aa8bc6f92eeb7b54a9eb0a # v0.15.5
uses: anchore/sbom-action/download-syft@767b08fd8822486ad890abb8f1d31721bebd651c # v0.15.7
- name: Install Ko
uses: ko-build/setup-ko@ace48d793556083a76f1e3e6068850c1f4a369aa # v0.6
- name: Run GoReleaser
Expand Down
20 changes: 19 additions & 1 deletion pkg/storage/db/new.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package db

import (
"context"
"database/sql"
"fmt"
"time"

"github.com/kyverno/reports-server/pkg/storage/api"
_ "github.com/lib/pq"
"k8s.io/klog/v2"
)

const (
maxRetries = 10
backoffDuration = 15 * time.Second
)

func New(config *PostgresConfig) (api.Storage, error) {
klog.Infof("starting postgres db, config: %s", config.String())
db, err := sql.Open("postgres", config.String())
Expand All @@ -17,7 +24,18 @@ func New(config *PostgresConfig) (api.Storage, error) {
return nil, err
}

klog.Info("pinging postgres db")
sleepDuration := 0 * time.Second
for attempt := 1; attempt <= maxRetries; attempt++ {
time.Sleep(sleepDuration)
klog.Infof("pinging postgres db, attempt: %d", attempt)
err := db.PingContext(context.TODO())
if err == nil {
break
}
klog.Error("failed to ping db", err.Error())
sleepDuration = sleepDuration + backoffDuration
}

err = db.Ping()
if err != nil {
klog.Error("failed to ping db", err.Error())
Expand Down

0 comments on commit c7cdcc1

Please sign in to comment.