Skip to content

Commit

Permalink
fix(database) failed to initialize database core
Browse files Browse the repository at this point in the history
fix failed to initialize database core

Signed-off-by: zhuhuijun <zhuhuijunzhj@gmail.com>
  • Loading branch information
Ghostbaby committed Dec 12, 2020
1 parent 33e8b7e commit 32049bc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ docker-build: dist/harbor-operator_linux_amd64/manager
docker-push:
docker push "$(IMG)"

.PHONY: dist/harbor-operator_linux_amd64/manager
dist/harbor-operator_linux_amd64/manager:
mkdir -p dist/harbor-operator_linux_amd64
CGO_ENABLED=0 \
Expand Down
2 changes: 1 addition & 1 deletion apis/goharbor.io/v1alpha2/harbor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (r *HarborStorageImageChartStorageSpec) Validate() error {

type HarborStorageImageChartStorageFileSystemSpec struct {
// +kubebuilder:validation:Optional
ChartPersistentVolume *HarborStoragePersistentVolumeSpec `json:"chartPersistentVolume"`
ChartPersistentVolume *HarborStoragePersistentVolumeSpec `json:"chartPersistentVolume,omitempty"`

// +kubebuilder:validation:Required
RegistryPersistentVolume HarborStorageRegistryPersistentVolumeSpec `json:"registryPersistentVolume"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ spec:
storage: 1Gi
replicas: 2
version: "12"
storageClassName: default
resources:
limits:
cpu: 500m
Expand All @@ -58,7 +57,6 @@ spec:
version: RELEASE.2020-08-13T02-39-50Z
volumeClaimTemplate:
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
Expand Down
3 changes: 1 addition & 2 deletions pkg/cluster/controllers/database/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ func GetInitDB() map[string]string {

func GetUsers() map[string]api.UserFlags {
return map[string]api.UserFlags{
"zalando": {
DefaultDatabaseUser: {
"superuser",
"createdb",
},
"foo_user": {},
}
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/cluster/controllers/database/readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
ClairDatabase = "clair"
NotaryServerDatabase = "notaryserver"
NotarySignerDatabase = "notarysigner"
DefaultDatabaseName = "postgres"
DefaultDatabaseUser = "harbor"

CoreSecretName = "core"
ClairSecretName = "clair"
Expand Down Expand Up @@ -94,7 +94,7 @@ func addProperties(name string, conn *Connect, properties *lcm.Properties) {
func getHarborDatabaseSpec(name string, conn *Connect) *goharborv1alpha2.HarborDatabaseSpec {
return &goharborv1alpha2.HarborDatabaseSpec{
PostgresCredentials: harbormetav1.PostgresCredentials{
Username: DefaultDatabaseName,
Username: DefaultDatabaseUser,
PasswordRef: getDatabasePasswordRefName(name),
},
Hosts: []harbormetav1.PostgresHostSpec{
Expand Down Expand Up @@ -174,15 +174,15 @@ func (p *PostgreSQLController) GetInClusterDatabaseConn(name, pw string) (*Conne
Host: host,
Port: InClusterDatabasePort,
Password: pw,
Username: InClusterDatabaseUserName,
Database: InClusterDatabaseName,
Username: DefaultDatabaseUser,
Database: CoreDatabase,
}

return conn, nil
}

func GenInClusterPasswordSecretName(crName string) string {
return fmt.Sprintf("postgres.%s.credentials", crName)
func GenInClusterPasswordSecretName(user, crName string) string {
return fmt.Sprintf("%s.%s.credentials", user, crName)
}

// GetInClusterHost returns the Database master pod ip or service name.
Expand All @@ -209,7 +209,7 @@ func (p *PostgreSQLController) GetInClusterHost(name string) (string, error) {
func (p *PostgreSQLController) GetInClusterDatabasePassword() (string, error) {
var pw string

secretName := GenInClusterPasswordSecretName(p.resourceName())
secretName := GenInClusterPasswordSecretName(DefaultDatabaseUser, p.resourceName())

secret, err := p.GetSecret(secretName)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/cluster/controllers/database/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const (

func (p *PostgreSQLController) GetDatabases() map[string]string {
databases := map[string]string{
CoreDatabase: DefaultDatabaseName,
CoreDatabase: DefaultDatabaseUser,
}

if p.HarborCluster.Spec.Notary != nil {
databases[NotaryServerDatabase] = DefaultDatabaseName
databases[NotarySignerDatabase] = DefaultDatabaseName
databases[NotaryServerDatabase] = DefaultDatabaseUser
databases[NotarySignerDatabase] = DefaultDatabaseUser
}

return databases
Expand Down

0 comments on commit 32049bc

Please sign in to comment.