From b7e5ce4efe434e6ab5c62d32b5bcaa039ddeed89 Mon Sep 17 00:00:00 2001 From: Wilson Wang <3913185+wilsonwang371@users.noreply.github.com> Date: Wed, 27 Apr 2022 06:47:57 -0700 Subject: [PATCH] Update format by running gofumpt (#236) --- apiserver/cmd/main.go | 2 -- apiserver/pkg/util/cluster.go | 2 +- apiserver/pkg/util/time.go | 3 +-- .../raycluster/v1alpha1/raycluster_types.go | 4 ++-- .../v1alpha1/raycluster_types_test.go | 3 +-- ray-operator/controllers/common/pod.go | 20 ++++++++----------- ray-operator/controllers/common/pod_test.go | 2 +- .../controllers/raycluster_controller.go | 4 ++-- .../controllers/raycluster_controller_test.go | 6 +++--- ray-operator/controllers/suite_test.go | 8 +++++--- ray-operator/controllers/utils/util.go | 4 ++-- ray-operator/controllers/utils/util_test.go | 3 --- 12 files changed, 26 insertions(+), 35 deletions(-) diff --git a/apiserver/cmd/main.go b/apiserver/cmd/main.go index 9783db6999e..384013e27c7 100644 --- a/apiserver/cmd/main.go +++ b/apiserver/cmd/main.go @@ -3,7 +3,6 @@ package main import ( "context" "flag" - "math" "net" "net/http" @@ -35,7 +34,6 @@ func main() { go startRpcServer(resourceManager) startHttpProxy() - } type RegisterHttpHandlerFromEndpoint func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error diff --git a/apiserver/pkg/util/cluster.go b/apiserver/pkg/util/cluster.go index 0069dbdd70c..4a8f14e393b 100644 --- a/apiserver/pkg/util/cluster.go +++ b/apiserver/pkg/util/cluster.go @@ -17,7 +17,7 @@ type RayCluster struct { } // NewRayCluster creates a RayCluster. -//func NewRayCluster(apiCluster *api.Cluster, clusterRuntime *api.ClusterRuntime, computeRuntime *api.ComputeRuntime) *RayCluster { +// func NewRayCluster(apiCluster *api.Cluster, clusterRuntime *api.ClusterRuntime, computeRuntime *api.ComputeRuntime) *RayCluster { func NewRayCluster(apiCluster *api.Cluster, computeTemplateMap map[string]*api.ComputeTemplate) *RayCluster { // figure out how to build this computeTemplate := computeTemplateMap[apiCluster.ClusterSpec.HeadGroupSpec.ComputeTemplate] diff --git a/apiserver/pkg/util/time.go b/apiserver/pkg/util/time.go index 9259c5d8931..78a97ab6ac1 100644 --- a/apiserver/pkg/util/time.go +++ b/apiserver/pkg/util/time.go @@ -10,8 +10,7 @@ type TimeInterface interface { Now() time.Time } -type RealTime struct { -} +type RealTime struct{} func NewRealTime() TimeInterface { return &RealTime{} diff --git a/ray-operator/api/raycluster/v1alpha1/raycluster_types.go b/ray-operator/api/raycluster/v1alpha1/raycluster_types.go index 9f9b1690bb3..1471ebc8917 100644 --- a/ray-operator/api/raycluster/v1alpha1/raycluster_types.go +++ b/ray-operator/api/raycluster/v1alpha1/raycluster_types.go @@ -7,7 +7,7 @@ import ( // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. -//var app appsv1.Deployment{} +// var app appsv1.Deployment{} // RayClusterSpec defines the desired state of RayCluster type RayClusterSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster @@ -52,7 +52,7 @@ type WorkerGroupSpec struct { RayStartParams map[string]string `json:"rayStartParams"` // Template a pod template for the worker Template v1.PodTemplateSpec `json:"template"` - //ScaleStrategy defines which pods to remove + // ScaleStrategy defines which pods to remove ScaleStrategy ScaleStrategy `json:"scaleStrategy,omitempty"` } diff --git a/ray-operator/api/raycluster/v1alpha1/raycluster_types_test.go b/ray-operator/api/raycluster/v1alpha1/raycluster_types_test.go index 3ddb8e585d0..1f5fb503112 100644 --- a/ray-operator/api/raycluster/v1alpha1/raycluster_types_test.go +++ b/ray-operator/api/raycluster/v1alpha1/raycluster_types_test.go @@ -1,9 +1,8 @@ package v1alpha1 import ( - "testing" - "encoding/json" + "testing" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/ray-operator/controllers/common/pod.go b/ray-operator/controllers/common/pod.go index 367bb8b807b..27a1a27d81f 100644 --- a/ray-operator/controllers/common/pod.go +++ b/ray-operator/controllers/common/pod.go @@ -22,9 +22,7 @@ const ( SharedMemoryVolumeMountPath = "/dev/shm" ) -var ( - log = logf.Log.WithName("RayCluster-Controller") -) +var log = logf.Log.WithName("RayCluster-Controller") // DefaultHeadPodTemplate sets the config values func DefaultHeadPodTemplate(instance rayiov1alpha1.RayCluster, headSpec rayiov1alpha1.HeadGroupSpec, podName string, svcName string) v1.PodTemplateSpec { @@ -214,7 +212,6 @@ func convertCmdToString(cmdArr []string) (cmd string) { fmt.Fprintf(cmdAggr, " %s ", v) } return cmdAggr.String() - } func getRayContainerIndex(pod v1.Pod) (index int) { @@ -228,7 +225,7 @@ func getRayContainerIndex(pod v1.Pod) (index int) { } } } - //not found, use first container + // not found, use first container return 0 } @@ -268,7 +265,7 @@ func labelPod(rayNodeType rayiov1alpha1.RayNodeType, rayClusterName string, grou } func setInitContainerEnvVars(container *v1.Container, svcName string) { - //RAY_IP can be used in the DNS lookup + // RAY_IP can be used in the DNS lookup if container.Env == nil || len(container.Env) == 0 { container.Env = []v1.EnvVar{} } @@ -331,7 +328,7 @@ func envVarExists(envName string, envVars []v1.EnvVar) bool { return false } -//TODO auto complete params +// TODO auto complete params func setMissingRayStartParams(rayStartParams map[string]string, nodeType rayiov1alpha1.RayNodeType, svcName string) (completeStartParams map[string]string) { if nodeType == rayiov1alpha1.WorkerNode { if _, ok := rayStartParams["address"]; !ok { @@ -355,7 +352,6 @@ func setMissingRayStartParams(rayStartParams map[string]string, nodeType rayiov1 // concatenateContainerCommand with ray start func concatenateContainerCommand(nodeType rayiov1alpha1.RayNodeType, rayStartParams map[string]string, resource v1.ResourceRequirements) (fullCmd string) { - if _, ok := rayStartParams["num-cpus"]; !ok { cpu := resource.Limits[v1.ResourceCPU] if !cpu.IsZero() { @@ -408,7 +404,7 @@ func addEmptyDir(container *v1.Container, pod *v1.Pod) { if checkIfVolumeMounted(container, pod) { return } - //1) create a Volume of type emptyDir and add it to Volumes + // 1) create a Volume of type emptyDir and add it to Volumes emptyDirVolume := v1.Volume{ Name: SharedMemoryVolumeName, VolumeSource: v1.VolumeSource{ @@ -422,7 +418,7 @@ func addEmptyDir(container *v1.Container, pod *v1.Pod) { pod.Spec.Volumes = append(pod.Spec.Volumes, emptyDirVolume) } - //2) create a VolumeMount that uses the emptyDir + // 2) create a VolumeMount that uses the emptyDir mountedVolume := v1.VolumeMount{ MountPath: SharedMemoryVolumeMountPath, Name: SharedMemoryVolumeName, @@ -460,7 +456,7 @@ func cleanupInvalidVolumeMounts(container *v1.Container, pod *v1.Pod) { } } if !valid { - //remove the VolumeMount + // remove the VolumeMount container.VolumeMounts[index] = container.VolumeMounts[len(container.VolumeMounts)-1] container.VolumeMounts = container.VolumeMounts[:len(container.VolumeMounts)-1] } @@ -469,7 +465,7 @@ func cleanupInvalidVolumeMounts(container *v1.Container, pod *v1.Pod) { func findMemoryReqOrLimit(container v1.Container) (res *resource.Quantity) { var mem *resource.Quantity - //check the requests, if they are not set, check the limits. + // check the requests, if they are not set, check the limits. if q, ok := container.Resources.Requests[v1.ResourceMemory]; ok { mem = &q return mem diff --git a/ray-operator/controllers/common/pod_test.go b/ray-operator/controllers/common/pod_test.go index 3fbd2b02d13..60bb9301a85 100644 --- a/ray-operator/controllers/common/pod_test.go +++ b/ray-operator/controllers/common/pod_test.go @@ -178,7 +178,7 @@ func TestBuildPod(t *testing.T) { t.Fatalf("Expected `%v` but got `%v`", expectedResult, actualResult) } - //testing worker pod + // testing worker pod worker := cluster.Spec.WorkerGroupSpecs[0] podName = cluster.Name + DashSymbol + string(rayiov1alpha1.WorkerNode) + DashSymbol + worker.GroupName + DashSymbol + utils.FormatInt32(0) podTemplateSpec = DefaultWorkerPodTemplate(*cluster, worker, podName, svcName) diff --git a/ray-operator/controllers/raycluster_controller.go b/ray-operator/controllers/raycluster_controller.go index d702310afc8..c1d4256d479 100644 --- a/ray-operator/controllers/raycluster_controller.go +++ b/ray-operator/controllers/raycluster_controller.go @@ -285,9 +285,9 @@ func (r *RayClusterReconciler) reconcilePods(instance *rayiov1alpha1.RayCluster) // It will end being a simple: "if diff > 0 { } else { }" if diff > 0 { - //pods need to be added + // pods need to be added log.Info("reconcilePods", "add workers for group", worker.GroupName) - //create all workers of this group + // create all workers of this group var i int32 for i = 0; i < diff; i++ { log.Info("reconcilePods", "creating worker for group", worker.GroupName, fmt.Sprintf("index %d", i), fmt.Sprintf("in total %d", diff)) diff --git a/ray-operator/controllers/raycluster_controller_test.go b/ray-operator/controllers/raycluster_controller_test.go index 35c3aa1a59d..b6f9817f00a 100644 --- a/ray-operator/controllers/raycluster_controller_test.go +++ b/ray-operator/controllers/raycluster_controller_test.go @@ -47,7 +47,7 @@ var _ = Context("Inside the default namespace", func() { ctx := context.TODO() var workerPods corev1.PodList - var myRayCluster = &rayiov1alpha1.RayCluster{ + myRayCluster := &rayiov1alpha1.RayCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "raycluster-sample", Namespace: "default", @@ -126,7 +126,7 @@ var _ = Context("Inside the default namespace", func() { }, } - var filterLabels = client.MatchingLabels{common.RayClusterLabelKey: myRayCluster.Name, common.RayNodeGroupLabelKey: "small-group"} + filterLabels := client.MatchingLabels{common.RayClusterLabelKey: myRayCluster.Name, common.RayNodeGroupLabelKey: "small-group"} Describe("When creating a raycluster", func() { It("should create a raycluster object", func() { @@ -185,7 +185,7 @@ var _ = Context("Inside the default namespace", func() { Expect(err).NotTo(HaveOccurred(), "failed delete a pod") - //at least 3 pods should be in none-failed phase + // at least 3 pods should be in none-failed phase Eventually( listResourceFunc(ctx, &workerPods, filterLabels, &client.ListOptions{Namespace: "default"}), time.Second*15, time.Millisecond*500).Should(Equal(3), fmt.Sprintf("workerGroup %v", workerPods.Items)) diff --git a/ray-operator/controllers/suite_test.go b/ray-operator/controllers/suite_test.go index 019a1cb5091..583a31363c2 100644 --- a/ray-operator/controllers/suite_test.go +++ b/ray-operator/controllers/suite_test.go @@ -38,9 +38,11 @@ import ( // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -var cfg *rest.Config -var k8sClient client.Client -var testEnv *envtest.Environment +var ( + cfg *rest.Config + k8sClient client.Client + testEnv *envtest.Environment +) func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) diff --git a/ray-operator/controllers/utils/util.go b/ray-operator/controllers/utils/util.go index 0106c36455d..b42dd2dc749 100644 --- a/ray-operator/controllers/utils/util.go +++ b/ray-operator/controllers/utils/util.go @@ -25,7 +25,7 @@ func CheckName(s string) string { maxLenght := 50 // 63 - (max(8,6) + 5 ) // 6 to 8 char are consumed at the end with "-head-" or -worker- + 5 generated. if len(s) > maxLenght { - //shorten the name + // shorten the name offset := int(math.Abs(float64(maxLenght) - float64(len(s)))) fmt.Printf("pod name is too long: len = %v, we will shorten it by offset = %v\n", len(s), offset) s = s[offset:] @@ -50,7 +50,7 @@ func CheckLabel(s string) string { maxLenght := 63 if len(s) > maxLenght { - //shorten the name + // shorten the name offset := int(math.Abs(float64(maxLenght) - float64(len(s)))) fmt.Printf("label value is too long: len = %v, we will shorten it by offset = %v\n", len(s), offset) s = s[offset:] diff --git a/ray-operator/controllers/utils/util_test.go b/ray-operator/controllers/utils/util_test.go index b22b762ad11..d29bf47336f 100644 --- a/ray-operator/controllers/utils/util_test.go +++ b/ray-operator/controllers/utils/util_test.go @@ -29,11 +29,9 @@ func TestStatus(t *testing.T) { if !IsCreated(pod) { t.Fail() } - } func TestCheckName(t *testing.T) { - // test 1 -> change str := "72fbcc7e-a661-4b18e-ca41-e903-fc3ae634b18e-lazer090scholar-director-s" str = CheckName(str) @@ -56,7 +54,6 @@ func TestCheckName(t *testing.T) { } func createSomePod() (pod *corev1.Pod) { - return &corev1.Pod{ TypeMeta: metav1.TypeMeta{ APIVersion: "v1",