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)
| 205 | // renewCACertificate renews a CA certificate if needed, returning the updated |
| 206 | // secret if the secret has been renewed |
| 207 | func 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. |
no test coverage detected