Skip to content

cmd/root: Add support for configuration files - #828

Closed
martymichal wants to merge 4 commits into
containers:mainfrom
martymichal:cmd/add-config-file-support
Closed

martymichal wants to merge 4 commits into
containers:mainfrom
martymichal:cmd/add-config-file-support

Conversation

@martymichal

Copy link
Copy Markdown
Member

Some aspects of Toolbox could be configured (e.g., the default used
image). Let's enable that!

@martymichal martymichal added 5. Help Wanted Extra attention is needed 6. Major Change May cause breakage 2. Design Design discussion 3. New Feature New feature 2. Under The Hood Multiple areas of the app are influenced by this ticket labels Jul 3, 2021
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 3, 2021
Some aspects of Toolbox could be configured (e.g., the default used
image). Let's enable that!

containers#828
@martymichal
martymichal force-pushed the cmd/add-config-file-support branch from d8ece80 to 740eb63 Compare July 3, 2021 22:05
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 8, 2021
It was not apparent on first glance that the second parameter
represented a release (resp. tag).

containers#828
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 8, 2021
Some aspects of Toolbox could be configured (e.g., the default used
image).

containers#828
@martymichal
martymichal force-pushed the cmd/add-config-file-support branch from 740eb63 to d751368 Compare July 8, 2021 13:43
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 8, 2021
It was not apparent on first glance that the second parameter
represented a release (resp. tag).

containers#828
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 8, 2021
ResolveContainerAndImageNames() function does too much work. It makes
more sense to have two functions: one for image name resolving and other
for container name resolving.

containers#828
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 8, 2021
The file format is TOML[0] but the file extension is .conf to follow the
convention set by Podman.

containers#828
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 8, 2021
Some aspects of Toolbox could be configured (e.g., the default used
image).

containers#828
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 8, 2021
@martymichal
martymichal force-pushed the cmd/add-config-file-support branch from d751368 to 0df5933 Compare July 8, 2021 13:47
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@debarshiray debarshiray left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, @HarryMichal ! Some quick comments:

Comment thread data/config/toolbox.conf Resolved
Comment thread data/config/toolbox.conf Resolved
Comment thread src/cmd/root.go Resolved
Comment thread src/pkg/utils/utils.go Resolved
Comment thread src/pkg/utils/utils.go Resolved
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 13, 2021
The ResolveContainerAndImageNames() function does too much work. It
makes more sense to have two functions: one for resolving the image
name and another for resolving the container name.

containers#828
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 13, 2021
The ResolveContainerAndImageNames() function does too much work. It
makes more sense to have two functions: one for resolving the image
name and another for resolving the container name.

containers#828
containers#838
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 13, 2021
The ResolveContainerAndImageNames() function does too much work. It
makes more sense to have two functions: one for resolving the image
name and another for resolving the container name.

containers#828
containers#838
@debarshiray

Copy link
Copy Markdown
Member

I split out the break-up of ResolveContainerAndImageNames into #838

Comment thread src/cmd/root.go Resolved
Comment thread src/pkg/utils/utils.go Resolved
Comment thread data/config/toolbox.conf Resolved
Figuring out the default toolbox image for a given distribution only
needs to happen as part of resolving the final toolbox image name from
the given command line options.

Fallout from c990fb4

containers#828
debarshiray pushed a commit to martymichal/toolbox that referenced this pull request Jul 21, 2021
The file format is TOML[0] but the file extension is .conf to follow the
convention set by Podman.

containers#828
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
Figuring out the default toolbox image for a given distribution only
needs to happen as part of resolving the final toolbox image name from
the given command line options.

Fallout from c990fb4

containers#828
containers#851
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
A subsequent commit will add support for configuration files, which can
override the default toolbox image. Since this override affects all
commands, it effectively ends up adding a fourth option to the 'enter'
command, other than the existing options to change the distribution,
release and container. This makes it a lot more difficult to reason
when only 'toolbox enter --release N' is enough to enter the created
container.

containers#828
containers#851
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
The file format is TOML[0] but the file extension is .conf to follow the
convention set by Podman.

containers#828
containers#851
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
It looks like there are some oddities with Viper [1]. The errors can't
be examined with errors.As [2] and Viper doesn't actually throw
ConfigFileNotFoundError if a configuration file is not found. Secondly,
there's no way to find out if a key was actually specified in a
configuration file. The InConfig API doesn't return 'true' even if a
key was mentioned in a configuration file, and the IsSet API returns
'true' even if the key was only set via SetDefault in the code.

[1] https://pkg.go.dev/github.com/spf13/viper
[2] https://blog.golang.org/go1.13-errors

containers#828
containers#851
@debarshiray

Copy link
Copy Markdown
Member

I split out everything, other than the tests in #851

I left out the tests because they seem to be incomplete and not do anything.

debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
A subsequent commit will add support for configuration files, which can
override the default toolbox image. Since this override affects all
commands, it effectively ends up adding a fourth option to the 'enter'
command, other than the existing options to change the distribution,
release and container. This makes it a lot more difficult to reason
when only 'toolbox enter --release N' is enough to enter the created
container.

