Skip to content

Commit

Permalink
feat(replica-spec): Update corresponding golang files based on protob…
Browse files Browse the repository at this point in the history
…uf changes

Resolves: #4408
Signed-off-by: Chi-Sheng Liu <[email protected]>
  • Loading branch information
MortalHappiness committed May 18, 2024
1 parent ed46572 commit 81bceca
Show file tree
Hide file tree
Showing 5 changed files with 1,002 additions and 576 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,35 @@ type kfDistributedReplicaSpec interface {
GetImage() string
GetResources() *core.Resources
GetRestartPolicy() kfplugins.RestartPolicy
GetCommon() *kfplugins.CommonReplicaSpec
}

type allowsCommandOverride interface {
GetCommand() []string
}

func ToReplicaSpecWithOverrides(ctx context.Context, taskCtx pluginsCore.TaskExecutionContext, rs kfDistributedReplicaSpec, primaryContainerName string, isMaster bool) (*commonOp.ReplicaSpec, error) {
var replicas int32
var image string
var resources *core.Resources
var restartPolicy kfplugins.RestartPolicy

Check warning on line 308 in flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go#L305-L308

Added lines #L305 - L308 were not covered by tests

common := rs.GetCommon()
if common != nil {
replicas = common.GetReplicas()
image = common.GetImage()
resources = common.GetResources()
restartPolicy = common.GetRestartPolicy()
} else {
replicas = rs.GetReplicas()
image = rs.GetImage()
resources = rs.GetResources()
restartPolicy = rs.GetRestartPolicy()

Check warning on line 320 in flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go#L310-L320

Added lines #L310 - L320 were not covered by tests
}

taskCtxOptions := []flytek8s.PluginTaskExecutionContextOption{}
if rs != nil && rs.GetResources() != nil {
resources, err := flytek8s.ToK8sResourceRequirements(rs.GetResources())
if resources != nil {
resources, err := flytek8s.ToK8sResourceRequirements(resources)

Check warning on line 325 in flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go#L324-L325

Added lines #L324 - L325 were not covered by tests
if err != nil {
return nil, flyteerr.Errorf(flyteerr.BadTaskSpecification, "invalid TaskSpecification on Resources [%v], Err: [%v]", resources, err.Error())
}
Expand All @@ -321,26 +340,23 @@ func ToReplicaSpecWithOverrides(ctx context.Context, taskCtx pluginsCore.TaskExe
replicaSpec.Replicas = &replicas
}

if rs != nil {
var command []string
if v, ok := rs.(allowsCommandOverride); ok {
command = v.GetCommand()
}
if err := OverrideContainerSpec(
&replicaSpec.Template.Spec,
primaryContainerName,
rs.GetImage(),
command,
); err != nil {
return nil, err
}
var command []string
if v, ok := rs.(allowsCommandOverride); ok {
command = v.GetCommand()

Check warning on line 345 in flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go#L343-L345

Added lines #L343 - L345 were not covered by tests
}
if err := OverrideContainerSpec(
&replicaSpec.Template.Spec,
primaryContainerName,
image,
command,
); err != nil {
return nil, err

Check warning on line 353 in flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go#L347-L353

Added lines #L347 - L353 were not covered by tests
}

replicaSpec.RestartPolicy = ParseRestartPolicy(rs.GetRestartPolicy())
replicaSpec.RestartPolicy = ParseRestartPolicy(restartPolicy)

Check warning on line 356 in flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go#L356

Added line #L356 was not covered by tests

if !isMaster {
replicas := rs.GetReplicas()
replicaSpec.Replicas = &replicas
}
if !isMaster {
replicaSpec.Replicas = &replicas

Check warning on line 359 in flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/k8s/kfoperators/common/common_operator.go#L358-L359

Added lines #L358 - L359 were not covered by tests
}

return replicaSpec, nil
Expand Down
Loading

0 comments on commit 81bceca

Please sign in to comment.