mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
fix(ST1016): Use consistent method receiver names
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
committed by
Sebastiaan van Stijn
parent
9e9b6cc42e
commit
70139978d3
@@ -25,15 +25,15 @@ func NewRouter(b Backend, d experimentalProvider) router.Router {
|
||||
}
|
||||
|
||||
// Routes returns the available routers to the build controller
|
||||
func (r *buildRouter) Routes() []router.Route {
|
||||
return r.routes
|
||||
func (br *buildRouter) Routes() []router.Route {
|
||||
return br.routes
|
||||
}
|
||||
|
||||
func (r *buildRouter) initRoutes() {
|
||||
r.routes = []router.Route{
|
||||
router.NewPostRoute("/build", r.postBuild),
|
||||
router.NewPostRoute("/build/prune", r.postPrune),
|
||||
router.NewPostRoute("/build/cancel", r.postCancel),
|
||||
func (br *buildRouter) initRoutes() {
|
||||
br.routes = []router.Route{
|
||||
router.NewPostRoute("/build", br.postBuild),
|
||||
router.NewPostRoute("/build/prune", br.postPrune),
|
||||
router.NewPostRoute("/build/cancel", br.postCancel),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@ func NewRouter(b Backend, decoder httputils.ContainerDecoder) router.Router {
|
||||
}
|
||||
|
||||
// Routes returns the available routers to the checkpoint controller
|
||||
func (r *checkpointRouter) Routes() []router.Route {
|
||||
return r.routes
|
||||
func (cr *checkpointRouter) Routes() []router.Route {
|
||||
return cr.routes
|
||||
}
|
||||
|
||||
func (r *checkpointRouter) initRoutes() {
|
||||
r.routes = []router.Route{
|
||||
router.NewGetRoute("/containers/{name:.*}/checkpoints", r.getContainerCheckpoints, router.Experimental),
|
||||
router.NewPostRoute("/containers/{name:.*}/checkpoints", r.postContainerCheckpoint, router.Experimental),
|
||||
router.NewDeleteRoute("/containers/{name}/checkpoints/{checkpoint}", r.deleteContainerCheckpoint, router.Experimental),
|
||||
func (cr *checkpointRouter) initRoutes() {
|
||||
cr.routes = []router.Route{
|
||||
router.NewGetRoute("/containers/{name:.*}/checkpoints", cr.getContainerCheckpoints, router.Experimental),
|
||||
router.NewPostRoute("/containers/{name:.*}/checkpoints", cr.postContainerCheckpoint, router.Experimental),
|
||||
router.NewDeleteRoute("/containers/{name}/checkpoints/{checkpoint}", cr.deleteContainerCheckpoint, router.Experimental),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
)
|
||||
|
||||
func (s *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
func (cr *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
if err := httputils.ParseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -18,7 +18,7 @@ func (s *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http.R
|
||||
return err
|
||||
}
|
||||
|
||||
err := s.backend.CheckpointCreate(vars["name"], options)
|
||||
err := cr.backend.CheckpointCreate(vars["name"], options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -27,12 +27,12 @@ func (s *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http.R
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
func (cr *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
if err := httputils.ParseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
checkpoints, err := s.backend.CheckpointList(vars["name"], checkpoint.ListOptions{
|
||||
checkpoints, err := cr.backend.CheckpointList(vars["name"], checkpoint.ListOptions{
|
||||
CheckpointDir: r.Form.Get("dir"),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -42,12 +42,12 @@ func (s *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.R
|
||||
return httputils.WriteJSON(w, http.StatusOK, checkpoints)
|
||||
}
|
||||
|
||||
func (s *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
func (cr *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
if err := httputils.ParseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := s.backend.CheckpointDelete(vars["name"], checkpoint.DeleteOptions{
|
||||
err := cr.backend.CheckpointDelete(vars["name"], checkpoint.DeleteOptions{
|
||||
CheckpointDir: r.Form.Get("dir"),
|
||||
CheckpointID: vars["checkpoint"],
|
||||
})
|
||||
|
||||
@@ -18,14 +18,14 @@ func NewRouter(backend Backend) router.Router {
|
||||
}
|
||||
|
||||
// Routes returns the available routes
|
||||
func (r *distributionRouter) Routes() []router.Route {
|
||||
return r.routes
|
||||
func (dr *distributionRouter) Routes() []router.Route {
|
||||
return dr.routes
|
||||
}
|
||||
|
||||
// initRoutes initializes the routes in the distribution router
|
||||
func (r *distributionRouter) initRoutes() {
|
||||
r.routes = []router.Route{
|
||||
func (dr *distributionRouter) initRoutes() {
|
||||
dr.routes = []router.Route{
|
||||
// GET
|
||||
router.NewGetRoute("/distribution/{name:.*}/json", r.getDistributionInfo),
|
||||
router.NewGetRoute("/distribution/{name:.*}/json", dr.getDistributionInfo),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
func (dr *distributionRouter) getDistributionInfo(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
if err := httputils.ParseForm(r); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res
|
||||
// For a search it is not an error if no auth was given. Ignore invalid
|
||||
// AuthConfig to increase compatibility with the existing API.
|
||||
authConfig, _ := registry.DecodeAuthConfig(r.Header.Get(registry.AuthHeader))
|
||||
repos, err := s.backend.GetRepositories(ctx, namedRef, authConfig)
|
||||
repos, err := dr.backend.GetRepositories(ctx, namedRef, authConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res
|
||||
// - https://github.com/moby/moby/blob/12c7411b6b7314bef130cd59f1c7384a7db06d0b/distribution/pull.go#L76-L152
|
||||
var lastErr error
|
||||
for _, repo := range repos {
|
||||
distributionInspect, err := s.fetchManifest(ctx, repo, namedRef)
|
||||
distributionInspect, err := dr.fetchManifest(ctx, repo, namedRef)
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
continue
|
||||
@@ -76,7 +76,7 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res
|
||||
return lastErr
|
||||
}
|
||||
|
||||
func (s *distributionRouter) fetchManifest(ctx context.Context, distrepo distribution.Repository, namedRef reference.Named) (registry.DistributionInspect, error) {
|
||||
func (dr *distributionRouter) fetchManifest(ctx context.Context, distrepo distribution.Repository, namedRef reference.Named) (registry.DistributionInspect, error) {
|
||||
var distributionInspect registry.DistributionInspect
|
||||
if canonicalRef, ok := namedRef.(reference.Canonical); !ok {
|
||||
namedRef = reference.TagNameOnly(namedRef)
|
||||
|
||||
@@ -22,22 +22,22 @@ func NewRouter(b Backend, c ClusterBackend) router.Router {
|
||||
}
|
||||
|
||||
// Routes returns the available routes to the network controller
|
||||
func (r *networkRouter) Routes() []router.Route {
|
||||
return r.routes
|
||||
func (n *networkRouter) Routes() []router.Route {
|
||||
return n.routes
|
||||
}
|
||||
|
||||
func (r *networkRouter) initRoutes() {
|
||||
r.routes = []router.Route{
|
||||
func (n *networkRouter) initRoutes() {
|
||||
n.routes = []router.Route{
|
||||
// GET
|
||||
router.NewGetRoute("/networks", r.getNetworksList),
|
||||
router.NewGetRoute("/networks/", r.getNetworksList),
|
||||
router.NewGetRoute("/networks/{id:.+}", r.getNetwork),
|
||||
router.NewGetRoute("/networks", n.getNetworksList),
|
||||
router.NewGetRoute("/networks/", n.getNetworksList),
|
||||
router.NewGetRoute("/networks/{id:.+}", n.getNetwork),
|
||||
// POST
|
||||
router.NewPostRoute("/networks/create", r.postNetworkCreate),
|
||||
router.NewPostRoute("/networks/{id:.*}/connect", r.postNetworkConnect),
|
||||
router.NewPostRoute("/networks/{id:.*}/disconnect", r.postNetworkDisconnect),
|
||||
router.NewPostRoute("/networks/prune", r.postNetworksPrune),
|
||||
router.NewPostRoute("/networks/create", n.postNetworkCreate),
|
||||
router.NewPostRoute("/networks/{id:.*}/connect", n.postNetworkConnect),
|
||||
router.NewPostRoute("/networks/{id:.*}/disconnect", n.postNetworkDisconnect),
|
||||
router.NewPostRoute("/networks/prune", n.postNetworksPrune),
|
||||
// DELETE
|
||||
router.NewDeleteRoute("/networks/{id:.*}", r.deleteNetwork),
|
||||
router.NewDeleteRoute("/networks/{id:.*}", n.deleteNetwork),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,22 +18,22 @@ func NewRouter(b Backend) router.Router {
|
||||
}
|
||||
|
||||
// Routes returns the available routers to the plugin controller
|
||||
func (r *pluginRouter) Routes() []router.Route {
|
||||
return r.routes
|
||||
func (pr *pluginRouter) Routes() []router.Route {
|
||||
return pr.routes
|
||||
}
|
||||
|
||||
func (r *pluginRouter) initRoutes() {
|
||||
r.routes = []router.Route{
|
||||
router.NewGetRoute("/plugins", r.listPlugins),
|
||||
router.NewGetRoute("/plugins/{name:.*}/json", r.inspectPlugin),
|
||||
router.NewGetRoute("/plugins/privileges", r.getPrivileges),
|
||||
router.NewDeleteRoute("/plugins/{name:.*}", r.removePlugin),
|
||||
router.NewPostRoute("/plugins/{name:.*}/enable", r.enablePlugin),
|
||||
router.NewPostRoute("/plugins/{name:.*}/disable", r.disablePlugin),
|
||||
router.NewPostRoute("/plugins/pull", r.pullPlugin),
|
||||
router.NewPostRoute("/plugins/{name:.*}/push", r.pushPlugin),
|
||||
router.NewPostRoute("/plugins/{name:.*}/upgrade", r.upgradePlugin),
|
||||
router.NewPostRoute("/plugins/{name:.*}/set", r.setPlugin),
|
||||
router.NewPostRoute("/plugins/create", r.createPlugin),
|
||||
func (pr *pluginRouter) initRoutes() {
|
||||
pr.routes = []router.Route{
|
||||
router.NewGetRoute("/plugins", pr.listPlugins),
|
||||
router.NewGetRoute("/plugins/{name:.*}/json", pr.inspectPlugin),
|
||||
router.NewGetRoute("/plugins/privileges", pr.getPrivileges),
|
||||
router.NewDeleteRoute("/plugins/{name:.*}", pr.removePlugin),
|
||||
router.NewPostRoute("/plugins/{name:.*}/enable", pr.enablePlugin),
|
||||
router.NewPostRoute("/plugins/{name:.*}/disable", pr.disablePlugin),
|
||||
router.NewPostRoute("/plugins/pull", pr.pullPlugin),
|
||||
router.NewPostRoute("/plugins/{name:.*}/push", pr.pushPlugin),
|
||||
router.NewPostRoute("/plugins/{name:.*}/upgrade", pr.upgradePlugin),
|
||||
router.NewPostRoute("/plugins/{name:.*}/set", pr.setPlugin),
|
||||
router.NewPostRoute("/plugins/create", pr.createPlugin),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ func NewRouter(b Backend) router.Router {
|
||||
}
|
||||
|
||||
// Routes returns the available routers to the session controller
|
||||
func (r *sessionRouter) Routes() []router.Route {
|
||||
return r.routes
|
||||
func (sr *sessionRouter) Routes() []router.Route {
|
||||
return sr.routes
|
||||
}
|
||||
|
||||
func (r *sessionRouter) initRoutes() {
|
||||
r.routes = []router.Route{
|
||||
router.NewPostRoute("/session", r.startSession),
|
||||
func (sr *sessionRouter) initRoutes() {
|
||||
sr.routes = []router.Route{
|
||||
router.NewPostRoute("/session", sr.startSession),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,21 +20,21 @@ func NewRouter(b Backend, cb ClusterBackend) router.Router {
|
||||
}
|
||||
|
||||
// Routes returns the available routes to the volumes controller
|
||||
func (r *volumeRouter) Routes() []router.Route {
|
||||
return r.routes
|
||||
func (v *volumeRouter) Routes() []router.Route {
|
||||
return v.routes
|
||||
}
|
||||
|
||||
func (r *volumeRouter) initRoutes() {
|
||||
r.routes = []router.Route{
|
||||
func (v *volumeRouter) initRoutes() {
|
||||
v.routes = []router.Route{
|
||||
// GET
|
||||
router.NewGetRoute("/volumes", r.getVolumesList),
|
||||
router.NewGetRoute("/volumes/{name:.*}", r.getVolumeByName),
|
||||
router.NewGetRoute("/volumes", v.getVolumesList),
|
||||
router.NewGetRoute("/volumes/{name:.*}", v.getVolumeByName),
|
||||
// POST
|
||||
router.NewPostRoute("/volumes/create", r.postVolumesCreate),
|
||||
router.NewPostRoute("/volumes/prune", r.postVolumesPrune),
|
||||
router.NewPostRoute("/volumes/create", v.postVolumesCreate),
|
||||
router.NewPostRoute("/volumes/prune", v.postVolumesPrune),
|
||||
// PUT
|
||||
router.NewPutRoute("/volumes/{name:.*}", r.putVolumesUpdate),
|
||||
router.NewPutRoute("/volumes/{name:.*}", v.putVolumesUpdate),
|
||||
// DELETE
|
||||
router.NewDeleteRoute("/volumes/{name:.*}", r.deleteVolumes),
|
||||
router.NewDeleteRoute("/volumes/{name:.*}", v.deleteVolumes),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,44 +219,44 @@ func readManifest(ctx context.Context, store content.Provider, desc ocispec.Desc
|
||||
|
||||
// ImagePlatform returns the platform of the image manifest.
|
||||
// If the manifest list doesn't have a platform filled, it will be read from the config.
|
||||
func (m *ImageManifest) ImagePlatform(ctx context.Context) (ocispec.Platform, error) {
|
||||
target := m.Target()
|
||||
func (im *ImageManifest) ImagePlatform(ctx context.Context) (ocispec.Platform, error) {
|
||||
target := im.Target()
|
||||
if target.Platform != nil {
|
||||
return *target.Platform, nil
|
||||
}
|
||||
|
||||
var out ocispec.Platform
|
||||
err := m.ReadConfig(ctx, &out)
|
||||
err := im.ReadConfig(ctx, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// ReadConfig gets the image config and unmarshals it into the provided struct.
|
||||
// The provided struct should be a pointer to the config struct or its subset.
|
||||
func (m *ImageManifest) ReadConfig(ctx context.Context, outConfig interface{}) error {
|
||||
configDesc, err := m.Config(ctx)
|
||||
func (im *ImageManifest) ReadConfig(ctx context.Context, outConfig interface{}) error {
|
||||
configDesc, err := im.Config(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return readJSON(ctx, m.ContentStore(), configDesc, outConfig)
|
||||
return readJSON(ctx, im.ContentStore(), configDesc, outConfig)
|
||||
}
|
||||
|
||||
// PresentContentSize returns the size of the image's content that is present in the content store.
|
||||
func (m *ImageManifest) PresentContentSize(ctx context.Context) (int64, error) {
|
||||
cs := m.ContentStore()
|
||||
func (im *ImageManifest) PresentContentSize(ctx context.Context) (int64, error) {
|
||||
cs := im.ContentStore()
|
||||
var size int64
|
||||
err := c8dimages.Walk(ctx, presentChildrenHandler(cs, func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
|
||||
size += desc.Size
|
||||
return nil, nil
|
||||
}), m.Target())
|
||||
}), im.Target())
|
||||
return size, err
|
||||
}
|
||||
|
||||
// SnapshotUsage returns the disk usage of the image's snapshots.
|
||||
func (m *ImageManifest) SnapshotUsage(ctx context.Context, snapshotter snapshots.Snapshotter) (snapshots.Usage, error) {
|
||||
diffIDs, err := m.RootFS(ctx)
|
||||
func (im *ImageManifest) SnapshotUsage(ctx context.Context, snapshotter snapshots.Snapshotter) (snapshots.Usage, error) {
|
||||
diffIDs, err := im.RootFS(ctx)
|
||||
if err != nil {
|
||||
return snapshots.Usage{}, errors.Wrapf(err, "failed to get rootfs of image %s", m.Name())
|
||||
return snapshots.Usage{}, errors.Wrapf(err, "failed to get rootfs of image %s", im.Name())
|
||||
}
|
||||
|
||||
imageSnapshotID := identity.ChainID(diffIDs).String()
|
||||
@@ -266,12 +266,12 @@ func (m *ImageManifest) SnapshotUsage(ctx context.Context, snapshotter snapshots
|
||||
return snapshots.Usage{Size: 0}, nil
|
||||
}
|
||||
log.G(ctx).WithError(err).WithFields(log.Fields{
|
||||
"image": m.Name(),
|
||||
"target": m.Target(),
|
||||
"image": im.Name(),
|
||||
"target": im.Target(),
|
||||
"snapshotID": imageSnapshotID,
|
||||
}).Warn("failed to calculate snapshot usage of image")
|
||||
|
||||
return snapshots.Usage{}, errors.Wrapf(err, "failed to calculate snapshot usage of image %s", m.Name())
|
||||
return snapshots.Usage{}, errors.Wrapf(err, "failed to calculate snapshot usage of image %s", im.Name())
|
||||
}
|
||||
return unpackedUsage, nil
|
||||
}
|
||||
|
||||
@@ -50,9 +50,9 @@ func NewHandleAt(ns netns.NsHandle, nlFamilies ...int) (Handle, error) {
|
||||
return Handle{nlh}, nil
|
||||
}
|
||||
|
||||
func (h Handle) Close() {
|
||||
if h.Handle != nil {
|
||||
h.Handle.Close()
|
||||
func (nlh Handle) Close() {
|
||||
if nlh.Handle != nil {
|
||||
nlh.Handle.Close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -240,39 +240,39 @@ func ValidateFixedCIDRV6(val string) error {
|
||||
|
||||
// Validate performs a static validation on the network configuration parameters.
|
||||
// Whatever can be assessed a priori before attempting any programming.
|
||||
func (c *networkConfiguration) Validate() error {
|
||||
if c.Mtu < 0 {
|
||||
return errdefs.InvalidParameter(fmt.Errorf("invalid MTU number: %d", c.Mtu))
|
||||
func (ncfg *networkConfiguration) Validate() error {
|
||||
if ncfg.Mtu < 0 {
|
||||
return errdefs.InvalidParameter(fmt.Errorf("invalid MTU number: %d", ncfg.Mtu))
|
||||
}
|
||||
|
||||
if c.EnableIPv4 {
|
||||
if ncfg.EnableIPv4 {
|
||||
// If IPv4 is enabled, AddressIPv4 must have been configured.
|
||||
if c.AddressIPv4 == nil {
|
||||
if ncfg.AddressIPv4 == nil {
|
||||
return errdefs.System(errors.New("no IPv4 address was allocated for the bridge"))
|
||||
}
|
||||
// If default gw is specified, it must be part of bridge subnet
|
||||
if c.DefaultGatewayIPv4 != nil {
|
||||
if !c.AddressIPv4.Contains(c.DefaultGatewayIPv4) {
|
||||
if ncfg.DefaultGatewayIPv4 != nil {
|
||||
if !ncfg.AddressIPv4.Contains(ncfg.DefaultGatewayIPv4) {
|
||||
return errInvalidGateway
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if c.EnableIPv6 {
|
||||
if ncfg.EnableIPv6 {
|
||||
// If IPv6 is enabled, AddressIPv6 must have been configured.
|
||||
if c.AddressIPv6 == nil {
|
||||
if ncfg.AddressIPv6 == nil {
|
||||
return errdefs.System(errors.New("no IPv6 address was allocated for the bridge"))
|
||||
}
|
||||
// AddressIPv6 must be IPv6, and not overlap with the LL subnet prefix.
|
||||
addr, ok := netiputil.ToPrefix(c.AddressIPv6)
|
||||
addr, ok := netiputil.ToPrefix(ncfg.AddressIPv6)
|
||||
if !ok {
|
||||
return errdefs.InvalidParameter(fmt.Errorf("invalid IPv6 address '%s'", c.AddressIPv6))
|
||||
return errdefs.InvalidParameter(fmt.Errorf("invalid IPv6 address '%s'", ncfg.AddressIPv6))
|
||||
}
|
||||
if err := validateIPv6Subnet(addr); err != nil {
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
// If a default gw is specified, it must belong to AddressIPv6's subnet
|
||||
if c.DefaultGatewayIPv6 != nil && !c.AddressIPv6.Contains(c.DefaultGatewayIPv6) {
|
||||
if ncfg.DefaultGatewayIPv6 != nil && !ncfg.AddressIPv6.Contains(ncfg.DefaultGatewayIPv6) {
|
||||
return errInvalidGateway
|
||||
}
|
||||
}
|
||||
@@ -281,87 +281,87 @@ func (c *networkConfiguration) Validate() error {
|
||||
}
|
||||
|
||||
// Conflicts check if two NetworkConfiguration objects overlap
|
||||
func (c *networkConfiguration) Conflicts(o *networkConfiguration) error {
|
||||
func (ncfg *networkConfiguration) Conflicts(o *networkConfiguration) error {
|
||||
if o == nil {
|
||||
return errors.New("same configuration")
|
||||
}
|
||||
|
||||
// Also empty, because only one network with empty name is allowed
|
||||
if c.BridgeName == o.BridgeName {
|
||||
if ncfg.BridgeName == o.BridgeName {
|
||||
return errors.New("networks have same bridge name")
|
||||
}
|
||||
|
||||
// They must be in different subnets
|
||||
if (c.AddressIPv4 != nil && o.AddressIPv4 != nil) &&
|
||||
(c.AddressIPv4.Contains(o.AddressIPv4.IP) || o.AddressIPv4.Contains(c.AddressIPv4.IP)) {
|
||||
if (ncfg.AddressIPv4 != nil && o.AddressIPv4 != nil) &&
|
||||
(ncfg.AddressIPv4.Contains(o.AddressIPv4.IP) || o.AddressIPv4.Contains(ncfg.AddressIPv4.IP)) {
|
||||
return errors.New("networks have overlapping IPv4")
|
||||
}
|
||||
|
||||
// They must be in different v6 subnets
|
||||
if (c.AddressIPv6 != nil && o.AddressIPv6 != nil) &&
|
||||
(c.AddressIPv6.Contains(o.AddressIPv6.IP) || o.AddressIPv6.Contains(c.AddressIPv6.IP)) {
|
||||
if (ncfg.AddressIPv6 != nil && o.AddressIPv6 != nil) &&
|
||||
(ncfg.AddressIPv6.Contains(o.AddressIPv6.IP) || o.AddressIPv6.Contains(ncfg.AddressIPv6.IP)) {
|
||||
return errors.New("networks have overlapping IPv6")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *networkConfiguration) fromLabels(labels map[string]string) error {
|
||||
func (ncfg *networkConfiguration) fromLabels(labels map[string]string) error {
|
||||
var err error
|
||||
for label, value := range labels {
|
||||
switch label {
|
||||
case BridgeName:
|
||||
c.BridgeName = value
|
||||
ncfg.BridgeName = value
|
||||
case netlabel.DriverMTU:
|
||||
if c.Mtu, err = strconv.Atoi(value); err != nil {
|
||||
if ncfg.Mtu, err = strconv.Atoi(value); err != nil {
|
||||
return parseErr(label, value, err.Error())
|
||||
}
|
||||
case netlabel.EnableIPv4:
|
||||
if c.EnableIPv4, err = strconv.ParseBool(value); err != nil {
|
||||
if ncfg.EnableIPv4, err = strconv.ParseBool(value); err != nil {
|
||||
return parseErr(label, value, err.Error())
|
||||
}
|
||||
case netlabel.EnableIPv6:
|
||||
if c.EnableIPv6, err = strconv.ParseBool(value); err != nil {
|
||||
if ncfg.EnableIPv6, err = strconv.ParseBool(value); err != nil {
|
||||
return parseErr(label, value, err.Error())
|
||||
}
|
||||
case EnableIPMasquerade:
|
||||
if c.EnableIPMasquerade, err = strconv.ParseBool(value); err != nil {
|
||||
if ncfg.EnableIPMasquerade, err = strconv.ParseBool(value); err != nil {
|
||||
return parseErr(label, value, err.Error())
|
||||
}
|
||||
case IPv4GatewayMode:
|
||||
if c.GwModeIPv4, err = newGwMode(value); err != nil {
|
||||
if ncfg.GwModeIPv4, err = newGwMode(value); err != nil {
|
||||
return parseErr(label, value, err.Error())
|
||||
}
|
||||
case IPv6GatewayMode:
|
||||
if c.GwModeIPv6, err = newGwMode(value); err != nil {
|
||||
if ncfg.GwModeIPv6, err = newGwMode(value); err != nil {
|
||||
return parseErr(label, value, err.Error())
|
||||
}
|
||||
case EnableICC:
|
||||
if c.EnableICC, err = strconv.ParseBool(value); err != nil {
|
||||
if ncfg.EnableICC, err = strconv.ParseBool(value); err != nil {
|
||||
return parseErr(label, value, err.Error())
|
||||
}
|
||||
case TrustedHostInterfaces:
|
||||
c.TrustedHostInterfaces = strings.FieldsFunc(value, func(r rune) bool { return r == ':' })
|
||||
ncfg.TrustedHostInterfaces = strings.FieldsFunc(value, func(r rune) bool { return r == ':' })
|
||||
case InhibitIPv4:
|
||||
if c.InhibitIPv4, err = strconv.ParseBool(value); err != nil {
|
||||
if ncfg.InhibitIPv4, err = strconv.ParseBool(value); err != nil {
|
||||
return parseErr(label, value, err.Error())
|
||||
}
|
||||
case DefaultBridge:
|
||||
if c.DefaultBridge, err = strconv.ParseBool(value); err != nil {
|
||||
if ncfg.DefaultBridge, err = strconv.ParseBool(value); err != nil {
|
||||
return parseErr(label, value, err.Error())
|
||||
}
|
||||
case DefaultBindingIP:
|
||||
if c.DefaultBindingIP = net.ParseIP(value); c.DefaultBindingIP == nil {
|
||||
if ncfg.DefaultBindingIP = net.ParseIP(value); ncfg.DefaultBindingIP == nil {
|
||||
return parseErr(label, value, "nil ip")
|
||||
}
|
||||
case netlabel.ContainerIfacePrefix:
|
||||
c.ContainerIfacePrefix = value
|
||||
ncfg.ContainerIfacePrefix = value
|
||||
case netlabel.HostIPv4:
|
||||
if c.HostIPv4 = net.ParseIP(value); c.HostIPv4 == nil {
|
||||
if ncfg.HostIPv4 = net.ParseIP(value); ncfg.HostIPv4 == nil {
|
||||
return parseErr(label, value, "nil ip")
|
||||
}
|
||||
case netlabel.HostIPv6:
|
||||
if c.HostIPv6 = net.ParseIP(value); c.HostIPv6 == nil {
|
||||
if ncfg.HostIPv6 = net.ParseIP(value); ncfg.HostIPv6 == nil {
|
||||
return parseErr(label, value, "nil ip")
|
||||
}
|
||||
}
|
||||
@@ -589,32 +589,32 @@ func parseNetworkGenericOptions(data interface{}) (*networkConfiguration, error)
|
||||
return config, err
|
||||
}
|
||||
|
||||
func (c *networkConfiguration) processIPAM(ipamV4Data, ipamV6Data []driverapi.IPAMData) error {
|
||||
func (ncfg *networkConfiguration) processIPAM(ipamV4Data, ipamV6Data []driverapi.IPAMData) error {
|
||||
if len(ipamV4Data) > 1 || len(ipamV6Data) > 1 {
|
||||
return types.ForbiddenErrorf("bridge driver doesn't support multiple subnets")
|
||||
}
|
||||
|
||||
if len(ipamV4Data) > 0 {
|
||||
c.AddressIPv4 = ipamV4Data[0].Pool
|
||||
ncfg.AddressIPv4 = ipamV4Data[0].Pool
|
||||
|
||||
if ipamV4Data[0].Gateway != nil {
|
||||
c.AddressIPv4 = types.GetIPNetCopy(ipamV4Data[0].Gateway)
|
||||
ncfg.AddressIPv4 = types.GetIPNetCopy(ipamV4Data[0].Gateway)
|
||||
}
|
||||
|
||||
if gw, ok := ipamV4Data[0].AuxAddresses[DefaultGatewayV4AuxKey]; ok {
|
||||
c.DefaultGatewayIPv4 = gw.IP
|
||||
ncfg.DefaultGatewayIPv4 = gw.IP
|
||||
}
|
||||
}
|
||||
|
||||
if len(ipamV6Data) > 0 {
|
||||
c.AddressIPv6 = ipamV6Data[0].Pool
|
||||
ncfg.AddressIPv6 = ipamV6Data[0].Pool
|
||||
|
||||
if ipamV6Data[0].Gateway != nil {
|
||||
c.AddressIPv6 = types.GetIPNetCopy(ipamV6Data[0].Gateway)
|
||||
ncfg.AddressIPv6 = types.GetIPNetCopy(ipamV6Data[0].Gateway)
|
||||
}
|
||||
|
||||
if gw, ok := ipamV6Data[0].AuxAddresses[DefaultGatewayV6AuxKey]; ok {
|
||||
c.DefaultGatewayIPv6 = gw.IP
|
||||
ncfg.DefaultGatewayIPv6 = gw.IP
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ func (d *driver) parseNetworkOptions(id string, genericOptions map[string]string
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func (c *networkConfiguration) processIPAM(id string, ipamV4Data, ipamV6Data []driverapi.IPAMData) error {
|
||||
func (ncfg *networkConfiguration) processIPAM(id string, ipamV4Data, ipamV6Data []driverapi.IPAMData) error {
|
||||
if len(ipamV6Data) > 0 {
|
||||
return types.ForbiddenErrorf("windowsshim driver doesn't support v6 subnets")
|
||||
}
|
||||
|
||||
@@ -77,12 +77,12 @@ func closeNetworkDBInstances(t *testing.T, dbs []*NetworkDB) {
|
||||
}
|
||||
}
|
||||
|
||||
func (db *NetworkDB) verifyNodeExistence(t *testing.T, node string, present bool) {
|
||||
func (nDB *NetworkDB) verifyNodeExistence(t *testing.T, node string, present bool) {
|
||||
t.Helper()
|
||||
for i := 0; i < 80; i++ {
|
||||
db.RLock()
|
||||
_, ok := db.nodes[node]
|
||||
db.RUnlock()
|
||||
nDB.RLock()
|
||||
_, ok := nDB.nodes[node]
|
||||
nDB.RUnlock()
|
||||
if present && ok {
|
||||
return
|
||||
}
|
||||
@@ -94,10 +94,10 @@ func (db *NetworkDB) verifyNodeExistence(t *testing.T, node string, present bool
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
}
|
||||
|
||||
t.Errorf("%v(%v): Node existence verification for node %s failed", db.config.Hostname, db.config.NodeID, node)
|
||||
t.Errorf("%v(%v): Node existence verification for node %s failed", nDB.config.Hostname, nDB.config.NodeID, node)
|
||||
}
|
||||
|
||||
func (db *NetworkDB) verifyNetworkExistence(t *testing.T, node string, id string, present bool) {
|
||||
func (nDB *NetworkDB) verifyNetworkExistence(t *testing.T, node string, id string, present bool) {
|
||||
t.Helper()
|
||||
|
||||
const sleepInterval = 50 * time.Millisecond
|
||||
@@ -108,15 +108,15 @@ func (db *NetworkDB) verifyNetworkExistence(t *testing.T, node string, id string
|
||||
maxRetries = 80
|
||||
}
|
||||
for i := int64(0); i < maxRetries; i++ {
|
||||
db.RLock()
|
||||
nn, nnok := db.networks[node]
|
||||
nDB.RLock()
|
||||
nn, nnok := nDB.networks[node]
|
||||
if nnok {
|
||||
n, ok := nn[id]
|
||||
var leaving bool
|
||||
if ok {
|
||||
leaving = n.leaving
|
||||
}
|
||||
db.RUnlock()
|
||||
nDB.RUnlock()
|
||||
if present && ok {
|
||||
return
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func (db *NetworkDB) verifyNetworkExistence(t *testing.T, node string, id string
|
||||
return
|
||||
}
|
||||
} else {
|
||||
db.RUnlock()
|
||||
nDB.RUnlock()
|
||||
}
|
||||
|
||||
time.Sleep(sleepInterval)
|
||||
@@ -136,11 +136,11 @@ func (db *NetworkDB) verifyNetworkExistence(t *testing.T, node string, id string
|
||||
t.Error("Network existence verification failed")
|
||||
}
|
||||
|
||||
func (db *NetworkDB) verifyEntryExistence(t *testing.T, tname, nid, key, value string, present bool) {
|
||||
func (nDB *NetworkDB) verifyEntryExistence(t *testing.T, tname, nid, key, value string, present bool) {
|
||||
t.Helper()
|
||||
n := 80
|
||||
for i := 0; i < n; i++ {
|
||||
v, err := db.GetEntry(tname, nid, key)
|
||||
v, err := nDB.GetEntry(tname, nid, key)
|
||||
if present && err == nil && string(v) == value {
|
||||
return
|
||||
}
|
||||
@@ -151,7 +151,7 @@ func (db *NetworkDB) verifyEntryExistence(t *testing.T, tname, nid, key, value s
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
}
|
||||
|
||||
t.Errorf("Entry existence verification test failed for %v(%v)", db.config.Hostname, db.config.NodeID)
|
||||
t.Errorf("Entry existence verification test failed for %v(%v)", nDB.config.Hostname, nDB.config.NodeID)
|
||||
}
|
||||
|
||||
func testWatch(t *testing.T, ch chan events.Event, ev interface{}, tname, nid, key, value string) {
|
||||
@@ -482,20 +482,20 @@ func TestNetworkDBCRUDMediumCluster(t *testing.T) {
|
||||
func TestNetworkDBNodeJoinLeaveIteration(t *testing.T) {
|
||||
dbs := createNetworkDBInstances(t, 2, "node", DefaultConfig())
|
||||
|
||||
dbChangeWitness := func(db *NetworkDB) func(network string, expectNodeCount int) {
|
||||
staleNetworkTime := db.networkClock.Time()
|
||||
dbChangeWitness := func(nDB *NetworkDB) func(network string, expectNodeCount int) {
|
||||
staleNetworkTime := nDB.networkClock.Time()
|
||||
return func(network string, expectNodeCount int) {
|
||||
check := func(t poll.LogT) poll.Result {
|
||||
networkTime := db.networkClock.Time()
|
||||
networkTime := nDB.networkClock.Time()
|
||||
if networkTime <= staleNetworkTime {
|
||||
return poll.Continue("network time is stale, no change registered yet.")
|
||||
}
|
||||
count := -1
|
||||
db.Lock()
|
||||
if nodes, ok := db.networkNodes[network]; ok {
|
||||
nDB.Lock()
|
||||
if nodes, ok := nDB.networkNodes[network]; ok {
|
||||
count = len(nodes)
|
||||
}
|
||||
db.Unlock()
|
||||
nDB.Unlock()
|
||||
if count != expectNodeCount {
|
||||
return poll.Continue("current number of nodes is %d, expect %d.", count, expectNodeCount)
|
||||
}
|
||||
|
||||
@@ -651,20 +651,20 @@ func (sb *Sandbox) joinLeaveEnd() {
|
||||
// Less defines an ordering over endpoints, with better candidates for the default
|
||||
// gateway sorted first.
|
||||
//
|
||||
// <=> Returns true if a < b, false if a > b and advances to next level if a == b
|
||||
// epi.prio <=> epj.prio # 2 < 1
|
||||
// epi.gw <=> epj.gw # non-gw < gw
|
||||
// epi.internal <=> epj.internal # non-internal < internal
|
||||
// epi.hasGw <=> epj.hasGw # (gw4 and gw6) < (gw4 or gw6) < (no gw)
|
||||
// epi.name <=> epj.name # bar < foo
|
||||
func (epi *Endpoint) Less(epj *Endpoint) bool {
|
||||
sbi, _ := epi.getSandbox()
|
||||
// <=> Returns true if a < b, false if a > b and advances to next level if a == b
|
||||
// ep.prio <=> epj.prio # 2 < 1
|
||||
// ep.gw <=> epj.gw # non-gw < gw
|
||||
// ep.internal <=> epj.internal # non-internal < internal
|
||||
// ep.hasGw <=> epj.hasGw # (gw4 and gw6) < (gw4 or gw6) < (no gw)
|
||||
// ep.name <=> epj.name # bar < foo
|
||||
func (ep *Endpoint) Less(epj *Endpoint) bool {
|
||||
sbi, _ := ep.getSandbox()
|
||||
sbj, _ := epj.getSandbox()
|
||||
|
||||
// Prio defaults to 0
|
||||
var prioi, prioj int
|
||||
if sbi != nil {
|
||||
prioi = sbi.epPriority[epi.ID()]
|
||||
prioi = sbi.epPriority[ep.ID()]
|
||||
}
|
||||
if sbj != nil {
|
||||
prioj = sbj.epPriority[epj.ID()]
|
||||
@@ -673,13 +673,13 @@ func (epi *Endpoint) Less(epj *Endpoint) bool {
|
||||
return prioi > prioj
|
||||
}
|
||||
|
||||
gwNeti := epi.endpointInGWNetwork()
|
||||
gwNeti := ep.endpointInGWNetwork()
|
||||
gwNetj := epj.endpointInGWNetwork()
|
||||
if gwNeti != gwNetj {
|
||||
return gwNetj
|
||||
}
|
||||
|
||||
inti := epi.getNetwork().Internal()
|
||||
inti := ep.getNetwork().Internal()
|
||||
intj := epj.getNetwork().Internal()
|
||||
if inti != intj {
|
||||
return intj
|
||||
@@ -695,13 +695,13 @@ func (epi *Endpoint) Less(epj *Endpoint) bool {
|
||||
}
|
||||
return 0
|
||||
}
|
||||
gwCounti := gwCount(epi)
|
||||
gwCounti := gwCount(ep)
|
||||
gwCountj := gwCount(epj)
|
||||
if gwCounti != gwCountj {
|
||||
return gwCounti > gwCountj
|
||||
}
|
||||
|
||||
return epi.network.Name() < epj.network.Name()
|
||||
return ep.network.Name() < epj.network.Name()
|
||||
}
|
||||
|
||||
func (sb *Sandbox) NdotsSet() bool {
|
||||
|
||||
@@ -10,10 +10,10 @@ type BuilderContext interface {
|
||||
Remove(string)
|
||||
}
|
||||
|
||||
func (bc *tarSum) Remove(filename string) {
|
||||
for i, fis := range bc.sums {
|
||||
func (ts *tarSum) Remove(filename string) {
|
||||
for i, fis := range ts.sums {
|
||||
if fis.Name() == filename {
|
||||
bc.sums = append(bc.sums[:i], bc.sums[i+1:]...)
|
||||
ts.sums = append(ts.sums[:i], ts.sums[i+1:]...)
|
||||
// Note, we don't just return because there could be
|
||||
// more than one with this name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user