Skip to content

Commit 04af7a8

Browse files
authored
Small var and comment name fixes (#111)
1 parent fb80f1b commit 04af7a8

File tree

8 files changed

+24
-23
lines changed

8 files changed

+24
-23
lines changed

cmd/node-termination-handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434
spotITN = "Spot ITN"
3535
)
3636

37-
type monitorFunc func(chan<- drainevent.DrainEvent, chan<- drainevent.DrainEvent, *ec2metadata.EC2MetadataService) error
37+
type monitorFunc func(chan<- drainevent.DrainEvent, chan<- drainevent.DrainEvent, *ec2metadata.Service) error
3838

3939
func main() {
4040
signalChan := make(chan os.Signal, 1)
@@ -63,7 +63,7 @@ func main() {
6363
if nthConfig.EnableScheduledEventDraining {
6464
err = handleRebootUncordon(drainEventStore, *node)
6565
if err != nil {
66-
log.Printf("Unable to complete the uncordon after reboot workflow on startup: %v", err)
66+
log.Printf("Unable to complete the uncordon after reboot workflow on startup: %v\n", err)
6767
}
6868
}
6969

pkg/drainevent/scheduled-event.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const (
3636
)
3737

3838
// MonitorForScheduledEvents continuously monitors metadata for scheduled events and sends drain events to the passed in channel
39-
func MonitorForScheduledEvents(drainChan chan<- DrainEvent, cancelChan chan<- DrainEvent, imds *ec2metadata.EC2MetadataService) error {
39+
func MonitorForScheduledEvents(drainChan chan<- DrainEvent, cancelChan chan<- DrainEvent, imds *ec2metadata.Service) error {
4040
drainEvents, err := checkForScheduledEvents(imds)
4141
if err != nil {
4242
return err
@@ -54,7 +54,7 @@ func MonitorForScheduledEvents(drainChan chan<- DrainEvent, cancelChan chan<- Dr
5454
}
5555

5656
// checkForScheduledEvents Checks EC2 instance metadata for a scheduled event requiring a node drain
57-
func checkForScheduledEvents(imds *ec2metadata.EC2MetadataService) ([]DrainEvent, error) {
57+
func checkForScheduledEvents(imds *ec2metadata.Service) ([]DrainEvent, error) {
5858
scheduledEvents, err := imds.GetScheduledMaintenanceEvents()
5959
if err != nil {
6060
return nil, fmt.Errorf("Unable to parse metadata response: %w", err)

pkg/drainevent/spot-itn-event.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const (
2828
)
2929

3030
// MonitorForSpotITNEvents continuously monitors metadata for spot ITNs and sends drain events to the passed in channel
31-
func MonitorForSpotITNEvents(drainChan chan<- DrainEvent, cancelChan chan<- DrainEvent, imds *ec2metadata.EC2MetadataService) error {
31+
func MonitorForSpotITNEvents(drainChan chan<- DrainEvent, cancelChan chan<- DrainEvent, imds *ec2metadata.Service) error {
3232
drainEvent, err := checkForSpotInterruptionNotice(imds)
3333
if err != nil {
3434
return err
@@ -41,7 +41,7 @@ func MonitorForSpotITNEvents(drainChan chan<- DrainEvent, cancelChan chan<- Drai
4141
}
4242

4343
// checkForSpotInterruptionNotice Checks EC2 instance metadata for a spot interruption termination notice
44-
func checkForSpotInterruptionNotice(imds *ec2metadata.EC2MetadataService) (*DrainEvent, error) {
44+
func checkForSpotInterruptionNotice(imds *ec2metadata.Service) (*DrainEvent, error) {
4545
instanceAction, err := imds.GetSpotITNEvent()
4646
if instanceAction == nil && err == nil {
4747
// if there are no spot itns and no errors

pkg/draineventstore/drain-event-store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/aws/aws-node-termination-handler/pkg/drainevent"
2222
)
2323

24-
// Store is a the drain event store data structure
24+
// Store is the drain event store data structure
2525
type Store struct {
2626
sync.RWMutex
2727
NthConfig config.Config

pkg/ec2metadata/ec2metadata.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const (
5151
secondsBeforeTTLRefresh = 15
5252
)
5353

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 {
5656
httpClient http.Client
5757
tries int
5858
metadataURL string
@@ -98,17 +98,17 @@ type NodeMetadata struct {
9898
LocalIP string
9999
}
100100

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{
104104
metadataURL: metadataURL,
105105
tries: tries,
106106
httpClient: http.Client{},
107107
}
108108
}
109109

110110
// GetScheduledMaintenanceEvents retrieves EC2 scheduled maintenance events from imds
111-
func (e *EC2MetadataService) GetScheduledMaintenanceEvents() ([]ScheduledEventDetail, error) {
111+
func (e *Service) GetScheduledMaintenanceEvents() ([]ScheduledEventDetail, error) {
112112
resp, err := e.Request(ScheduledEventPath)
113113
if resp != nil && (resp.StatusCode < 200 || resp.StatusCode >= 300) {
114114
return nil, fmt.Errorf("Metadata request received http status code: %d", resp.StatusCode)
@@ -125,8 +125,8 @@ func (e *EC2MetadataService) GetScheduledMaintenanceEvents() ([]ScheduledEventDe
125125
return scheduledEvents, nil
126126
}
127127

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) {
130130
resp, err := e.Request(SpotInstanceActionPath)
131131
// 404s are normal when querying for the 'latest/meta-data/spot' path
132132
if resp != nil && resp.StatusCode == 404 {
@@ -147,7 +147,7 @@ func (e *EC2MetadataService) GetSpotITNEvent() (instanceAction *InstanceAction,
147147
}
148148

149149
// 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) {
151151
resp, err := e.Request(path)
152152
if resp != nil && (resp.StatusCode < 200 || resp.StatusCode >= 300) {
153153
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
166166
// Request sends an http request to IMDSv1 or v2 at the specified path
167167
// It is up to the caller to handle http status codes on the response
168168
// 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) {
170170
req, err := http.NewRequest(http.MethodGet, e.metadataURL+contextPath, nil)
171171
if err != nil {
172172
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)
203203
return resp, nil
204204
}
205205

206-
func (e *EC2MetadataService) getV2Token() (string, int, error) {
206+
func (e *Service) getV2Token() (string, int, error) {
207207
req, err := http.NewRequest(http.MethodPut, e.metadataURL+tokenRefreshPath, nil)
208208
if err != nil {
209209
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
262262
return resp, err
263263
}
264264

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 {
267267
var metadata NodeMetadata
268268
metadata.InstanceID, _ = e.GetMetadataInfo(InstanceIDPath)
269269
metadata.InstanceType, _ = e.GetMetadataInfo(InstanceTypePath)

pkg/ec2metadata/ec2metadata_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func TestGetScheduledMaintenanceEventsSuccess(t *testing.T) {
269269
defer server.Close()
270270

271271
expectedStructs := []ec2metadata.ScheduledEventDetail{
272-
ec2metadata.ScheduledEventDetail{
272+
{
273273
NotBefore: notBefore,
274274
Code: code,
275275
Description: description,
@@ -398,7 +398,7 @@ func TestGetMetadataServiceSuccess(t *testing.T) {
398398
h.Equals(t, `x1.32xlarge`, resp)
399399
}
400400

401-
func TestHydrateNodeMetadata(t *testing.T) {
401+
func TestGetNodeMetadata(t *testing.T) {
402402
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
403403
rw.Header().Add("X-aws-ec2-metadata-token-ttl-seconds", "100")
404404
if req.URL.String() == "/latest/api/token" {

pkg/node/node.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func New(nthConfig config.Config) (*Node, error) {
6363
}, nil
6464
}
6565

66+
// NewWithValues will construct a node struct with a drain helper
6667
func NewWithValues(nthConfig config.Config, drainHelper *drain.Helper) (*Node, error) {
6768
return &Node{
6869
nthConfig: nthConfig,

pkg/webhook/webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestPostSuccess(t *testing.T) {
8484
}
8585
h.Equals(t, req.Header.Get("Content-type"), headerMap["Content-type"])
8686

87-
// Test requst body
87+
// Test request body
8888
requestBody, err := ioutil.ReadAll(req.Body)
8989
if err != nil {
9090
t.Error("Unable to read request body.")

0 commit comments

Comments
 (0)