Skip to content

Commit 6fb8680

Browse files
committed
Remove logging and change TTL to 1 hour
1 parent d150428 commit 6fb8680

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

pkg/cloud/client.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"time"
2626

2727
corev1 "k8s.io/api/core/v1"
28-
ctrl "sigs.k8s.io/controller-runtime"
2928

3029
"gopkg.in/yaml.v3"
3130
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/metrics"
@@ -73,9 +72,8 @@ type SecretConfig struct {
7372

7473
var clientCache *ttlcache.Cache
7574
var cacheMutex sync.Mutex
76-
var log = ctrl.Log.WithName("Client")
7775

78-
const cacheExpiration = time.Duration(1 * time.Minute)
76+
const cacheExpiration = time.Duration(1 * time.Hour)
7977

8078
// UnmarshalAllSecretConfigs parses a yaml document for each secret.
8179
func UnmarshalAllSecretConfigs(in []byte, out *[]SecretConfig) error {
@@ -95,6 +93,7 @@ func UnmarshalAllSecretConfigs(in []byte, out *[]SecretConfig) error {
9593
return nil
9694
}
9795

96+
// NewClientFromK8sSecret returns a client from a k8s secret
9897
func NewClientFromK8sSecret(endpointSecret *corev1.Secret) (Client, error) {
9998
endpointSecretStrings := map[string]string{}
10099
for k, v := range endpointSecret.Data {
@@ -143,7 +142,7 @@ func NewClientFromYamlPath(confPath string, secretName string) (Client, error) {
143142
return NewClientFromConf(conf)
144143
}
145144

146-
// Creates a new Cloud Client form a map of strings to strings.
145+
// NewClientFromConf creates a new Cloud Client form a map of strings to strings.
147146
func NewClientFromConf(conf Config) (Client, error) {
148147
cacheMutex.Lock()
149148
defer cacheMutex.Unlock()
@@ -152,12 +151,10 @@ func NewClientFromConf(conf Config) (Client, error) {
152151
clientCache = ttlcache.NewCache()
153152
clientCache.SetTTL(cacheExpiration)
154153
clientCache.SkipTtlExtensionOnHit(false)
155-
log.V(1).Info("NewClientFromConf: New client cache created", "expiration", cacheExpiration.String())
156154
}
157155

158156
clientCacheKey := generateClientCacheKey(conf)
159157
if client, exists := clientCache.Get(clientCacheKey); exists {
160-
log.V(1).Info("NewClientFromConf: Using a cached client", "APIUrl", conf.APIUrl, "APIKey", conf.APIKey, "cache size", clientCache.Count())
161158
return client.(Client), nil
162159
}
163160

@@ -174,7 +171,6 @@ func NewClientFromConf(conf Config) (Client, error) {
174171
c.csAsync = cloudstack.NewClient(conf.APIUrl, conf.APIKey, conf.SecretKey, verifySSL)
175172
c.customMetrics = metrics.NewCustomMetrics()
176173
clientCache.Set(clientCacheKey, c)
177-
log.V(1).Info("NewClientFromConf: Created a new client and added to the client cache", "APIUrl", conf.APIUrl, "APIKey", conf.APIKey, "cache size", clientCache.Count())
178174

179175
return c, nil
180176
}
@@ -196,7 +192,7 @@ func (c *client) NewClientInDomainAndAccount(domain string, account string) (Cli
196192
return NewClientFromConf(c.config)
197193
}
198194

199-
// Create a client from a CloudStack-Go API client. Mostly used for testing.
195+
// NewClientFromCSAPIClient creates a client from a CloudStack-Go API client. Mostly used for testing.
200196
func NewClientFromCSAPIClient(cs *cloudstack.CloudStackClient) Client {
201197
c := &client{cs: cs, csAsync: cs, customMetrics: metrics.NewCustomMetrics()}
202198
return c

0 commit comments

Comments
 (0)