Skip to content

Commit

Permalink
libpod: set cid network alias in setupContainer()
Browse files Browse the repository at this point in the history
Since we have sqlite there is no point in duplicating this acroos two db
backends. Just set earlier when we validate the networks anyway.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Jul 11, 2023
1 parent e6dbb42 commit b6ec212
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
2 changes: 0 additions & 2 deletions libpod/boltdb_state_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,6 @@ func (s *BoltState) addContainer(ctr *Container, pod *Pod) error {
if opts.InterfaceName == "" {
return fmt.Errorf("network interface name cannot be an empty string: %w", define.ErrInvalidArg)
}
// always add the short id as alias for docker compat
opts.Aliases = append(opts.Aliases, ctr.config.ID[:12])
optBytes, err := json.Marshal(opts)
if err != nil {
return fmt.Errorf("marshalling network options JSON for container %s: %w", ctr.ID(), err)
Expand Down
2 changes: 2 additions & 0 deletions libpod/runtime_ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
return nil, errors.New("failed to find free network interface name")
}
}
// always add the short id as alias for docker compat
opts.Aliases = append(opts.Aliases, ctr.config.ID[:12])

normalizeNetworks[netName] = opts
}
Expand Down
6 changes: 0 additions & 6 deletions libpod/sqlite_state_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,6 @@ func (s *SQLiteState) rewriteContainerConfig(ctr *Container, newCfg *ContainerCo
}

func (s *SQLiteState) addContainer(ctr *Container) (defErr error) {
for net := range ctr.config.Networks {
opts := ctr.config.Networks[net]
opts.Aliases = append(opts.Aliases, ctr.config.ID[:12])
ctr.config.Networks[net] = opts
}

configJSON, err := json.Marshal(ctr.config)
if err != nil {
return fmt.Errorf("marshalling container config json: %w", err)
Expand Down

0 comments on commit b6ec212

Please sign in to comment.