mirror of
https://github.com/psviderski/uncloud.git
synced 2026-10-06 13:18:58 +00:00
feat(runtime-templates): add support for runtime templates in bind mounts (#412)
This commit is contained in:
1 parent
88dda435e7
commit
5c33e4be86
17 files changed
+571
-10
No files matched your search
+18
-2
@@ -38,9 +38,10 @@ func assertServiceMatchesSpec(t *testing.T, svc api.Service, spec api.ServiceSpe
|
||||
}
|
||||
|
||||
func assertContainerMatchesSpec(t *testing.T, ctr api.ServiceContainer, spec api.ServiceSpec) {
|
||||
spec = spec.SetDefaults()
|
||||
status := deploy.EvalContainerSpecChange(ctr.ServiceSpec, spec)
|
||||
desiredSpec := spec.SetDefaults()
|
||||
status := deploy.EvalContainerSpecChange(ctr.ServiceSpec, desiredSpec)
|
||||
assert.Equal(t, deploy.ContainerUpToDate, status)
|
||||
spec = renderRuntimeTemplatesForContainer(t, desiredSpec, ctr.Name)
|
||||
|
||||
// Verify labels.
|
||||
assert.True(t, api.ValidateServiceID(ctr.Config.Labels[api.LabelServiceID]))
|
||||
@@ -148,8 +149,10 @@ func assertHookContainersMatchSpec(t *testing.T, svc api.Service, spec api.Servi
|
||||
t.Helper()
|
||||
require.NotEmpty(t, svc.HookContainers, "Expected at least one hook container")
|
||||
|
||||
desiredSpec := spec
|
||||
for _, mc := range svc.HookContainers {
|
||||
ctr := mc.Container
|
||||
spec := renderRuntimeTemplatesForContainer(t, desiredSpec, ctr.Name)
|
||||
|
||||
// Verify labels.
|
||||
assert.True(t, api.ValidateServiceID(ctr.Config.Labels[api.LabelServiceID]))
|
||||
@@ -215,6 +218,19 @@ func assertHookContainersMatchSpec(t *testing.T, svc api.Service, spec api.Servi
|
||||
}
|
||||
}
|
||||
|
||||
func renderRuntimeTemplatesForContainer(
|
||||
t *testing.T, spec api.ServiceSpec, containerName string,
|
||||
) api.ServiceSpec {
|
||||
t.Helper()
|
||||
|
||||
renderedSpec, err := spec.RenderRuntimeTemplates(api.RuntimeTemplateContext{
|
||||
Container: api.RuntimeTemplateContainerContext{Name: containerName},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
return renderedSpec
|
||||
}
|
||||
|
||||
func assertContainerMountsMatchSpec(t *testing.T, mounts []mount.Mount, spec api.ServiceSpec) {
|
||||
expectedMounts, err := machinedocker.ToDockerMounts(spec.Volumes, spec.Container.VolumeMounts)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -282,6 +282,11 @@ func TestComposeDeployment(t *testing.T) {
|
||||
ContainerPath: "/host/etc/passwd",
|
||||
ReadOnly: true,
|
||||
},
|
||||
{
|
||||
VolumeName: "bind-b78f4a1e9255dca2997ee1006f32b0fc168bac785cf2440f00aa84c61e58f6fb",
|
||||
ContainerPath: "/host/{{.Container.Name}}",
|
||||
ReadOnly: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Volumes: []api.VolumeSpec{
|
||||
@@ -297,6 +302,14 @@ func TestComposeDeployment(t *testing.T) {
|
||||
CreateHostPath: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "bind-b78f4a1e9255dca2997ee1006f32b0fc168bac785cf2440f00aa84c61e58f6fb",
|
||||
Type: api.VolumeTypeBind,
|
||||
BindOptions: &api.BindOptions{
|
||||
HostPath: "/tmp/uncloud-e2e/{{.Container.Name}}",
|
||||
CreateHostPath: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Replicas: 3,
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ services:
|
||||
volumes:
|
||||
- test-compose-volumes-data1:/data1
|
||||
- /etc/passwd:/host/etc/passwd:ro
|
||||
- "/tmp/uncloud-e2e/{{.Container.Name}}:/host/{{.Container.Name}}:ro"
|
||||
deploy:
|
||||
replicas: 3
|
||||
test-compose-volumes-service2:
|
||||
|
||||
Reference in new issue
Block a user