@@ -34,8 +34,8 @@ const (
34
34
DefaultMetadataErrorWaitSeconds = 1
35
35
)
36
36
37
- // GceMetadataWatcherConfig is the configuration for a GCE metadata watcher
38
- type GceMetadataWatcherConfig struct {
37
+ // Config is the configuration for a GCE metadata watcher
38
+ type Config struct {
39
39
// Source is the metadata source to watch
40
40
// Valid values are 'instance' and 'project'
41
41
// Default is 'instance'
@@ -63,13 +63,13 @@ type GceMetadataWatcherConfig struct {
63
63
64
64
// ParseConfig parses the config for the watcher
65
65
// It validates the config, sets defaults if missing, and returns the config
66
- func ParseConfig (config interface {}) (* GceMetadataWatcherConfig , error ) {
66
+ func ParseConfig (config interface {}) (* Config , error ) {
67
67
cfgMap , ok := config .(map [string ]interface {})
68
68
if ! ok {
69
69
return nil , fmt .Errorf ("invalid config" )
70
70
}
71
71
72
- cfg := & GceMetadataWatcherConfig {
72
+ cfg := & Config {
73
73
Source : DefaultSource ,
74
74
Recursive : DefaultRecursive ,
75
75
MetadataUrl : DefaultMetadataUrl ,
@@ -134,18 +134,7 @@ func ParseConfig(config interface{}) (*GceMetadataWatcherConfig, error) {
134
134
}
135
135
136
136
type GceMetadataWatcher struct {
137
- // Key is the key to watch in the GCE metadata
138
- Key string
139
-
140
- // Recursive is whether to recurse the metadata keys
141
- Recursive bool
142
-
143
- // MetadataUrl is the URL this watcher will use when reading from the GCE
144
- // metadata server
145
- MetadataUrl string
146
-
147
- // MetadataErrorWait is the time to wait before trying failed metadata request
148
- MetadataErrorWait time.Duration
137
+ Config
149
138
150
139
// lastETag is the last etag, used to compare changes
151
140
lastETag string
@@ -170,13 +159,15 @@ func New(cfg config.Config, log *slog.Logger) (*GceMetadataWatcher, error) {
170
159
ctx , cancel := context .WithCancel (context .Background ())
171
160
172
161
return & GceMetadataWatcher {
173
- Key : pcfg .Key ,
174
- Recursive : pcfg .Recursive ,
175
- MetadataUrl : pcfg .MetadataUrl ,
176
- MetadataErrorWait : time .Duration (pcfg .MetadataErrorWaitSeconds ) * time .Second ,
177
- log : log ,
178
- ctx : ctx ,
179
- cancel : cancel ,
162
+ Config : Config {
163
+ Key : pcfg .Key ,
164
+ Recursive : pcfg .Recursive ,
165
+ MetadataUrl : pcfg .MetadataUrl ,
166
+ MetadataErrorWaitSeconds : pcfg .MetadataErrorWaitSeconds ,
167
+ },
168
+ log : log ,
169
+ ctx : ctx ,
170
+ cancel : cancel ,
180
171
}, nil
181
172
}
182
173
@@ -256,7 +247,7 @@ func (w *GceMetadataWatcher) Watch(change chan interface{}) {
256
247
// bit before trying again to prevent hammering the metadata server.
257
248
// Since we're in a for loop here the retrys will come VERY fast without
258
249
// this sleep.
259
- time .Sleep (w . MetadataErrorWait )
250
+ time .Sleep (time . Duration ( w . MetadataErrorWaitSeconds ) * time . Second )
260
251
continue
261
252
}
262
253
0 commit comments