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

Commit

Permalink
Add docker credential to databricks job config
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <pingsutw@apache.org>
  • Loading branch information
pingsutw committed Jun 21, 2023
1 parent dfdf6f9 commit cbe51c2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions go/tasks/plugins/webapi/databricks/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ const (
databricksAPI string = "/api/2.0/jobs/runs"
newCluster string = "new_cluster"
dockerImage string = "docker_image"
basicAuth string = "basic_auth"
sparkConfig string = "spark_conf"
sparkPythonTask string = "spark_python_task"
pythonFile string = "python_file"
parameters string = "parameters"
url string = "url"
userName string = "username"
password string = "password"
)

// for mocking/testing purposes, and we'll override this method
Expand Down Expand Up @@ -85,9 +88,12 @@ func (p Plugin) Create(ctx context.Context, taskCtx webapi.TaskExecutionContextR
return nil, nil, err
}

token, err := taskCtx.SecretManager().Get(ctx, p.cfg.TokenKey)
if err != nil {
return nil, nil, err
var token string
if len(p.cfg.TokenKey) != 0 {
token, err = taskCtx.SecretManager().Get(ctx, p.cfg.TokenKey)
if err != nil {
return nil, nil, err
}

Check warning on line 96 in go/tasks/plugins/webapi/databricks/plugin.go

View check run for this annotation

Codecov / codecov/patch

go/tasks/plugins/webapi/databricks/plugin.go#L95-L96

Added lines #L95 - L96 were not covered by tests
}

container := taskTemplate.GetContainer()
Expand All @@ -101,6 +107,9 @@ func (p Plugin) Create(ctx context.Context, taskCtx webapi.TaskExecutionContextR
if len(sparkJob.DatabricksToken) != 0 {
token = sparkJob.DatabricksToken
}
if len(token) == 0 {
return nil, nil, errors.Errorf(pluginErrors.BadTaskSpecification, "missing databricks token")
}

Check warning on line 112 in go/tasks/plugins/webapi/databricks/plugin.go

View check run for this annotation

Codecov / codecov/patch

go/tasks/plugins/webapi/databricks/plugin.go#L111-L112

Added lines #L111 - L112 were not covered by tests
modifiedArgs, err := template.Render(ctx, container.GetArgs(), template.Parameters{
TaskExecMetadata: taskCtx.TaskExecutionMetadata(),
Inputs: taskCtx.InputReader(),
Expand All @@ -119,6 +128,11 @@ func (p Plugin) Create(ctx context.Context, taskCtx webapi.TaskExecutionContextR

if _, ok := databricksJob[newCluster]; ok {
databricksJob[newCluster].(map[string]interface{})[dockerImage] = map[string]string{url: container.Image}
dockerUserName, _ := taskCtx.SecretManager().Get(ctx, "docker-username")
dockerPassword, _ := taskCtx.SecretManager().Get(ctx, "docker-password")
if len(dockerUserName) == 0 && len(dockerPassword) == 0 {
databricksJob[newCluster].(map[string]interface{})[basicAuth] = map[string]string{userName: dockerUserName, password: dockerPassword}
}

Check warning on line 135 in go/tasks/plugins/webapi/databricks/plugin.go

View check run for this annotation

Codecov / codecov/patch

go/tasks/plugins/webapi/databricks/plugin.go#L134-L135

Added lines #L134 - L135 were not covered by tests
if len(sparkJob.SparkConf) != 0 {
databricksJob[newCluster].(map[string]interface{})[sparkConfig] = sparkJob.SparkConf
}
Expand Down

0 comments on commit cbe51c2

Please sign in to comment.