Skip to content

Commit

Permalink
fix postgres databse has no data (#1272)
Browse files Browse the repository at this point in the history
Signed-off-by: root <[email protected]>
  • Loading branch information
ldpliu authored Dec 13, 2024
1 parent 1e9f112 commit 7f89972
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
jobLabel: prometheus-postgres-exporter
namespaceSelector:
matchNames:
- multicluster-global-hub
- {{.Namespace}}
selector:
matchLabels:
name: {{.Name}} # match to the service name
Expand Down
11 changes: 7 additions & 4 deletions operator/pkg/controllers/storage/postgres_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package storage
import (
"context"
"fmt"
"strings"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -28,7 +29,7 @@ var (
builtinPostgresCertName = fmt.Sprintf("%s-cert", BuiltinPostgresName)
builtinPostgresConfigName = fmt.Sprintf("%s-config", BuiltinPostgresName)
builtinPostgresInitName = fmt.Sprintf("%s-init", BuiltinPostgresName)
builtinPartialPostgresURI = fmt.Sprintf("@%s.%s.svc:5432/hoh?sslmode=verify-ca", BuiltinPostgresName,
builtinPartialPostgresURI = fmt.Sprintf("%s.%s.svc:5432/hoh?sslmode=verify-ca", BuiltinPostgresName,
utils.GetDefaultNamespace())
)

Expand Down Expand Up @@ -99,7 +100,9 @@ func InitPostgresByStatefulset(ctx context.Context, mgh *globalhubv1alpha4.Multi
PostgresReadonlyUsername: credential.postgresReadonlyUsername,
PostgresReadonlyUserPassword: credential.postgresReadonlyUserPassword,
StorageClass: mgh.Spec.DataLayerSpec.StorageClass,
PostgresURI: builtinPartialPostgresURI,
// Postgres exporter should disable sslmode
// https://github.com/prometheus-community/postgres_exporter?tab=readme-ov-file#environment-variables
PostgresURI: strings.ReplaceAll(builtinPartialPostgresURI, "sslmode=verify-ca", "sslmode=disable"),
Resources: operatorutils.GetResources(operatorconstants.Postgres,
mgh.Spec.AdvancedSpec),
EnableMetrics: mgh.Spec.EnableMetrics,
Expand Down Expand Up @@ -129,9 +132,9 @@ func InitPostgresByStatefulset(ctx context.Context, mgh *globalhubv1alpha4.Multi
}
return &config.PostgresConnection{
SuperuserDatabaseURI: "postgresql://" + credential.postgresAdminUsername + ":" +
credential.postgresAdminUserPassword + builtinPartialPostgresURI,
credential.postgresAdminUserPassword + "@" + builtinPartialPostgresURI,
ReadonlyUserDatabaseURI: "postgresql://" + credential.postgresReadonlyUsername + ":" +
credential.postgresReadonlyUserPassword + builtinPartialPostgresURI,
credential.postgresReadonlyUserPassword + "@" + builtinPartialPostgresURI,
CACert: []byte(ca),
}, nil
}
Expand Down

0 comments on commit 7f89972

Please sign in to comment.