Skip to content

Commit 10c8b57

Browse files
committed
config_linux.go: replace omitempty with omitzero
For some fields (like nested struct fields), omitempty has no effect but omitzero does. Let's use it (everywhere -- for consistency). NOTE it might result in some compatibility issues since now zero-only fields are not serialized. Since linter-extra thinks it's a new code, add some naming exceptions. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 9c9b700 commit 10c8b57

File tree

2 files changed

+40
-38
lines changed

2 files changed

+40
-38
lines changed

.golangci-extra.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ linters:
2323
# Legacy names we can't change without breaking compatibility.
2424
- path: stats.go
2525
text: "(type|struct field) (CpuUsage|CpuStats) should be "
26+
- path: config_linux.go
27+
text: "struct field (CpuShares|CpuQuota|CpuBurst|CpuPeriod|CpuRtRuntime|CpuWeight) should be "

config_linux.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,132 +16,132 @@ const (
1616
// Cgroup holds properties of a cgroup on Linux.
1717
type Cgroup struct {
1818
// Name specifies the name of the cgroup
19-
Name string `json:"name,omitempty"`
19+
Name string `json:"name,omitzero"`
2020

2121
// Parent specifies the name of parent of cgroup or slice
22-
Parent string `json:"parent,omitempty"`
22+
Parent string `json:"parent,omitzero"`
2323

2424
// Path specifies the path to cgroups that are created and/or joined by the container.
2525
// The path is assumed to be relative to the host system cgroup mountpoint.
26-
Path string `json:"path,omitempty"`
26+
Path string `json:"path,omitzero"`
2727

2828
// ScopePrefix describes prefix for the scope name.
29-
ScopePrefix string `json:"scope_prefix,omitempty"`
29+
ScopePrefix string `json:"scope_prefix,omitzero"`
3030

3131
// Resources contains various cgroups settings to apply.
3232
*Resources
3333

3434
// Systemd tells if systemd should be used to manage cgroups.
35-
Systemd bool `json:"Systemd,omitempty"`
35+
Systemd bool `json:"Systemd,omitzero"`
3636

3737
// SystemdProps are any additional properties for systemd,
3838
// derived from org.systemd.property.xxx annotations.
3939
// Ignored unless systemd is used for managing cgroups.
4040
SystemdProps []systemdDbus.Property `json:"-"`
4141

4242
// Rootless tells if rootless cgroups should be used.
43-
Rootless bool `json:"Rootless,omitempty"`
43+
Rootless bool `json:"Rootless,omitzero"`
4444

4545
// The host UID that should own the cgroup, or nil to accept
4646
// the default ownership. This should only be set when the
4747
// cgroupfs is to be mounted read/write.
4848
// Not all cgroup manager implementations support changing
4949
// the ownership.
50-
OwnerUID *int `json:"owner_uid,omitempty"`
50+
OwnerUID *int `json:"owner_uid,omitzero"`
5151
}
5252

5353
type Resources struct {
5454
// Devices is the set of access rules for devices in the container.
55-
Devices []*devices.Rule `json:"devices,omitempty"`
55+
Devices []*devices.Rule `json:"devices,omitzero"`
5656

5757
// Memory limit (in bytes).
58-
Memory int64 `json:"memory,omitempty"`
58+
Memory int64 `json:"memory,omitzero"`
5959

6060
// Memory reservation or soft_limit (in bytes).
61-
MemoryReservation int64 `json:"memory_reservation,omitempty"`
61+
MemoryReservation int64 `json:"memory_reservation,omitzero"`
6262

6363
// Total memory usage (memory+swap); use -1 for unlimited swap.
64-
MemorySwap int64 `json:"memory_swap,omitempty"`
64+
MemorySwap int64 `json:"memory_swap,omitzero"`
6565

6666
// CPU shares (relative weight vs. other containers).
67-
CpuShares uint64 `json:"cpu_shares,omitempty"` //nolint:revive // Suppress "var-naming: struct field CpuShares should be CPUShares".
67+
CpuShares uint64 `json:"cpu_shares,omitzero"`
6868

6969
// CPU hardcap limit (in usecs). Allowed cpu time in a given period.
70-
CpuQuota int64 `json:"cpu_quota,omitempty"` //nolint:revive // Suppress "var-naming: struct field CpuQuota should be CPUQuota".
70+
CpuQuota int64 `json:"cpu_quota,omitzero"`
7171

7272
// CPU hardcap burst limit (in usecs). Allowed accumulated cpu time additionally for burst in a given period.
73-
CpuBurst *uint64 `json:"cpu_burst,omitempty"` //nolint:revive // Suppress "var-naming: struct field CpuBurst should be CPUBurst".
73+
CpuBurst *uint64 `json:"cpu_burst,omitzero"`
7474

7575
// CPU period to be used for hardcapping (in usecs). 0 to use system default.
76-
CpuPeriod uint64 `json:"cpu_period,omitempty"` //nolint:revive // Suppress "var-naming: struct field CpuPeriod should be CPUPeriod".
76+
CpuPeriod uint64 `json:"cpu_period,omitzero"`
7777

7878
// How many time CPU will use in realtime scheduling (in usecs).
79-
CpuRtRuntime int64 `json:"cpu_rt_quota,omitempty"` //nolint:revive // Suppress "var-naming: struct field CpuRtRuntime should be CPURtRuntime".
79+
CpuRtRuntime int64 `json:"cpu_rt_quota,omitzero"`
8080

8181
// CPU period to be used for realtime scheduling (in usecs).
82-
CpuRtPeriod uint64 `json:"cpu_rt_period,omitempty"` //nolint:revive // Suppress "var-naming: struct field CpuQuota should be CPUQuota".
82+
CpuRtPeriod uint64 `json:"cpu_rt_period,omitzero"`
8383

8484
// Cpuset CPUs to use.
85-
CpusetCpus string `json:"cpuset_cpus,omitempty"`
85+
CpusetCpus string `json:"cpuset_cpus,omitzero"`
8686

8787
// Cpuset memory nodes to use.
88-
CpusetMems string `json:"cpuset_mems,omitempty"`
88+
CpusetMems string `json:"cpuset_mems,omitzero"`
8989

9090
// Cgroup's SCHED_IDLE value.
91-
CPUIdle *int64 `json:"cpu_idle,omitempty"`
91+
CPUIdle *int64 `json:"cpu_idle,omitzero"`
9292

9393
// Process limit; set < `0' to disable limit. `nil` means "keep current limit".
94-
PidsLimit *int64 `json:"pids_limit,omitempty"`
94+
PidsLimit *int64 `json:"pids_limit,omitzero"`
9595

9696
// Specifies per cgroup weight, range is from 10 to 1000.
97-
BlkioWeight uint16 `json:"blkio_weight,omitempty"`
97+
BlkioWeight uint16 `json:"blkio_weight,omitzero"`
9898

9999
// Tasks' weight in the given cgroup while competing with the cgroup's child cgroups, range is from 10 to 1000, cfq scheduler only.
100-
BlkioLeafWeight uint16 `json:"blkio_leaf_weight,omitempty"`
100+
BlkioLeafWeight uint16 `json:"blkio_leaf_weight,omitzero"`
101101

102102
// Weight per cgroup per device, can override BlkioWeight.
103-
BlkioWeightDevice []*WeightDevice `json:"blkio_weight_device,omitempty"`
103+
BlkioWeightDevice []*WeightDevice `json:"blkio_weight_device,omitzero"`
104104

105105
// IO read rate limit per cgroup per device, bytes per second.
106-
BlkioThrottleReadBpsDevice []*ThrottleDevice `json:"blkio_throttle_read_bps_device,omitempty"`
106+
BlkioThrottleReadBpsDevice []*ThrottleDevice `json:"blkio_throttle_read_bps_device,omitzero"`
107107

108108
// IO write rate limit per cgroup per device, bytes per second.
109-
BlkioThrottleWriteBpsDevice []*ThrottleDevice `json:"blkio_throttle_write_bps_device,omitempty"`
109+
BlkioThrottleWriteBpsDevice []*ThrottleDevice `json:"blkio_throttle_write_bps_device,omitzero"`
110110

111111
// IO read rate limit per cgroup per device, IO per second.
112-
BlkioThrottleReadIOPSDevice []*ThrottleDevice `json:"blkio_throttle_read_iops_device,omitempty"`
112+
BlkioThrottleReadIOPSDevice []*ThrottleDevice `json:"blkio_throttle_read_iops_device,omitzero"`
113113

114114
// IO write rate limit per cgroup per device, IO per second.
115-
BlkioThrottleWriteIOPSDevice []*ThrottleDevice `json:"blkio_throttle_write_iops_device,omitempty"`
115+
BlkioThrottleWriteIOPSDevice []*ThrottleDevice `json:"blkio_throttle_write_iops_device,omitzero"`
116116

117117
// Freeze value for the process.
118-
Freezer FreezerState `json:"freezer,omitempty"`
118+
Freezer FreezerState `json:"freezer,omitzero"`
119119

120120
// Hugetlb limit (in bytes).
121-
HugetlbLimit []*HugepageLimit `json:"hugetlb_limit,omitempty"`
121+
HugetlbLimit []*HugepageLimit `json:"hugetlb_limit,omitzero"`
122122

123123
// Whether to disable OOM killer.
124-
OomKillDisable bool `json:"oom_kill_disable,omitempty"`
124+
OomKillDisable bool `json:"oom_kill_disable,omitzero"`
125125

126126
// Tuning swappiness behaviour per cgroup.
127-
MemorySwappiness *uint64 `json:"memory_swappiness,omitempty"`
127+
MemorySwappiness *uint64 `json:"memory_swappiness,omitzero"`
128128

129129
// Set priority of network traffic for container.
130-
NetPrioIfpriomap []*IfPrioMap `json:"net_prio_ifpriomap,omitempty"`
130+
NetPrioIfpriomap []*IfPrioMap `json:"net_prio_ifpriomap,omitzero"`
131131

132132
// Set class identifier for container's network packets.
133-
NetClsClassid uint32 `json:"net_cls_classid_u,omitempty"`
133+
NetClsClassid uint32 `json:"net_cls_classid_u,omitzero"`
134134

135135
// Rdma resource restriction configuration.
136-
Rdma map[string]LinuxRdma `json:"rdma,omitempty"`
136+
Rdma map[string]LinuxRdma `json:"rdma,omitzero"`
137137

138138
// Used on cgroups v2:
139139

140140
// CpuWeight sets a proportional bandwidth limit.
141-
CpuWeight uint64 `json:"cpu_weight,omitempty"` //nolint:revive // Suppress "var-naming: struct field CpuWeight should be CPUWeight".
141+
CpuWeight uint64 `json:"cpu_weight,omitzero"`
142142

143143
// Unified is cgroupv2-only key-value map.
144-
Unified map[string]string `json:"unified,omitempty"`
144+
Unified map[string]string `json:"unified,omitzero"`
145145

146146
// SkipDevices allows to skip configuring device permissions.
147147
// Used by e.g. kubelet while creating a parent cgroup (kubepods)
@@ -165,5 +165,5 @@ type Resources struct {
165165
// MemoryCheckBeforeUpdate is a flag for cgroup v2 managers to check
166166
// if the new memory limits (Memory and MemorySwap) being set are lower
167167
// than the current memory usage, and reject if so.
168-
MemoryCheckBeforeUpdate bool `json:"memory_check_before_update,omitempty"`
168+
MemoryCheckBeforeUpdate bool `json:"memory_check_before_update,omitzero"`
169169
}

0 commit comments

Comments
 (0)