@@ -25,7 +25,6 @@ import (
25
25
"time"
26
26
27
27
corev1 "k8s.io/api/core/v1"
28
- ctrl "sigs.k8s.io/controller-runtime"
29
28
30
29
"gopkg.in/yaml.v3"
31
30
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/metrics"
@@ -73,9 +72,8 @@ type SecretConfig struct {
73
72
74
73
var clientCache * ttlcache.Cache
75
74
var cacheMutex sync.Mutex
76
- var log = ctrl .Log .WithName ("Client" )
77
75
78
- const cacheExpiration = time .Duration (1 * time .Minute )
76
+ const cacheExpiration = time .Duration (1 * time .Hour )
79
77
80
78
// UnmarshalAllSecretConfigs parses a yaml document for each secret.
81
79
func UnmarshalAllSecretConfigs (in []byte , out * []SecretConfig ) error {
@@ -95,6 +93,7 @@ func UnmarshalAllSecretConfigs(in []byte, out *[]SecretConfig) error {
95
93
return nil
96
94
}
97
95
96
+ // NewClientFromK8sSecret returns a client from a k8s secret
98
97
func NewClientFromK8sSecret (endpointSecret * corev1.Secret ) (Client , error ) {
99
98
endpointSecretStrings := map [string ]string {}
100
99
for k , v := range endpointSecret .Data {
@@ -143,7 +142,7 @@ func NewClientFromYamlPath(confPath string, secretName string) (Client, error) {
143
142
return NewClientFromConf (conf )
144
143
}
145
144
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.
147
146
func NewClientFromConf (conf Config ) (Client , error ) {
148
147
cacheMutex .Lock ()
149
148
defer cacheMutex .Unlock ()
@@ -152,12 +151,10 @@ func NewClientFromConf(conf Config) (Client, error) {
152
151
clientCache = ttlcache .NewCache ()
153
152
clientCache .SetTTL (cacheExpiration )
154
153
clientCache .SkipTtlExtensionOnHit (false )
155
- log .V (1 ).Info ("NewClientFromConf: New client cache created" , "expiration" , cacheExpiration .String ())
156
154
}
157
155
158
156
clientCacheKey := generateClientCacheKey (conf )
159
157
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 ())
161
158
return client .(Client ), nil
162
159
}
163
160
@@ -174,7 +171,6 @@ func NewClientFromConf(conf Config) (Client, error) {
174
171
c .csAsync = cloudstack .NewClient (conf .APIUrl , conf .APIKey , conf .SecretKey , verifySSL )
175
172
c .customMetrics = metrics .NewCustomMetrics ()
176
173
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 ())
178
174
179
175
return c , nil
180
176
}
@@ -196,7 +192,7 @@ func (c *client) NewClientInDomainAndAccount(domain string, account string) (Cli
196
192
return NewClientFromConf (c .config )
197
193
}
198
194
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.
200
196
func NewClientFromCSAPIClient (cs * cloudstack.CloudStackClient ) Client {
201
197
c := & client {cs : cs , csAsync : cs , customMetrics : metrics .NewCustomMetrics ()}
202
198
return c
0 commit comments