Skip to content

Commit

Permalink
Update format by running gofumpt (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonwang371 authored Apr 27, 2022
1 parent 5bc854b commit 3091392
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 35 deletions.
2 changes: 0 additions & 2 deletions apiserver/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"flag"

"math"
"net"
"net/http"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apiserver/pkg/util/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions apiserver/pkg/util/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ type TimeInterface interface {
Now() time.Time
}

type RealTime struct {
}
type RealTime struct{}

func NewRealTime() TimeInterface {
return &RealTime{}
Expand Down
4 changes: 2 additions & 2 deletions ray-operator/api/raycluster/v1alpha1/raycluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
20 changes: 8 additions & 12 deletions ray-operator/controllers/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -228,7 +225,7 @@ func getRayContainerIndex(pod v1.Pod) (index int) {
}
}
}
//not found, use first container
// not found, use first container
return 0
}

Expand Down Expand Up @@ -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{}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down Expand Up @@ -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{
Expand All @@ -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,
Expand Down Expand Up @@ -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]
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ray-operator/controllers/common/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ray-operator/controllers/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions ray-operator/controllers/raycluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 5 additions & 3 deletions ray-operator/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ray-operator/controllers/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand All @@ -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:]
Expand Down
3 changes: 0 additions & 3 deletions ray-operator/controllers/utils/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -56,7 +54,6 @@ func TestCheckName(t *testing.T) {
}

func createSomePod() (pod *corev1.Pod) {

return &corev1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand Down

0 comments on commit 3091392

Please sign in to comment.