Skip to content

Commit 3a1a600

Browse files
committed
feat: priority to reuse apiserver-etcd-client if present
1 parent 93adf87 commit 3a1a600

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

controlplane/kubeadm/internal/cluster.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@ func (m *Management) GetWorkloadCluster(ctx context.Context, cluster *clusterv1.
137137
if err != nil {
138138
return nil, err
139139
}
140-
141-
// If the CA key is defined, the cluster is using a managed etcd, and so we can generate a new
142-
// etcd client certificate for the controllers.
143-
// Otherwise the cluster is using an external etcd; in this case the only option to connect to etcd is to re-use
144-
// the apiserver-etcd-client certificate.
145-
// TODO: consider if we can detect if we are using external etcd in a more explicit way (e.g. looking at the config instead of deriving from the existing certificates)
146-
var clientCert tls.Certificate
147-
if keyData != nil {
140+
// If the apiserver-etcd-client certificate exists, use it.
141+
// Otherwise, try to generate a new etcd client certificate for the controllers.
142+
clientCert, err := m.getAPIServerEtcdClientCert(ctx, clusterKey)
143+
if !apierrors.IsNotFound(err) {
144+
return nil, err
145+
}
146+
if keyData == nil {
147+
return nil, fmt.Errorf("missing keyData in etcd CA bundle %s/%s and no apiserver-etcd-client certificate found", clusterKey.Namespace, fmt.Sprintf("%s-etcd", clusterKey.Name))
148+
} else {
148149
// Get client cert from cache if possible, otherwise generate it and add it to the cache.
149150
// Note: The caching assumes that the etcd CA is not rotated during the lifetime of a Cluster.
150151
if entry, ok := m.ClientCertCache.Has(ClientCertEntry{Cluster: clusterKey, ClusterUID: cluster.UID, EncryptionAlgorithm: keyEncryptionAlgorithm}.Key()); ok {
@@ -157,11 +158,6 @@ func (m *Management) GetWorkloadCluster(ctx context.Context, cluster *clusterv1.
157158
}
158159
m.ClientCertCache.Add(ClientCertEntry{Cluster: clusterKey, ClusterUID: cluster.UID, ClientCert: &clientCert, EncryptionAlgorithm: keyEncryptionAlgorithm})
159160
}
160-
} else {
161-
clientCert, err = m.getAPIServerEtcdClientCert(ctx, clusterKey)
162-
if err != nil {
163-
return nil, err
164-
}
165161
}
166162

167163
caPool := x509.NewCertPool()

0 commit comments

Comments
 (0)