Skip to content

Commit 560ef3d

Browse files
kaichiachencraigcondit
authored andcommitted
[YUNIKORN-3024] Update to go 1.23 (#950)
Closes: #950 Signed-off-by: Craig Condit <ccondit@apache.org> (cherry picked from commit 2964df3)
1 parent e4f21c7 commit 560ef3d

24 files changed

Lines changed: 148 additions & 47 deletions

.go_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.22
1+
1.23

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# options for analysis running
1919
run:
2020
issues-exit-code: 1
21-
skip-dirs-use-default: true
2221
modules-download-mode: readonly
2322
timeout: 10m
2423

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ endif
162162
export PATH := $(BASE_DIR)/$(SHELLCHECK_PATH):$(PATH)
163163

164164
# golangci-lint
165-
GOLANGCI_LINT_VERSION=1.57.2
165+
GOLANGCI_LINT_VERSION=1.63.4
166166
GOLANGCI_LINT_PATH=$(TOOLS_DIR)/golangci-lint-v$(GOLANGCI_LINT_VERSION)
167167
GOLANGCI_LINT_BIN=$(GOLANGCI_LINT_PATH)/golangci-lint
168168
GOLANGCI_LINT_ARCHIVE=golangci-lint-$(GOLANGCI_LINT_VERSION)-$(OS)-$(EXEC_ARCH).tar.gz

pkg/admission/admission_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"bytes"
2323
"crypto/sha256"
2424
"encoding/json"
25+
"errors"
2526
"fmt"
2627
"io"
2728
"net/http"
@@ -607,7 +608,7 @@ func (c *AdmissionController) validateConfigMap(namespace string, cm *v1.ConfigM
607608
return nil
608609
}
609610
if !responseData.Allowed {
610-
err = fmt.Errorf(responseData.Reason)
611+
err = errors.New(responseData.Reason)
611612
log.Log(log.Admission).Error("Configmap validation failed, aborting", zap.Error(err))
612613
return err
613614
}

pkg/admission/admission_controller_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,9 @@ func TestMutate(t *testing.T) {
568568
assert.Check(t, resp.Allowed, "response not allowed for unknown object type")
569569
assert.Check(t, len(resp.Patch) > 0, "empty patch for deployment")
570570
annotations := annotationsFromDeployment(t, resp.Patch)
571-
assert.Equal(t, annotations[common.UserInfoAnnotation].(string), "{\"user\":\"testExtUser\"}")
571+
annotationValue, ok := annotations[common.UserInfoAnnotation].(string)
572+
assert.Assert(t, ok, "UserInfoAnnotation value is not a string")
573+
assert.Equal(t, annotationValue, "{\"user\":\"testExtUser\"}")
572574

573575
// deployment - annotation is not set, bypassAuth is enabled
574576
ac = prepareController(t, "", "", "^kube-system$,^bypass$", "", "^nolabel$", true, true)
@@ -838,7 +840,9 @@ func schedulerName(t *testing.T, patch []byte) string {
838840
ops := parsePatch(t, patch)
839841
for _, op := range ops {
840842
if op.Path == "/spec/schedulerName" {
841-
return op.Value.(string)
843+
val, ok := op.Value.(string)
844+
assert.Assert(t, ok, "scheduler name value is not a string")
845+
return val
842846
}
843847
}
844848
return ""
@@ -848,7 +852,9 @@ func labels(t *testing.T, patch []byte) map[string]interface{} {
848852
ops := parsePatch(t, patch)
849853
for _, op := range ops {
850854
if op.Path == "/metadata/labels" {
851-
return op.Value.(map[string]interface{})
855+
val, ok := op.Value.(map[string]interface{})
856+
assert.Assert(t, ok, "labels value is not a map")
857+
return val
852858
}
853859
}
854860
return make(map[string]interface{})
@@ -858,7 +864,9 @@ func annotationsFromDeployment(t *testing.T, patch []byte) map[string]interface{
858864
ops := parsePatch(t, patch)
859865
for _, op := range ops {
860866
if op.Path == "/spec/template/metadata/annotations" {
861-
return op.Value.(map[string]interface{})
867+
val, ok := op.Value.(map[string]interface{})
868+
assert.Assert(t, ok, "annotations value is not a map")
869+
return val
862870
}
863871
}
864872
return make(map[string]interface{})

pkg/cache/application_state.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ func newAppState() *fsm.FSM { //nolint:funlen
470470
RejectApplication.String(): func(_ context.Context, event *fsm.Event) {
471471
app := event.Args[0].(*Application) //nolint:errcheck
472472
eventArgs := make([]string, 1)
473-
if err := events.GetEventArgsAsStrings(eventArgs, event.Args[1].([]interface{})); err != nil {
473+
generic := event.Args[1].([]interface{}) //nolint:errcheck
474+
if err := events.GetEventArgsAsStrings(eventArgs, generic); err != nil {
474475
log.Log(log.ShimFSM).Error("fail to parse event arg", zap.Error(err))
475476
return
476477
}
@@ -484,7 +485,8 @@ func newAppState() *fsm.FSM { //nolint:funlen
484485
FailApplication.String(): func(_ context.Context, event *fsm.Event) {
485486
app := event.Args[0].(*Application) //nolint:errcheck
486487
eventArgs := make([]string, 1)
487-
if err := events.GetEventArgsAsStrings(eventArgs, event.Args[1].([]interface{})); err != nil {
488+
generic := event.Args[1].([]interface{}) //nolint:errcheck
489+
if err := events.GetEventArgsAsStrings(eventArgs, generic); err != nil {
488490
log.Log(log.ShimFSM).Error("fail to parse event arg", zap.Error(err))
489491
return
490492
}
@@ -498,7 +500,8 @@ func newAppState() *fsm.FSM { //nolint:funlen
498500
ReleaseAppAllocation.String(): func(_ context.Context, event *fsm.Event) {
499501
app := event.Args[0].(*Application) //nolint:errcheck
500502
eventArgs := make([]string, 2)
501-
if err := events.GetEventArgsAsStrings(eventArgs, event.Args[1].([]interface{})); err != nil {
503+
generic := event.Args[1].([]interface{}) //nolint:errcheck
504+
if err := events.GetEventArgsAsStrings(eventArgs, generic); err != nil {
502505
log.Log(log.ShimFSM).Error("fail to parse event arg", zap.Error(err))
503506
return
504507
}

pkg/cache/placeholder_manager.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type PlaceholderManager struct {
4040
// and keep retrying deleting them in order to avoid wasting resources.
4141
orphanPods map[string]*v1.Pod
4242
stopChan chan struct{}
43-
running atomic.Value
43+
running atomic.Bool
4444
cleanupTime time.Duration
4545
// a simple mutex will do we do not have separate read and write paths
4646
locking.RWMutex
@@ -54,11 +54,8 @@ var (
5454
func NewPlaceholderManager(clients *client.Clients) *PlaceholderManager {
5555
mu.Lock()
5656
defer mu.Unlock()
57-
var r atomic.Value
58-
r.Store(false)
5957
placeholderMgr = &PlaceholderManager{
6058
clients: clients,
61-
running: r,
6259
orphanPods: make(map[string]*v1.Pod),
6360
stopChan: make(chan struct{}),
6461
cleanupTime: 5 * time.Second,
@@ -173,7 +170,7 @@ func (mgr *PlaceholderManager) Stop() {
173170
}
174171

175172
func (mgr *PlaceholderManager) isRunning() bool {
176-
return mgr.running.Load().(bool)
173+
return mgr.running.Load()
177174
}
178175

179176
func (mgr *PlaceholderManager) setRunning(flag bool) {

pkg/cache/scheduler_callback.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (callback *AsyncRMCallback) PreemptionPredicates(args *si.PreemptionPredica
191191
}
192192
return &si.PreemptionPredicatesResponse{
193193
Success: ok,
194-
Index: int32(index),
194+
Index: int32(index), //nolint:gosec
195195
}
196196
}
197197

pkg/cache/task_state.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ func callbacks(states *TStates) fsm.Callbacks {
402402
task := event.Args[0].(*Task) //nolint:errcheck
403403
eventArgs := make([]string, 1)
404404
reason := ""
405-
if err := events.GetEventArgsAsStrings(eventArgs, event.Args[1].([]interface{})); err != nil {
405+
generic := event.Args[1].([]interface{}) //nolint:errcheck
406+
if err := events.GetEventArgsAsStrings(eventArgs, generic); err != nil {
406407
log.Log(log.ShimFSM).Error("failed to parse event arg", zap.Error(err))
407408
reason = err.Error()
408409
} else {
@@ -421,7 +422,8 @@ func callbacks(states *TStates) fsm.Callbacks {
421422
beforeHook(TaskAllocated): func(_ context.Context, event *fsm.Event) {
422423
task := event.Args[0].(*Task) //nolint:errcheck
423424
eventArgs := make([]string, 2)
424-
if err := events.GetEventArgsAsStrings(eventArgs, event.Args[1].([]interface{})); err != nil {
425+
generic := event.Args[1].([]interface{}) //nolint:errcheck
426+
if err := events.GetEventArgsAsStrings(eventArgs, generic); err != nil {
425427
log.Log(log.ShimFSM).Error("failed to parse event arg", zap.Error(err))
426428
return
427429
}

pkg/client/apifactory_mock.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,18 @@ func (m *MockedAPIProvider) UpdatePriorityClass(oldObj *schedv1.PriorityClass, n
397397
}
398398
}
399399

400-
func (m *MockedAPIProvider) GetPodBindStats() BindStats {
401-
return m.clients.KubeClient.(*KubeClientMock).GetBindStats()
400+
func (m *MockedAPIProvider) GetPodBindStats() *BindStats {
401+
kubeClient, ok := m.clients.KubeClient.(*KubeClientMock)
402+
if !ok {
403+
log.Log(log.Test).Error("failed to get KubeClientMock")
404+
return nil
405+
}
406+
bindStats := kubeClient.GetBindStats()
407+
return &bindStats
402408
}
403409

404410
func (m *MockedAPIProvider) GetBoundPods(clear bool) []BoundPod {
405-
return m.clients.KubeClient.(*KubeClientMock).GetBoundPods(clear)
411+
return m.clients.KubeClient.(*KubeClientMock).GetBoundPods(clear) // nolint: errcheck
406412
}
407413

408414
// MockedPersistentVolumeInformer implements PersistentVolumeInformer interface

0 commit comments

Comments
 (0)