Merge pull request #21270 from ehazlett/resource-labels
Add Label support for Images (build), Networks and Volumes on Creation Upstream-commit: 53d2e5e9d754ce8fbef733759e9ec450514133e3 Component: engine
This commit is contained in:
@ -82,6 +82,15 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
|
||||
}
|
||||
options.BuildArgs = buildArgs
|
||||
}
|
||||
var labels = map[string]string{}
|
||||
labelsJSON := r.FormValue("labels")
|
||||
if labelsJSON != "" {
|
||||
if err := json.NewDecoder(strings.NewReader(labelsJSON)).Decode(&labels); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
options.Labels = labels
|
||||
}
|
||||
|
||||
return options, nil
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ type Backend interface {
|
||||
GetNetworkByName(idName string) (libnetwork.Network, error)
|
||||
GetNetworksByID(partialID string) []libnetwork.Network
|
||||
GetAllNetworks() []libnetwork.Network
|
||||
CreateNetwork(name, driver string, ipam network.IPAM, options map[string]string, internal bool, enableIPv6 bool) (libnetwork.Network, error)
|
||||
CreateNetwork(name, driver string, ipam network.IPAM, options map[string]string, labels map[string]string, internal bool, enableIPv6 bool) (libnetwork.Network, error)
|
||||
ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error
|
||||
DisconnectContainerFromNetwork(containerName string, network libnetwork.Network, force bool) error
|
||||
DeleteNetwork(name string) error
|
||||
|
||||
@ -91,7 +91,7 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr
|
||||
warning = fmt.Sprintf("Network with name %s (id : %s) already exists", nw.Name(), nw.ID())
|
||||
}
|
||||
|
||||
nw, err = n.backend.CreateNetwork(create.Name, create.Driver, create.IPAM, create.Options, create.Internal, create.EnableIPv6)
|
||||
nw, err = n.backend.CreateNetwork(create.Name, create.Driver, create.IPAM, create.Options, create.Labels, create.Internal, create.EnableIPv6)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -163,16 +163,18 @@ func buildNetworkResource(nw libnetwork.Network) *types.NetworkResource {
|
||||
return r
|
||||
}
|
||||
|
||||
info := nw.Info()
|
||||
r.Name = nw.Name()
|
||||
r.ID = nw.ID()
|
||||
r.Scope = nw.Info().Scope()
|
||||
r.Scope = info.Scope()
|
||||
r.Driver = nw.Type()
|
||||
r.EnableIPv6 = nw.Info().IPv6Enabled()
|
||||
r.Internal = nw.Info().Internal()
|
||||
r.Options = nw.Info().DriverOptions()
|
||||
r.EnableIPv6 = info.IPv6Enabled()
|
||||
r.Internal = info.Internal()
|
||||
r.Options = info.DriverOptions()
|
||||
r.Containers = make(map[string]types.EndpointResource)
|
||||
buildIpamResources(r, nw)
|
||||
r.Internal = nw.Info().Internal()
|
||||
buildIpamResources(r, info)
|
||||
r.Internal = info.Internal()
|
||||
r.Labels = info.Labels()
|
||||
|
||||
epl := nw.Endpoints()
|
||||
for _, e := range epl {
|
||||
@ -191,10 +193,10 @@ func buildNetworkResource(nw libnetwork.Network) *types.NetworkResource {
|
||||
return r
|
||||
}
|
||||
|
||||
func buildIpamResources(r *types.NetworkResource, nw libnetwork.Network) {
|
||||
id, opts, ipv4conf, ipv6conf := nw.Info().IpamConfig()
|
||||
func buildIpamResources(r *types.NetworkResource, nwInfo libnetwork.NetworkInfo) {
|
||||
id, opts, ipv4conf, ipv6conf := nwInfo.IpamConfig()
|
||||
|
||||
ipv4Info, ipv6Info := nw.Info().IpamInfo()
|
||||
ipv4Info, ipv6Info := nwInfo.IpamInfo()
|
||||
|
||||
r.IPAM.Driver = id
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@ import (
|
||||
type Backend interface {
|
||||
Volumes(filter string) ([]*types.Volume, []string, error)
|
||||
VolumeInspect(name string) (*types.Volume, error)
|
||||
VolumeCreate(name, driverName string,
|
||||
opts map[string]string) (*types.Volume, error)
|
||||
VolumeCreate(name, driverName string, opts, labels map[string]string) (*types.Volume, error)
|
||||
VolumeRm(name string) error
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ func (v *volumeRouter) postVolumesCreate(ctx context.Context, w http.ResponseWri
|
||||
return err
|
||||
}
|
||||
|
||||
volume, err := v.backend.VolumeCreate(req.Name, req.Driver, req.DriverOpts)
|
||||
volume, err := v.backend.VolumeCreate(req.Name, req.Driver, req.DriverOpts, req.Labels)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user