Skip to content

Commit decc0c3

Browse files
authored
Merge pull request #12921 from ivelichkovich/privatekeyflake
🌱 add DisableCertPrivateKey function for clustercache for test flake
2 parents 1c66738 + 38268cb commit decc0c3

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

controllers/clustercache/cluster_accessor.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ type clusterAccessorConfig struct {
8282
// connection after creating a connection failed.
8383
ConnectionCreationRetryInterval time.Duration
8484

85+
// DisableClientCertificatePrivateKey is the flag to disable the creation of the client
86+
// certificate private key.
87+
DisableClientCertificatePrivateKey bool
88+
8589
// Cache is the config used for the cache that the clusterAccessor creates.
8690
Cache *clusterAccessorCacheConfig
8791

@@ -284,7 +288,7 @@ func (ca *clusterAccessor) Connect(ctx context.Context) (retErr error) {
284288
// Only generate the clientCertificatePrivateKey once as there is no need to regenerate it after disconnect/connect.
285289
// Note: This has to be done before setting connection, because otherwise this code wouldn't be re-entrant if the
286290
// private key generation fails because we check Connected above.
287-
if ca.lockedState.clientCertificatePrivateKey == nil {
291+
if ca.lockedState.clientCertificatePrivateKey == nil && !ca.config.DisableClientCertificatePrivateKey {
288292
log.V(6).Info("Generating client certificate private key")
289293
clientCertificatePrivateKey, err := certs.NewPrivateKey()
290294
if err != nil {

controllers/clustercache/cluster_cache.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,12 @@ func (cc *clusterCache) SetConnectionCreationRetryInterval(interval time.Duratio
698698
cc.clusterAccessorConfig.ConnectionCreationRetryInterval = interval
699699
}
700700

701+
// DisablePrivateKeyGeneration can be used to disable the creation of cluster cert private key on clusteraccessor.
702+
// This method should only be used for tests and is not part of the public ClusterCache interface.
703+
func (cc *clusterCache) DisablePrivateKeyGeneration() {
704+
cc.clusterAccessorConfig.DisableClientCertificatePrivateKey = true
705+
}
706+
701707
// Shutdown can be used to shut down the ClusterCache in unit tests.
702708
// This method should only be used for tests because it hasn't been designed for production usage
703709
// in a manager (race conditions with manager shutdown etc.).

internal/controllers/machine/suite_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ func TestMain(m *testing.M) {
9696
clusterCache.(interface{ SetConnectionCreationRetryInterval(time.Duration) }).
9797
SetConnectionCreationRetryInterval(2 * time.Second)
9898

99+
clusterCache.(interface{ DisablePrivateKeyGeneration() }).DisablePrivateKeyGeneration()
100+
99101
if err := (&Reconciler{
100102
Client: mgr.GetClient(),
101103
APIReader: mgr.GetAPIReader(),

0 commit comments

Comments
 (0)