Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 2 additions & 40 deletions cmd/nerdctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (
"strings"
"time"

"github.com/containerd/containerd"
"github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/nerdctl/pkg/config"
ncdefaults "github.com/containerd/nerdctl/pkg/defaults"
"github.com/containerd/nerdctl/pkg/logging"
"github.com/containerd/nerdctl/pkg/rootlessutil"
Expand Down Expand Up @@ -134,44 +132,8 @@ func xmain() error {
return app.Execute()
}

// Config corresponds to nerdctl.toml .
// See docs/config.md .
type Config struct {
Debug bool `toml:"debug"`
DebugFull bool `toml:"debug_full"`
Address string `toml:"address"`
Namespace string `toml:"namespace"`
Snapshotter string `toml:"snapshotter"`
CNIPath string `toml:"cni_path"`
CNINetConfPath string `toml:"cni_netconfpath"`
DataRoot string `toml:"data_root"`
CgroupManager string `toml:"cgroup_manager"`
InsecureRegistry bool `toml:"insecure_registry"`
HostsDir []string `toml:"hosts_dir"`
Experimental bool `toml:"experimental"`
}

// NewConfig creates a default Config object statically,
// without interpolating CLI flags, env vars, and toml.
func NewConfig() *Config {
return &Config{
Debug: false,
DebugFull: false,
Address: defaults.DefaultAddress,
Namespace: namespaces.Default,
Snapshotter: containerd.DefaultSnapshotter,
CNIPath: ncdefaults.CNIPath(),
CNINetConfPath: ncdefaults.CNINetConfPath(),
DataRoot: ncdefaults.DataRoot(),
CgroupManager: ncdefaults.CgroupManager(),
InsecureRegistry: false,
HostsDir: ncdefaults.HostsDirs(),
Experimental: true,
}
}

func initRootCmdFlags(rootCmd *cobra.Command, tomlPath string) (*pflag.FlagSet, error) {
cfg := NewConfig()
cfg := config.New()
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.

Is it better to init GlobalCommandOptions here and then pass it to config.New()

cfg := GlobalCommandOptions{...}
config.New(cfg)

to keep the code semantic.
Cc @Zheaoli

if r, err := os.Open(tomlPath); err == nil {
logrus.Debugf("Loading config from %q", tomlPath)
defer r.Close()
Expand Down
21 changes: 21 additions & 0 deletions pkg/api/types/global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright The containerd Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package types

import "github.com/containerd/nerdctl/pkg/config"

type GlobalCommandOptions config.Config
Comment thread
Zheaoli marked this conversation as resolved.
60 changes: 60 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright The containerd Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

import (
"github.com/containerd/containerd"
"github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/namespaces"
ncdefaults "github.com/containerd/nerdctl/pkg/defaults"
)

// Config corresponds to nerdctl.toml .
// See docs/config.md .
type Config struct {
Debug bool `toml:"debug"`
DebugFull bool `toml:"debug_full"`
Address string `toml:"address"`
Namespace string `toml:"namespace"`
Snapshotter string `toml:"snapshotter"`
CNIPath string `toml:"cni_path"`
CNINetConfPath string `toml:"cni_netconfpath"`
DataRoot string `toml:"data_root"`
CgroupManager string `toml:"cgroup_manager"`
InsecureRegistry bool `toml:"insecure_registry"`
HostsDir []string `toml:"hosts_dir"`
Experimental bool `toml:"experimental"`
}

// New creates a default Config object statically,
// without interpolating CLI flags, env vars, and toml.
func New() *Config {
return &Config{
Debug: false,
DebugFull: false,
Address: defaults.DefaultAddress,
Namespace: namespaces.Default,
Snapshotter: containerd.DefaultSnapshotter,
CNIPath: ncdefaults.CNIPath(),
CNINetConfPath: ncdefaults.CNINetConfPath(),
DataRoot: ncdefaults.DataRoot(),
CgroupManager: ncdefaults.CgroupManager(),
InsecureRegistry: false,
HostsDir: ncdefaults.HostsDirs(),
Experimental: true,
}
}