Skip to content

Commit

Permalink
fix: check if podSpec is not nil
Browse files Browse the repository at this point in the history
Signed-off-by: machichima <nary12321@gmail.com>
  • Loading branch information
machichima committed Feb 12, 2025
1 parent a783bdd commit c7dbcfb
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions flyteplugins/go/tasks/plugins/k8s/spark/spark.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,24 @@ func createDriverSpec(ctx context.Context, taskCtx pluginsCore.TaskExecutionCont

driverPod := sparkJob.GetDriverPod()
if driverPod != nil {
var customPodSpec *v1.PodSpec
if driverPod.GetPodSpec() != nil {
var customPodSpec *v1.PodSpec

err = utils.UnmarshalStructToObj(driverPod.GetPodSpec(), &customPodSpec)
if err != nil {
return nil, errors.Errorf(errors.BadTaskSpecification,
"Unable to unmarshal driver pod spec [%v], Err: [%v]", driverPod.GetPodSpec(), err.Error())
err = utils.UnmarshalStructToObj(driverPod.GetPodSpec(), &customPodSpec)
if err != nil {
return nil, errors.Errorf(errors.BadTaskSpecification,
"Unable to unmarshal driver pod spec [%v], Err: [%v]", driverPod.GetPodSpec(), err.Error())
}

Check warning on line 210 in flyteplugins/go/tasks/plugins/k8s/spark/spark.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/spark/spark.go#L208-L210

Added lines #L208 - L210 were not covered by tests

podSpec, err = flytek8s.MergePodSpecs(podSpec, customPodSpec, primaryContainerName, "")
if err != nil {
return nil, err
}

Check warning on line 215 in flyteplugins/go/tasks/plugins/k8s/spark/spark.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/spark/spark.go#L214-L215

Added lines #L214 - L215 were not covered by tests
}

if driverPod.GetPrimaryContainerName() != "" {
primaryContainerName = driverPod.GetPrimaryContainerName()
}

Check warning on line 220 in flyteplugins/go/tasks/plugins/k8s/spark/spark.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/spark/spark.go#L219-L220

Added lines #L219 - L220 were not covered by tests

podSpec, err = flytek8s.MergePodSpecs(podSpec, customPodSpec, primaryContainerName, "")
if err != nil {
return nil, err
}
}

primaryContainer, err := flytek8s.GetContainer(podSpec, primaryContainerName)
Expand Down Expand Up @@ -251,22 +253,23 @@ func createExecutorSpec(ctx context.Context, taskCtx pluginsCore.TaskExecutionCo

executorPod := sparkJob.GetExecutorPod()
if executorPod != nil {
var customPodSpec *v1.PodSpec
if executorPod.GetPodSpec() != nil {
var customPodSpec *v1.PodSpec

err = utils.UnmarshalStructToObj(executorPod.GetPodSpec(), &customPodSpec)
if err != nil {
return nil, errors.Errorf(errors.BadTaskSpecification,
"Unable to unmarshal executor pod spec [%v], Err: [%v]", executorPod.GetPodSpec(), err.Error())
}
err = utils.UnmarshalStructToObj(executorPod.GetPodSpec(), &customPodSpec)
if err != nil {
return nil, errors.Errorf(errors.BadTaskSpecification,
"Unable to unmarshal executor pod spec [%v], Err: [%v]", executorPod.GetPodSpec(), err.Error())
}

Check warning on line 263 in flyteplugins/go/tasks/plugins/k8s/spark/spark.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/spark/spark.go#L261-L263

Added lines #L261 - L263 were not covered by tests

podSpec, err = flytek8s.MergePodSpecs(podSpec, customPodSpec, primaryContainerName, "")
if err != nil {
return nil, err
}

Check warning on line 268 in flyteplugins/go/tasks/plugins/k8s/spark/spark.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/spark/spark.go#L267-L268

Added lines #L267 - L268 were not covered by tests
}
if executorPod.GetPrimaryContainerName() != "" {
primaryContainerName = executorPod.GetPrimaryContainerName()
}

Check warning on line 272 in flyteplugins/go/tasks/plugins/k8s/spark/spark.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/spark/spark.go#L271-L272

Added lines #L271 - L272 were not covered by tests

podSpec, err = flytek8s.MergePodSpecs(podSpec, customPodSpec, primaryContainerName, "")
if err != nil {
return nil, err
}
}

primaryContainer, err := flytek8s.GetContainer(podSpec, primaryContainerName)
Expand Down

0 comments on commit c7dbcfb

Please sign in to comment.