Skip to content

Commit

Permalink
Always use sha for sandbox image (flyteorg#266)
Browse files Browse the repository at this point in the history
* Always use sha for sandbox image

Signed-off-by: Yuvraj <[email protected]>

* Upgrade go 1.17

Signed-off-by: Yuvraj <[email protected]>
  • Loading branch information
yindia authored and austin362667 committed May 7, 2024
1 parent 8c6868d commit 426841b
Show file tree
Hide file tree
Showing 20 changed files with 427 additions and 195 deletions.
40 changes: 36 additions & 4 deletions flytectl/.github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
- master

jobs:
build:
name: Run tests and lint
dry-run-goreleaser:
name: Dry Run Goreleaser
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -22,23 +22,55 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
- uses: actions/setup-go@v2
with:
go-version: '1.16'
go-version: '1.17'
- name: Run GoReleaser dry run
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: --snapshot --skip-publish --rm-dist

unit-test:
name: Run unit test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: "2"
- uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
- uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: Unit Tests
env:
GO111MODULE: "on"
CI_ENV: "true"
GITHUB_TOKEN: ${{ secrets.FLYTE_BOT_PAT }}
run: make install && make test_unit_without_flag
- name: Push CodeCov
uses: codecov/[email protected]
with:
file: coverage.txt
flags: unittests
fail_ci_if_error: true


lint:
name: Run Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: "2"
- uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: Lint
env:
GO111MODULE: "on"
Expand All @@ -50,6 +82,6 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with:
go-version: '1.16'
go-version: '1.17'
- name: Go generate and diff
run: DELTA_CHECK=true make generate
2 changes: 1 addition & 1 deletion flytectl/.github/workflows/generate-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
lfs: true
- uses: actions/setup-go@v1
with:
go-version: '1.16'
go-version: '1.17'
- uses: actions/setup-python@v1
with:
python-version: 3.8
Expand Down
2 changes: 1 addition & 1 deletion flytectl/.github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fetch-depth: "0"
- uses: actions/setup-go@v2
with:
go-version: '1.16'
go-version: '1.17'
- name: Run GoReleaser dry run
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion flytectl/.github/workflows/update-flyte-component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.17
- uses: crazy-max/ghaction-import-gpg@v3
with:
gpg-private-key: ${{ secrets.FLYTE_BOT_GPG_PRIVATE_KEY }}
Expand Down
41 changes: 41 additions & 0 deletions flytectl/cmd/config/subcommand/project/project_config_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package project

import (
"errors"
"testing"

"github.com/flyteorg/flytectl/clierrors"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"

"github.com/stretchr/testify/assert"
)

Expand All @@ -25,3 +29,40 @@ func TestGetProjectSpec(t *testing.T) {
assert.Equal(t, "flytesnacks test", response.Description)
})
}

func TestMapToAdminState(t *testing.T) {
t.Run("Successful mapToAdminState with archive", func(t *testing.T) {
c := &ConfigProject{
Archive: true,
}
state, err := c.MapToAdminState()
assert.Nil(t, err)
assert.Equal(t, admin.Project_ARCHIVED, state)
})
t.Run("Successful mapToAdminState with activate", func(t *testing.T) {
c := &ConfigProject{
Activate: true,
}
state, err := c.MapToAdminState()
assert.Nil(t, err)
assert.Equal(t, admin.Project_ACTIVE, state)
})
t.Run("Invalid state", func(t *testing.T) {
c := &ConfigProject{
Activate: true,
Archive: true,
}
state, err := c.MapToAdminState()
assert.NotNil(t, err)
assert.Equal(t, errors.New(clierrors.ErrInvalidStateUpdate), err)
assert.Equal(t, admin.Project_ACTIVE, state)
})
t.Run("deprecated Flags Test", func(t *testing.T) {
c := &ConfigProject{
ActivateProject: true,
}
state, err := c.MapToAdminState()
assert.Nil(t, err)
assert.Equal(t, admin.Project_ACTIVE, state)
})
}
1 change: 1 addition & 0 deletions flytectl/cmd/config/subcommand/sandbox/config_flags.go

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

14 changes: 14 additions & 0 deletions flytectl/cmd/config/subcommand/sandbox/config_flags_test.go

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

