Skip to content

Commit d6ca68f

Browse files
committed
include error handling
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 17fe1b1 commit d6ca68f

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

pkg/inspecttypes/dockercompat/dockercompat.go

+23-12
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ type ImageMetadata struct {
9696
LastTagTime time.Time `json:",omitempty"`
9797
}
9898

99-
type LoggerLogConfig struct {
99+
type loggerLogConfig struct {
100100
Driver string `json:"driver"`
101101
Opts map[string]string `json:"opts,omitempty"`
102102
LogURI string `json:"-"`
@@ -140,7 +140,7 @@ type Container struct {
140140
type HostConfig struct {
141141
// Binds []string // List of volume bindings for this container
142142
ContainerIDFile string // File (path) where the containerId is written
143-
LogConfig LoggerLogConfig // Configuration of the logs for this container
143+
LogConfig loggerLogConfig // Configuration of the logs for this container
144144
// NetworkMode NetworkMode // Network mode to use for the container
145145
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
146146
// RestartPolicy RestartPolicy // Restart policy to be used for the container
@@ -265,7 +265,7 @@ type DeviceMapping struct {
265265
CgroupPermissions string
266266
}
267267

268-
type CPUSettings struct {
268+
type cpuSettings struct {
269269
cpuSetCpus string
270270
cpuSetMems string
271271
cpuShares uint64
@@ -378,7 +378,7 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
378378
c.HostConfig.LogConfig.LogURI = nerdctlLoguri
379379
}
380380
if logConfigJSON, ok := n.Labels[labels.LogConfig]; ok {
381-
var logConfig LoggerLogConfig
381+
var logConfig loggerLogConfig
382382
err := json.Unmarshal([]byte(logConfigJSON), &logConfig)
383383
if err != nil {
384384
return nil, fmt.Errorf("failed to unmarshal log config: %v", err)
@@ -388,14 +388,16 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
388388
c.HostConfig.LogConfig = logConfig
389389
} else {
390390
// If LogConfig label is not present, set default values
391-
c.HostConfig.LogConfig = LoggerLogConfig{
391+
c.HostConfig.LogConfig = loggerLogConfig{
392392
Driver: "json-file",
393393
Opts: make(map[string]string),
394394
}
395395
}
396396

397-
// var hostConfigLabel HostConfigLabel
398-
hostConfigLabel, _ := getHostConfigLabelFromNative(n.Labels)
397+
hostConfigLabel, err := getHostConfigLabelFromNative(n.Labels)
398+
if err != nil {
399+
return nil, fmt.Errorf("failed to fetch HostConfigLabel: %v", err)
400+
}
399401

400402
c.HostConfig.BlkioWeight = hostConfigLabel.BlkioWeight
401403
c.HostConfig.ContainerIDFile = hostConfigLabel.CidFile
@@ -485,18 +487,27 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
485487
c.HostConfig.DNSOptions = dnsSettings.DNSResolvConfOptions
486488
c.HostConfig.DNSSearch = dnsSettings.DNSSearchDomains
487489

488-
oomScoreAdj, _ := getOomScoreAdjFromNative(n.Spec.(*specs.Spec))
490+
oomScoreAdj, err := getOomScoreAdjFromNative(n.Spec.(*specs.Spec))
491+
if err != nil {
492+
return nil, fmt.Errorf("failed to get OomScoreAdj value: %v", err)
493+
}
489494
c.HostConfig.OomScoreAdj = oomScoreAdj
490495

491496
c.HostConfig.ReadonlyRootfs = false
492497
if n.Spec.(*specs.Spec).Root != nil && n.Spec.(*specs.Spec).Root.Readonly {
493498
c.HostConfig.ReadonlyRootfs = n.Spec.(*specs.Spec).Root.Readonly
494499
}
495500

496-
utsMode, _ := getUtsModeFromNative(n.Spec.(*specs.Spec))
501+
utsMode, err := getUtsModeFromNative(n.Spec.(*specs.Spec))
502+
if err != nil {
503+
return nil, fmt.Errorf("failed to get UtsMode value: %v", err)
504+
}
497505
c.HostConfig.UTSMode = utsMode
498506

499-
sysctls, _ := getSysctlFromNative(n.Spec.(*specs.Spec))
507+
sysctls, err := getSysctlFromNative(n.Spec.(*specs.Spec))
508+
if err != nil {
509+
return nil, fmt.Errorf("failed to get UtsMode value: %v", err)
510+
}
500511
c.HostConfig.Sysctls = sysctls
501512

502513
if n.Runtime.Name != "" {
@@ -680,8 +691,8 @@ func networkSettingsFromNative(n *native.NetNS, sp *specs.Spec) (*NetworkSetting
680691
return res, nil
681692
}
682693

683-
func cpuSettingsFromNative(sp *specs.Spec) (*CPUSettings, error) {
684-
res := &CPUSettings{}
694+
func cpuSettingsFromNative(sp *specs.Spec) (*cpuSettings, error) {
695+
res := &cpuSettings{}
685696
if sp.Linux != nil && sp.Linux.Resources != nil && sp.Linux.Resources.CPU != nil {
686697
if sp.Linux.Resources.CPU.Cpus != "" {
687698
res.cpuSetCpus = sp.Linux.Resources.CPU.Cpus

pkg/inspecttypes/dockercompat/dockercompat_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestContainerFromNative(t *testing.T) {
7878
HostConfig: &HostConfig{
7979
PortBindings: nat.PortMap{},
8080
GroupAdd: []string{},
81-
LogConfig: LoggerLogConfig{
81+
LogConfig: loggerLogConfig{
8282
Driver: "json-file",
8383
Opts: map[string]string{},
8484
},
@@ -163,7 +163,7 @@ func TestContainerFromNative(t *testing.T) {
163163
HostConfig: &HostConfig{
164164
PortBindings: nat.PortMap{},
165165
GroupAdd: []string{},
166-
LogConfig: LoggerLogConfig{
166+
LogConfig: loggerLogConfig{
167167
Driver: "json-file",
168168
Opts: map[string]string{},
169169
},
@@ -245,7 +245,7 @@ func TestContainerFromNative(t *testing.T) {
245245
HostConfig: &HostConfig{
246246
PortBindings: nat.PortMap{},
247247
GroupAdd: []string{},
248-
LogConfig: LoggerLogConfig{
248+
LogConfig: loggerLogConfig{
249249
Driver: "json-file",
250250
Opts: map[string]string{},
251251
},

0 commit comments

Comments
 (0)