Skip to content

Commit aad6c6a

Browse files
Aaron Lehmannniau
authored andcommitted
Clarify that NetworkAttachment target is an ID
PR moby#1600 added a FindNetwork function to the store package to resolve a NetworkAttachment's target by ID, name, or name prefix. I think this is based on a misleading comment in the NetworkAttachment definition saying that the target can be a name or an ID. In fact, it's always an ID, and existing code passes it directly to GetNetwork. Clarify the comment and remove FindNetwork. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
1 parent ea7c5ef commit aad6c6a

File tree

4 files changed

+5
-21
lines changed

4 files changed

+5
-21
lines changed

api/types.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/types.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ message TaskStatus {
447447
// instructing Swarm on how this service should work on the particular
448448
// network.
449449
message NetworkAttachmentConfig {
450-
// Target specifies the target network for attachment. This value may be a
451-
// network name or identifier. Only identifiers are supported at this time.
450+
// Target specifies the target network for attachment. This value must be a
451+
// network ID.
452452
string target = 1;
453453
// Aliases specifies a list of discoverable alternate names for the service on this Target.
454454
repeated string aliases = 2;

manager/controlapi/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (s *Server) validateNetworks(networks []*api.NetworkAttachmentConfig) error
174174
for _, na := range networks {
175175
var network *api.Network
176176
s.store.View(func(tx store.ReadTx) {
177-
network = store.FindNetwork(tx, na.Target)
177+
network = store.GetNetwork(tx, na.Target)
178178
})
179179
if network == nil {
180180
continue

manager/state/store/networks.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,6 @@ func FindNetworks(tx ReadTx, by By) ([]*api.Network, error) {
183183
return networkList, err
184184
}
185185

186-
// FindNetwork is a utility function which returns the first
187-
// network for which the target string matches the ID, or
188-
// the name or the ID prefix.
189-
func FindNetwork(tx ReadTx, target string) *api.Network {
190-
if n := GetNetwork(tx, target); n != nil {
191-
return n
192-
}
193-
if list, err := FindNetworks(tx, ByName(target)); err == nil && len(list) == 1 {
194-
return list[0]
195-
}
196-
if list, err := FindNetworks(tx, ByIDPrefix(target)); err == nil && len(list) == 1 {
197-
return list[0]
198-
}
199-
return nil
200-
}
201-
202186
type networkIndexerByID struct{}
203187

204188
func (ni networkIndexerByID) FromArgs(args ...interface{}) ([]byte, error) {

0 commit comments

Comments
 (0)