Skip to content

Commit b31cc61

Browse files
author
Haiyan Meng
committed
remove unnecessary return error value
Signed-off-by: Haiyan Meng <hmeng@redhat.com>
1 parent a217d8c commit b31cc61

2 files changed

Lines changed: 17 additions & 43 deletions

File tree

cmd/ocitools/generate.go

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
124124
if len(pair) != 2 {
125125
return fmt.Errorf("incorrectly specified annotation: %s", s)
126126
}
127-
if err := g.AddAnnotation(pair[0], pair[1]); err != nil {
128-
return err
129-
}
127+
g.AddAnnotation(pair[0], pair[1])
130128
}
131129
}
132130

@@ -254,9 +252,7 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
254252
if err != nil {
255253
return err
256254
}
257-
if err := g.AddTmpfsMount(dest, options); err != nil {
258-
return err
259-
}
255+
g.AddTmpfsMount(dest, options)
260256
}
261257
}
262258

@@ -272,40 +268,31 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
272268
if err != nil {
273269
return err
274270
}
275-
276-
if err := g.AddBindMount(source, dest, options); err != nil {
277-
return err
278-
}
271+
g.AddBindMount(source, dest, options)
279272
}
280273
}
281274

282275
if context.IsSet("prestart") {
283276
preStartHooks := context.StringSlice("prestart")
284277
for _, hook := range preStartHooks {
285278
path, args := parseHook(hook)
286-
if err := g.AddPreStartHook(path, args); err != nil {
287-
return err
288-
}
279+
g.AddPreStartHook(path, args)
289280
}
290281
}
291282

292283
if context.IsSet("poststop") {
293284
postStopHooks := context.StringSlice("poststop")
294285
for _, hook := range postStopHooks {
295286
path, args := parseHook(hook)
296-
if err := g.AddPostStopHook(path, args); err != nil {
297-
return err
298-
}
287+
g.AddPostStopHook(path, args)
299288
}
300289
}
301290

302291
if context.IsSet("poststart") {
303292
postStartHooks := context.StringSlice("poststart")
304293
for _, hook := range postStartHooks {
305294
path, args := parseHook(hook)
306-
if err := g.AddPostStartHook(path, args); err != nil {
307-
return err
308-
}
295+
g.AddPostStartHook(path, args)
309296
}
310297
}
311298

@@ -322,9 +309,7 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
322309
return err
323310
}
324311

325-
if err := g.AddLinuxUIDMapping(hid, cid, size); err != nil {
326-
return err
327-
}
312+
g.AddLinuxUIDMapping(hid, cid, size)
328313
}
329314

330315
for _, gidMap := range gidMaps {
@@ -333,9 +318,7 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
333318
return err
334319
}
335320

336-
if err := g.AddLinuxGIDMapping(hid, cid, size); err != nil {
337-
return err
338-
}
321+
g.AddLinuxGIDMapping(hid, cid, size)
339322
}
340323

341324
var sd string

generate/generate.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,9 @@ func (g *Generator) ClearAnnotations() {
244244
}
245245

