Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
Signed-off-by: Bernhard Stadlbauer <[email protected]>
  • Loading branch information
bstadlbauer committed Dec 29, 2022
1 parent ae66bc4 commit 565c942
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 41 deletions.
3 changes: 0 additions & 3 deletions go/tasks/pluginmachinery/flytek8s/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func ToK8sEnvVar(env []*core.KeyValuePair) []v1.EnvVar {
return envVars
}


// TODO we should modify the container resources to contain a map of enum values?
// Also we should probably create tolerations / taints, but we could do that as a post process
func ToK8sResourceList(resources []*core.Resources_ResourceEntry) (v1.ResourceList, error) {
Expand Down Expand Up @@ -53,7 +52,6 @@ func ToK8sResourceList(resources []*core.Resources_ResourceEntry) (v1.ResourceLi
return k8sResources, nil
}


func ToK8sResourceRequirements(resources *core.Resources) (*v1.ResourceRequirements, error) {
res := &v1.ResourceRequirements{}
if resources == nil {
Expand All @@ -72,7 +70,6 @@ func ToK8sResourceRequirements(resources *core.Resources) (*v1.ResourceRequireme
return res, nil
}


func GetServiceAccountNameFromTaskExecutionMetadata(taskExecutionMetadata pluginmachinery_core.TaskExecutionMetadata) string {
var serviceAccount string
securityContext := taskExecutionMetadata.GetSecurityContext()
Expand Down
3 changes: 0 additions & 3 deletions go/tasks/pluginmachinery/flytek8s/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"
)


func TestToK8sEnvVar(t *testing.T) {
e := ToK8sEnvVar([]*core.KeyValuePair{
{Key: "k1", Value: "v1"},
Expand All @@ -28,7 +27,6 @@ func TestToK8sEnvVar(t *testing.T) {
assert.Empty(t, e)
}


func TestToK8sResourceList(t *testing.T) {
{
r, err := ToK8sResourceList([]*core.Resources_ResourceEntry{
Expand Down Expand Up @@ -119,7 +117,6 @@ func TestToK8sResourceRequirements(t *testing.T) {
}
}


func TestGetServiceAccountNameFromTaskExecutionMetadata(t *testing.T) {
mockTaskExecMetadata := mocks.TaskExecutionMetadata{}
mockTaskExecMetadata.OnGetSecurityContext().Return(core.SecurityContext{
Expand Down
17 changes: 6 additions & 11 deletions go/tasks/plugins/k8s/dask/dask.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ func (p daskResourceHandler) BuildResource(ctx context.Context, taskCtx pluginsC
if err != nil {
return nil, err
}
jobSpec, err := createJobSpec(*workerSpec, *schedulerSpec, *defaults)
if err != nil {
return nil, err
}
jobSpec := createJobSpec(*workerSpec, *schedulerSpec, *defaults)

job := &daskAPI.DaskJob{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -195,7 +192,7 @@ func createWorkerSpec(cluster plugins.DaskWorkerGroup, defaults defaults) (*dask
}

wokerSpec := v1.PodSpec{
Affinity: &v1.Affinity{},
Affinity: &v1.Affinity{},
Containers: []v1.Container{
{
Name: "dask-worker",
Expand All @@ -216,7 +213,7 @@ func createWorkerSpec(cluster plugins.DaskWorkerGroup, defaults defaults) (*dask

return &daskAPI.WorkerSpec{
Replicas: int(cluster.GetNumberOfWorkers()),
Spec: wokerSpec,
Spec: wokerSpec,
}, nil
}

Expand Down Expand Up @@ -289,15 +286,13 @@ func createSchedulerSpec(cluster plugins.DaskScheduler, clusterName string, defa
}, nil
}

func createJobSpec(workerSpec daskAPI.WorkerSpec, schedulerSpec daskAPI.SchedulerSpec, defaults defaults) (*daskAPI.DaskJobSpec, error) {
jobContainer := defaults.JobRunnerContainer

func createJobSpec(workerSpec daskAPI.WorkerSpec, schedulerSpec daskAPI.SchedulerSpec, defaults defaults) *daskAPI.DaskJobSpec {
return &daskAPI.DaskJobSpec{
Job: daskAPI.JobSpec{
Spec: v1.PodSpec{
RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{
jobContainer,
defaults.JobRunnerContainer,
},
},
},
Expand All @@ -310,7 +305,7 @@ func createJobSpec(workerSpec daskAPI.WorkerSpec, schedulerSpec daskAPI.Schedule
Scheduler: schedulerSpec,
},
},
}, nil
}
}

func (p daskResourceHandler) GetTaskPhase(ctx context.Context, pluginContext k8s.PluginContext, r client.Object) (pluginsCore.PhaseInfo, error) {
Expand Down
41 changes: 17 additions & 24 deletions go/tasks/plugins/k8s/dask/dask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ func dummpyDaskCustomObj(customImage string, resources *core.Resources) *plugins
}

workers := plugins.DaskWorkerGroup{
NumberOfWorkers: 10,
Image: customImage,
Resources: resources,
NumberOfWorkers: 10,
Image: customImage,
Resources: resources,
}

daskJob := plugins.DaskJob{
Scheduler: &scheduler,
Workers: &workers,
Workers: &workers,
}
return &daskJob
}

func dummyDaskTaskTemplate(id string, customImage string, resources *core.Resources) *core.TaskTemplate {
func dummyDaskTaskTemplate(customImage string, resources *core.Resources) *core.TaskTemplate {
// In a real usecase, resources will always be filled, but might be empty
if resources == nil {
resources = &core.Resources{
Expand All @@ -111,7 +111,7 @@ func dummyDaskTaskTemplate(id string, customImage string, resources *core.Resour
envVars = append(envVars, &core.KeyValuePair{Key: envVar.Name, Value: envVar.Value})
}
return &core.TaskTemplate{
Id: &core.Identifier{Name: id},
Id: &core.Identifier{Name: "test-build-resource"},
Type: daskTaskType,
Target: &core.TaskTemplate_Container{
Container: &core.Container{
Expand Down Expand Up @@ -172,10 +172,9 @@ func dummyDaskTaskContext(taskTemplate *core.TaskTemplate, resources *v1.Resourc
}

func TestBuildResourceDaskHappyPath(t *testing.T) {
taskName := "test-build-resource"
daskResourceHandler := daskResourceHandler{}

taskTemplate := dummyDaskTaskTemplate(taskName, "", nil)
taskTemplate := dummyDaskTaskTemplate("", nil)
taskContext := dummyDaskTaskContext(taskTemplate, nil, false)
resource, err := daskResourceHandler.BuildResource(context.TODO(), taskContext)
assert.Nil(t, err)
Expand All @@ -187,8 +186,8 @@ func TestBuildResourceDaskHappyPath(t *testing.T) {
var defaultNodeSelector map[string]string
var defaultAffinity *v1.Affinity
defaultWorkerAffinity := v1.Affinity{
NodeAffinity: nil,
PodAffinity: nil,
NodeAffinity: nil,
PodAffinity: nil,
PodAntiAffinity: nil,
}

Expand Down Expand Up @@ -283,7 +282,7 @@ func TestBuildResourceDaskCustomImages(t *testing.T) {
customImage := "customImage"

daskResourceHandler := daskResourceHandler{}
taskTemplate := dummyDaskTaskTemplate("test-build-resource", customImage, nil)
taskTemplate := dummyDaskTaskTemplate(customImage, nil)
taskContext := dummyDaskTaskContext(taskTemplate, &v1.ResourceRequirements{}, false)
resource, err := daskResourceHandler.BuildResource(context.TODO(), taskContext)
assert.Nil(t, err)
Expand Down Expand Up @@ -316,7 +315,7 @@ func TestBuildResourceDaskDefaultResoureRequirements(t *testing.T) {
}

daskResourceHandler := daskResourceHandler{}
taskTemplate := dummyDaskTaskTemplate("test-build-resource", "", nil)
taskTemplate := dummyDaskTaskTemplate("", nil)
taskContext := dummyDaskTaskContext(taskTemplate, &flyteWorkflowResources, false)
resource, err := daskResourceHandler.BuildResource(context.TODO(), taskContext)
assert.Nil(t, err)
Expand Down Expand Up @@ -373,7 +372,7 @@ func TestBuildResourcesDaskCustomResoureRequirements(t *testing.T) {
}

daskResourceHandler := daskResourceHandler{}
taskTemplate := dummyDaskTaskTemplate("test-build-resource", "", &protobufResources)
taskTemplate := dummyDaskTaskTemplate("", &protobufResources)
taskContext := dummyDaskTaskContext(taskTemplate, &flyteWorkflowResources, false)
resource, err := daskResourceHandler.BuildResource(context.TODO(), taskContext)
assert.Nil(t, err)
Expand All @@ -398,7 +397,6 @@ func TestBuildResourcesDaskCustomResoureRequirements(t *testing.T) {
assert.Contains(t, workerSpec.Containers[0].Args, "15G")
}


func TestBuildResourceDaskInterruptible(t *testing.T) {
var defaultNodeSelector map[string]string
var defaultAffinity *v1.Affinity
Expand All @@ -421,18 +419,15 @@ func TestBuildResourceDaskInterruptible(t *testing.T) {
},
}


assert.NoError(t, config.SetK8sPluginConfig(&config.K8sPluginConfig{
InterruptibleNodeSelector: interruptibleNodeSelector,
InterruptibleNodeSelectorRequirement: interruptibleNodeSelectorRequirement,
InterruptibleTolerations: interruptibleTolerations,
InterruptibleNodeSelector: interruptibleNodeSelector,
InterruptibleNodeSelectorRequirement: interruptibleNodeSelectorRequirement,
InterruptibleTolerations: interruptibleTolerations,
}))


taskName := "test-build-resource"
daskResourceHandler := daskResourceHandler{}

taskTemplate := dummyDaskTaskTemplate(taskName, "", nil)
taskTemplate := dummyDaskTaskTemplate("", nil)
taskContext := dummyDaskTaskContext(taskTemplate, nil, true)
resource, err := daskResourceHandler.BuildResource(context.TODO(), taskContext)
assert.Nil(t, err)
Expand Down Expand Up @@ -463,8 +458,6 @@ func TestBuildResourceDaskInterruptible(t *testing.T) {
)
}



func TestGetPropertiesDask(t *testing.T) {
daskResourceHandler := daskResourceHandler{}
expected := k8s.PluginProperties{}
Expand All @@ -480,7 +473,7 @@ func TestBuildIdentityResourceDask(t *testing.T) {
},
}

taskTemplate := dummyDaskTaskTemplate("test-build-resource", "", nil)
taskTemplate := dummyDaskTaskTemplate("", nil)
taskContext := dummyDaskTaskContext(taskTemplate, &v1.ResourceRequirements{}, false)
identityResources, err := daskResourceHandler.BuildIdentityResource(context.TODO(), taskContext.TaskExecutionMetadata())
if err != nil {
Expand Down

0 comments on commit 565c942

Please sign in to comment.