MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / renewCACertificate

Function renewCACertificate

pkg/certs/k8s.go:207–239  ·  view source on GitHub ↗

renewCACertificate renews a CA certificate if needed, returning the updated secret if the secret has been renewed

(ctx context.Context, kubeClient client.Client, secret *corev1.Secret)

Source from the content-addressed store, hash-verified

205// renewCACertificate renews a CA certificate if needed, returning the updated
206// secret if the secret has been renewed
207func renewCACertificate(ctx context.Context, kubeClient client.Client, secret *corev1.Secret) (*corev1.Secret, error) {
208 // Verify the temporal validity of this CA
209 pair, err := ParseCASecret(secret)
210 if err != nil {
211 return nil, err
212 }
213
214 expiring, _, err := pair.IsExpiring()
215 if err != nil {
216 return nil, err
217 }
218 if !expiring {
219 return secret, nil
220 }
221
222 privateKey, err := pair.ParseECPrivateKey()
223 if err != nil {
224 return nil, err
225 }
226
227 err = pair.RenewCertificate(privateKey, nil, nil)
228 if err != nil {
229 return nil, err
230 }
231
232 secret.Data[CACertKey] = pair.Certificate
233 err = kubeClient.Update(ctx, secret)
234 if err != nil {
235 return nil, err
236 }
237
238 return secret, nil
239}
240
241// ensureCertificatesAreUpToDate will setup the PKI infrastructure that is needed for the operator
242// to correctly work and makes sure that the mounted certificates are the latest.

Callers 1

Calls 5

ParseCASecretFunction · 0.85
IsExpiringMethod · 0.80
ParseECPrivateKeyMethod · 0.80
RenewCertificateMethod · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected