Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-2051] fix staticcheck errors #693

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions pkg/admission/conf/am_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/admission/webhook_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type WebhookManager interface {

type webhookManagerImpl struct {
conf *conf.AdmissionControllerConf
namespace string
serviceName string
clientset kubernetes.Interface
conflictAttempts int
Expand Down
4 changes: 2 additions & 2 deletions pkg/appmgmt/general/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@

// filter pods by scheduler name and state
func (os *Manager) filterPods(obj interface{}) bool {
switch obj.(type) {
switch object := obj.(type) {

Check warning on line 123 in pkg/appmgmt/general/general.go

View check run for this annotation

Codecov / codecov/patch

pkg/appmgmt/general/general.go#L123

Added line #L123 was not covered by tests
case *v1.Pod:
pod := obj.(*v1.Pod)
pod := object

Check warning on line 125 in pkg/appmgmt/general/general.go

View check run for this annotation

Codecov / codecov/patch

pkg/appmgmt/general/general.go#L125

Added line #L125 was not covered by tests
return utils.GetApplicationIDFromPod(pod) != ""
default:
return false
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
65 changes: 32 additions & 33 deletions pkg/cache/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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},
Expand All @@ -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",
},
Expand All @@ -353,35 +352,35 @@ 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},
},
}

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},
},
}

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},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand All @@ -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{
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down
5 changes: 2 additions & 3 deletions pkg/cmd/shim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/dispatcher/dispatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

Expand Down
25 changes: 12 additions & 13 deletions pkg/plugin/scheduler_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/helpers/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/framework/helpers/k8s/k8s_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading