Skip to content

Commit

Permalink
node-installer: enable containerd debug logging for debug runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Meyer <[email protected]>
  • Loading branch information
katexochen committed Aug 9, 2024
1 parent 8308853 commit ccce725
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
12 changes: 11 additions & 1 deletion nodeinstaller/internal/config/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ContainerdConfig struct {
// TTRPC configuration settings
TTRPC any `toml:"ttrpc,omitempty"`
// Debug and profiling settings
Debug any `toml:"debug,omitempty"`
Debug Debug `toml:"debug,omitempty"`
// Metrics and monitoring settings
Metrics any `toml:"metrics,omitempty"`
// DisabledPlugins are IDs of plugins to disable. Disabled plugins won't be
Expand Down Expand Up @@ -96,3 +96,13 @@ type Runtime struct {
// podsandbox - means use Controller implementation from sbserver podsandbox package.
Sandboxer string `toml:"sandboxer,omitempty" json:"sandboxer,omitempty"`
}

// Debug provides debug configuration.
type Debug struct {
Address string `toml:"address,omitempty"`
UID int `toml:"uid,omitempty"`
GID int `toml:"gid,omitempty"`
Level string `toml:"level,omitempty"`
// Format represents the logging format. Supported values are 'text' and 'json'.
Format string `toml:"format,omitempty"`
}
9 changes: 7 additions & 2 deletions nodeinstaller/node-installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func run(ctx context.Context, fetcher assetFetcher, platform platforms.Platform,
return fmt.Errorf("getting runtime handler name: %w", err)
}

if err := patchContainerdConfig(runtimeHandler, runtimeBase, containerdConfigPath, platform); err != nil {
if err := patchContainerdConfig(runtimeHandler, runtimeBase, containerdConfigPath, platform, config.DebugRuntime); err != nil {
return fmt.Errorf("patching containerd configuration: %w", err)
}

Expand Down Expand Up @@ -183,14 +183,19 @@ func containerdRuntimeConfig(basePath, configPath string, platform platforms.Pla
return os.WriteFile(configPath, rawConfig, os.ModePerm)
}

func patchContainerdConfig(runtimeHandler, basePath, configPath string, platform platforms.Platform) error {
func patchContainerdConfig(runtimeHandler, basePath, configPath string, platform platforms.Platform, debugRuntime bool) error {
existingRaw, existing, err := parseExistingContainerdConfig(configPath)
if err != nil {
fmt.Printf("Failed to parse existing containerd config: %v\n", err)
fmt.Println("Creating a new containerd base config.")
existing = constants.ContainerdBaseConfig()
}

if debugRuntime {
// Enable containerd debug logging.
existing.Debug.Level = "debug"
}

// Ensure section for the snapshotter proxy plugin exists.
if existing.ProxyPlugins == nil {
existing.ProxyPlugins = make(map[string]config.ProxyPlugin)
Expand Down
2 changes: 1 addition & 1 deletion nodeinstaller/node-installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestPatchContainerdConfig(t *testing.T) {
runtimeHandler := "my-runtime"

err = patchContainerdConfig(runtimeHandler,
filepath.Join("/opt/edgeless", runtimeHandler), configPath, tc.platform)
filepath.Join("/opt/edgeless", runtimeHandler), configPath, tc.platform, true)
if tc.wantErr {
require.Error(err)
return
Expand Down
3 changes: 3 additions & 0 deletions nodeinstaller/testdata/expected-aks-clh-snp.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
version = 2

[debug]
level = 'debug'

[metrics]
address = '0.0.0.0:10257'

Expand Down
3 changes: 3 additions & 0 deletions nodeinstaller/testdata/expected-bare-metal-qemu-snp.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
version = 2

[debug]
level = 'debug'

[metrics]
address = '0.0.0.0:10257'

Expand Down
3 changes: 3 additions & 0 deletions nodeinstaller/testdata/expected-bare-metal-qemu-tdx.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
version = 2

[debug]
level = 'debug'

[metrics]
address = '0.0.0.0:10257'

Expand Down

0 comments on commit ccce725

Please sign in to comment.