-
Notifications
You must be signed in to change notification settings - Fork 76
K8SPG-1017 leaf cert function needs to check whether the existing secret is already managed by internal PKI before switching to cert-manager #1578
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
Changes from 2 commits
efb0845
c0c13d2
9909d88
eba0700
2f23135
a211bbc
29e346e
2cdeb53
0c84baa
1954966
b89d4fa
792a747
a6c2fa4
9b59493
4d11f75
e9875aa
37fd1ec
90534f7
9e506d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -231,12 +231,12 @@ func (r *Reconciler) reconcileClusterCertificate( | |
| return cluster.Spec.CustomTLSSecret, nil | ||
| } | ||
|
|
||
| certManagerInstalled, err := r.isCertManagerInstalled(ctx, cluster.Namespace) | ||
| certManagerManaged, err := r.isRootCACertManagerManaged(ctx, cluster) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to check if cert-manager is installed") | ||
| return nil, errors.Wrap(err, "failed to check if cert-manager manages root CA") | ||
| } | ||
|
|
||
| if certManagerInstalled { | ||
| if certManagerManaged { | ||
| return r.reconcileCertManagerClusterCertificate(ctx, root, cluster, primaryService, replicaService) | ||
| } | ||
|
|
||
|
|
@@ -361,6 +361,24 @@ func (r *Reconciler) reconcileCertManagerClusterCertificate( | |
| }), nil | ||
| } | ||
|
|
||
| func (r *Reconciler) isRootCACertManagerManaged(ctx context.Context, cluster *v1beta1.PostgresCluster) (bool, error) { | ||
| installed, err := r.isCertManagerInstalled(ctx, cluster.Namespace) | ||
| if err != nil || !installed { | ||
| return false, err | ||
| } | ||
|
|
||
| rootSecret := &corev1.Secret{ObjectMeta: naming.PostgresRootCASecret(cluster)} | ||
| err = r.Client.Get(ctx, client.ObjectKeyFromObject(rootSecret), rootSecret) | ||
| if err != nil { | ||
| if k8serrors.IsNotFound(err) { | ||
| return true, nil | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we really return true here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no pre-existing internally-managed secret to conflict with. Since cert-manager is available and no secret has been created yet, it's safe to let cert-manager create and manage the root CA from scratch. That's the idea.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also check
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| return false, errors.WithStack(err) | ||
| } | ||
|
|
||
| return rootSecret.Annotations["cert-manager.io/certificate-name"] != "", nil | ||
| } | ||
|
|
||
| func (r *Reconciler) isCertManagerInstalled(ctx context.Context, ns string) (bool, error) { | ||
| if r.RestConfig == nil { | ||
| return false, nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fixed