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

Support default platform config in nerdctl.toml #1184

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

YangKian
Copy link

@YangKian YangKian commented Jul 3, 2022

close #1154

Signed-off-by: Yang Qinyao yqysummy@gmail.com

type RunConfig struct {
Platform string `toml:"platform"`
Network []string `toml:"network"`
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we reuse the compose structure? https://pkg.go.dev/github.com/compose-spec/compose-go@v1.2.8/types#ServiceConfig

(Some fields such as image and container_name cannot be supported and should raise an error.)

Copy link
Member

Choose a reason for hiding this comment

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

I think we should not reuse https://pkg.go.dev/github.com/compose-spec/compose-go@v1.2.8/types#ServiceConfig.

I think this would be a little bit complicated for user. For instance, like #1128, maybe people just need config like this

[default_run_config]
network=["test"]

Copy link
Author

Choose a reason for hiding this comment

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

I'm afraid we can't reuse the compose structure. I agree with @Zheaoli ’s option, the ServiceConfig is complicated for users. Another reason is that even if the parameters have the same name, they may not have the same type in different scenarios, e.g. platform only needs to be a string in the run command, but it needs to be a []string in the build command because it needs to support parsing parameters like arm64,amd64

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Hi @AkihiroSuda, I'd like to do some double-check to make sure I understand your suggestion correctly:

[default_run_config] will be decoded as ServiceConfig and [default_build_config] will be decoded as BuildConfig, right?

And another question,

(Some fields such as image and container_name cannot be supported and should raise an error.)

which means If the user adds these unsupported fields to the [default_run_config] section of the Nerdctl.toml file, we should raise an error when decoding?

Copy link
Member

Choose a reason for hiding this comment

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

[default_run_config] will be decoded as ServiceConfig and [default_build_config] will be decoded as BuildConfig, right?

ServiceConfig contains BuildConfig, so no need to have [default_build_config].
A single default_template (per namespace) will suffice.

which means If the user adds these unsupported fields to the [default_run_config] section of the Nerdctl.toml file, we should raise an error when decoding?

Yes. At least a warning should be printed.
Like this: https://github.com/containerd/nerdctl/search?q=reflectutil.UnknownNonEmptyFields

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your patience and useful hints, I will follow the advice to complete the implementation

CgroupManager string `toml:"cgroup_manager"`
InsecureRegistry bool `toml:"insecure_registry"`
HostsDir []string `toml:"hosts_dir"`
RunConfig *RunConfig `toml:"default_run_config"`
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be map[string]... where the key is a containerd namespace string such as "default"?

Copy link
Author

Choose a reason for hiding this comment

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

I think both map[string]... and user-defined structs are legal, I find an example from https://pkg.go.dev/github.com/pelletier/go-toml@v1.9.5#section-readme and test it works.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, if I can reuse the compose structure, then here I can just use map[namespace]ServiceConfig to avoid defining multiple similar structures. I'll have some try, thanks!

Copy link
Author

Choose a reason for hiding this comment

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

I think it is more appropriate to choose parsing to structs than to maps here, so that only fields defined in structs will be parsed, and unsupported fields will be ignored in parsing even if they are mistakenly written to the configuration file by the user.

type RunConfig struct {
Platform string `toml:"platform"`
Network []string `toml:"network"`
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we should not reuse https://pkg.go.dev/github.com/compose-spec/compose-go@v1.2.8/types#ServiceConfig.

I think this would be a little bit complicated for user. For instance, like #1128, maybe people just need config like this

[default_run_config]
network=["test"]

cmd/nerdctl/main.go Outdated Show resolved Hide resolved
cmd/nerdctl/main_test.go Outdated Show resolved Hide resolved
cmd/nerdctl/main_test.go Outdated Show resolved Hide resolved
@Zheaoli
Copy link
Member

Zheaoli commented Jul 30, 2022

@YangKian Is there any update about this PR? And you may need solve the conflict first

@YangKian
Copy link
Author

@Zheaoli I'm sorry I've been a little busy at work lately and haven't had time to continue, but I should have more free time to continue writing starting next week. The ServiceConfig-based update is about 60% complete. I'll finish the rest as soon as I can, and then I think we can start the review first and finish the final update after the upstream pr merged.

@YangKian YangKian force-pushed the platform branch 2 times, most recently from ad0f6d9 to 7d70734 Compare August 31, 2022 14:38
@Zheaoli
Copy link
Member

Zheaoli commented Dec 1, 2022

@YangKian Is there any update on this PR?

@Zheaoli
Copy link
Member

Zheaoli commented Dec 1, 2022

I may take a hand on this PR base on what the owner has already done because the owner may not have enough time to do this if there is not any update on this PR before this weekend. cc @AkihiroSuda

@YangKian YangKian force-pushed the platform branch 3 times, most recently from dc08bdd to d171092 Compare December 18, 2022 14:52
Signed-off-by: YangKian <1207783292@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow default platform to be specified with NERDCTL_DEFAULT_PLATFORM / DOCKER_DEFAULT_PLATFORM
3 participants