Skip to content

Commit

Permalink
Add switch control features to ensure compatibility with older versio…
Browse files Browse the repository at this point in the history
…ns of Nydusd

Signed-off-by: Guijie Wang <wgj1128@mail.dlut.edu.cn>
  • Loading branch information
Guijie Wang committed Jul 20, 2023
1 parent 97631e6 commit 635dacf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const (
type Experimental struct {
EnableStargz bool `toml:"enable_stargz"`
EnableReferrerDetect bool `toml:"enable_referrer_detect"`
EnableConfigSource bool `toml:"enable_config_source"`
}

type CgroupConfig struct {
Expand Down
3 changes: 3 additions & 0 deletions config/daemonconfig/daemonconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ type DeviceConfig struct {
// We don't have to persist configuration file for fscache since its configuration
// is passed through HTTP API.
func DumpConfigFile(c interface{}, path string) error {
if config.IsConfigSourceEnabled() {
return nil
}
b, err := json.Marshal(c)
if err != nil {
return errors.Wrapf(err, "marshal config")
Expand Down
4 changes: 4 additions & 0 deletions config/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func GetDaemonProfileCPUDuration() int64 {
return globalConfig.origin.SystemControllerConfig.DebugConfig.ProfileDuration
}

func IsConfigSourceEnabled() bool {
return globalConfig.origin.Experimental.EnableConfigSource && globalConfig.origin.SystemControllerConfig.Enable
}

func ProcessConfigurations(c *SnapshotterConfig) error {
if c.LoggingConfig.LogDir == "" {
c.LoggingConfig.LogDir = filepath.Join(c.Root, logging.DefaultLogDirName)
Expand Down
10 changes: 2 additions & 8 deletions pkg/daemon/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"reflect"
"strconv"
"strings"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -124,20 +123,15 @@ func WithThreadNum(num int) Opt {
}
}

func WithConfig(id string) Opt {
func WithConfig(config string) Opt {
return func(cmd *DaemonCommand) {
config := strings.Replace("/api/v1/daemons/{id}/config", "{id}", id, 1)
cmd.Config = config
}
}

func WithConfigSource(source string) Opt {
return func(cmd *DaemonCommand) {
if source == "" {
cmd.ConfigSource = "/run/containerd-nydus/system.sock"
} else {
cmd.ConfigSource = source
}
cmd.ConfigSource = source
}
}

Expand Down
22 changes: 17 additions & 5 deletions pkg/manager/daemon_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package manager

import (
"fmt"
"os"
"os/exec"
"strings"
Expand All @@ -25,6 +26,8 @@ import (
metrics "github.com/containerd/nydus-snapshotter/pkg/metrics/tool"
)

const endpointGetDaemonConfig string = "/api/v1/daemons/%s/config"

// Fork the nydusd daemon with the process PID decided
func (m *Manager) StartDaemon(d *daemon.Daemon) error {
cmd, err := m.BuildDaemonCommand(d, "", false)
Expand Down Expand Up @@ -145,11 +148,20 @@ func (m *Manager) BuildDaemonCommand(d *daemon.Daemon, bin string, upgrade bool)
return nil, errors.Wrapf(err, "locate bootstrap %s", bootstrap)
}

cmdOpts = append(cmdOpts,
command.WithConfig(d.States.ID),
command.WithConfigSource(""),
command.WithBootstrap(bootstrap),
)
if config.IsConfigSourceEnabled() {
configApiPath := fmt.Sprintf(endpointGetDaemonConfig, d.States.ID)
cmdOpts = append(cmdOpts,
command.WithConfig(configApiPath),
command.WithConfigSource(config.SystemControllerAddress()),
command.WithBootstrap(bootstrap),
)
} else {
configFilePath := d.ConfigFile("")
cmdOpts = append(cmdOpts,
command.WithConfig(configFilePath),
command.WithBootstrap(bootstrap),
)
}
default:
return nil, errors.Errorf("invalid daemon mode %s ", d.States.DaemonMode)
}
Expand Down

0 comments on commit 635dacf

Please sign in to comment.