containers#828
containers#851
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
The file format is TOML[0] but the file extension is .conf to follow the
convention set by Podman.

containers#828
containers#851
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
It looks like there are some oddities with Viper [1]. The errors can't
be examined with errors.As [2] and Viper doesn't actually throw
ConfigFileNotFoundError if a configuration file is not found. Secondly,
there's no way to find out if a key was actually specified in a
configuration file. The InConfig API doesn't return 'true' even if a
key was mentioned in a configuration file, and the IsSet API returns
'true' even if the key was only set via SetDefault in the code.

Some changes by Debarshi Ray.

[1] https://pkg.go.dev/github.com/spf13/viper
[2] https://blog.golang.org/go1.13-errors

containers#828
containers#851
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
Figuring out the default toolbox image for a given distribution only
needs to happen as part of resolving the final toolbox image name from
the given command line options.

Fallout from c990fb4

containers#828
containers#851
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
A subsequent commit will add support for configuration files, which can
override the default toolbox image. Since this override affects all
commands, it effectively ends up adding a fourth option to the 'enter'
command, other than the existing options to change the distribution,
release and container. This makes it a lot more difficult to reason
when only 'toolbox enter --release N' is enough to enter the created
container.

containers#828
containers#851
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
The file format is TOML[0] but the file extension is .conf to follow the
convention set by Podman.

containers#828
containers#851
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
It looks like there are some oddities with Viper [1]. The errors can't
be examined with errors.As [2] and Viper doesn't actually throw
ConfigFileNotFoundError if a configuration file is not found. Secondly,
there's no way to find out if a key was actually specified in a
configuration file. The InConfig API doesn't return 'true' even if a
key was mentioned in a configuration file, and the IsSet API returns
'true' even if the key was only set via SetDefault in the code.

Some changes by Debarshi Ray.

[1] https://pkg.go.dev/github.com/spf13/viper
[2] https://blog.golang.org/go1.13-errors

containers#828
containers#851
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
The file format is TOML[0] but the file extension is .conf to follow the
convention set by Podman.

containers#828
containers#851
debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Jul 23, 2021
It looks like there are some oddities with Viper [1]. The errors can't
be examined with errors.As [2] and Viper doesn't actually throw
ConfigFileNotFoundError if a configuration file is not found. Secondly,
there's no way to find out if a key was actually specified in a
configuration file. The InConfig API doesn't return 'true' even if a
key was mentioned in a configuration file, and the IsSet API returns
'true' even if the key was only set via SetDefault in the code.

Some changes by Debarshi Ray.

[1] https://pkg.go.dev/github.com/spf13/viper
[2] https://blog.golang.org/go1.13-errors

containers#828
containers#851
@martymichal

Copy link
Copy Markdown
Member Author

Closing. The work on tests can be done in a separate PR.

martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 29, 2021
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 29, 2021
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 29, 2021
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 29, 2021
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 29, 2021
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 29, 2021
martymichal added a commit to martymichal/toolbox that referenced this pull request Jul 29, 2021
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jul 31, 2022
The idea of splitting ResolveContainerAndImageNames into two public
functions [1] didn't turn out to be so useful [2].  Splitting things
even further might make it worse.  A better approach might be to
(re-)unify the code further.

This is the first step towards that.

This reverts the following commits:
  * 5c8ad7a
  * 02f45fd
  * 8b6418d

... but retains the test cases that were not tied to the changes in
those commits.

[1] Commit fd75608
    containers#828
    containers#838

[2] containers#977

containers#937
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Jul 31, 2022
The idea of splitting ResolveContainerAndImageNames into two public
functions [1] didn't turn out to be so useful [2].  It pushed the
burden on the callers, who needed to carefully call the split
functions in the right order, because the container, distro, image and
release values are very tightly related.  This opens the door for
mistakes.

A better approach would be to restore ResolveContainerAndImageNames as
the single public API.  If necessary it could be internally split into
smaller private functions.  It would keep things simple for the
callers.

Note that this commit doesn't include the private split.  If necessary,
it can be done in future.

This reverts commit fd75608.

[1] Commit fd75608
    containers#828
    containers#838

[2] containers#977

containers#937
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Aug 1, 2022
The idea of splitting ResolveContainerAndImageNames into two public
functions [1] didn't turn out to be so useful [2].  Splitting things
even further might make it worse.  A better approach might be to
(re-)unify the code further.

This is the first step towards that.

This reverts the following commits:
  * 5c8ad7a
  * 02f45fd
  * 8b6418d

... but retains the test cases that were not tied to the changes in
those commits.

[1] Commit fd75608
    containers#828
    containers#838

[2] containers#977

containers#937
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. Design Design discussion 2. Under The Hood Multiple areas of the app are influenced by this ticket 3. New Feature New feature 5. Help Wanted Extra attention is needed 6. Major Change May cause breakage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants