colima icon indicating copy to clipboard operation
colima copied to clipboard

Colima runs should never overwrite configuration on disk

Open purajit opened this issue 1 year ago • 5 comments

Description

Currently, running colima start with any configuration overwrites the profile on disk:

➜  colima start > /dev/null 2>&1 && yq .memory ~/.colima/default/colima.yaml
2

➜  colima stop  > /dev/null 2>&1 && colima start -m 4  > /dev/null 2>&1 && yq .memory ~/.colima/default/colima.yaml
4

➜  colima stop  > /dev/null 2>&1 && colima start -m 8  > /dev/null 2>&1 &&  yq .memory ~/.colima/default/colima.yaml
8

➜  colima start

# within container
$ free -h | head -2 | tail -1 | awk '{print $2}'
7.7Gi

This is highly undesirable unless explicitly asked for (for instance, maybe with a --save-config), since this means that a run of just colima start implies running the previous configuration, rather than running a profile you had saved. The point of a profile is to have a consistent saved config you can rely on, and any CLI args should be assumed to be overrides just for that specific run.

This is especially true when you're not using a profile, where the assumption of running colima start with no args would be to choose the documented defaults (for example, 2GB of memory).

(I also understand here that there might be a split in opinions on what the assumed behavior is, in which case I'd request at least having an option to prevent overwriting the configuration on disk, even if it doesn't default to that)

purajit avatar Feb 08 '23 19:02 purajit

I can understand your point.

Yeah, Colima basically merges the CLI flags (if specified) with the current config to generate a new config file, and thereafter starts off the (newly generated) config file.

It is kinda convenient and works for most people.

(I also understand here that there might be a split in opinions on what the assumed behavior is, in which case I'd request at least having an option to prevent overwriting the configuration on disk, even if it doesn't default to that)

I have no objections with that. What shall we call it? --temporary-config, --discard-config, --override-config=false, --save-config=false ? Naming things is hard :|

I would prefer to have a flag that the zero value defaults to the current behaviour i.e specifying it would disable overwriting the config file.

abiosoft avatar Feb 08 '23 20:02 abiosoft

I would prefer to have a flag that the zero value defaults to the current behaviour i.e specifying it would disable overwriting the config file.

Makes sense, I'm not too opinionated on that

What shall we call it?

Again, no strong opinions. I think --override-config=false or --save-config=false are the most obvious.

I haven't dug into the codebase, but how reasonable would it be to have this flag in the profile config as well, indicating that that profile should never be overwritten by CLI?

A use case would be to distribute a colima profile for everyone working in an org with some canonical configs, which won't unintentionally be changed when someone's running some experiments. If it's something you're ok with but can't prioritize, I can give it a shot.

purajit avatar Feb 08 '23 20:02 purajit

how reasonable would it be to have this flag in the profile config as well, indicating that that profile should never be overwritten by CLI?

Simply having a locked config might suffice.

# Prevent this config file from being updated by user specified CLI flags and temporary edits via the `--edit` flag.
# By default, Colima updates the config file to persist the changes specified via CLI flags or temporary edits.
# Default: false
locked: false

The other question woud be the behaviour of the --edit flag, should it be handled in similar fashion like the sample yaml snippet above?

abiosoft avatar Feb 08 '23 21:02 abiosoft

Sorry, had a busy week.

I'm happy with that configuration, and I think it makes sense to prevent --edit from altering it as well.

Btw another behavior I've noticed, which may impact even people who don't want to lock their profiles - any additional comments written get erased. So for instance, even without changing any configs, if my original config had comment explanations for why a certain default was changed, it gets erased on a plain colima start.

purajit avatar Feb 16 '23 04:02 purajit

The current behavior is extremely jarring and reads as a bug rather than a feature. Please do not touch the config unless it is asked for. And it is very natural for most people to assume overwriting the config would be opt-in rather than opt-out, so if you go with --save-config as the flag, I would vote that it should default to false . A simple colima start should simply run the default config.

pangdaxing23 avatar Feb 13 '24 14:02 pangdaxing23