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

add a flag to control whether enable kubeconfig keychain #131

Merged
merged 1 commit into from
Aug 16, 2022
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
6 changes: 5 additions & 1 deletion cmd/containerd-nydus-grpc/app/snapshotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func Start(ctx context.Context, cfg config.Config) error {
opt := ServeOptions{
ListeningSocketPath: cfg.Address,
}
auth.InitKubeSecretListener(ctx, cfg.KubeconfigPath)

if cfg.EnableKubeconfigKeychain {
auth.InitKubeSecretListener(ctx, cfg.KubeconfigPath)
}

return Serve(ctx, rs, opt, stopSignal)
}
59 changes: 34 additions & 25 deletions cmd/containerd-nydus-grpc/pkg/command/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,32 @@ const (
)

type Args struct {
Address string
LogLevel string
LogDir string
ConfigPath string
RootDir string
CacheDir string
GCPeriod string
ValidateSignature bool
PublicKeyFile string
ConvertVpcRegistry bool
NydusdBinaryPath string
NydusImageBinaryPath string
SharedDaemon bool
DaemonMode string
FsDriver string
SyncRemove bool
EnableMetrics bool
MetricsFile string
EnableStargz bool
DisableCacheManager bool
LogToStdout bool
EnableNydusOverlayFS bool
NydusdThreadNum int
CleanupOnClose bool
KubeconfigPath string
Address string
LogLevel string
LogDir string
ConfigPath string
RootDir string
CacheDir string
GCPeriod string
ValidateSignature bool
PublicKeyFile string
ConvertVpcRegistry bool
NydusdBinaryPath string
NydusImageBinaryPath string
SharedDaemon bool
DaemonMode string
FsDriver string
SyncRemove bool
EnableMetrics bool
MetricsFile string
EnableStargz bool
DisableCacheManager bool
LogToStdout bool
EnableNydusOverlayFS bool
NydusdThreadNum int
CleanupOnClose bool
KubeconfigPath string
EnableKubeconfigKeychain bool
}

type Flags struct {
Expand Down Expand Up @@ -209,6 +210,12 @@ func buildFlags(args *Args) []cli.Flag {
Usage: "path to the kubeconfig file",
Destination: &args.KubeconfigPath,
},
&cli.BoolFlag{
Name: "enable-kubeconfig-keychain",
Value: false,
Usage: "synchronize `kubernetes.io/dockerconfigjson` secret from kubernetes API server with provided `--kubeconfig-path` (default `$KUBECONFIG` or `~/.kube/config`)",
Destination: &args.EnableKubeconfigKeychain,
},
}
}

Expand Down Expand Up @@ -284,5 +291,7 @@ func Validate(args *Args, cfg *config.Config) error {
cfg.NydusdThreadNum = args.NydusdThreadNum
cfg.SyncRemove = args.SyncRemove
cfg.KubeconfigPath = args.KubeconfigPath
cfg.EnableKubeconfigKeychain = args.EnableKubeconfigKeychain

return cfg.SetupNydusBinaryPaths()
}
51 changes: 26 additions & 25 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,32 @@ const (
)

type Config struct {
Address string `toml:"-"`
ConvertVpcRegistry bool `toml:"-"`
DaemonCfgPath string `toml:"daemon_cfg_path"`
DaemonCfg DaemonConfig `toml:"-"`
PublicKeyFile string `toml:"-"`
RootDir string `toml:"-"`
CacheDir string `toml:"cache_dir"`
GCPeriod time.Duration `toml:"gc_period"`
ValidateSignature bool `toml:"validate_signature"`
NydusdBinaryPath string `toml:"nydusd_binary_path"`
NydusImageBinaryPath string `toml:"nydus_image_binary"`
DaemonMode string `toml:"daemon_mode"`
FsDriver string `toml:"daemon_backend"`
SyncRemove bool `toml:"sync_remove"`
EnableMetrics bool `toml:"enable_metrics"`
MetricsFile string `toml:"metrics_file"`
EnableStargz bool `toml:"enable_stargz"`
LogLevel string `toml:"-"`
LogDir string `toml:"log_dir"`
LogToStdout bool `toml:"log_to_stdout"`
DisableCacheManager bool `toml:"disable_cache_manager"`
EnableNydusOverlayFS bool `toml:"enable_nydus_overlayfs"`
NydusdThreadNum int `toml:"nydusd_thread_num"`
CleanupOnClose bool `toml:"cleanup_on_close"`
KubeconfigPath string `toml:"kubeconfig_path"`
Address string `toml:"-"`
ConvertVpcRegistry bool `toml:"-"`
DaemonCfgPath string `toml:"daemon_cfg_path"`
DaemonCfg DaemonConfig `toml:"-"`
PublicKeyFile string `toml:"-"`
RootDir string `toml:"-"`
CacheDir string `toml:"cache_dir"`
GCPeriod time.Duration `toml:"gc_period"`
ValidateSignature bool `toml:"validate_signature"`
NydusdBinaryPath string `toml:"nydusd_binary_path"`
NydusImageBinaryPath string `toml:"nydus_image_binary"`
DaemonMode string `toml:"daemon_mode"`
FsDriver string `toml:"daemon_backend"`
SyncRemove bool `toml:"sync_remove"`
EnableMetrics bool `toml:"enable_metrics"`
MetricsFile string `toml:"metrics_file"`
EnableStargz bool `toml:"enable_stargz"`
LogLevel string `toml:"-"`
LogDir string `toml:"log_dir"`
LogToStdout bool `toml:"log_to_stdout"`
DisableCacheManager bool `toml:"disable_cache_manager"`
EnableNydusOverlayFS bool `toml:"enable_nydus_overlayfs"`
NydusdThreadNum int `toml:"nydusd_thread_num"`
CleanupOnClose bool `toml:"cleanup_on_close"`
KubeconfigPath string `toml:"kubeconfig_path"`
EnableKubeconfigKeychain bool `toml:"enable_kubeconfig_keychain"`
}

func (c *Config) FillupWithDefaults() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (kc PassKeyChain) TokenBase() bool {
}

// FromLabels finds image pull username and secret from snapshot labels.
// Returned `nil` means no validated username and secrect are passed, it should
// Returned `nil` means no valid username and secret is passed, it should
// not override input nydusd configuration.
func FromLabels(labels map[string]string) *PassKeyChain {
u, found := labels[label.NydusImagePullUsername]
Expand Down