Skip to content

Commit

Permalink
Presto - add option to use namespace as the user (flyteorg#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
wild-endeavor authored Jun 16, 2020
1 parent 2d6cce4 commit 650bacb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions flyteplugins/go/tasks/plugins/presto/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var (
Environment: URLMustParse(""),
DefaultRoutingGroup: "adhoc",
DefaultUser: "flyte-default-user",
UseNamespaceAsUser: true,
RoutingGroupConfigs: []RoutingGroupConfig{{Name: "adhoc", Limit: 100}, {Name: "etl", Limit: 25}},
RefreshCacheConfig: RefreshCacheConfig{
Name: "presto",
Expand All @@ -101,6 +102,7 @@ type Config struct {
Environment config.URL `json:"environment" pflag:",Environment endpoint for Presto to use"`
DefaultRoutingGroup string `json:"defaultRoutingGroup" pflag:",Default Presto routing group"`
DefaultUser string `json:"defaultUser" pflag:",Default Presto user"`
UseNamespaceAsUser bool `json:"useNamespaceAsUser" pflag:",Use the K8s namespace as the user"`
RoutingGroupConfigs []RoutingGroupConfig `json:"routingGroupConfigs" pflag:"-,A list of cluster configs. Each of the configs corresponds to a service cluster"`
RefreshCacheConfig RefreshCacheConfig `json:"refreshCacheConfig" pflag:"Refresh cache config"`
ReadRateLimiterConfig RateLimiterConfig `json:"readRateLimiterConfig" pflag:"Rate limiter config for read requests going to Presto"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions flyteplugins/go/tasks/plugins/presto/config/config_flags_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions flyteplugins/go/tasks/plugins/presto/execution_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ type Query struct {
ExternalLocation string `json:"externalLocation"`
}

const PrestoSource = "flyte"

// This is the main state iteration
func HandleExecutionState(
ctx context.Context,
Expand Down Expand Up @@ -296,6 +298,11 @@ func GetNextQuery(
if err != nil {
return Query{}, err
}
var user = getUser(ctx, prestoCfg.DefaultUser)

if prestoCfg.UseNamespaceAsUser {
user = tCtx.TaskExecutionMetadata().GetNamespace()
}

statement = fmt.Sprintf(`CREATE TABLE hive.flyte_temporary_tables."%s_temp" AS %s`, tempTableName, statement)

Expand All @@ -305,8 +312,8 @@ func GetNextQuery(
RoutingGroup: resolveRoutingGroup(ctx, routingGroup, prestoCfg),
Catalog: catalog,
Schema: schema,
Source: "flyte",
User: getUser(ctx, prestoCfg.DefaultUser),
Source: PrestoSource,
User: user,
},
TempTableName: tempTableName + "_temp",
ExternalTableName: tempTableName + "_external",
Expand Down

0 comments on commit 650bacb

Please sign in to comment.