Skip to content

Commit 47056ad

Browse files
Add envd version feature gate (#2207)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b271665 commit 47056ad

8 files changed

Lines changed: 49 additions & 61 deletions

File tree

packages/api/internal/handlers/sandbox_create.go

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
1717
"go.opentelemetry.io/otel/attribute"
1818
"go.opentelemetry.io/otel/trace"
19+
"go.uber.org/zap"
1920
"golang.org/x/net/idna"
2021

2122
"github.com/e2b-dev/infra/packages/api/internal/api"
@@ -31,6 +32,7 @@ import (
3132
"github.com/e2b-dev/infra/packages/shared/pkg/ginutils"
3233
"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
3334
"github.com/e2b-dev/infra/packages/shared/pkg/id"
35+
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
3436
sbxlogger "github.com/e2b-dev/infra/packages/shared/pkg/logger/sandbox"
3537
sandbox_network "github.com/e2b-dev/infra/packages/shared/pkg/sandbox-network"
3638
"github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
@@ -185,9 +187,15 @@ func (a *APIStore) PostSandboxes(c *gin.Context) {
185187
}
186188

187189
sbxVolumeMounts, err := convertAPIVolumesToOrchestratorVolumes(
188-
ctx, a.sqlcDB, a.featureFlags, teamInfo.ID, apiVolumeMounts,
190+
ctx, a.sqlcDB, a.featureFlags, teamInfo.ID, apiVolumeMounts, build,
189191
)
190192
if err != nil {
193+
if errors.Is(err, errVolumesNotSupported) {
194+
a.sendAPIStoreError(c, http.StatusBadRequest, err.Error())
195+
196+
return
197+
}
198+
191199
if errors.Is(err, ErrVolumeMountsDisabled) {
192200
a.sendAPIStoreError(c, http.StatusBadRequest, "Volume mounts are not enabled.")
193201

@@ -292,21 +300,36 @@ func (im InvalidVolumeMountsError) Error() string {
292300
return fmt.Sprintf("invalid mounts:\n%s", strings.Join(errs, "\n"))
293301
}
294302

295-
func convertAPIVolumesToOrchestratorVolumes(
296-
ctx context.Context,
297-
sqlClient *sqlcdb.Client,
298-
featureFlags featureFlagsClient,
299-
teamID uuid.UUID,
300-
volumeMounts []api.SandboxVolumeMount,
301-
) ([]*orchestrator.SandboxVolumeMount, error) {
303+
var errVolumesNotSupported = errors.New("volumes are not supported")
304+
305+
var errNoEnvdVersion = errors.New("no envd version provided")
306+
307+
const minEnvdVersionForVolumes = "0.5.8"
308+
309+
func convertAPIVolumesToOrchestratorVolumes(ctx context.Context, sqlClient *sqlcdb.Client, featureFlags featureFlagsClient, teamID uuid.UUID, volumeMounts []api.SandboxVolumeMount, env *queries.EnvBuild) ([]*orchestrator.SandboxVolumeMount, error) {
310+
// are any volumes configured?
302311
if len(volumeMounts) == 0 {
303312
return []*orchestrator.SandboxVolumeMount{}, nil // only b/c you should never return (nil, nil)
304313
}
305314

315+
// are volumes enabled?
306316
if !featureFlags.BoolFlag(ctx, featureflags.PersistentVolumesFlag) {
307317
return nil, ErrVolumeMountsDisabled
308318
}
309319

320+
// does your envd version support volumes?
321+
if envdVersion := sharedUtils.DerefOrDefault(env.EnvdVersion, ""); envdVersion == "" {
322+
logger.L().Warn(ctx, "envd version is unset")
323+
324+
return nil, errNoEnvdVersion
325+
} else if ok, err := sharedUtils.IsGTEVersion(envdVersion, minEnvdVersionForVolumes); err != nil {
326+
logger.L().Warn(ctx, "failed to check envd version", zap.Error(err), zap.String("envd_version", envdVersion))
327+
328+
return nil, fmt.Errorf("invalid envd version %q: %w", envdVersion, err)
329+
} else if !ok {
330+
return nil, fmt.Errorf("%w; template must be rebuilt. Template envd version is %s, must be at least %s to support volumes", errVolumesNotSupported, envdVersion, minEnvdVersionForVolumes)
331+
}
332+
310333
// get volumes from the database
311334
dbVolumesMap, err := getDBVolumesMap(ctx, sqlClient, teamID, volumeMounts)
312335
if err != nil {

packages/api/internal/handlers/sandbox_create_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/e2b-dev/infra/packages/db/queries"
1616
"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
1717
sandbox_network "github.com/e2b-dev/infra/packages/shared/pkg/sandbox-network"
18+
"github.com/e2b-dev/infra/packages/shared/pkg/utils"
1819
)
1920

2021
func TestBuildAutoResumeConfig(t *testing.T) {
@@ -453,7 +454,7 @@ func TestOrchestrator_convertVolumeMounts(t *testing.T) {
453454

454455
actual, err := convertAPIVolumesToOrchestratorVolumes(
455456
t.Context(), db.SqlcClient, ffClient,
456-
teamID, tc.input,
457+
teamID, tc.input, &queries.EnvBuild{EnvdVersion: utils.ToPtr("0.5.8")},
457458
)
458459
assert.Equal(t, tc.err, err)
459460
assert.Equal(t, tc.expected, actual)
@@ -483,7 +484,7 @@ func TestOrchestrator_convertVolumeMounts(t *testing.T) {
483484
t.Context(), db.SqlcClient, ffClient,
484485
teamID, []api.SandboxVolumeMount{
485486
{Name: "vol1", Path: "/vol1"},
486-
},
487+
}, &queries.EnvBuild{EnvdVersion: utils.ToPtr("0.5.8")},
487488
)
488489
require.NoError(t, err)
489490
assert.Equal(t, []*orchestrator.SandboxVolumeMount{

packages/envd/.goreleaser.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

packages/envd/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
processRpc "github.com/e2b-dev/infra/packages/envd/internal/services/process"
2828
processSpec "github.com/e2b-dev/infra/packages/envd/internal/services/spec/process"
2929
"github.com/e2b-dev/infra/packages/envd/internal/utils"
30+
"github.com/e2b-dev/infra/packages/envd/pkg"
3031
)
3132

3233
const (
@@ -47,8 +48,6 @@ const (
4748
)
4849

4950
var (
50-
Version = "0.5.8"
51-
5251
commitSHA string
5352

5453
isNotFC bool
@@ -134,7 +133,7 @@ func main() {
134133
parseFlags()
135134

136135
if versionFlag {
137-
fmt.Printf("%s\n", Version)
136+
fmt.Printf("%s\n", pkg.Version)
138137

139138
return
140139
}

packages/envd/pkg/version.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package pkg
2+
3+
const Version = "0.5.8"

packages/shared/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ prep-cluster:
2626
.PHONY: test
2727
test:
2828
go test -v ./pkg/...
29+
30+
.PHONY: lint
31+
lint:
32+
golangci-lint run --fix ./...

tests/integration/go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ replace github.com/e2b-dev/infra/packages/db => ../../packages/db
1010

1111
replace github.com/e2b-dev/infra/packages/clickhouse => ../../packages/clickhouse
1212

13+
replace github.com/e2b-dev/infra/packages/envd => ../../packages/envd
14+
1315
tool (
1416
github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
1517
gotest.tools/gotestsum
@@ -20,6 +22,7 @@ require (
2022
github.com/e2b-dev/infra/packages/auth v0.0.0
2123
github.com/e2b-dev/infra/packages/clickhouse v0.0.0
2224
github.com/e2b-dev/infra/packages/db v0.0.0
25+
github.com/e2b-dev/infra/packages/envd v0.0.0-00010101000000-000000000000
2326
github.com/e2b-dev/infra/packages/shared v0.0.0
2427
github.com/google/uuid v1.6.0
2528
github.com/jackc/pgx/v5 v5.7.5
@@ -124,8 +127,6 @@ require (
124127
github.com/oapi-codegen/oapi-codegen/v2 v2.5.1 // indirect
125128
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
126129
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
127-
github.com/onsi/ginkgo v1.16.5 // indirect
128-
github.com/onsi/gomega v1.38.1 // indirect
129130
github.com/opencontainers/go-digest v1.0.0 // indirect
130131
github.com/opencontainers/image-spec v1.1.1 // indirect
131132
github.com/orcaman/concurrent-map/v2 v2.0.1 // indirect

tests/integration/seed.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
authdb "github.com/e2b-dev/infra/packages/db/pkg/auth"
1616
authqueries "github.com/e2b-dev/infra/packages/db/pkg/auth/queries"
1717
dbtypes "github.com/e2b-dev/infra/packages/db/pkg/types"
18+
"github.com/e2b-dev/infra/packages/envd/pkg"
1819
"github.com/e2b-dev/infra/packages/shared/pkg/keys"
1920
"github.com/e2b-dev/infra/packages/shared/pkg/templates"
2021
)
@@ -207,7 +208,7 @@ INSERT INTO env_builds (
207208
cluster_node_id, version, created_at, updated_at
208209
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, CURRENT_TIMESTAMP)
209210
`, build.id, "FROM e2bdev/base:latest", dbtypes.BuildStatusUploaded,
210-
2, 512, 512, 1982, "vmlinux-6.1.102", "v1.12.1_a41d3fb", "0.5.0",
211+
2, 512, 512, 1982, "vmlinux-6.1.102", "v1.12.1_a41d3fb", pkg.Version,
211212
"integration-test-node", templates.TemplateV1Version, build.createdAt)
212213
} else {
213214
err = db.TestsRawSQL(ctx, `
@@ -217,7 +218,7 @@ INSERT INTO env_builds (
217218
cluster_node_id, version, updated_at
218219
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, CURRENT_TIMESTAMP)
219220
`, build.id, "FROM e2bdev/base:latest", dbtypes.BuildStatusUploaded,
220-
2, 512, 512, 1982, "vmlinux-6.1.102", "v1.12.1_a41d3fb", "0.5.0",
221+
2, 512, 512, 1982, "vmlinux-6.1.102", "v1.12.1_a41d3fb", pkg.Version,
221222
"integration-test-node", templates.TemplateV1Version)
222223
}
223224
if err != nil {

0 commit comments

Comments
 (0)