Skip to content

Commit

Permalink
Fix named volume error (#1496)
Browse files Browse the repository at this point in the history
* Fix named volume error

Signed-off-by: Javier López Barba <javier@okteto.com>

* Add tests to cover volume validation

Signed-off-by: Javier López Barba <javier@okteto.com>
  • Loading branch information
jLopezbarb committed May 10, 2021
1 parent 1b293c9 commit 2cec6cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/model/stack_serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (serviceRaw *ServiceRaw) ToService(svcName string, stack *Stack) (*Service,

svc.Volumes, svc.VolumeMounts = splitVolumesByType(serviceRaw.Volumes, stack)
for _, volume := range svc.VolumeMounts {
if !strings.HasPrefix(volume.LocalPath, ".") && volume.LocalPath != "" {
if !strings.HasPrefix(volume.LocalPath, ".") && !strings.HasPrefix(volume.LocalPath, "/") && volume.LocalPath != "" {
return nil, fmt.Errorf("Named volume '%s' is used in service '%s' but no declaration was found in the volumes section.", volume.ToString(), svcName)
}
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/model/stack_serializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,21 @@ func Test_validateVolumesUnmarshalling(t *testing.T) {
manifest: []byte("services:\n app:\n volumes: \n - redpanda:/var/lib/redpanda/data\n image: okteto/vote:1\n"),
expectedError: true,
},
{
name: "volume-absolute-path",
manifest: []byte("services:\n app:\n volumes: \n - /var/lib/redpanda/:/var/lib/redpanda/data\n image: okteto/vote:1\n"),
expectedError: false,
},
{
name: "volume-relative-path",
manifest: []byte("services:\n app:\n volumes: \n - /var/lib/redpanda:/var/lib/redpanda/data\n image: okteto/vote:1\n"),
expectedError: false,
},
{
name: "pv",
manifest: []byte("services:\n app:\n volumes: \n - /var/lib/redpanda/data\n image: okteto/vote:1\n"),
expectedError: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 2cec6cf

Please sign in to comment.