Skip to content

Commit

Permalink
fix(database) the core and notary pods cannot start up
Browse files Browse the repository at this point in the history
The core and notary pods cannot start up when reinstall the Harbor
instance

fix #528

Signed-off-by: zhuhuijun <zhuhuijunzhj@gmail.com>
  • Loading branch information
Ghostbaby committed Apr 8, 2021
1 parent ec1b1e3 commit 699fb61
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/cluster/controllers/database/readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ func (p *PostgreSQLController) Readiness(ctx context.Context, harborcluster *goh
return nil, err
}

secret, err := p.DeployComponentSecret(ctx, conn, harborcluster.Namespace, getDatabasePasswordRefName(name))
if err != nil {
return nil, err
}

if err := controllerutil.SetControllerReference(harborcluster, secret, p.Scheme); err != nil {
if err := p.DeployComponentSecret(ctx, conn, getDatabasePasswordRefName(name), harborcluster); err != nil {
return nil, err
}

Expand Down Expand Up @@ -106,22 +101,27 @@ func getDatabasePasswordRefName(name string) string {
}

// DeployComponentSecret deploy harbor component database secret.
func (p *PostgreSQLController) DeployComponentSecret(ctx context.Context, conn *Connect, ns string, secretName string) (*corev1.Secret, error) {
func (p *PostgreSQLController) DeployComponentSecret(ctx context.Context, conn *Connect, secretName string, harborcluster *goharborv1.HarborCluster) error {
ns := harborcluster.Namespace
secret := &corev1.Secret{}
sc := p.GetDatabaseSecret(conn, ns, secretName)

if err := controllerutil.SetControllerReference(harborcluster, sc, p.Scheme); err != nil {
return err
}

err := p.Client.Get(ctx, types.NamespacedName{Name: secretName, Namespace: ns}, secret)
if kerr.IsNotFound(err) {
p.Log.Info("Creating Harbor Component Secret", "namespace", ns, "name", secretName)

if err := p.Client.Create(ctx, sc); err != nil {
return nil, err
return err
}
} else if err != nil {
return nil, err
return err
}

return secret, nil
return nil
}

// GetInClusterDatabaseInfo returns inCluster database connection client.
Expand Down

0 comments on commit 699fb61

Please sign in to comment.