Skip to content

Commit

Permalink
SkyPilot updates
Browse files Browse the repository at this point in the history
Signed-off-by: aavarghese <[email protected]>
  • Loading branch information
aavarghese committed Jul 23, 2024
1 parent f4b1f45 commit cff976d
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 6 deletions.
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ require (

require (
github.com/IBM/go-sdk-core/v5 v5.16.3 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/coreos/yaml v0.0.0-20141224210557-6b16a5714269 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-openapi/errors v0.21.0 // indirect
github.com/go-openapi/strfmt v0.22.1 // indirect
Expand All @@ -38,6 +40,11 @@ require (
github.com/juju/proxy v0.0.0-20220207021845-4d37a2e6a78f // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
Expand All @@ -57,6 +64,7 @@ require (
github.com/Microsoft/hcsshim v0.12.4 // indirect
github.com/Unknwon/goconfig v1.0.0 // indirect
github.com/abbot/go-http-auth v0.4.0 // indirect
github.com/ahmetb/go-dexec v0.0.0-20240429060713-f13091af5825
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand All @@ -77,7 +85,7 @@ require (
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/cli v26.1.4+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v26.1.4+incompatible // indirect
github.com/docker/docker v26.1.4+incompatible
github.com/docker/docker-credential-helpers v0.8.2 // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
Expand All @@ -88,6 +96,7 @@ require (
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsouza/go-dockerclient v1.11.0
github.com/go-chi/chi/v5 v5.0.12 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
Expand Down
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ github.com/Unknwon/goconfig v1.0.0 h1:9IAu/BYbSLQi8puFjUQApZTxIHqSwrj5d8vpP8vTq4
github.com/Unknwon/goconfig v1.0.0/go.mod h1:wngxua9XCNjvHjDiTiV26DaKDT+0c63QR6H5hjVUUxw=
github.com/abbot/go-http-auth v0.4.0 h1:QjmvZ5gSC7jm3Zg54DqWE/T5m1t2AfDu6QlXJT0EVT0=
github.com/abbot/go-http-auth v0.4.0/go.mod h1:Cz6ARTIzApMJDzh5bRMSUou6UMSp0IEXg9km/ci7TJM=
github.com/ahmetb/go-dexec v0.0.0-20240429060713-f13091af5825 h1:TnbGurKPZ6wv4noePGiuT4XBbkwgHEiYveB0FUKgojc=
github.com/ahmetb/go-dexec v0.0.0-20240429060713-f13091af5825/go.mod h1:w2DmE+EPHh6+osqQz68ZX3J/tWT3I1ytom+K890LHi4=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
Expand Down Expand Up @@ -128,6 +130,8 @@ github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c/go.mod h1:Uw6UezgYA44ePAFQYUehOuCzmy5zmg/+nl2ZfMWGkpA=
github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQV8=
github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1 h1:ZClxb8laGDf5arXfYcAtECDFgAgHklGI8CxgjHnXKJ4=
github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand All @@ -152,6 +156,8 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsouza/go-dockerclient v1.11.0 h1:4ZAk6W7rPAtPXm7198EFqA5S68rwnNQORxlOA5OurCA=
github.com/fsouza/go-dockerclient v1.11.0/go.mod h1:0I3TQCRseuPTzqlY4Y3ajfsg2VAdMQoazrkxJTiJg8s=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA=
Expand Down Expand Up @@ -424,12 +430,20 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mittwald/go-helm-client v0.12.9 h1:tfI5ECgrbfAolA9TnlCeA5F2TEIvdsOxVmoSyW80lCI=
github.com/mittwald/go-helm-client v0.12.9/go.mod h1:ukR3Et5zbfBij7bFL1ZnLvPytsbBXCrI2qQYr2yVi9I=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc=
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/moby/sys/mountinfo v0.7.1 h1:/tTvQaSJRr2FshkhXiIpux6fQ2Zvc4j7tAhMTStAG2g=
github.com/moby/sys/mountinfo v0.7.1/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc=
github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo=
github.com/moby/sys/user v0.1.0 h1:WmZ93f5Ux6het5iituh9x2zAG7NFY9Aqi49jjE1PaQg=
github.com/moby/sys/user v0.1.0/go.mod h1:fKJhFOnsCN6xZ5gSfbM6zaHGgDJMrqt9/reuj4T7MmU=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
52 changes: 52 additions & 0 deletions pkg/be/skypilot/authenticate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package skypilot

import (
"errors"
"fmt"
"os"
"os/exec"
"path"

"github.com/IBM/go-sdk-core/v4/core"
"github.com/IBM/vpc-go-sdk/vpcv1"
)

func Authenticator(apiKey string, resourceGroupID string) (*vpcv1.VpcV1, error) {
vpcService, err := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{
Authenticator: &core.IamAuthenticator{
ApiKey: apiKey,
},
})
if err != nil {
return nil, errors.New("Error creating VPC Service with apikey" + apiKey)
}

//To access IBM’s VPC service, store the apikey and resource group in $HOME/.ibm/credentials.yaml
credsPath := os.Getenv("HOME") + "/.ibm/credentials.yaml"
err = os.MkdirAll(path.Dir(credsPath), 0755)
if err != nil {
return nil, err
}
f, err := os.Create(credsPath)
if err != nil {
return nil, err
}

defer f.Close()
d := []string{"iam_api_key: " + apiKey, "resource_group_id: " + resourceGroupID}

for _, v := range d {
_, err = fmt.Fprintln(f, v)
if err != nil {
return nil, err
}
}

cmd := exec.Command("/bin/bash", "-c", "env DOCKER_HOST=unix:///var/run/docker.sock docker run -td --rm --name sky -v ${HOME}/.sky:/root/.sky:rw -v $HOME/.ibm:/root/.ibm:rw berkeleyskypilot/skypilot-nightly")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("Internal Error starting docker container: %v", err)
}
return vpcService, nil
}
26 changes: 26 additions & 0 deletions pkg/be/skypilot/down.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package skypilot

import (
"fmt"
"os"
"os/exec"
)

func stopOrDownSkyCluster(name string, down bool) error {
cmd := exec.Command("/bin/bash", "-c", "env DOCKER_HOST=unix:///var/run/docker.sock docker exec sky sky stop --yes "+name)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("Internal Error running SkyPilot stop cmd: %v", err)
}

if down {
cmd = exec.Command("/bin/bash", "-c", "env DOCKER_HOST=unix:///var/run/docker.sock docker exec sky sky down --yes "+name+" ; docker stop sky")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("Internal Error running SkyPilot down cmd: %v", err)
}
}
return nil
}
85 changes: 85 additions & 0 deletions pkg/be/skypilot/launch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package skypilot

import (
"fmt"
"os"
"os/exec"
"strconv"

"lunchpail.io/pkg/assembly"
"lunchpail.io/pkg/be"
"lunchpail.io/pkg/ir/llir"
)

type Action string

const (
Launch Action = "launch"
Stop Action = "stop"
Down Action = "down"
)

func launchSkyCluster(name string, ir llir.LLIR, count int, zone string, profile string, imageID string) error {
appYamlString, err := ir.Marshal()
if err != nil {
return fmt.Errorf("Failed to marshall yaml: %v", err)
}

f, err := os.Create("app.yaml")
if err != nil {
return err
}
defer f.Close()
_, err = f.WriteString(appYamlString)
if err != nil {
return err
}

cmdStr := "env DOCKER_HOST=unix:///var/run/docker.sock docker exec sky sky launch -c " + name + " --workdir . --cloud ibm --num-nodes " + strconv.Itoa(count) +
" --zone " + zone + " --image-id " + imageID + " --instance-type " + profile + " --env SKYPILOT_DEBUG=1" +
" --idle-minutes-to-autostop 10 --yes \"kubectl apply -f app.yaml\""
cmd := exec.Command("/bin/bash", "-c", cmdStr)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("Internal Error running SkyPilot launch cmd: %v", err)
}
return nil
}

func SetAction(aopts assembly.Options, ir llir.LLIR, runname string, action Action) error {

if action == Stop || action == Down {
if err := stopOrDownSkyCluster(runname, action == Down); err != nil {
return err
}
} else if action == Launch {
vpcService, err := Authenticator(aopts.ApiKey, aopts.ResourceGroupID)
if err != nil {
return err
}

var workerCount int32
for _, c := range ir.Components {
for _, j := range c.Jobs {
workerCount = *j.Spec.Parallelism
}
}
//Compute number of VSIs to be provisioned and job parallelism for each VSI
parallelism, numInstances, err := be.ComputeParallelismAndInstanceCount(vpcService, aopts.Profile, workerCount)
if err != nil {
return fmt.Errorf("Failed to compute number of instances and job parallelism: %v", err)
}

for _, c := range ir.Components {
for _, j := range c.Jobs {
*j.Spec.Parallelism = int32(parallelism)
}
}

if err := launchSkyCluster(runname, ir, numInstances, aopts.Zone, aopts.Profile, aopts.ImageID); err != nil {
return err
}
}
return nil
}
10 changes: 8 additions & 2 deletions pkg/boot/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package boot
import (
"context"
"fmt"
"strings"

"golang.org/x/sync/errgroup"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"lunchpail.io/pkg/assembly"
"lunchpail.io/pkg/be"
"lunchpail.io/pkg/be/ibmcloud"
"lunchpail.io/pkg/be/kubernetes"
"lunchpail.io/pkg/be/skypilot"
"lunchpail.io/pkg/fe/linker"
"lunchpail.io/pkg/observe/runs"
)
Expand Down Expand Up @@ -103,7 +106,7 @@ func nans(opts DownOptions) (string, string) {
func Down(runname string, opts DownOptions) error {
assemblyName, namespace := nans(opts)

if runname == "" {
if strings.EqualFold(opts.TargetPlatform, be.Kubernetes.String()) && runname == "" {
singletonRun, err := runs.Singleton(assemblyName, namespace)
if err != nil {
return err
Expand All @@ -124,12 +127,15 @@ func Down(runname string, opts DownOptions) error {
upOptions.UseThisRunName = runname

var action ibmcloud.Action
var actionSP skypilot.Action
if opts.DeleteCloudResources {
action = ibmcloud.Delete
actionSP = skypilot.Down
} else {
action = ibmcloud.Stop
actionSP = skypilot.Stop
}
if err := upDown(upOptions, kubernetes.DeleteIt, action); err != nil {
if err := upDown(upOptions, kubernetes.DeleteIt, action, actionSP); err != nil {
return err
}

Expand Down
11 changes: 8 additions & 3 deletions pkg/boot/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"lunchpail.io/pkg/be"
"lunchpail.io/pkg/be/ibmcloud"
"lunchpail.io/pkg/be/kubernetes"
"lunchpail.io/pkg/be/skypilot"
"lunchpail.io/pkg/fe"
"lunchpail.io/pkg/observe/status"
)

type UpOptions = fe.CompileOptions

func upDown(opts UpOptions, operation kubernetes.Operation, action ibmcloud.Action) error {
func upDown(opts UpOptions, operation kubernetes.Operation, action ibmcloud.Action, actionSP skypilot.Action) error {
aopts := opts.AssemblyOptions
if linked, err := fe.Compile(opts); err != nil {
return err
Expand All @@ -32,13 +33,17 @@ func upDown(opts UpOptions, operation kubernetes.Operation, action ibmcloud.Acti
return status.UI(linked.Runname, status.Options{Namespace: linked.Namespace, Watch: true, Verbose: opts.Verbose, Summary: false, Nloglines: 500, IntervalSeconds: 5})
}
} else if strings.EqualFold(aopts.TargetPlatform, be.SkyPilot.String()) {
return nil //TODO
if err := skypilot.SetAction(aopts, linked.Ir, linked.Runname, actionSP); err != nil {
return err
} else if opts.Watch {
return status.UI(linked.Runname, status.Options{Namespace: linked.Namespace, Watch: true, Verbose: opts.Verbose, Summary: false, Nloglines: 500, IntervalSeconds: 5})
}
}

return nil

}

func Up(opts UpOptions) error {
return upDown(opts, kubernetes.ApplyIt, ibmcloud.Create)
return upDown(opts, kubernetes.ApplyIt, ibmcloud.Create, skypilot.Launch)
}

0 comments on commit cff976d

Please sign in to comment.