Skip to content

Commit

Permalink
fix(capi): keys for kubeadm-bootstrap controller
Browse files Browse the repository at this point in the history
  • Loading branch information
prometherion committed Aug 1, 2023
1 parent d99ffb0 commit 751ce37
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/resources/ca_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package resources

import (
"bytes"
"context"
"fmt"

Expand Down Expand Up @@ -96,6 +97,13 @@ func (r *CACertificate) mutate(ctx context.Context, tenantControlPlane *kamajiv1
if err != nil {
logger.Info(fmt.Sprintf("%s certificate-private_key pair is not valid: %s", kubeadmconstants.CACertAndKeyBaseName, err.Error()))
}
// Appending the Cluster API required keys if they're missing:
// with this we're sure to avoid introducing breaking changes.
if isValid && (!bytes.Equal(r.resource.Data[corev1.TLSCertKey], r.resource.Data[kubeadmconstants.CACertName]) || !bytes.Equal(r.resource.Data[kubeadmconstants.CAKeyName], r.resource.Data[corev1.TLSPrivateKeyKey])) {
r.resource.Data[corev1.TLSCertKey] = r.resource.Data[kubeadmconstants.CACertName]
r.resource.Data[corev1.TLSPrivateKeyKey] = r.resource.Data[kubeadmconstants.CAKeyName]
}

if isValid {
return nil
}
Expand All @@ -122,6 +130,11 @@ func (r *CACertificate) mutate(ctx context.Context, tenantControlPlane *kamajiv1
r.resource.Data = map[string][]byte{
kubeadmconstants.CACertName: ca.Certificate,
kubeadmconstants.CAKeyName: ca.PrivateKey,
// Required for Cluster API integration which is reading the basic TLS keys.
// We cannot switch over basic corev1.Secret keys for backward compatibility,
// it would require a new CA generation breaking all the clusters deployed.
corev1.TLSCertKey: ca.Certificate,
corev1.TLSPrivateKeyKey: ca.PrivateKey,
}

r.resource.SetLabels(utilities.KamajiLabels(tenantControlPlane.GetName(), r.GetName()))
Expand Down

0 comments on commit 751ce37

Please sign in to comment.