3 changes: 3 additions & 0 deletions flytectl/cmd/config/subcommand/sandbox/sandbox_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type Config struct {
// from there.
Image string `json:"image" pflag:",Optional. Provide a fully qualified path to a Flyte compliant docker image."`

// Default value false represents that flytectl will not use latest pre release if exist
Prerelease bool `json:"pre" pflag:",Optional. Pre release Version of flyte will be used for sandbox."`

// Optionally it is possible to use local sandbox image
// If local flag pass then flytectl will not pull image from registry. Usually useful, if you want to test your local images without pushing them to a registry
ImagePullPolicy ImagePullPolicy `json:"imagePullPolicy" pflag:",Optional. Defines the image pull behavior [Always/IfNotPresent/Never]"`
Expand Down
2 changes: 1 addition & 1 deletion flytectl/cmd/register/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/flyteorg/flytestdlib/logger"

"github.com/google/go-github/v37/github"
"github.com/google/go-github/v42/github"

rconfig "github.com/flyteorg/flytectl/cmd/config/subcommand/register"
cmdCore "github.com/flyteorg/flytectl/cmd/core"
Expand Down
2 changes: 1 addition & 1 deletion flytectl/cmd/register/register_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"github.com/flyteorg/flytestdlib/logger"
"github.com/flyteorg/flytestdlib/storage"
"github.com/google/go-github/v37/github"
"github.com/google/go-github/v42/github"

"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
Expand Down
65 changes: 19 additions & 46 deletions flytectl/cmd/sandbox/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"path/filepath"
"time"

"github.com/flyteorg/flytectl/clierrors"
"github.com/flyteorg/flytectl/pkg/util/githubutil"

"github.com/avast/retry-go"
"github.com/flyteorg/flytectl/clierrors"
"github.com/olekukonko/tablewriter"
corev1api "k8s.io/api/core/v1"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
Expand Down Expand Up @@ -64,15 +64,13 @@ Specify a Flyte Sandbox image pull policy. Possible pull policy values are Alway
flytectl sandbox start --image docker.io/my-override:latest --imagePullPolicy Always
Usage
`
k8sEndpoint = "https://127.0.0.1:30086"
flyteNamespace = "flyte"
flyteRepository = "flyte"
dind = "dind"
sandboxSupportedVersion = "v0.10.0"
diskPressureTaint = "node.kubernetes.io/disk-pressure"
taintEffect = "NoSchedule"
sandboxContextName = "flyte-sandbox"
sandboxDockerContext = "default"
k8sEndpoint = "https://127.0.0.1:30086"
flyteNamespace = "flyte"
diskPressureTaint = "node.kubernetes.io/disk-pressure"
taintEffect = "NoSchedule"
sandboxContextName = "flyte-sandbox"
sandboxDockerContext = "default"
imageName = "cr.flyte.org/flyteorg/flyte-sandbox"
)

type ExecResult struct {
Expand Down Expand Up @@ -160,20 +158,23 @@ func startSandbox(ctx context.Context, cli docker.Docker, reader io.Reader) (*bu
} else if vol != nil {
volumes = append(volumes, *vol)
}

image, err := getSandboxImage(sandboxConfig.DefaultConfig.Version, sandboxConfig.DefaultConfig.Image)
if err != nil {
return nil, err
sandboxImage := sandboxConfig.DefaultConfig.Image
if len(sandboxConfig.DefaultConfig.Image) == 0 {
image, version, err := githubutil.GetSandboxImage(sandboxConfig.DefaultConfig.Version, imageName)
if err != nil {
return nil, err
}
sandboxImage = image
fmt.Printf("%v Running Flyte %s release\n", emoji.Whale, version)
}
fmt.Printf("%v pulling docker image for release %s\n", emoji.Whale, image)

if err := docker.PullDockerImage(ctx, cli, image, sandboxConfig.DefaultConfig.ImagePullPolicy); err != nil {
fmt.Printf("%v pulling docker image for release %s\n", emoji.Whale, sandboxImage)
if err := docker.PullDockerImage(ctx, cli, sandboxImage, sandboxConfig.DefaultConfig.ImagePullPolicy); err != nil {
return nil, err
}

fmt.Printf("%v booting Flyte-sandbox container\n", emoji.FactoryWorker)
exposedPorts, portBindings, _ := docker.GetSandboxPorts()
ID, err := docker.StartContainer(ctx, cli, volumes, exposedPorts, portBindings, docker.FlyteSandboxClusterName, image)
ID, err := docker.StartContainer(ctx, cli, volumes, exposedPorts, portBindings, docker.FlyteSandboxClusterName, sandboxImage)
if err != nil {
fmt.Printf("%v Something went wrong: Failed to start Sandbox container %v, Please check your docker client and try again. \n", emoji.GrimacingFace, emoji.Whale)
return nil, err
Expand All @@ -187,34 +188,6 @@ func startSandbox(ctx context.Context, cli docker.Docker, reader io.Reader) (*bu
return logReader, nil
}

// Returns the alternate image if specified, else
// if no version is specified then the Latest release of cr.flyte.org/flyteorg/flyte-sandbox:dind is used
// else cr.flyte.org/flyteorg/flyte-sandbox:dind-{SHA}, where sha is derived from the version.
func getSandboxImage(version string, alternateImage string) (string, error) {

if len(alternateImage) > 0 {
return alternateImage, nil
}

var tag = dind
if len(version) > 0 {
isGreater, err := util.IsVersionGreaterThan(version, sandboxSupportedVersion)
if err != nil {
return "", err
}
if !isGreater {
return "", fmt.Errorf("version flag only supported with flyte %s+ release", sandboxSupportedVersion)
}
sha, err := githubutil.GetSHAFromVersion(version, flyteRepository)
if err != nil {
return "", err
}
tag = fmt.Sprintf("%s-%s", dind, sha)
}

return docker.GetSandboxImage(tag), nil
}

func mountVolume(file, destination string) (*mount.Mount, error) {
if len(file) > 0 {
source, err := filepath.Abs(file)
Expand Down
Loading

0 comments on commit 426841b

Please sign in to comment.