Skip to content

Commit 54ba287

Browse files
[Chore][Linter] Upgrade golangci-lint to 1.60.3 (#2362)
Signed-off-by: Chi-Sheng Liu <[email protected]>
1 parent e1edb4c commit 54ba287

File tree

8 files changed

+30
-21
lines changed

8 files changed

+30
-21
lines changed

.github/workflows/test-job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
- name: Install golangci-lint
1616
run: |
17-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.58.1
17+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.60.3
1818
mv ./bin/golangci-lint /usr/local/bin/golangci-lint
1919
shell: bash
2020
- uses: actions/checkout@v3

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ repos:
2727
hooks:
2828
- id: gitleaks
2929

30+
- repo: local
31+
hooks:
32+
- id: check-golangci-lint-version
33+
name: golangci-lint version check
34+
entry: bash -c 'version="1.60.3"; [ "$(golangci-lint --version | grep -oP "(?<=version )[\d\.]+")" = "$version" ] || echo "golangci-lint version is not $version"'
35+
language: system
36+
always_run: true
37+
fail_fast: true
38+
pass_filenames: false
39+
3040
- repo: local
3141
hooks:
3242
- id: golangci-lint-ray-operator

ray-operator/controllers/ray/common/pod.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ func labelPod(rayNodeType rayv1.RayNodeType, rayClusterName string, groupName st
536536
}
537537

538538
func setInitContainerEnvVars(container *corev1.Container, fqdnRayIP string) {
539-
if container.Env == nil || len(container.Env) == 0 {
539+
if len(container.Env) == 0 {
540540
container.Env = []corev1.EnvVar{}
541541
}
542542
// Init containers in both head and worker require FQ_RAY_IP.
@@ -552,7 +552,7 @@ func setInitContainerEnvVars(container *corev1.Container, fqdnRayIP string) {
552552
func setContainerEnvVars(pod *corev1.Pod, rayNodeType rayv1.RayNodeType, rayStartParams map[string]string, fqdnRayIP string, headPort string, rayStartCmd string, creatorCRDType utils.CRDType) {
553553
// TODO: Audit all environment variables to identify which should not be modified by users.
554554
container := &pod.Spec.Containers[utils.RayContainerIndex]
555-
if container.Env == nil || len(container.Env) == 0 {
555+
if len(container.Env) == 0 {
556556
container.Env = []corev1.EnvVar{}
557557
}
558558

ray-operator/controllers/ray/raycluster_controller.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
errstd "errors"
66
"fmt"
7+
"math"
78
"os"
89
"reflect"
910
"runtime"
@@ -436,12 +437,12 @@ func (r *RayClusterReconciler) reconcileRouteOpenShift(ctx context.Context, inst
436437
return err
437438
}
438439

439-
if headRoutes.Items != nil && len(headRoutes.Items) == 1 {
440+
if len(headRoutes.Items) == 1 {
440441
logger.Info("reconcileIngresses", "head service route found", headRoutes.Items[0].Name)
441442
return nil
442443
}
443444

444-
if headRoutes.Items == nil || len(headRoutes.Items) == 0 {
445+
if len(headRoutes.Items) == 0 {
445446
route, err := common.BuildRouteForHeadService(*instance)
446447
if err != nil {
447448
return err
@@ -468,12 +469,12 @@ func (r *RayClusterReconciler) reconcileIngressKubernetes(ctx context.Context, i
468469
return err
469470
}
470471

471-
if headIngresses.Items != nil && len(headIngresses.Items) == 1 {
472+
if len(headIngresses.Items) == 1 {
472473
logger.Info("reconcileIngresses", "head service ingress found", headIngresses.Items[0].Name)
473474
return nil
474475
}
475476

476-
if headIngresses.Items == nil || len(headIngresses.Items) == 0 {
477+
if len(headIngresses.Items) == 0 {
477478
ingress, err := common.BuildIngressForHeadService(ctx, *instance)
478479
if err != nil {
479480
return err
@@ -665,7 +666,7 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
665666
r.Recorder.Eventf(instance, corev1.EventTypeNormal, string(utils.DeletedHeadPod),
666667
"Deleted head Pod %s/%s; Pod status: %s; Pod restart policy: %s; Ray container terminated status: %v",
667668
headPod.Namespace, headPod.Name, headPod.Status.Phase, headPod.Spec.RestartPolicy, getRayContainerStateTerminated(headPod))
668-
return fmt.Errorf(reason)
669+
return errstd.New(reason)
669670
}
670671
} else if len(headPods.Items) == 0 {
671672
// Create head Pod if it does not exist.
@@ -769,7 +770,11 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
769770
worker.NumOfHosts = 1
770771
}
771772
numExpectedPods := workerReplicas * worker.NumOfHosts
772-
diff := numExpectedPods - int32(len(runningPods.Items))
773+
774+
if len(runningPods.Items) > math.MaxInt32 {
775+
return errstd.New("len(runningPods.Items) exceeds math.MaxInt32")
776+
}
777+
diff := numExpectedPods - int32(len(runningPods.Items)) //nolint:gosec // Already checked in the previous line.
773778

774779
logger.Info("reconcilePods", "workerReplicas", workerReplicas, "NumOfHosts", worker.NumOfHosts, "runningPods", len(runningPods.Items), "diff", diff)
775780

ray-operator/controllers/ray/rayservice_controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package ray
22

33
import (
44
"context"
5+
errstd "errors"
56
"fmt"
7+
"math"
68
"os"
79
"reflect"
810
"strconv"
@@ -246,7 +248,10 @@ func (r *RayServiceReconciler) calculateStatus(ctx context.Context, rayServiceIn
246248
for _, subset := range serveEndPoints.Subsets {
247249
numServeEndpoints += len(subset.Addresses)
248250
}
249-
rayServiceInstance.Status.NumServeEndpoints = int32(numServeEndpoints)
251+
if numServeEndpoints > math.MaxInt32 {
252+
return errstd.New("numServeEndpoints exceeds math.MaxInt32")
253+
}
254+
rayServiceInstance.Status.NumServeEndpoints = int32(numServeEndpoints) //nolint:gosec // Already checked in the previous line.
250255
return nil
251256
}
252257

ray-operator/controllers/ray/utils/util.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"reflect"
1111
"strconv"
1212
"strings"
13-
"time"
1413
"unicode"
1514

1615
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -502,14 +501,6 @@ func CompareJsonStruct(objA interface{}, objB interface{}) bool {
502501
return reflect.DeepEqual(v1, v2)
503502
}
504503

505-
func ConvertUnixTimeToMetav1Time(unixTime uint64) *metav1.Time {
506-
// The Ray jobInfo returns the start_time, which is a unix timestamp in milliseconds.
507-
// https://docs.ray.io/en/latest/cluster/jobs-package-ref.html#jobinfo
508-
t := time.Unix(int64(unixTime)/1000, int64(unixTime)%1000*1000000)
509-
kt := metav1.NewTime(t)
510-
return &kt
511-
}
512-
513504
// Json-serializes obj and returns its hash string
514505
func GenerateJsonHash(obj interface{}) (string, error) {
515506
serialObj, err := json.Marshal(obj)

ray-operator/test/support/meta.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ type labelSelector string
66

77
var _ Option[*metav1.ListOptions] = (*labelSelector)(nil)
88

9-
//nolint:unused // To be removed when the false-positivity is fixed.
109
func (l labelSelector) applyTo(options *metav1.ListOptions) error {
1110
options.LabelSelector = string(l)
1211
return nil

ray-operator/test/support/test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type Option[T any] interface {
3333

3434
type errorOption[T any] func(to T) error
3535

36-
//nolint:unused // To be removed when the false-positivity is fixed.
3736
func (o errorOption[T]) applyTo(to T) error {
3837
return o(to)
3938
}

0 commit comments

Comments
 (0)