提交 88e32380 编写于 作者: L liqingping

style: lint error

上级 5d44d1e8
......@@ -101,8 +101,8 @@ func runCommand(cmd *cobra.Command, options *CreateOptions) error {
return err
}
ctx := handler.NewContext(config,
context.Background(),
ctx := handler.NewContext(context.Background(),
config,
mgr.GetClient(),
mgr.GetEventRecorderFor("di-operator"),
ctrl.Log.WithName("di-operator"))
......
package e2e
import (
"context"
"flag"
"os"
"path/filepath"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
div1alpha2 "opendilab.org/di-orchestrator/pkg/api/v1alpha2"
)
func TestE2E(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t,
"E2E Suite",
[]Reporter{printer.NewlineReporter{}})
}
var (
k8sClient client.Client
clientset *kubernetes.Clientset
kubeconfig string
exampleJobsDir string
sharedVolumesDir string
)
func init() {
testing.Init()
if flag.Lookup("kubeconfig") == nil {
flag.StringVar(&kubeconfig, "kubeconfig", "", "kubeconfig file path")
}
flag.StringVar(&sharedVolumesDir, "shared-volumes-dir", "/data/nfs/ding/", "dir to shared volumes")
flag.StringVar(&exampleJobsDir, "example-jobs-dir", "./config", "dir to the example jobs")
flag.Parse()
kubeconfig = flag.Lookup("kubeconfig").Value.String()
if kubeconfig == "" {
kubeconfig = os.Getenv("KUBECONFIG")
if kubeconfig == "" {
kubeconfig = filepath.Join(homeDir(), ".kube", "config")
}
}
}
func homeDir() string {
if h := os.Getenv("HOME"); h != "" {
return h
}
return os.Getenv("USERPROFILE") // windows
}
var _ = BeforeSuite(func() {
// uses the current context in kubeconfig
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
Expect(err).NotTo(HaveOccurred())
err = div1alpha2.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
//+kubebuilder:scaffold:scheme
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
clientset, err = kubernetes.NewForConfig(cfg)
Expect(err).NotTo(HaveOccurred())
k8sClient.DeleteAllOf(context.Background(), &div1alpha2.DIJob{},
client.InNamespace(namespace), client.MatchingLabels{"stability-test": "dijobs"})
})
var _ = AfterSuite(func() {
})
// import (
// "context"
// "flag"
// "os"
// "path/filepath"
// "testing"
// . "github.com/onsi/ginkgo"
// . "github.com/onsi/gomega"
// "k8s.io/client-go/kubernetes"
// "k8s.io/client-go/kubernetes/scheme"
// "k8s.io/client-go/tools/clientcmd"
// "sigs.k8s.io/controller-runtime/pkg/client"
// "sigs.k8s.io/controller-runtime/pkg/envtest/printer"
// div1alpha2 "opendilab.org/di-orchestrator/pkg/api/v1alpha2"
// )
// func TestE2E(t *testing.T) {
// RegisterFailHandler(Fail)
// RunSpecsWithDefaultAndCustomReporters(t,
// "E2E Suite",
// []Reporter{printer.NewlineReporter{}})
// }
// var (
// k8sClient client.Client
// clientset *kubernetes.Clientset
// kubeconfig string
// exampleJobsDir string
// sharedVolumesDir string
// )
// func init() {
// testing.Init()
// if flag.Lookup("kubeconfig") == nil {
// flag.StringVar(&kubeconfig, "kubeconfig", "", "kubeconfig file path")
// }
// flag.StringVar(&sharedVolumesDir, "shared-volumes-dir", "/data/nfs/ding/", "dir to shared volumes")
// flag.StringVar(&exampleJobsDir, "example-jobs-dir", "./config", "dir to the example jobs")
// flag.Parse()
// kubeconfig = flag.Lookup("kubeconfig").Value.String()
// if kubeconfig == "" {
// kubeconfig = os.Getenv("KUBECONFIG")
// if kubeconfig == "" {
// kubeconfig = filepath.Join(homeDir(), ".kube", "config")
// }
// }
// }
// func homeDir() string {
// if h := os.Getenv("HOME"); h != "" {
// return h
// }
// return os.Getenv("USERPROFILE") // windows
// }
// var _ = BeforeSuite(func() {
// // uses the current context in kubeconfig
// cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
// Expect(err).NotTo(HaveOccurred())
// err = div1alpha2.AddToScheme(scheme.Scheme)
// Expect(err).NotTo(HaveOccurred())
// //+kubebuilder:scaffold:scheme
// k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
// Expect(err).NotTo(HaveOccurred())
// Expect(k8sClient).NotTo(BeNil())
// clientset, err = kubernetes.NewForConfig(cfg)
// Expect(err).NotTo(HaveOccurred())
// k8sClient.DeleteAllOf(context.Background(), &div1alpha2.DIJob{},
// client.InNamespace(namespace), client.MatchingLabels{"stability-test": "dijobs"})
// })
// var _ = AfterSuite(func() {
// })
此差异已折叠。
......@@ -41,7 +41,6 @@ func GetDIServerURL() string {
url := os.Getenv(ENVServerURL)
if url == "" {
return "di-server.di-system:8080"
} else {
return url
}
return url
}
package gpu_allocator
package gpuallocator
import (
"fmt"
......
package gpu_allocator
package gpuallocator
import (
"testing"
......
......@@ -21,7 +21,6 @@ import (
"fmt"
"path/filepath"
"testing"
"time"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
......@@ -43,9 +42,9 @@ import (
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
const (
timeout = 5 * time.Second
interval = 250 * time.Millisecond
duration = 200 * time.Millisecond
// timeout = 5 * time.Second
// interval = 250 * time.Millisecond
// duration = 200 * time.Millisecond
)
// var cfg *rest.Config
......@@ -91,8 +90,8 @@ var _ = BeforeSuite(func() {
})
Expect(err).NotTo(HaveOccurred())
ctx := handler.NewContext(cfg,
context.Background(),
ctx := handler.NewContext(context.Background(),
cfg,
k8sManager.GetClient(),
k8sManager.GetEventRecorderFor("di-operator"),
ctrl.Log.WithName("di-operator"))
......
......@@ -17,7 +17,7 @@ type Context struct {
Recorder record.EventRecorder
}
func NewContext(config *rest.Config, ctx context.Context, client client.Client, recorder record.EventRecorder, logger logr.Logger) *Context {
func NewContext(ctx context.Context, config *rest.Config, client client.Client, recorder record.EventRecorder, logger logr.Logger) *Context {
return &Context{
config: config,
ctx: ctx,
......
......@@ -182,27 +182,27 @@ func (c *Context) UpdateDIJobStatusInCluster(job *div1alpha2.DIJob) error {
return err
}
func (r *Context) UpdateJobStatus(
func (c *Context) UpdateJobStatus(
job *div1alpha2.DIJob, phase div1alpha2.Phase, reason string, msg string) {
updateDIJobConditions(job, phase, reason, msg)
switch phase {
case div1alpha2.JobPending, div1alpha2.JobStarting:
r.Recorder.Eventf(job, corev1.EventTypeNormal, reason, msg)
c.Recorder.Eventf(job, corev1.EventTypeNormal, reason, msg)
case div1alpha2.JobRunning:
if job.Status.Phase != div1alpha2.JobRunning {
r.Recorder.Eventf(job, corev1.EventTypeNormal, reason, msg)
c.Recorder.Eventf(job, corev1.EventTypeNormal, reason, msg)
}
case div1alpha2.JobRestarting:
job.Status.Generation += 1
r.Recorder.Eventf(job, corev1.EventTypeWarning, reason, msg)
job.Status.Generation++
c.Recorder.Eventf(job, corev1.EventTypeWarning, reason, msg)
case div1alpha2.JobFailed:
job.Status.ReadyReplicas = 0
r.Recorder.Eventf(job, corev1.EventTypeWarning, reason, msg)
c.Recorder.Eventf(job, corev1.EventTypeWarning, reason, msg)
case div1alpha2.JobSucceeded:
job.Status.ReadyReplicas = 0
r.Recorder.Eventf(job, corev1.EventTypeNormal, reason, msg)
c.Recorder.Eventf(job, corev1.EventTypeNormal, reason, msg)
default:
r.Recorder.Eventf(job, corev1.EventTypeNormal, reason, msg)
c.Recorder.Eventf(job, corev1.EventTypeNormal, reason, msg)
}
job.Status.Phase = phase
}
......
......@@ -68,10 +68,6 @@ func (s *DIServer) needMultiDDPLearnerPod(resource commontypes.ResourceQuantity)
return false, nil
}
func needAggregator(resource commontypes.ResourceQuantity) bool {
return resource.GPU.Value() > 1
}
func (s *DIServer) updateDIJobStatusInCluster(job *div1alpha2.DIJob) error {
var err error
for i := 0; i < statusUpdateRetries; i++ {
......
......@@ -26,9 +26,8 @@ import (
)
var (
apiVersion = "v1alpha2"
replicasAPI = "/replicas"
replicasFailedAPI = "/replicas/failed"
apiVersion = "v1alpha2"
replicasAPI = "/replicas"
)
func withAPIVersion(api string) string {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册