Skip to content

Commit 4bb3325

Browse files
committed
allow setting a replica count in extensions.
1 parent 253d534 commit 4bb3325

File tree

6 files changed

+278
-268
lines changed

6 files changed

+278
-268
lines changed

internal/frontend/cuefrontendopaque/server.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,18 @@ var (
2626
"args", "env", "services", "ports", "unstable_permissions", "permissions", "probe", "probes", "security",
2727
"sidecars", "mounts", "resources", "requires", "tolerations", "annotations",
2828
"resourceLimits", "resourceRequests", "terminationGracePeriodSeconds",
29-
"extensions", "nodeSelector",
29+
"extensions", "nodeSelector", "replicas",
3030
// This is needed for the "spec" in server templates. This can't be a private field, otherwise it can't be overridden.
3131
"spec"}
3232

3333
serverFields = append(slices.Clone(extensionFields),
34-
"name", "class", "integration", "image", "imageFrom", "unstable_naming", "replicas", "spec")
34+
"name", "class", "integration", "image", "imageFrom", "unstable_naming", "spec")
3535
)
3636

3737
type cueServer struct {
3838
Name string `json:"name"`
3939
Class string `json:"class"`
4040

41-
Replicas int32 `json:"replicas"`
42-
4341
cueServerExtension
4442
}
4543

@@ -65,6 +63,8 @@ type cueServerExtension struct {
6563

6664
TerminationGracePeriodSeconds int64 `json:"terminationGracePeriodSeconds,omitempty"`
6765

66+
Replicas int32 `json:"replicas"`
67+
6868
Extensions []string `json:"extensions,omitempty"`
6969
}
7070

@@ -100,7 +100,6 @@ func parseCueServer(ctx context.Context, env *schema.Environment, pl parsing.Ear
100100
Name: bits.Name,
101101
Framework: schema.Framework_OPAQUE,
102102
RunByDefault: true,
103-
Replicas: bits.Replicas,
104103
Self: fragment,
105104
}
106105

@@ -111,9 +110,6 @@ func parseCueServer(ctx context.Context, env *schema.Environment, pl parsing.Ear
111110
out.DeployableClass = string(schema.DeployableClass_STATEFUL)
112111
case "daemonset", string(schema.DeployableClass_DAEMONSET):
113112
out.DeployableClass = string(schema.DeployableClass_DAEMONSET)
114-
if bits.Replicas > 0 {
115-
return nil, fnerrors.NewWithLocation(loc, "daemon set deployments do not support custom replica counts")
116-
}
117113
default:
118114
return nil, fnerrors.NewWithLocation(loc, "%s: server class is not supported", bits.Class)
119115
}
@@ -388,6 +384,10 @@ func parseServerExtension(ctx context.Context, env *schema.Environment, pl parsi
388384
})
389385
}
390386

387+
if bits.Replicas > 0 {
388+
out.Replicas = bits.Replicas
389+
}
390+
391391
for _, ext := range bits.Extensions {
392392
pkg := schema.PackageName(ext)
393393
if err := invariants.EnsurePackageLoaded(ctx, pl, loc.PackageName, pkg); err != nil {

internal/planning/deploy/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ func PrepareRunOpts(ctx context.Context, stack *planning.Stack, srv planning.Pla
872872
out.ErrorLocation = srv.Location
873873
out.PackageRef = srv.Proto().GetPackageRef()
874874
out.Class = schema.DeployableClass(proto.DeployableClass)
875-
out.Replicas = proto.Replicas
875+
out.Replicas = frag.Replicas
876876
out.Id = proto.Id
877877
out.Name = proto.Name
878878
out.Volumes = append(out.Volumes, frag.Volume...)

internal/planning/stack.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ func (cs *computeState) computeServerContents(ctx context.Context, rp *resourceP
364364
ps.MergedFragment.NodeSelector = append(ps.MergedFragment.NodeSelector, frag.NodeSelector...)
365365
ps.MergedFragment.Listener = append(ps.MergedFragment.Listener, frag.Listener...)
366366

367+
if frag.Replicas != 0 {
368+
if ps.MergedFragment.Replicas != 0 && frag.Replicas != ps.MergedFragment.Replicas {
369+
return fnerrors.New("incompatible replicas definition")
370+
} else if ps.MergedFragment.Replicas == 0 {
371+
ps.MergedFragment.Replicas = frag.Replicas
372+
}
373+
}
374+
367375
if frag.Permissions != nil {
368376
if ps.MergedFragment.Permissions == nil {
369377
ps.MergedFragment.Permissions = &schema.ServerPermissions{}
@@ -699,6 +707,7 @@ func evalProvision(ctx context.Context, secs is.SecretsSource, server Server, no
699707
ComputePlanWith: append(slices.Clone(node.ComputePlanWith), combinedProps.ComputePlanWith...),
700708
ServerFragments: fragments,
701709
}
710+
702711
parsed.PrepareProps.ProvisionInput = combinedProps.ProvisionInput
703712
parsed.PrepareProps.Extension = combinedProps.Extension
704713
parsed.PrepareProps.ServerExtension = combinedProps.ServerExtension

internal/versions/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"api_version": 110,
2+
"api_version": 111,
33
"minimum_api_version": 40,
44
"cache_version": 1
55
}

0 commit comments

Comments
 (0)