diff --git a/pkg/admission/conf/am_conf.go b/pkg/admission/conf/am_conf.go index a079369f0..7b2827d81 100644 --- a/pkg/admission/conf/am_conf.go +++ b/pkg/admission/conf/am_conf.go @@ -397,17 +397,6 @@ func parseConfigBool(config map[string]string, key string, defaultValue bool) bo return result } -func parseConfigInt(config map[string]string, key string, defaultValue int) int { - value := parseConfigString(config, key, fmt.Sprintf("%d", defaultValue)) - result, err := strconv.ParseInt(value, 10, 31) - if err != nil { - log.Log(log.AdmissionConf).Error("Unable to parse int value, using default", - zap.String("key", key), zap.String("value", value), zap.Int("default", defaultValue), zap.Error(err)) - return defaultValue - } - return int(result) -} - func parseConfigString(config map[string]string, key string, defaultValue string) string { if value, ok := config[key]; ok { return value diff --git a/pkg/admission/webhook_manager.go b/pkg/admission/webhook_manager.go index 32cf5ab29..19e57efcd 100644 --- a/pkg/admission/webhook_manager.go +++ b/pkg/admission/webhook_manager.go @@ -69,7 +69,6 @@ type WebhookManager interface { type webhookManagerImpl struct { conf *conf.AdmissionControllerConf - namespace string serviceName string clientset kubernetes.Interface conflictAttempts int diff --git a/pkg/appmgmt/general/general.go b/pkg/appmgmt/general/general.go index 181c29276..0164ce599 100644 --- a/pkg/appmgmt/general/general.go +++ b/pkg/appmgmt/general/general.go @@ -120,9 +120,9 @@ func getOwnerReference(pod *v1.Pod) []metav1.OwnerReference { // filter pods by scheduler name and state func (os *Manager) filterPods(obj interface{}) bool { - switch obj.(type) { + switch object := obj.(type) { case *v1.Pod: - pod := obj.(*v1.Pod) + pod := object return utils.GetApplicationIDFromPod(pod) != "" default: return false diff --git a/pkg/cache/context_test.go b/pkg/cache/context_test.go index 0a3af42d3..69f699460 100644 --- a/pkg/cache/context_test.go +++ b/pkg/cache/context_test.go @@ -468,12 +468,12 @@ func TestUpdatePodInCache(t *testing.T) { // ensure a terminated pod is removed context.updatePodInCache(pod1, pod3) - found, ok := context.schedulerCache.GetPod("UID-00001") + _, ok = context.schedulerCache.GetPod("UID-00001") assert.Check(t, !ok, "pod still found after termination") // ensure a non-terminated pod is updated context.updatePodInCache(pod1, pod2) - found, ok = context.schedulerCache.GetPod("UID-00001") + found, ok := context.schedulerCache.GetPod("UID-00001") if assert.Check(t, ok, "pod not found after update") { assert.Check(t, found.GetAnnotations()["test.state"] == "updated", "pod state not updated") } diff --git a/pkg/cache/task_test.go b/pkg/cache/task_test.go index ff1cfb6fb..f9b9afcb1 100644 --- a/pkg/cache/task_test.go +++ b/pkg/cache/task_test.go @@ -28,7 +28,6 @@ import ( v1 "k8s.io/api/core/v1" schedulingv1 "k8s.io/api/scheduling/v1" "k8s.io/apimachinery/pkg/api/resource" - apis "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" k8sEvents "k8s.io/client-go/tools/events" @@ -52,11 +51,11 @@ func TestTaskStateTransitions(t *testing.T) { }, }) pod := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-resource-test-00001", UID: "UID-00001", }, @@ -113,11 +112,11 @@ func TestTaskIllegalEventHandling(t *testing.T) { }, }) pod := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-resource-test-00001", UID: "UID-00001", }, @@ -164,11 +163,11 @@ func TestReleaseTaskAllocation(t *testing.T) { }, }) pod := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-resource-test-00001", UID: "UID-00001", }, @@ -248,11 +247,11 @@ func TestReleaseTaskAsk(t *testing.T) { }, }) pod := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-resource-test-00001", UID: "UID-00001", }, @@ -310,11 +309,11 @@ func TestCreateTask(t *testing.T) { // pod has timestamp defined pod0 := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-00", UID: "UID-00", CreationTimestamp: metav1.Time{Time: time0}, @@ -323,11 +322,11 @@ func TestCreateTask(t *testing.T) { // pod has no timestamp defined pod1 := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-00", UID: "UID-00", }, @@ -353,11 +352,11 @@ func TestSortTasks(t *testing.T) { "bob", testGroups, map[string]string{}, mockedSchedulerAPI) pod0 := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-00", UID: "UID-00", CreationTimestamp: metav1.Time{Time: time0}, @@ -365,11 +364,11 @@ func TestSortTasks(t *testing.T) { } pod1 := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-01", UID: "UID-01", CreationTimestamp: metav1.Time{Time: time1}, @@ -377,11 +376,11 @@ func TestSortTasks(t *testing.T) { } pod2 := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-02", UID: "UID-02", CreationTimestamp: metav1.Time{Time: time2}, @@ -408,11 +407,11 @@ func TestIsTerminated(t *testing.T) { app := NewApplication("app01", "root.default", "bob", testGroups, map[string]string{}, mockedSchedulerAPI) pod := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-01", UID: "UID-01", }, @@ -435,11 +434,11 @@ func TestSetTaskGroup(t *testing.T) { app := NewApplication("app01", "root.default", "bob", testGroups, map[string]string{}, mockedSchedulerAPI) pod := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-01", UID: "UID-01", }, @@ -503,11 +502,11 @@ func TestHandleSubmitTaskEvent(t *testing.T) { }) var priority int32 = 1000 pod1 := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-test-00001", UID: "UID-00001", }, @@ -520,11 +519,11 @@ func TestHandleSubmitTaskEvent(t *testing.T) { } var priority2 int32 = 1001 pod2 := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-test-00002", UID: "UID-00002", Annotations: map[string]string{ @@ -597,11 +596,11 @@ func TestSimultaneousTaskCompleteAndAllocate(t *testing.T) { }) pod1 := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-test-00001", UID: podUID, }, @@ -667,11 +666,11 @@ func TestUpdatePodCondition(t *testing.T) { } pod := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-test-00001", }, Status: v1.PodStatus{ @@ -694,11 +693,11 @@ func TestUpdatePodCondition(t *testing.T) { assert.Equal(t, v1.PodPending, task.podStatus.Phase) podWithCondition := &v1.Pod{ - TypeMeta: apis.TypeMeta{ + TypeMeta: metav1.TypeMeta{ Kind: "Pod", APIVersion: "v1", }, - ObjectMeta: apis.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "pod-test-00001", }, Status: v1.PodStatus{ diff --git a/pkg/cmd/shim/main.go b/pkg/cmd/shim/main.go index d071d9fd0..9f2406706 100644 --- a/pkg/cmd/shim/main.go +++ b/pkg/cmd/shim/main.go @@ -31,7 +31,6 @@ import ( "github.com/apache/yunikorn-k8shim/pkg/conf" "github.com/apache/yunikorn-k8shim/pkg/log" "github.com/apache/yunikorn-k8shim/pkg/shim" - "github.com/apache/yunikorn-scheduler-interface/lib/go/api" ) func main() { @@ -50,8 +49,8 @@ func main() { log.Log(log.Shim).Info("Starting scheduler", zap.String("name", constants.SchedulerName)) serviceContext := entrypoint.StartAllServicesWithLogger(log.RootLogger(), log.GetZapConfigs()) - if sa, ok := serviceContext.RMProxy.(api.SchedulerAPI); ok { - ss := shim.NewShimScheduler(sa, conf.GetSchedulerConf(), configMaps) + if serviceContext.RMProxy != nil { + ss := shim.NewShimScheduler(serviceContext.RMProxy, conf.GetSchedulerConf(), configMaps) ss.Run() signalChan := make(chan os.Signal, 1) diff --git a/pkg/dispatcher/dispatch_test.go b/pkg/dispatcher/dispatch_test.go index 42d745c50..04a8e20be 100644 --- a/pkg/dispatcher/dispatch_test.go +++ b/pkg/dispatcher/dispatch_test.go @@ -206,9 +206,9 @@ func TestDispatchTimeout(t *testing.T) { // start the handler, but waiting on a flag RegisterEventHandler(EventTypeApp, func(obj interface{}) { if appEvent, ok := obj.(TestAppEvent); ok { - fmt.Println(fmt.Sprintf("handling %s", appEvent.appID)) + fmt.Printf("handling %s\n", appEvent.appID) <-appEvent.flag - fmt.Println(fmt.Sprintf("handling %s DONE", appEvent.appID)) + fmt.Printf("handling %s DONE\n", appEvent.appID) } }) diff --git a/pkg/plugin/scheduler_plugin.go b/pkg/plugin/scheduler_plugin.go index a9e9911b5..4201c6f17 100644 --- a/pkg/plugin/scheduler_plugin.go +++ b/pkg/plugin/scheduler_plugin.go @@ -40,7 +40,6 @@ import ( "github.com/apache/yunikorn-k8shim/pkg/dispatcher" "github.com/apache/yunikorn-k8shim/pkg/log" "github.com/apache/yunikorn-k8shim/pkg/shim" - "github.com/apache/yunikorn-scheduler-interface/lib/go/api" ) const ( @@ -265,20 +264,20 @@ func NewSchedulerPlugin(_ runtime.Object, handle framework.Handle) (framework.Pl // start the YK core scheduler serviceContext := entrypoint.StartAllServicesWithLogger(log.RootLogger(), log.GetZapConfigs()) - if sa, ok := serviceContext.RMProxy.(api.SchedulerAPI); ok { - // we need our own informer factory here because the informers we get from the framework handle aren't yet initialized - informerFactory := informers.NewSharedInformerFactory(handle.ClientSet(), 0) - ss := shim.NewShimSchedulerForPlugin(sa, informerFactory, conf.GetSchedulerConf(), configMaps) - ss.Run() - - p := &YuniKornSchedulerPlugin{ - context: ss.GetContext(), - } - events.SetRecorder(handle.EventRecorder()) - return p, nil + if serviceContext.RMProxy == nil { + return nil, fmt.Errorf("internal error: serviceContext should implement interface api.SchedulerAPI") } - return nil, fmt.Errorf("internal error: serviceContext should implement interface api.SchedulerAPI") + // we need our own informer factory here because the informers we get from the framework handle aren't yet initialized + informerFactory := informers.NewSharedInformerFactory(handle.ClientSet(), 0) + ss := shim.NewShimSchedulerForPlugin(serviceContext.RMProxy, informerFactory, conf.GetSchedulerConf(), configMaps) + ss.Run() + + p := &YuniKornSchedulerPlugin{ + context: ss.GetContext(), + } + events.SetRecorder(handle.EventRecorder()) + return p, nil } func (sp *YuniKornSchedulerPlugin) getTask(appID, taskID string) (app interfaces.ManagedApp, task interfaces.ManagedTask, ok bool) { diff --git a/test/e2e/admission_controller/admission_controller_suite_test.go b/test/e2e/admission_controller/admission_controller_suite_test.go index 5b27064d4..7f874c968 100644 --- a/test/e2e/admission_controller/admission_controller_suite_test.go +++ b/test/e2e/admission_controller/admission_controller_suite_test.go @@ -25,7 +25,6 @@ import ( . "github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2/reporters" - "github.com/onsi/gomega" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" @@ -176,7 +175,7 @@ func getPodSpec(restartPolicy v1.RestartPolicy) v1.PodTemplateSpec { func TestAdmissionController(t *testing.T) { ReportAfterSuite("TestAdmissionController", func(report Report) { err := common.CreateJUnitReportDir() - Ω(err).NotTo(gomega.HaveOccurred()) + Ω(err).NotTo(HaveOccurred()) err = reporters.GenerateJUnitReportWithConfig( report, filepath.Join(configmanager.YuniKornTestConfig.LogDir, "TEST-admission_controller_junit.xml"), diff --git a/test/e2e/framework/helpers/common/utils.go b/test/e2e/framework/helpers/common/utils.go index 66c5c3f14..789bdddea 100644 --- a/test/e2e/framework/helpers/common/utils.go +++ b/test/e2e/framework/helpers/common/utils.go @@ -200,7 +200,7 @@ func CompareQueueMap(a map[string]interface{}, b map[string]interface{}) (bool, func GetSubQueues(q map[string]interface{}) ([]map[string]interface{}, error) { qs, ok := q["queues"] if !ok { - return nil, fmt.Errorf("Invalid arguments") + return nil, fmt.Errorf("invalid arguments") } if qs == nil { diff --git a/test/e2e/framework/helpers/k8s/k8s_utils.go b/test/e2e/framework/helpers/k8s/k8s_utils.go index 742a580bb..7bf206677 100644 --- a/test/e2e/framework/helpers/k8s/k8s_utils.go +++ b/test/e2e/framework/helpers/k8s/k8s_utils.go @@ -756,12 +756,12 @@ func (k *KubeCtl) WaitForPodCount(namespace string, wanted int, timeout time.Dur return wait.PollUntilContextTimeout(context.TODO(), time.Millisecond*100, timeout, false, k.isNumPod(namespace, wanted).WithContext()) } -func (k *KubeCtl) WaitForPodStateStable(namespace string, podName string, timeout time.Duration) (error, v1.PodPhase) { +func (k *KubeCtl) WaitForPodStateStable(namespace string, podName string, timeout time.Duration) (v1.PodPhase, error) { var lastPhase v1.PodPhase samePhases := 0 err := wait.PollUntilContextTimeout(context.TODO(), time.Second, timeout, false, k.isPodStable(namespace, podName, &samePhases, 3, &lastPhase).WithContext()) - return err, lastPhase + return lastPhase, err } // Returns the list of currently scheduled or running pods in `namespace` with the given selector diff --git a/test/e2e/framework/helpers/yunikorn/rest_api_utils.go b/test/e2e/framework/helpers/yunikorn/rest_api_utils.go index 3487e8106..972087af6 100644 --- a/test/e2e/framework/helpers/yunikorn/rest_api_utils.go +++ b/test/e2e/framework/helpers/yunikorn/rest_api_utils.go @@ -291,7 +291,7 @@ func GetFailedHealthChecks() (string, error) { var failCheck string healthCheck, err := restClient.GetHealthCheck() if err != nil { - return "", fmt.Errorf("Failed to get scheduler health check from API") + return "", fmt.Errorf("failed to get scheduler health check from API") } if !healthCheck.Healthy { for _, check := range healthCheck.HealthChecks { diff --git a/test/e2e/framework/helpers/yunikorn/yk_utils.go b/test/e2e/framework/helpers/yunikorn/yk_utils.go index 799567387..f6a645b4f 100644 --- a/test/e2e/framework/helpers/yunikorn/yk_utils.go +++ b/test/e2e/framework/helpers/yunikorn/yk_utils.go @@ -131,7 +131,7 @@ func RestartYunikornAndAddTolerations(kClient *k8s.KubeCtl, addTolerations bool, if addTolerations { schedulerPodName, err = kClient.GetSchedulerPod() Ω(err).NotTo(gomega.HaveOccurred()) - err2, ykPhase := kClient.WaitForPodStateStable(configmanager.YuniKornTestConfig.YkNamespace, schedulerPodName, 30*time.Second) + ykPhase, err2 := kClient.WaitForPodStateStable(configmanager.YuniKornTestConfig.YkNamespace, schedulerPodName, 30*time.Second) Ω(err2).NotTo(gomega.HaveOccurred()) if ykPhase == v1.PodPending { fmt.Fprintf(ginkgo.GinkgoWriter, "Scheduler pod is in Pending state\n") diff --git a/test/e2e/node_resources/node_resources_suite_test.go b/test/e2e/node_resources/node_resources_suite_test.go index dcc3c041c..abef9c433 100644 --- a/test/e2e/node_resources/node_resources_suite_test.go +++ b/test/e2e/node_resources/node_resources_suite_test.go @@ -29,7 +29,6 @@ import ( "github.com/apache/yunikorn-k8shim/test/e2e/framework/configmanager" "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/common" - "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/k8s" "github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/yunikorn" ) @@ -54,7 +53,6 @@ func TestNodeResources(t *testing.T) { var oldConfigMap = new(v1.ConfigMap) var annotation = "ann-" + common.RandSeq(10) -var kClient = k8s.KubeCtl{} //nolint var _ = BeforeSuite(func() { annotation = "ann-" + common.RandSeq(10)