@@ -51,8 +51,8 @@ const (
51
51
secondsBeforeTTLRefresh = 15
52
52
)
53
53
54
- // EC2MetadataService is used to query the EC2 instance metadata service v1 and v2
55
- type EC2MetadataService struct {
54
+ // Service is used to query the EC2 instance metadata service v1 and v2
55
+ type Service struct {
56
56
httpClient http.Client
57
57
tries int
58
58
metadataURL string
@@ -98,17 +98,17 @@ type NodeMetadata struct {
98
98
LocalIP string
99
99
}
100
100
101
- // New constructs an instance of the EC2MetadataService client
102
- func New (metadataURL string , tries int ) * EC2MetadataService {
103
- return & EC2MetadataService {
101
+ // New constructs an instance of the Service client
102
+ func New (metadataURL string , tries int ) * Service {
103
+ return & Service {
104
104
metadataURL : metadataURL ,
105
105
tries : tries ,
106
106
httpClient : http.Client {},
107
107
}
108
108
}
109
109
110
110
// GetScheduledMaintenanceEvents retrieves EC2 scheduled maintenance events from imds
111
- func (e * EC2MetadataService ) GetScheduledMaintenanceEvents () ([]ScheduledEventDetail , error ) {
111
+ func (e * Service ) GetScheduledMaintenanceEvents () ([]ScheduledEventDetail , error ) {
112
112
resp , err := e .Request (ScheduledEventPath )
113
113
if resp != nil && (resp .StatusCode < 200 || resp .StatusCode >= 300 ) {
114
114
return nil , fmt .Errorf ("Metadata request received http status code: %d" , resp .StatusCode )
@@ -125,8 +125,8 @@ func (e *EC2MetadataService) GetScheduledMaintenanceEvents() ([]ScheduledEventDe
125
125
return scheduledEvents , nil
126
126
}
127
127
128
- // GetSpotITNEvent retrieves EC2 scheduled maintenance events from imds
129
- func (e * EC2MetadataService ) GetSpotITNEvent () (instanceAction * InstanceAction , err error ) {
128
+ // GetSpotITNEvent retrieves EC2 spot interruption events from imds
129
+ func (e * Service ) GetSpotITNEvent () (instanceAction * InstanceAction , err error ) {
130
130
resp , err := e .Request (SpotInstanceActionPath )
131
131
// 404s are normal when querying for the 'latest/meta-data/spot' path
132
132
if resp != nil && resp .StatusCode == 404 {
@@ -147,7 +147,7 @@ func (e *EC2MetadataService) GetSpotITNEvent() (instanceAction *InstanceAction,
147
147
}
148
148
149
149
// GetMetadataInfo generic function for retrieving ec2 metadata
150
- func (e * EC2MetadataService ) GetMetadataInfo (path string ) (info string , err error ) {
150
+ func (e * Service ) GetMetadataInfo (path string ) (info string , err error ) {
151
151
resp , err := e .Request (path )
152
152
if resp != nil && (resp .StatusCode < 200 || resp .StatusCode >= 300 ) {
153
153
return "" , fmt .Errorf ("Metadata request received http status code: %d" , resp .StatusCode )
@@ -166,7 +166,7 @@ func (e *EC2MetadataService) GetMetadataInfo(path string) (info string, err erro
166
166
// Request sends an http request to IMDSv1 or v2 at the specified path
167
167
// It is up to the caller to handle http status codes on the response
168
168
// An error will only be returned if the request is unable to be made
169
- func (e * EC2MetadataService ) Request (contextPath string ) (* http.Response , error ) {
169
+ func (e * Service ) Request (contextPath string ) (* http.Response , error ) {
170
170
req , err := http .NewRequest (http .MethodGet , e .metadataURL + contextPath , nil )
171
171
if err != nil {
172
172
return nil , fmt .Errorf ("Unable to construct an http get request to IDMS for %s: %w" , e .metadataURL + contextPath , err )
@@ -203,7 +203,7 @@ func (e *EC2MetadataService) Request(contextPath string) (*http.Response, error)
203
203
return resp , nil
204
204
}
205
205
206
- func (e * EC2MetadataService ) getV2Token () (string , int , error ) {
206
+ func (e * Service ) getV2Token () (string , int , error ) {
207
207
req , err := http .NewRequest (http .MethodPut , e .metadataURL + tokenRefreshPath , nil )
208
208
if err != nil {
209
209
return "" , - 1 , fmt .Errorf ("Unable to construct http put request to retrieve imdsv2 token: %w" , err )
@@ -262,8 +262,8 @@ func retry(attempts int, sleep time.Duration, httpReq func() (*http.Response, er
262
262
return resp , err
263
263
}
264
264
265
- // HydrateNodeMetadata attempts to gather additional ec2 instance information from the metadata service
266
- func (e * EC2MetadataService ) GetNodeMetadata () NodeMetadata {
265
+ // GetNodeMetadata attempts to gather additional ec2 instance information from the metadata service
266
+ func (e * Service ) GetNodeMetadata () NodeMetadata {
267
267
var metadata NodeMetadata
268
268
metadata .InstanceID , _ = e .GetMetadataInfo (InstanceIDPath )
269
269
metadata .InstanceType , _ = e .GetMetadataInfo (InstanceTypePath )
0 commit comments