From 9413f1c0b1dda7099f92100f47e5b79663774e44 Mon Sep 17 00:00:00 2001 From: Pavel Sviderski Date: Thu, 24 Apr 2025 13:37:25 +1000 Subject: [PATCH] feat: define essential container spec parameters --- pkg/api/resources.go | 14 ++++++++++++++ pkg/api/service.go | 19 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 pkg/api/resources.go diff --git a/pkg/api/resources.go b/pkg/api/resources.go new file mode 100644 index 00000000..096585e8 --- /dev/null +++ b/pkg/api/resources.go @@ -0,0 +1,14 @@ +package api + +type CPUResources struct { + // Limit is the maximum amount of CPU nanocores (1000000000 = 1 CPU core) the container can use. + Limit int64 +} + +type MemoryResources struct { + // Limit is the maximum amount of memory (in bytes) the container can use. + Limit int64 + // Reservation is the minimum amount of memory (in bytes) the container needs to run efficiently. + // TODO: implement a placement constraint that checks available memory on machines. + Reservation int64 +} diff --git a/pkg/api/service.go b/pkg/api/service.go index 696a9610..1d1bca44 100644 --- a/pkg/api/service.go +++ b/pkg/api/service.go @@ -162,6 +162,8 @@ func (s *ServiceSpec) Clone() ServiceSpec { type ContainerSpec struct { // Command overrides the default CMD of the image to be executed when running a container. Command []string + // CPU resource allocation for the container. + CPU CPUResources // Entrypoint overrides the default ENTRYPOINT of the image. Entrypoint []string // Env defines the environment variables to set inside the container. @@ -169,14 +171,22 @@ type ContainerSpec struct { Image string // Run a custom init inside the container. If nil, use the daemon's configured settings. Init *bool + // LogDriver overrides the default logging driver for the container. Each Docker daemon can have its own default. + LogDriver *LogDriver + // Memory resource allocation for the container. + Memory MemoryResources + // Privileged gives extended privileges to the container. This is a security risk and should be used with caution. + Privileged bool // PullPolicy determines when to pull the image from the registry or use the image already available in the cluster. // Default is PullPolicyMissing if empty. PullPolicy string + // User overrides the default user of the image used to run the container. Format: user|UID[:group|GID]. + User string // VolumeMounts specifies how volumes are mounted into the container filesystem. // Each mount references a volume defined in ServiceSpec.Volumes. VolumeMounts []VolumeMount // Volumes is list of data volumes to mount into the container. - // TODO(lhf): replace with []VolumeMounts + // TODO(lhf): delete all usage, has been replaced with []VolumeMounts. Volumes []string } @@ -254,6 +264,13 @@ func (e EnvVars) ToSlice() []string { return env } +type LogDriver struct { + // Name of the logging driver to use. + Name string + // Options is the configuration options to pass to the logging driver. + Options map[string]string +} + type RunServiceResponse struct { ID string Name string