Browse code

libnetwork/osl: remove Sandbox.Info()

"Pay no attention to the implementation behind the curtain!"

There's only one implementation of the Sandbox interface, and only one implementation
of the Info interface, and they both happens to be implemented by the same type:
networkNamespace. Let's merge these interfaces.

And now that we know that there's one, and only one Info, we can drop the charade,
and relieve the Sandbox from its dual personality.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2023/08/20 17:04:21
Showing 6 changed files
... ...
@@ -313,7 +313,7 @@ func (n *network) leaveSandbox() {
313 313
 // to be called while holding network lock
314 314
 func (n *network) destroySandbox() {
315 315
 	if n.sbox != nil {
316
-		for _, iface := range n.sbox.Info().Interfaces() {
316
+		for _, iface := range n.sbox.Interfaces() {
317 317
 			if err := iface.Remove(); err != nil {
318 318
 				log.G(context.TODO()).Debugf("Remove interface %s failed: %v", iface.SrcName(), err)
319 319
 			}
... ...
@@ -441,7 +441,7 @@ func (n *network) setupSubnetSandbox(s *subnet, brName, vxlanName string) error
441 441
 		sbox.InterfaceOptions().Master(brName)); err != nil {
442 442
 		// If adding vxlan device to the overlay namespace fails, remove the bridge interface we
443 443
 		// already added to the namespace. This allows the caller to try the setup again.
444
-		for _, iface := range sbox.Info().Interfaces() {
444
+		for _, iface := range sbox.Interfaces() {
445 445
 			if iface.SrcName() == brName {
446 446
 				if ierr := iface.Remove(); ierr != nil {
447 447
 					log.G(context.TODO()).Errorf("removing bridge failed from ov ns %v failed, %v", n.sbox.Key(), ierr)
... ...
@@ -468,7 +468,7 @@ func (n *network) setupSubnetSandbox(s *subnet, brName, vxlanName string) error
468 468
 
469 469
 func setDefaultVLAN(sbox osl.Sandbox) error {
470 470
 	var brName string
471
-	for _, i := range sbox.Info().Interfaces() {
471
+	for _, i := range sbox.Interfaces() {
472 472
 		if i.Bridge() {
473 473
 			brName = i.DstName()
474 474
 		}
... ...
@@ -455,10 +455,6 @@ func (n *networkNamespace) nsPath() string {
455 455
 	return n.path
456 456
 }
457 457
 
458
-func (n *networkNamespace) Info() Info {
459
-	return n
460
-}
461
-
462 458
 func (n *networkNamespace) Key() string {
463 459
 	return n.path
464 460
 }
... ...
@@ -86,9 +86,6 @@ type Sandbox interface {
86 86
 	// InvokeFunc invoke a function in the network namespace.
87 87
 	InvokeFunc(func()) error
88 88
 
89
-	// Info returns an interface with methods to get sandbox state.
90
-	Info() Info
91
-
92 89
 	// Destroy destroys the sandbox.
93 90
 	Destroy() error
94 91
 
... ...
@@ -97,6 +94,8 @@ type Sandbox interface {
97 97
 
98 98
 	// ApplyOSTweaks applies operating system specific knobs on the sandbox.
99 99
 	ApplyOSTweaks([]SandboxType)
100
+
101
+	Info
100 102
 }
101 103
 
102 104
 // NeighborOptionSetter interface defines the option setter methods for interface options
... ...
@@ -407,7 +407,7 @@ func TestSandboxCreate(t *testing.T) {
407 407
 		t.Fatalf("Failed to generate new sandbox info: %v", err)
408 408
 	}
409 409
 
410
-	for _, i := range tbox.Info().Interfaces() {
410
+	for _, i := range tbox.Interfaces() {
411 411
 		err = s.AddInterface(i.SrcName(), i.DstName(),
412 412
 			tbox.InterfaceOptions().Bridge(i.Bridge()),
413 413
 			tbox.InterfaceOptions().Address(i.Address()),
... ...
@@ -417,12 +417,12 @@ func TestSandboxCreate(t *testing.T) {
417 417
 		}
418 418
 	}
419 419
 
420
-	err = s.SetGateway(tbox.Info().Gateway())
420
+	err = s.SetGateway(tbox.Gateway())
421 421
 	if err != nil {
422 422
 		t.Fatalf("Failed to set gateway to sandbox: %v", err)
423 423
 	}
424 424
 
425
-	err = s.SetGatewayIPv6(tbox.Info().GatewayIPv6())
425
+	err = s.SetGatewayIPv6(tbox.GatewayIPv6())
426 426
 	if err != nil {
427 427
 		t.Fatalf("Failed to set ipv6 gateway to sandbox: %v", err)
428 428
 	}
... ...
@@ -506,7 +506,7 @@ func TestAddRemoveInterface(t *testing.T) {
506 506
 		t.Fatalf("Failed to generate new sandbox info: %v", err)
507 507
 	}
508 508
 
509
-	for _, i := range tbox.Info().Interfaces() {
509
+	for _, i := range tbox.Interfaces() {
510 510
 		err = s.AddInterface(i.SrcName(), i.DstName(),
511 511
 			tbox.InterfaceOptions().Bridge(i.Bridge()),
512 512
 			tbox.InterfaceOptions().Address(i.Address()),
... ...
@@ -518,14 +518,14 @@ func TestAddRemoveInterface(t *testing.T) {
518 518
 
519 519
 	verifySandbox(t, s, []string{"0", "1", "2"})
520 520
 
521
-	interfaces := s.Info().Interfaces()
521
+	interfaces := s.Interfaces()
522 522
 	if err := interfaces[0].Remove(); err != nil {
523 523
 		t.Fatalf("Failed to remove interfaces from sandbox: %v", err)
524 524
 	}
525 525
 
526 526
 	verifySandbox(t, s, []string{"1", "2"})
527 527
 
528
-	i := tbox.Info().Interfaces()[0]
528
+	i := tbox.Interfaces()[0]
529 529
 	if err := s.AddInterface(i.SrcName(), i.DstName(),
530 530
 		tbox.InterfaceOptions().Bridge(i.Bridge()),
531 531
 		tbox.InterfaceOptions().Address(i.Address()),
... ...
@@ -140,7 +140,7 @@ func (sb *Sandbox) Statistics() (map[string]*types.InterfaceStatistics, error) {
140 140
 	}
141 141
 
142 142
 	var err error
143
-	for _, i := range osb.Info().Interfaces() {
143
+	for _, i := range osb.Interfaces() {
144 144
 		if m[i.DstName()], err = i.Statistics(); err != nil {
145 145
 			return m, err
146 146
 		}
... ...
@@ -705,7 +705,7 @@ func (sb *Sandbox) DisableService() (err error) {
705 705
 }
706 706
 
707 707
 func releaseOSSboxResources(osSbox osl.Sandbox, ep *Endpoint) {
708
-	for _, i := range osSbox.Info().Interfaces() {
708
+	for _, i := range osSbox.Interfaces() {
709 709
 		// Only remove the interfaces owned by this endpoint from the sandbox.
710 710
 		if ep.hasInterface(i.SrcName()) {
711 711
 			if err := i.Remove(); err != nil {
... ...
@@ -69,7 +69,7 @@ func (n *Network) findLBEndpointSandbox() (*Endpoint, *Sandbox, error) {
69 69
 // aliases to the interface.
70 70
 func findIfaceDstName(sb *Sandbox, ep *Endpoint) string {
71 71
 	srcName := ep.Iface().SrcName()
72
-	for _, i := range sb.osSbox.Info().Interfaces() {
72
+	for _, i := range sb.osSbox.Interfaces() {
73 73
 		if i.SrcName() == srcName {
74 74
 			return i.DstName()
75 75
 		}