Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Nov 6, 2024
1 parent a6349e9 commit 10e7be1
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 284 deletions.
1 change: 0 additions & 1 deletion backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,6 @@ func (s *Service) watchModuleChanges(ctx context.Context, sendChange func(respon
if moduleSchema.Runtime == nil {
moduleSchema.Runtime = &schemapb.ModuleRuntime{
Language: message.Language,
Image: "ftl0/ftl-runner",
}
}
moduleSchema.Runtime.CreateTime = timestamppb.New(message.CreatedAt)
Expand Down
26 changes: 13 additions & 13 deletions backend/controller/scaling/k8sscaling/deployment_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,21 @@ func (r *DeploymentProvisioner) handleNewDeployment(ctx context.Context, dep *sc
}

// runner images use the same tag as the controller
rawRunnerImage := optional.Ptr(dep.Runtime.Image).Default("ftl0/ftl-runner")
var runnerImage string
if dep.Runtime.Image != "" {
if strings.HasPrefix(dep.Runtime.Image, "ftl0/") {
// Images in the ftl0 namespace should use the same tag as the controller and use the same namespace as ourImage
runnerImage = strings.ReplaceAll(ourImage, "ftl-controller", dep.Runtime.Image[len(`ftl0/`):])
} else {
// Images outside of the ftl0 namespace should use the same tag as the controller
ourImageComponents := strings.Split(ourImage, ":")
if len(ourImageComponents) != 2 {
return fmt.Errorf("expected <name>:<tag> for image name %q", ourImage)
}
runnerImage = dep.Runtime.Image + ":" + ourImageComponents[1]
}
if len(strings.Split(rawRunnerImage, ":")) != 1 {
return fmt.Errorf("module runtime's image should not contain a tag: %s", rawRunnerImage)
}
if strings.HasPrefix(rawRunnerImage, "ftl0/") {
// Images in the ftl0 namespace should use the same tag as the controller and use the same namespace as ourImage
runnerImage = strings.ReplaceAll(ourImage, "ftl-controller", rawRunnerImage[len(`ftl0/`):])
} else {
runnerImage = strings.ReplaceAll(ourImage, "controller", "runner")
// Images outside of the ftl0 namespace should use the same tag as the controller
ourImageComponents := strings.Split(ourImage, ":")
if len(ourImageComponents) != 2 {
return fmt.Errorf("expected <name>:<tag> for image name %q", ourImage)
}
runnerImage = rawRunnerImage + ":" + ourImageComponents[1]
}

deployment.Name = name
Expand Down
419 changes: 210 additions & 209 deletions backend/protos/xyz/block/ftl/v1/schema/schema.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/protos/xyz/block/ftl/v1/schema/schema.proto
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ message ModuleRuntime {
int32 min_replicas = 3;
optional string os = 4;
optional string arch = 5;
string image = 6;
optional string image = 6;
}

message Optional {
Expand Down

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

6 changes: 0 additions & 6 deletions go-runtime/goplugin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,6 @@ func build(ctx context.Context, projectRoot, stubsRoot string, buildCtx buildCon
if !ok {
return buildFailure(buildCtx, isAutomaticRebuild, buildErrs...), nil
}
module.Runtime = &schema.ModuleRuntime{
CreateTime: time.Now(),
Language: "go",
MinReplicas: 1,
Image: "ftl0/ftl-runner",
}

moduleProto := module.ToProto().(*schemapb.Module) //nolint:forcetypeassert
return &langpb.BuildEvent{
Expand Down
10 changes: 1 addition & 9 deletions internal/buildengine/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,7 @@ func handleBuildResult(ctx context.Context, projectConfig projectconfig.Config,
logger.Infof("Module built (%.2fs)", time.Since(result.StartTime).Seconds())

// write schema proto to deploy directory
sch := result.Schema
// // TODO: decide if image is passed along specially or if plugin should just return runtime info optionally and we default things here
// sch.Runtime = &schema.ModuleRuntime{
// CreateTime: time.Now(),
// Language: c.Language,
// MinReplicas: 1,
// Image: result.Image,
// }
schemaBytes, err := proto.Marshal(sch.ToProto())
schemaBytes, err := proto.Marshal(result.Schema.ToProto())
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal schema: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/buildengine/languageplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"

"connectrpc.com/connect"
Expand Down Expand Up @@ -547,6 +548,9 @@ func buildResultFromProto(result either.Either[*langpb.BuildEvent_BuildSuccess,
if err != nil {
return BuildResult{}, fmt.Errorf("failed to parse schema: %w", err)
}
if moduleSch.Runtime != nil && len(strings.Split(moduleSch.Runtime.Image, ":")) != 1 {
return BuildResult{}, fmt.Errorf("image tag not supported in runtime image: %s", moduleSch.Runtime.Image)
}

errs := langpb.ErrorsFromProto(buildSuccess.Errors)
builderrors.SortErrorsByPosition(errs)
Expand Down
8 changes: 6 additions & 2 deletions internal/schema/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ type ModuleRuntime struct {
MinReplicas int32 `protobuf:"3"`
OS string `protobuf:"4,optional"`
Arch string `protobuf:"5,optional"`
Image string `protobuf:"6"`
// Image is the name of the runner image. Defaults to "ftl0/ftl-runner".
// Must not include a tag, as FTL's version will be used as the tag.
Image string `protobuf:"6,optional"`
}

type Module struct {
Expand Down Expand Up @@ -232,14 +234,16 @@ func (m *Module) ToProto() proto.Message {
CreateTime: timestamppb.New(m.Runtime.CreateTime),
Language: m.Runtime.Language,
MinReplicas: m.Runtime.MinReplicas,
Image: m.Runtime.Image,
}
if m.Runtime.OS != "" {
runtime.Os = &m.Runtime.OS
}
if m.Runtime.Arch != "" {
runtime.Arch = &m.Runtime.Arch
}
if m.Runtime.Arch != "" {
runtime.Image = &m.Runtime.Image
}
}
return &schemapb.Module{
Pos: posToProto(m.Pos),
Expand Down

Large diffs are not rendered by default.

0 comments on commit 10e7be1

Please sign in to comment.