Skip to content

Commit

Permalink
refactor: rearrange fe.PrepareForRun() to allow passing in HLIR via f…
Browse files Browse the repository at this point in the history
…e.PrepareHLIRForRun()

Signed-off-by: Nick Mitchell <nickm@us.ibm.com>
  • Loading branch information
starpit committed Oct 11, 2024
1 parent 996889a commit ccd883d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 39 deletions.
24 changes: 3 additions & 21 deletions pkg/fe/linker/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,13 @@ import (
"os/user"

"lunchpail.io/pkg/build"
"lunchpail.io/pkg/fe/linker/queue"
"lunchpail.io/pkg/lunchpail"
)

func Configure(appname, runname string, internalS3Port int, opts build.Options) (string, queue.Spec, error) {
queueSpec, err := queue.ParseFlag(opts.Queue, runname, internalS3Port)
if err != nil {
return "", queue.Spec{}, err
}

func Configure(appname, runname string, opts build.Options) (string, error) {
user, err := user.Current()
if err != nil {
return "", queue.Spec{}, err
}

if queueSpec.Endpoint == "" {
// see charts/workstealer/templates/s3/service... the hostname of the service has a max length
queueSpec.Auto = true
queueSpec.Port = internalS3Port
queueSpec.Endpoint = fmt.Sprintf("localhost:%d", internalS3Port)
queueSpec.AccessKey = "lunchpail"
queueSpec.SecretKey = "lunchpail"
}
if queueSpec.Bucket == "" {
queueSpec.Bucket = queueSpec.Name
return "", err
}

yaml := fmt.Sprintf(`
Expand Down Expand Up @@ -58,5 +40,5 @@ lunchpail:
fmt.Fprintf(os.Stderr, "shrinkwrap app values=%s\n", yaml)
}

return yaml, queueSpec, nil
return yaml, nil
}
27 changes: 25 additions & 2 deletions pkg/fe/linker/queue/parse.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package queue

import "fmt"
import (
"fmt"
"math/rand"
)

func ParseFlag(flag, runname string) (Spec, error) {
// Assign a port for the internal S3 (TODO: we only need to do
// this if this run will be using an internal S3). We use the
// range of "ephemeral"
// ports. https://en.wikipedia.org/wiki/Ephemeral_bbport
portMin := 49152
portMax := 65535
internalS3Port := rand.Intn(portMax-portMin+1) + portMin

func ParseFlag(flag, runname string, internalS3Port int) (Spec, error) {
isRclone, spec, err := parseFlagAsRclone(flag, runname, internalS3Port)

if err != nil {
Expand All @@ -11,5 +22,17 @@ func ParseFlag(flag, runname string, internalS3Port int) (Spec, error) {
return Spec{}, fmt.Errorf("Unsupported scheme for queue: '%s'", flag)
}

if spec.Endpoint == "" {
// see charts/workstealer/templates/s3/service... the hostname of the service has a max length
spec.Auto = true
spec.Port = internalS3Port
spec.Endpoint = fmt.Sprintf("localhost:%d", internalS3Port)
spec.AccessKey = "lunchpail"
spec.SecretKey = "lunchpail"
}
if spec.Bucket == "" {
spec.Bucket = spec.Name
}

return spec, nil
}
31 changes: 15 additions & 16 deletions pkg/fe/prepare-run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package fe

import (
"fmt"
"math/rand"
"os"

"lunchpail.io/pkg/be/helm"
"lunchpail.io/pkg/build"
"lunchpail.io/pkg/fe/linker"
"lunchpail.io/pkg/fe/linker/queue"
"lunchpail.io/pkg/fe/parser"
"lunchpail.io/pkg/fe/transformer"
"lunchpail.io/pkg/ir/hlir"
"lunchpail.io/pkg/ir/llir"
)

Expand Down Expand Up @@ -39,19 +40,8 @@ func PrepareForRun(runname string, popts PrepareOptions, opts build.Options) (ll
}
}

// Assign a port for the internal S3 (TODO: we only need to do
// this if this run will be using an internal S3). We use the
// range of "ephemeral"
// ports. https://en.wikipedia.org/wiki/Ephemeral_bbport
portMin := 49152
portMax := 65535
internalS3Port := rand.Intn(portMax-portMin+1) + portMin
if verbose {
fmt.Fprintf(os.Stderr, "Using internal S3 port %d\n", internalS3Port)
}

// Set up values that will be given to the application YAML
yamlValues, queueSpec, err := linker.Configure(build.Name(), runname, internalS3Port, opts)
yamlValues, err := linker.Configure(build.Name(), runname, opts)
if err != nil {
return llir.LLIR{}, err
}
Expand All @@ -77,14 +67,23 @@ func PrepareForRun(runname string, popts PrepareOptions, opts build.Options) (ll
return llir.LLIR{}, err
}

return PrepareHLIRForRun(hlir, runname, popts, opts)
}

func PrepareHLIRForRun(ir hlir.HLIR, runname string, popts PrepareOptions, opts build.Options) (llir.LLIR, error) {
queueSpec, err := queue.ParseFlag(opts.Queue, runname)
if err != nil {
return llir.LLIR{}, err
}

if popts.NoDispatchers {
if verbose {
if opts.Log.Verbose {
fmt.Fprintln(os.Stderr, "Removing application-provided dispatchers in favor of command line inputs")
}
hlir = hlir.RemoveDispatchers()
ir = ir.RemoveDispatchers()
}

// Finally we can transform the HLIR to the low-level
// intermediate representation (LLIR).
return transformer.Lower(build.Name(), runname, hlir, queueSpec, opts)
return transformer.Lower(build.Name(), runname, ir, queueSpec, opts)
}

0 comments on commit ccd883d

Please sign in to comment.