feat: add support for cap_add and cap_drop compose keys (#238)

This commit is contained in:
Andrey Viktorov
2026-01-10 15:13:03 +11:00
committed by GitHub
parent 1ea1d15845
commit 6c2f85d38a
8 changed files with 68 additions and 0 deletions
+2
View File
@@ -43,6 +43,8 @@ func ServiceSpecFromCompose(project *types.Project, serviceName string) (api.Ser
spec := api.ServiceSpec{
Container: api.ContainerSpec{
CapAdd: service.CapAdd,
CapDrop: service.CapDrop,
Command: service.Command,
Entrypoint: service.Entrypoint,
Env: env,
+2
View File
@@ -100,6 +100,8 @@ func TestServiceSpecFromCompose(t *testing.T) {
Name: "test",
Mode: api.ServiceModeReplicated,
Container: api.ContainerSpec{
CapAdd: []string{"NET_ADMIN"},
CapDrop: []string{"ALL"},
Command: []string{"nginx", "updated", "command"},
Entrypoint: []string{"/updated-docker-entrypoint.sh"},
Env: map[string]string{
+4
View File
@@ -1,5 +1,9 @@
services:
test:
cap_add:
- NET_ADMIN
cap_drop:
- ALL
command: ["nginx", "updated", "command"]
cpus: 0.5
entrypoint: ["/updated-docker-entrypoint.sh"]
+38
View File
@@ -9,6 +9,44 @@ import (
"github.com/stretchr/testify/assert"
)
func TestEvalContainerSpecChange_ContainerCapAdd(t *testing.T) {
t.Parallel()
currentSpec := api.ServiceSpec{
Container: api.ContainerSpec{
Image: "nginx:latest",
},
}
newSpec := api.ServiceSpec{
Container: api.ContainerSpec{
Image: "nginx:latest",
CapAdd: []string{"NET_ADMIN"},
},
}
assert.Equal(t, ContainerNeedsRecreate, EvalContainerSpecChange(currentSpec, newSpec))
assert.Equal(t, ContainerNeedsRecreate, EvalContainerSpecChange(newSpec, currentSpec))
}
func TestEvalContainerSpecChange_ContainerCapDrop(t *testing.T) {
t.Parallel()
currentSpec := api.ServiceSpec{
Container: api.ContainerSpec{
Image: "nginx:latest",
},
}
newSpec := api.ServiceSpec{
Container: api.ContainerSpec{
Image: "nginx:latest",
CapDrop: []string{"ALL"},
},
}
assert.Equal(t, ContainerNeedsRecreate, EvalContainerSpecChange(currentSpec, newSpec))
assert.Equal(t, ContainerNeedsRecreate, EvalContainerSpecChange(newSpec, currentSpec))
}
func TestEvalContainerSpecChange_ContainerResources(t *testing.T) {
t.Parallel()