Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/root: Add support for configuration files #828

Closed

Conversation

HarryMichal
Copy link
Member

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

@HarryMichal HarryMichal 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
HarryMichal added a commit to HarryMichal/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
@HarryMichal HarryMichal force-pushed the cmd/add-config-file-support branch from d8ece80 to 740eb63 Compare July 3, 2021 22:05
@softwarefactory-project-zuul
Copy link

Build failed.

HarryMichal added a commit to HarryMichal/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
HarryMichal added a commit to HarryMichal/toolbox that referenced this pull request Jul 8, 2021
Some aspects of Toolbox could be configured (e.g., the default used
image).

containers#828
@HarryMichal HarryMichal force-pushed the cmd/add-config-file-support branch from 740eb63 to d751368 Compare July 8, 2021 13:43
HarryMichal added a commit to HarryMichal/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
HarryMichal added a commit to HarryMichal/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
HarryMichal added a commit to HarryMichal/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
HarryMichal added a commit to HarryMichal/toolbox that referenced this pull request Jul 8, 2021
Some aspects of Toolbox could be configured (e.g., the default used
image).

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

Build failed.

Copy link
Member

@debarshiray debarshiray left a comment

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:

data/config/toolbox.conf Outdated Show resolved Hide resolved
data/config/toolbox.conf Outdated Show resolved Hide resolved
src/cmd/root.go Outdated Show resolved Hide resolved
src/pkg/utils/utils.go Outdated Show resolved Hide resolved
src/pkg/utils/utils.go Outdated Show resolved Hide 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
Member

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

src/cmd/root.go Outdated Show resolved Hide resolved
src/pkg/utils/utils.go Outdated Show resolved Hide 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 HarryMichal/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
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
@HarryMichal
Copy link
Member Author

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

HarryMichal added a commit to HarryMichal/toolbox that referenced this pull request Jul 29, 2021
HarryMichal added a commit to HarryMichal/toolbox that referenced this pull request Jul 29, 2021
HarryMichal added a commit to HarryMichal/toolbox that referenced this pull request Jul 29, 2021
HarryMichal added a commit to HarryMichal/toolbox that referenced this pull request Jul 29, 2021
HarryMichal added a commit to HarryMichal/toolbox that referenced this pull request Jul 29, 2021
HarryMichal added a commit to HarryMichal/toolbox that referenced this pull request Jul 29, 2021
HarryMichal added a commit to HarryMichal/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
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].  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 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 Aug 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 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 Aug 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 Sep 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
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Sep 1, 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 Sep 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
containers#1080
debarshiray added a commit to debarshiray/toolbox that referenced this pull request Sep 1, 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
containers#1080
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