footloose icon indicating copy to clipboard operation
footloose copied to clipboard

Validate the config file

Open dlespiau opened this issue 6 years ago • 4 comments

There are a few things that could do with validation, empty fields should default to reasonable values, machine names having to have a %d in them, validate machine names are valid hostnames, that both cluster name and machine names are valid docker container names, ...

dlespiau avatar Feb 08 '19 17:02 dlespiau

If a user gets the wrong indentation or misspells a field name, we should look into how to provide errors or warnings:

cluster:
  name: test
  privateKey: $HOME/.ssh/id_rsa
machines:
- count: 1
  spec:
    image: quay.io/footloose/ubuntu18.04
    name: test-%d
    portMappings:
    - containerPort: 22
  privileged: true
  ignite:
    cpus: 4
    memory: 2GB
    copyFiles:
      /foo/bar: /foo/bar

In this example, the user made an indentation error meaning ignite: and privileged: were not part of the spec:. Footloose in its current form will silently continue ignoring these unspecified fields.

Context from user issue

stealthybox avatar Sep 06 '19 22:09 stealthybox

Here's another example of specifying a field at the wrong level with no warnings:

cluster:
  name: cluster
  privateKey: cluster-key
machines:
- spec:
    count: 1
    image: quay.io/footloose/ubuntu18.04
    name: a-%d
- spec:
    count: 1
    image: quay.io/footloose/ubuntu18.04
    name: b-%d
footloose create
INFO[0000] Docker Image: quay.io/footloose/ubuntu18.04 present locally 
INFO[0000] Docker Image: quay.io/footloose/ubuntu18.04 present locally 
# no machines created

stealthybox avatar Sep 06 '19 22:09 stealthybox

When you don't pass a top-level name, footloose reports that containers with invalid names have already been created:

cluster:
# name: cluster
  privateKey: cluster-key
machines:
- count: 1
  spec:
    image: quay.io/footloose/ubuntu18.04
    name: a-%d
- count: 1
  spec:
    image: quay.io/footloose/ubuntu18.04
    name: b-%d
footloose create
INFO[0000] Docker Image: quay.io/footloose/ubuntu18.04 present locally 
INFO[0000] Docker Image: quay.io/footloose/ubuntu18.04 present locally 
INFO[0000] Creating machine: -a-0 ...                   
INFO[0000] Machine -a-0 is already created...           
INFO[0000] Creating machine: -b-0 ...                   
INFO[0000] Machine -b-0 is already created... 

It's worth noting that I actually just expected name to default to basename $PWD like docker-compose, so this was unexpected for me.

stealthybox avatar Sep 06 '19 22:09 stealthybox

Thanks for filing these validation cases!

dlespiau avatar Sep 07 '19 08:09 dlespiau