Skip to content

Commit 16300b0

Browse files
hyeong01Heeyoung Jung
andauthored
Upgrade Go version 1.23 to 1.25 (#1234)
Co-authored-by: Heeyoung Jung <jhyeong@amazon.com>
1 parent e24a1e5 commit 16300b0

33 files changed

Lines changed: 169 additions & 163 deletions

.github/workflows/build-and-test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
- cron: '0 19 * * 1-5'
1414

1515
env:
16-
DEFAULT_GO_VERSION: ^1.22.0
16+
DEFAULT_GO_VERSION: ^1.25.0
1717
GITHUB_USERNAME: ${{ secrets.EC2_BOT_GITHUB_USERNAME }}
1818
GITHUB_TOKEN: ${{ secrets.EC2_BOT_GITHUB_TOKEN }}
1919
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
@@ -71,7 +71,7 @@ jobs:
7171
cache: false
7272

7373
- name: Set up golangci-lint
74-
uses: golangci/golangci-lint-action@v3
74+
uses: golangci/golangci-lint-action@v7
7575
with:
7676
version: latest
7777
args: --timeout=5m

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permissions:
1010
id-token: write
1111

1212
env:
13-
DEFAULT_GO_VERSION: ^1.22.0
13+
DEFAULT_GO_VERSION: ^1.25.0
1414
GITHUB_USERNAME: ${{ secrets.EC2_BOT_GITHUB_USERNAME }}
1515
GITHUB_TOKEN: ${{ secrets.EC2_BOT_GITHUB_TOKEN }}
1616
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=$BUILDPLATFORM golang:1.22 as builder
1+
FROM --platform=$BUILDPLATFORM golang:1.25 as builder
22

33
## GOLANG env
44
ARG GOPROXY="https://proxy.golang.org|direct"

Dockerfile.windows

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ARG WINDOWS_VERSION=1809
22

33
# Build the manager binary
4-
FROM --platform=windows/amd64 golang:1.22 as builder
4+
FROM --platform=windows/amd64 golang:1.25 as builder
55

66
## GOLANG env
77
ENV GO111MODULE="on" CGO_ENABLED="0" GOOS="windows" GOARCH="amd64"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<a href="https://github.com/kubernetes/kubernetes/releases">
77
<img src="https://img.shields.io/badge/Kubernetes-%3E%3D%201.23-brightgreen" alt="kubernetes">
88
</a>
9-
<a href="https://golang.org/doc/go1.22">
9+
<a href="https://golang.org/doc/go1.25">
1010
<img src="https://img.shields.io/github/go-mod/go-version/aws/aws-node-termination-handler?color=blueviolet" alt="go-version">
1111
</a>
1212
<a href="https://opensource.org/licenses/Apache-2.0">

cmd/node-termination-handler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,12 @@ func main() {
279279
asgLaunchHandler := launch.New(interruptionEventStore, *node, nthConfig, metrics, recorder, clientset)
280280
drainCordonHander := draincordon.New(interruptionEventStore, *node, nthConfig, nodeMetadata, metrics, recorder)
281281

282+
InterruptionLoop:
282283
for range time.NewTicker(1 * time.Second).C {
283284
select {
284285
case <-signalChan:
285286
// Exit interruption loop if a SIGTERM is received or the channel is closed
286-
break
287+
break InterruptionLoop
287288
default:
288289
EventLoop:
289290
for event, ok := interruptionEventStore.GetActiveEvent(); ok; event, ok = interruptionEventStore.GetActiveEvent() {
@@ -320,7 +321,7 @@ func handleRebootUncordon(nodeName string, interruptionEventStore *interruptione
320321
}
321322
err = node.UncordonIfRebooted(nodeName)
322323
if err != nil {
323-
return fmt.Errorf("Unable to complete node label actions: %w", err)
324+
return fmt.Errorf("unable to complete node label actions: %w", err)
324325
}
325326
interruptionEventStore.IgnoreEvent(eventID)
326327
return nil

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/aws/aws-node-termination-handler
22

3-
go 1.22.0
3+
go 1.25
44

5-
toolchain go1.22.2
5+
toolchain go1.25.5
66

77
require (
88
github.com/Masterminds/sprig/v3 v3.2.3

pkg/config/config.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,12 @@ func ParseCliArgs() (config Config, err error) {
316316
}
317317

318318
// client-go expects these to be set in env vars
319-
os.Setenv(kubernetesServiceHostConfigKey, config.KubernetesServiceHost)
320-
os.Setenv(kubernetesServicePortConfigKey, config.KubernetesServicePort)
319+
if err := os.Setenv(kubernetesServiceHostConfigKey, config.KubernetesServiceHost); err != nil {
320+
return config, fmt.Errorf("failed to set %s environment variable: %w", kubernetesServiceHostConfigKey, err)
321+
}
322+
if err := os.Setenv(kubernetesServicePortConfigKey, config.KubernetesServicePort); err != nil {
323+
return config, fmt.Errorf("failed to set %s environment variable: %w", kubernetesServicePortConfigKey, err)
324+
}
321325

322326
return config, err
323327
}

pkg/ec2metadata/ec2metadata.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@ func New(metadataURL string, tries int) *Service {
139139
func (e *Service) GetScheduledMaintenanceEvents() ([]ScheduledEventDetail, error) {
140140
resp, err := e.Request(ScheduledEventPath)
141141
if resp != nil && (resp.StatusCode < 200 || resp.StatusCode >= 300) {
142-
return nil, fmt.Errorf("Metadata request received http status code: %d", resp.StatusCode)
142+
return nil, fmt.Errorf("metadata request received http status code: %d", resp.StatusCode)
143143
}
144144
if err != nil {
145-
return nil, fmt.Errorf("Unable to parse metadata response: %w", err)
145+
return nil, fmt.Errorf("unable to parse metadata response: %w", err)
146146
}
147-
defer resp.Body.Close()
147+
defer func() { _ = resp.Body.Close() }()
148148
var scheduledEvents []ScheduledEventDetail
149149
err = json.NewDecoder(resp.Body).Decode(&scheduledEvents)
150150
if err != nil {
151-
return nil, fmt.Errorf("Could not decode json retrieved from imds: %w", err)
151+
return nil, fmt.Errorf("could not decode json retrieved from imds: %w", err)
152152
}
153153
return scheduledEvents, nil
154154
}
@@ -160,16 +160,16 @@ func (e *Service) GetSpotITNEvent() (instanceAction *InstanceAction, err error)
160160
if resp != nil && resp.StatusCode == 404 {
161161
return nil, nil
162162
} else if resp != nil && (resp.StatusCode < 200 || resp.StatusCode >= 300) {
163-
return nil, fmt.Errorf("Metadata request received http status code: %d", resp.StatusCode)
163+
return nil, fmt.Errorf("metadata request received http status code: %d", resp.StatusCode)
164164
}
165165
if err != nil {
166-
return nil, fmt.Errorf("Unable to parse metadata response: %w", err)
166+
return nil, fmt.Errorf("unable to parse metadata response: %w", err)
167167
}
168-
defer resp.Body.Close()
168+
defer func() { _ = resp.Body.Close() }()
169169

170170
err = json.NewDecoder(resp.Body).Decode(&instanceAction)
171171
if err != nil {
172-
return nil, fmt.Errorf("Could not decode instance action response: %w", err)
172+
return nil, fmt.Errorf("could not decode instance action response: %w", err)
173173
}
174174
return instanceAction, nil
175175
}
@@ -181,16 +181,16 @@ func (e *Service) GetRebalanceRecommendationEvent() (rebalanceRec *RebalanceReco
181181
if resp != nil && resp.StatusCode == 404 {
182182
return nil, nil
183183
} else if resp != nil && (resp.StatusCode < 200 || resp.StatusCode >= 300) {
184-
return nil, fmt.Errorf("Metadata request received http status code: %d", resp.StatusCode)
184+
return nil, fmt.Errorf("metadata request received http status code: %d", resp.StatusCode)
185185
}
186186
if err != nil {
187-
return nil, fmt.Errorf("Unable to parse metadata response: %w", err)
187+
return nil, fmt.Errorf("unable to parse metadata response: %w", err)
188188
}
189-
defer resp.Body.Close()
189+
defer func() { _ = resp.Body.Close() }()
190190

191191
err = json.NewDecoder(resp.Body).Decode(&rebalanceRec)
192192
if err != nil {
193-
return nil, fmt.Errorf("Could not decode rebalance recommendation response: %w", err)
193+
return nil, fmt.Errorf("could not decode rebalance recommendation response: %w", err)
194194
}
195195
return rebalanceRec, nil
196196
}
@@ -203,16 +203,16 @@ func (e *Service) GetASGTargetLifecycleState() (state string, err error) {
203203
if resp != nil && resp.StatusCode == 404 {
204204
return "", nil
205205
} else if resp != nil && (resp.StatusCode < 200 || resp.StatusCode >= 300) {
206-
return "", fmt.Errorf("Metadata request received http status code: %d", resp.StatusCode)
206+
return "", fmt.Errorf("metadata request received http status code: %d", resp.StatusCode)
207207
}
208208
if err != nil {
209-
return "", fmt.Errorf("Unable to parse metadata response: %w", err)
209+
return "", fmt.Errorf("unable to parse metadata response: %w", err)
210210
}
211-
defer resp.Body.Close()
211+
defer func() { _ = resp.Body.Close() }()
212212

213213
body, err := io.ReadAll(resp.Body)
214214
if err != nil {
215-
return "", fmt.Errorf("Unable to parse http response. Status code: %d. %w", resp.StatusCode, err)
215+
return "", fmt.Errorf("unable to parse http response. Status code: %d. %w", resp.StatusCode, err)
216216
}
217217
return string(body), nil
218218
}
@@ -222,19 +222,19 @@ func (e *Service) GetMetadataInfo(path string, allowMissing bool) (info string,
222222
metadataInfo := ""
223223
resp, err := e.Request(path)
224224
if err != nil {
225-
return "", fmt.Errorf("Unable to parse metadata response: %w", err)
225+
return "", fmt.Errorf("unable to parse metadata response: %w", err)
226226
}
227227
if resp != nil {
228-
defer resp.Body.Close()
228+
defer func() { _ = resp.Body.Close() }()
229229
body, err := io.ReadAll(resp.Body)
230230
if err != nil {
231-
return "", fmt.Errorf("Unable to parse http response. Status code: %d. %w", resp.StatusCode, err)
231+
return "", fmt.Errorf("unable to parse http response. Status code: %d. %w", resp.StatusCode, err)
232232
}
233233
metadataInfo = string(body)
234234
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
235235
if resp.StatusCode != 404 || !allowMissing {
236236
log.Info().Msgf("Metadata response status code: %d. Body: %s", resp.StatusCode, metadataInfo)
237-
return "", fmt.Errorf("Metadata request received http status code: %d", resp.StatusCode)
237+
return "", fmt.Errorf("metadata request received http status code: %d", resp.StatusCode)
238238
} else {
239239
return "", nil
240240
}
@@ -249,7 +249,7 @@ func (e *Service) GetMetadataInfo(path string, allowMissing bool) (info string,
249249
func (e *Service) Request(contextPath string) (*http.Response, error) {
250250
req, err := http.NewRequest(http.MethodGet, e.metadataURL+contextPath, nil)
251251
if err != nil {
252-
return nil, fmt.Errorf("Unable to construct an http get request to IDMS for %s: %w", e.metadataURL+contextPath, err)
252+
return nil, fmt.Errorf("unable to construct an http get request to IDMS for %s: %w", e.metadataURL+contextPath, err)
253253
}
254254
var resp *http.Response
255255
for i := 0; i < tokenRetryAttempts; i++ {
@@ -274,7 +274,7 @@ func (e *Service) Request(contextPath string) (*http.Response, error) {
274274
}
275275
resp, err = retry(e.tries, 2*time.Second, httpReq)
276276
if err != nil {
277-
return nil, fmt.Errorf("Unable to get a response from IMDS: %w", err)
277+
return nil, fmt.Errorf("unable to get a response from IMDS: %w", err)
278278
}
279279
if resp != nil && resp.StatusCode == 401 {
280280
e.Lock()
@@ -297,7 +297,7 @@ func (e *Service) Request(contextPath string) (*http.Response, error) {
297297
func (e *Service) getV2Token() (string, int, error) {
298298
req, err := http.NewRequest(http.MethodPut, e.metadataURL+tokenRefreshPath, nil)
299299
if err != nil {
300-
return "", -1, fmt.Errorf("Unable to construct http put request to retrieve imdsv2 token: %w", err)
300+
return "", -1, fmt.Errorf("unable to construct http put request to retrieve imdsv2 token: %w", err)
301301
}
302302
req.Header.Add(tokenTTLHeader, strconv.Itoa(tokenTTL))
303303
httpReq := func() (*http.Response, error) {
@@ -308,13 +308,13 @@ func (e *Service) getV2Token() (string, int, error) {
308308
if err != nil {
309309
return "", -1, err
310310
}
311-
defer resp.Body.Close()
311+
defer func() { _ = resp.Body.Close() }()
312312
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
313-
return "", -1, fmt.Errorf("Received an http status code %d", resp.StatusCode)
313+
return "", -1, fmt.Errorf("received an http status code %d", resp.StatusCode)
314314
}
315315
token, err := io.ReadAll(resp.Body)
316316
if err != nil {
317-
return "", -1, fmt.Errorf("Unable to read token response from IMDSv2: %w", err)
317+
return "", -1, fmt.Errorf("unable to read token response from IMDSv2: %w", err)
318318
}
319319
ttl, err := ttlHeaderToInt(resp)
320320
if err != nil {
@@ -327,7 +327,7 @@ func (e *Service) getV2Token() (string, int, error) {
327327
func ttlHeaderToInt(resp *http.Response) (int, error) {
328328
ttl := resp.Header.Get(tokenTTLHeader)
329329
if ttl == "" {
330-
return -1, fmt.Errorf("No token TTL header found")
330+
return -1, fmt.Errorf("no token TTL header found")
331331
}
332332
ttlInt, err := strconv.Atoi(ttl)
333333
if err != nil {

pkg/ec2metadata/ec2metadata_internal_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
)
2828

2929
func TestRetry(t *testing.T) {
30-
var numRetries int = 3
31-
var errorMsg string = "Request failed"
30+
var numRetries = 3
31+
var errorMsg = "Request failed"
3232
var requestCount int
3333

3434
request := func() (*http.Response, error) {
@@ -42,7 +42,7 @@ func TestRetry(t *testing.T) {
4242

4343
resp, err := retry(numRetries, time.Microsecond, request)
4444
h.Assert(t, err != nil, "Should have gotten a \"Request failed\" error")
45-
defer resp.Body.Close()
45+
defer func() { _ = resp.Body.Close() }()
4646

4747
h.Equals(t, errorMsg, err.Error())
4848
h.Equals(t, numRetries, requestCount)

0 commit comments

Comments
 (0)