mirror of https://github.com/containers/podman.git
Merge pull request #15016 from Luap99/compat-netname
compat api: allow default bridge name for networks
This commit is contained in:
commit
5e43fb15cc
|
@ -23,6 +23,13 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func normalizeNetworkName(rt *libpod.Runtime, name string) (string, bool) {
|
||||||
|
if name == nettypes.BridgeNetworkDriver {
|
||||||
|
return rt.Network().DefaultNetworkName(), true
|
||||||
|
}
|
||||||
|
return name, false
|
||||||
|
}
|
||||||
|
|
||||||
func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
|
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
|
||||||
|
|
||||||
|
@ -44,13 +51,13 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
utils.Error(w, http.StatusBadRequest, define.ErrInvalidArg)
|
utils.Error(w, http.StatusBadRequest, define.ErrInvalidArg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
name := utils.GetName(r)
|
name, changed := normalizeNetworkName(runtime, utils.GetName(r))
|
||||||
net, err := runtime.Network().NetworkInspect(name)
|
net, err := runtime.Network().NetworkInspect(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.NetworkNotFound(w, name, err)
|
utils.NetworkNotFound(w, name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
report, err := convertLibpodNetworktoDockerNetwork(runtime, net)
|
report, err := convertLibpodNetworktoDockerNetwork(runtime, &net, changed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
|
@ -58,7 +65,7 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
utils.WriteResponse(w, http.StatusOK, report)
|
utils.WriteResponse(w, http.StatusOK, report)
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertLibpodNetworktoDockerNetwork(runtime *libpod.Runtime, network nettypes.Network) (*types.NetworkResource, error) {
|
func convertLibpodNetworktoDockerNetwork(runtime *libpod.Runtime, network *nettypes.Network, changeDefaultName bool) (*types.NetworkResource, error) {
|
||||||
cons, err := runtime.GetAllContainers()
|
cons, err := runtime.GetAllContainers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -107,11 +114,15 @@ func convertLibpodNetworktoDockerNetwork(runtime *libpod.Runtime, network nettyp
|
||||||
Config: ipamConfigs,
|
Config: ipamConfigs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name := network.Name
|
||||||
|
if changeDefaultName && name == runtime.Network().DefaultNetworkName() {
|
||||||
|
name = nettypes.BridgeNetworkDriver
|
||||||
|
}
|
||||||
report := types.NetworkResource{
|
report := types.NetworkResource{
|
||||||
Name: network.Name,
|
Name: name,
|
||||||
ID: network.ID,
|
ID: network.ID,
|
||||||
Driver: network.Driver,
|
Driver: network.Driver,
|
||||||
// TODO add Created: ,
|
Created: network.Created,
|
||||||
Internal: network.Internal,
|
Internal: network.Internal,
|
||||||
EnableIPv6: network.IPv6Enabled,
|
EnableIPv6: network.IPv6Enabled,
|
||||||
Labels: network.Labels,
|
Labels: network.Labels,
|
||||||
|
@ -149,7 +160,7 @@ func ListNetworks(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
reports := make([]*types.NetworkResource, 0, len(nets))
|
reports := make([]*types.NetworkResource, 0, len(nets))
|
||||||
for _, net := range nets {
|
for _, net := range nets {
|
||||||
report, err := convertLibpodNetworktoDockerNetwork(runtime, net)
|
report, err := convertLibpodNetworktoDockerNetwork(runtime, &net, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
|
@ -182,27 +193,22 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
network.Options = make(map[string]string)
|
network.Options = make(map[string]string)
|
||||||
|
|
||||||
// TODO: we should consider making this constants in c/common/libnetwork/types
|
// dockers bridge networks are always isolated from each other
|
||||||
|
if network.Driver == nettypes.BridgeNetworkDriver {
|
||||||
|
network.Options[nettypes.IsolateOption] = "true"
|
||||||
|
}
|
||||||
|
|
||||||
for opt, optVal := range networkCreate.Options {
|
for opt, optVal := range networkCreate.Options {
|
||||||
switch opt {
|
switch opt {
|
||||||
case "mtu":
|
case nettypes.MTUOption:
|
||||||
fallthrough
|
fallthrough
|
||||||
case "com.docker.network.driver.mtu":
|
case "com.docker.network.driver.mtu":
|
||||||
if network.Driver == nettypes.BridgeNetworkDriver {
|
network.Options[nettypes.MTUOption] = optVal
|
||||||
network.Options["mtu"] = optVal
|
|
||||||
}
|
|
||||||
case "icc":
|
|
||||||
fallthrough
|
|
||||||
case "com.docker.network.bridge.enable_icc":
|
|
||||||
// TODO: needs to be implemented
|
|
||||||
if network.Driver == nettypes.BridgeNetworkDriver {
|
|
||||||
responseWarning = "com.docker.network.bridge.enable_icc is not currently implemented"
|
|
||||||
}
|
|
||||||
case "com.docker.network.bridge.name":
|
case "com.docker.network.bridge.name":
|
||||||
if network.Driver == nettypes.BridgeNetworkDriver {
|
if network.Driver == nettypes.BridgeNetworkDriver {
|
||||||
network.NetworkInterface = optVal
|
network.NetworkInterface = optVal
|
||||||
}
|
}
|
||||||
case "mode":
|
case nettypes.ModeOption:
|
||||||
if network.Driver == nettypes.MacVLANNetworkDriver || network.Driver == nettypes.IPVLANNetworkDriver {
|
if network.Driver == nettypes.MacVLANNetworkDriver || network.Driver == nettypes.IPVLANNetworkDriver {
|
||||||
network.Options[opt] = optVal
|
network.Options[opt] = optVal
|
||||||
}
|
}
|
||||||
|
@ -305,7 +311,7 @@ func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
|
||||||
Timeout: query.Timeout,
|
Timeout: query.Timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
name := utils.GetName(r)
|
name, _ := normalizeNetworkName(runtime, utils.GetName(r))
|
||||||
reports, err := ic.NetworkRm(r.Context(), []string{name}, options)
|
reports, err := ic.NetworkRm(r.Context(), []string{name}, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Error(w, http.StatusInternalServerError, err)
|
utils.Error(w, http.StatusInternalServerError, err)
|
||||||
|
@ -340,7 +346,7 @@ func Connect(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
netOpts := nettypes.PerNetworkOptions{}
|
netOpts := nettypes.PerNetworkOptions{}
|
||||||
|
|
||||||
name := utils.GetName(r)
|
name, _ := normalizeNetworkName(runtime, utils.GetName(r))
|
||||||
if netConnect.EndpointConfig != nil {
|
if netConnect.EndpointConfig != nil {
|
||||||
if netConnect.EndpointConfig.Aliases != nil {
|
if netConnect.EndpointConfig.Aliases != nil {
|
||||||
netOpts.Aliases = netConnect.EndpointConfig.Aliases
|
netOpts.Aliases = netConnect.EndpointConfig.Aliases
|
||||||
|
@ -416,7 +422,7 @@ func Disconnect(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
name := utils.GetName(r)
|
name, _ := normalizeNetworkName(runtime, utils.GetName(r))
|
||||||
err := runtime.DisconnectContainerFromNetwork(netDisconnect.Container, name, netDisconnect.Force)
|
err := runtime.DisconnectContainerFromNetwork(netDisconnect.Container, name, netDisconnect.Force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, define.ErrNoSuchCtr) {
|
if errors.Is(err, define.ErrNoSuchCtr) {
|
||||||
|
|
|
@ -84,12 +84,24 @@ t GET networks?filters='{"dangling":["true","0"]}' 500 \
|
||||||
t GET networks?filters='{"name":["doesnotexists"]}' 200 \
|
t GET networks?filters='{"name":["doesnotexists"]}' 200 \
|
||||||
"[]"
|
"[]"
|
||||||
|
|
||||||
|
# check default name in list endpoint
|
||||||
|
t GET networks 200 \
|
||||||
|
.[].Name~.*bridge.*
|
||||||
|
|
||||||
# network inspect docker
|
# network inspect docker
|
||||||
t GET networks/$network1_id 200 \
|
t GET networks/$network1_id 200 \
|
||||||
.Name=network1 \
|
.Name=network1 \
|
||||||
.Id=$network1_id \
|
.Id=$network1_id \
|
||||||
.Scope=local
|
.Scope=local
|
||||||
|
|
||||||
|
# inspect default bridge network
|
||||||
|
t GET networks/bridge 200 \
|
||||||
|
.Name=bridge
|
||||||
|
|
||||||
|
# inspect default bridge network with real podman name should return real name
|
||||||
|
t GET networks/podman 200 \
|
||||||
|
.Name=podman
|
||||||
|
|
||||||
# network create docker
|
# network create docker
|
||||||
t POST networks/create Name=net3\ IPAM='{"Config":[]}' 201
|
t POST networks/create Name=net3\ IPAM='{"Config":[]}' 201
|
||||||
# network delete docker
|
# network delete docker
|
||||||
|
|
|
@ -212,7 +212,6 @@ function start_service() {
|
||||||
rm -f $DOCKER_SOCK
|
rm -f $DOCKER_SOCK
|
||||||
mkdir --mode 0755 $WORKDIR/{root,runroot,cni}
|
mkdir --mode 0755 $WORKDIR/{root,runroot,cni}
|
||||||
chcon --reference=/var/lib/containers $WORKDIR/root
|
chcon --reference=/var/lib/containers $WORKDIR/root
|
||||||
cp /etc/cni/net.d/*podman*conflist $WORKDIR/cni/
|
|
||||||
|
|
||||||
$PODMAN_BIN \
|
$PODMAN_BIN \
|
||||||
--log-level debug \
|
--log-level debug \
|
||||||
|
|
Loading…
Reference in New Issue