246246
// AddAnnotation adds an annotation into g.spec.Annotations.
247-
func (g *Generator) AddAnnotation(key, value string) error {
247+
func (g *Generator) AddAnnotation(key, value string) {
248248
g.initSpecAnnotations()
249249
g.spec.Annotations[key] = value
250-
return nil
251250
}
252251

253252
// RemoveAnnotation remove an annotation from g.spec.Annotations.
@@ -456,10 +455,9 @@ func (g *Generator) ClearLinuxSysctl() {
456455
}
457456

458457
// AddLinuxSysctl adds a new sysctl config into g.spec.Linux.Sysctl.
459-
func (g *Generator) AddLinuxSysctl(key, value string) error {
458+
func (g *Generator) AddLinuxSysctl(key, value string) {
460459
g.initSpecLinuxSysctl()
461460
g.spec.Linux.Sysctl[key] = value
462-
return nil
463461
}
464462

465463
// RemoveLinuxSysctl removes a sysctl config from g.spec.Linux.Sysctl.
@@ -751,7 +749,7 @@ func (g *Generator) ClearLinuxUIDMappings() {
751749
}
752750

753751
// AddLinuxUIDMapping adds uidMap into g.spec.Linux.UIDMappings.
754-
func (g *Generator) AddLinuxUIDMapping(hid, cid, size uint32) error {
752+
func (g *Generator) AddLinuxUIDMapping(hid, cid, size uint32) {
755753
idMapping := rspec.IDMapping{
756754
HostID: hid,
757755
ContainerID: cid,
@@ -760,7 +758,6 @@ func (g *Generator) AddLinuxUIDMapping(hid, cid, size uint32) error {
760758

761759
g.initSpecLinux()
762760
g.spec.Linux.UIDMappings = append(g.spec.Linux.UIDMappings, idMapping)
763-
return nil
764761
}
765762

766763
// ClearLinuxGIDMappings clear g.spec.Linux.GIDMappings.
@@ -772,7 +769,7 @@ func (g *Generator) ClearLinuxGIDMappings() {
772769
}
773770

774771
// AddLinuxGIDMapping adds gidMap into g.spec.Linux.GIDMappings.
775-
func (g *Generator) AddLinuxGIDMapping(hid, cid, size uint32) error {
772+
func (g *Generator) AddLinuxGIDMapping(hid, cid, size uint32) {
776773
idMapping := rspec.IDMapping{
777774
HostID: hid,
778775
ContainerID: cid,
@@ -781,7 +778,6 @@ func (g *Generator) AddLinuxGIDMapping(hid, cid, size uint32) error {
781778

782779
g.initSpecLinux()
783780
g.spec.Linux.GIDMappings = append(g.spec.Linux.GIDMappings, idMapping)
784-
return nil
785781
}
786782

787783
// SetLinuxRootPropagation sets g.spec.Linux.RootfsPropagation.
@@ -811,11 +807,10 @@ func (g *Generator) ClearPreStartHooks() {
811807
}
812808

813809
// AddPreStartHook add a prestart hook into g.spec.Hooks.Prestart.
814-
func (g *Generator) AddPreStartHook(path string, args []string) error {
810+
func (g *Generator) AddPreStartHook(path string, args []string) {
815811
g.initSpec()
816812
hook := rspec.Hook{Path: path, Args: args}
817813
g.spec.Hooks.Prestart = append(g.spec.Hooks.Prestart, hook)
818-
return nil
819814
}
820815

821816
// ClearPostStopHooks clear g.spec.Hooks.Poststop.
@@ -827,11 +822,10 @@ func (g *Generator) ClearPostStopHooks() {
827822
}
828823

829824
// AddPostStopHook adds a poststop hook into g.spec.Hooks.Poststop.
830-
func (g *Generator) AddPostStopHook(path string, args []string) error {
825+
func (g *Generator) AddPostStopHook(path string, args []string) {
831826
g.initSpec()
832827
hook := rspec.Hook{Path: path, Args: args}
833828
g.spec.Hooks.Poststop = append(g.spec.Hooks.Poststop, hook)
834-
return nil
835829
}
836830

837831
// ClearPostStartHooks clear g.spec.Hooks.Poststart.
@@ -843,15 +837,14 @@ func (g *Generator) ClearPostStartHooks() {
843837
}
844838

845839
// AddPostStartHook adds a poststart hook into g.spec.Hooks.Poststart.
846-
func (g *Generator) AddPostStartHook(path string, args []string) error {
840+
func (g *Generator) AddPostStartHook(path string, args []string) {
847841
g.initSpec()
848842
hook := rspec.Hook{Path: path, Args: args}
849843
g.spec.Hooks.Poststart = append(g.spec.Hooks.Poststart, hook)
850-
return nil
851844
}
852845

853846
// AddTmpfsMount adds a tmpfs mount into g.spec.Mounts.
854-
func (g *Generator) AddTmpfsMount(dest string, options []string) error {
847+
func (g *Generator) AddTmpfsMount(dest string, options []string) {
855848
mnt := rspec.Mount{
856849
Destination: dest,
857850
Type: "tmpfs",
@@ -861,7 +854,6 @@ func (g *Generator) AddTmpfsMount(dest string, options []string) error {
861854

862855
g.initSpec()
863856
g.spec.Mounts = append(g.spec.Mounts, mnt)
864-
return nil
865857
}
866858

867859
// AddCgroupsMount adds a cgroup mount into g.spec.Mounts.
@@ -888,7 +880,7 @@ func (g *Generator) AddCgroupsMount(mountCgroupOption string) error {
888880
}
889881

890882
// AddBindMount adds a bind mount into g.spec.Mounts.
891-
func (g *Generator) AddBindMount(source, dest, options string) error {
883+
func (g *Generator) AddBindMount(source, dest, options string) {
892884
if options == "" {
893885
options = "ro"
894886
}
@@ -903,7 +895,6 @@ func (g *Generator) AddBindMount(source, dest, options string) error {
903895
}
904896
g.initSpec()
905897
g.spec.Mounts = append(g.spec.Mounts, mnt)
906-
return nil
907898
}
908899

909900
// SetupPrivileged sets up the priviledge-related fields inside g.spec.

0 commit comments

Comments
 (0)