Skip to content

Commit

Permalink
[FunctionConfig] Change sidecars type to a list of containers (#3100)
Browse files Browse the repository at this point in the history
  • Loading branch information
rokatyy committed Dec 22, 2023
1 parent 7ad2928 commit 44cbd6e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,8 @@ The `spec` section contains the requirements and attributes and has the followin
| customScalingMetricSpecs | autosv2.MetricSpec | Custom function horizontal pod autoscaling [metric spec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#metricspec-v2-autoscaling), allowing to override the default |
| devices | []string | List of devices to be made available to the function. Relevant for local platform only. (e.g. /dev/video0:/dev/video0:rwm) |
| disableDefaultHttpTrigger | *bool | Disable default http trigger creation. If flag isn’t set, value is taken from the platform config. |
| sidecars.(name).name | string | the name of the sidecar container (optional, will be enriched from the map if not present) video0:rwm) |
| sidecars.(name).image | string | the image to run in the sidecar container (required) |
| sidecars.(name).imagePullPolicy | string | one of "Always", "Never", "IfNotPresent" | |
| sidecars.(name).resources | v1.ResourceRequirements | Kubernetes resource requirements |
| sidecars.(name).ports | []v1.ContainerPort | A list of ports to expose the container |
| sidecars.(name).command | []string | A list of commands to run in the container (Entrypoint array) |
| sidecars.(name).args | []string | a list of arguments to the entrypoint |
| sidecars.(name).livenessProbe | v1.Probe | See [kubernetes docs](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/) for more info |
| sidecars.(name).readinessProbe | v1.Probe | See [kubernetes docs](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/) for more info |
| initContainers | []*v1.Container | See [kubernetes docs](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) for more info |
| sidecars | []*v1.Container | See [kubernetes docs](https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/) for more info |

<a id="spec-example"></a>

Expand Down
2 changes: 1 addition & 1 deletion pkg/functionconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ type Spec struct {

// Sidecars are containers that run alongside the function container in the same pod
// the configuration for each sidecar is the same as k8s containers
Sidecars map[string]*v1.Container `json:"sidecars,omitempty"`
Sidecars []*v1.Container `json:"sidecars,omitempty"`

// InitContainers are specialized containers that run before app containers in a Pod
// Init containers can contain utilities or setup scripts not present in an app image
Expand Down
4 changes: 2 additions & 2 deletions pkg/platform/kube/functionres/lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,11 +1138,11 @@ func (lc *lazyClient) createOrUpdateDeployment(ctx context.Context,
}

// create sidecars if provided
for sidecarName, sidecarSpec := range function.Spec.Sidecars {
for _, sidecarSpec := range function.Spec.Sidecars {
lc.logger.DebugWithCtx(ctx,
"Creating sidecar container",
"functionName", function.Name,
"sidecarName", sidecarName)
"sidecarName", sidecarSpec.Name)
lc.platformConfigurationProvider.GetPlatformConfiguration().EnrichSupplementaryContainerResources(ctx,
lc.logger,
&sidecarSpec.Resources)
Expand Down
11 changes: 3 additions & 8 deletions pkg/platform/kube/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func (p *Platform) EnrichFunctionConfig(ctx context.Context, functionConfig *fun

p.enrichFunctionPreemptionSpec(ctx, p.Config.Kube.PreemptibleNodes, functionConfig)
p.enrichInitContainersSpec(functionConfig)
p.enrichSidecarsSpec(ctx, functionConfig)
p.enrichSidecarsSpec(functionConfig)
return nil
}

Expand Down Expand Up @@ -1516,13 +1516,8 @@ func (p *Platform) enrichInitContainersSpec(functionConfig *functionconfig.Confi
}
}

func (p *Platform) enrichSidecarsSpec(ctx context.Context, functionConfig *functionconfig.Config) {

for sidecarName, sidecar := range functionConfig.Spec.Sidecars {
if sidecar.Name == "" {
sidecar.Name = sidecarName
}

func (p *Platform) enrichSidecarsSpec(functionConfig *functionconfig.Config) {
for _, sidecar := range functionConfig.Spec.Sidecars {
p.enrichContainerSpec(sidecar, functionConfig)
}
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/platform/kube/test/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1391,8 +1391,8 @@ func (suite *DeployFunctionTestSuite) TestDeployFunctionWithSidecarSanity() {
}

// create a busybox sidecar
createFunctionOptions.FunctionConfig.Spec.Sidecars = map[string]*v1.Container{
sidecarContainerName: {
createFunctionOptions.FunctionConfig.Spec.Sidecars = []*v1.Container{
{
Name: sidecarContainerName,
Image: "busybox",
Command: commands,
Expand Down Expand Up @@ -1434,7 +1434,8 @@ func (suite *DeployFunctionTestSuite) TestDeployFunctionWithInitContainers() {
}
initContainerName := "init-container-test"
createFunctionOptions.FunctionConfig.Spec.InitContainers = []*v1.Container{
{Name: initContainerName,
{
Name: initContainerName,
Image: "busybox",
Command: command,
},
Expand Down Expand Up @@ -1536,9 +1537,8 @@ def handler(context, event):
}

// create a busybox sidecar
createFunctionOptions.FunctionConfig.Spec.Sidecars = map[string]*v1.Container{
sidecarContainerName: {
Name: sidecarContainerName,
createFunctionOptions.FunctionConfig.Spec.Sidecars = []*v1.Container{
{Name: sidecarContainerName,
Image: "busybox",
Command: commands,
},
Expand Down

0 comments on commit 44cbd6e

Please sign in to comment.