Skip to content

Commit

Permalink
[Chore][Linter] Upgrade golangci-lint to 1.60.3 (#2362)
Browse files Browse the repository at this point in the history
Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
  • Loading branch information
MortalHappiness authored Sep 8, 2024
1 parent e1edb4c commit 54ba287
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.58.1
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.60.3
mv ./bin/golangci-lint /usr/local/bin/golangci-lint
shell: bash
- uses: actions/checkout@v3
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ repos:
hooks:
- id: gitleaks

- repo: local
hooks:
- id: check-golangci-lint-version
name: golangci-lint version check
entry: bash -c 'version="1.60.3"; [ "$(golangci-lint --version | grep -oP "(?<=version )[\d\.]+")" = "$version" ] || echo "golangci-lint version is not $version"'
language: system
always_run: true
fail_fast: true
pass_filenames: false

- repo: local
hooks:
- id: golangci-lint-ray-operator
Expand Down
4 changes: 2 additions & 2 deletions ray-operator/controllers/ray/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func labelPod(rayNodeType rayv1.RayNodeType, rayClusterName string, groupName st
}

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

Expand Down
17 changes: 11 additions & 6 deletions ray-operator/controllers/ray/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
errstd "errors"
"fmt"
"math"
"os"
"reflect"
"runtime"
Expand Down Expand Up @@ -436,12 +437,12 @@ func (r *RayClusterReconciler) reconcileRouteOpenShift(ctx context.Context, inst
return err
}

if headRoutes.Items != nil && len(headRoutes.Items) == 1 {
if len(headRoutes.Items) == 1 {
logger.Info("reconcileIngresses", "head service route found", headRoutes.Items[0].Name)
return nil
}

if headRoutes.Items == nil || len(headRoutes.Items) == 0 {
if len(headRoutes.Items) == 0 {
route, err := common.BuildRouteForHeadService(*instance)
if err != nil {
return err
Expand All @@ -468,12 +469,12 @@ func (r *RayClusterReconciler) reconcileIngressKubernetes(ctx context.Context, i
return err
}

if headIngresses.Items != nil && len(headIngresses.Items) == 1 {
if len(headIngresses.Items) == 1 {
logger.Info("reconcileIngresses", "head service ingress found", headIngresses.Items[0].Name)
return nil
}

if headIngresses.Items == nil || len(headIngresses.Items) == 0 {
if len(headIngresses.Items) == 0 {
ingress, err := common.BuildIngressForHeadService(ctx, *instance)
if err != nil {
return err
Expand Down Expand Up @@ -665,7 +666,7 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
r.Recorder.Eventf(instance, corev1.EventTypeNormal, string(utils.DeletedHeadPod),
"Deleted head Pod %s/%s; Pod status: %s; Pod restart policy: %s; Ray container terminated status: %v",
headPod.Namespace, headPod.Name, headPod.Status.Phase, headPod.Spec.RestartPolicy, getRayContainerStateTerminated(headPod))
return fmt.Errorf(reason)
return errstd.New(reason)
}
} else if len(headPods.Items) == 0 {
// Create head Pod if it does not exist.
Expand Down Expand Up @@ -769,7 +770,11 @@ func (r *RayClusterReconciler) reconcilePods(ctx context.Context, instance *rayv
worker.NumOfHosts = 1
}
numExpectedPods := workerReplicas * worker.NumOfHosts
diff := numExpectedPods - int32(len(runningPods.Items))

if len(runningPods.Items) > math.MaxInt32 {
return errstd.New("len(runningPods.Items) exceeds math.MaxInt32")
}
diff := numExpectedPods - int32(len(runningPods.Items)) //nolint:gosec // Already checked in the previous line.

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

Expand Down
7 changes: 6 additions & 1 deletion ray-operator/controllers/ray/rayservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package ray

import (
"context"
errstd "errors"
"fmt"
"math"
"os"
"reflect"
"strconv"
Expand Down Expand Up @@ -246,7 +248,10 @@ func (r *RayServiceReconciler) calculateStatus(ctx context.Context, rayServiceIn
for _, subset := range serveEndPoints.Subsets {
numServeEndpoints += len(subset.Addresses)
}
rayServiceInstance.Status.NumServeEndpoints = int32(numServeEndpoints)
if numServeEndpoints > math.MaxInt32 {
return errstd.New("numServeEndpoints exceeds math.MaxInt32")
}
rayServiceInstance.Status.NumServeEndpoints = int32(numServeEndpoints) //nolint:gosec // Already checked in the previous line.
return nil
}

Expand Down
9 changes: 0 additions & 9 deletions ray-operator/controllers/ray/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"reflect"
"strconv"
"strings"
"time"
"unicode"

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

func ConvertUnixTimeToMetav1Time(unixTime uint64) *metav1.Time {
// The Ray jobInfo returns the start_time, which is a unix timestamp in milliseconds.
// https://docs.ray.io/en/latest/cluster/jobs-package-ref.html#jobinfo
t := time.Unix(int64(unixTime)/1000, int64(unixTime)%1000*1000000)
kt := metav1.NewTime(t)
return &kt
}

// Json-serializes obj and returns its hash string
func GenerateJsonHash(obj interface{}) (string, error) {
serialObj, err := json.Marshal(obj)
Expand Down
1 change: 0 additions & 1 deletion ray-operator/test/support/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type labelSelector string

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

//nolint:unused // To be removed when the false-positivity is fixed.
func (l labelSelector) applyTo(options *metav1.ListOptions) error {
options.LabelSelector = string(l)
return nil
Expand Down
1 change: 0 additions & 1 deletion ray-operator/test/support/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type Option[T any] interface {

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

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

0 comments on commit 54ba287

Please sign in to comment.