Sfoglia il codice sorgente

Add UnregisterNetwork backend method

Dan Williams 9 anni fa
parent
commit
f678fc0de6

+ 3 - 0
backend/alloc/alloc.go

@@ -50,3 +50,6 @@ func (m *AllocBackend) RegisterNetwork(ctx context.Context, network string, conf
 
 func (m *AllocBackend) Run(ctx context.Context) {
 }
+
+func (m *AllocBackend) UnregisterNetwork(ctx context.Context, name string) {
+}

+ 3 - 0
backend/awsvpc/awsvpc.go

@@ -248,3 +248,6 @@ func (m *AwsVpcBackend) detectRouteTableID(instanceID string, ec2c *ec2.EC2) err
 
 func (m *AwsVpcBackend) Run(ctx context.Context) {
 }
+
+func (m *AwsVpcBackend) UnregisterNetwork(ctx context.Context, name string) {
+}

+ 2 - 0
backend/common.go

@@ -42,4 +42,6 @@ type Backend interface {
 	// Called after the backend's first network has been registered to
 	// allow the plugin to watch dynamic events
 	Run(ctx context.Context)
+	// Called to clean up any network resources or operations
+	UnregisterNetwork(ctx context.Context, network string)
 }

+ 3 - 0
backend/gce/gce.go

@@ -161,6 +161,9 @@ func (g *GCEBackend) RegisterNetwork(ctx context.Context, network string, config
 func (g *GCEBackend) Run(ctx context.Context) {
 }
 
+func (g *GCEBackend) UnregisterNetwork(ctx context.Context, name string) {
+}
+
 func (g *GCEBackend) pollOperationStatus(operationName string) error {
 	for i := 0; i < 100; i++ {
 		operation, err := g.computeService.GlobalOperations.Get(g.project, operationName).Do()

+ 3 - 0
backend/hostgw/hostgw.go

@@ -118,6 +118,9 @@ func (rb *HostgwBackend) Run(ctx context.Context) {
 	}
 }
 
+func (rb *HostgwBackend) UnregisterNetwork(ctx context.Context, name string) {
+}
+
 func (rb *HostgwBackend) handleSubnetEvents(batch []subnet.Event) {
 	for _, evt := range batch {
 		switch evt.Type {

+ 3 - 0
backend/udp/udp.go

@@ -151,6 +151,9 @@ func (m *UdpBackend) Run(ctx context.Context) {
 	wg.Wait()
 }
 
+func (m *UdpBackend) UnregisterNetwork(ctx context.Context, name string) {
+}
+
 func newCtlSockets() (*os.File, *os.File, error) {
 	fds, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_SEQPACKET, 0)
 	if err != nil {

+ 3 - 0
backend/vxlan/vxlan.go

@@ -183,6 +183,9 @@ func (vb *VXLANBackend) Run(ctx context.Context) {
 	}
 }
 
+func (vb *VXLANBackend) UnregisterNetwork(ctx context.Context, name string) {
+}
+
 // So we can make it JSON (un)marshalable
 type hardwareAddr net.HardwareAddr
 

+ 2 - 0
network/network.go

@@ -126,6 +126,8 @@ func (n *Network) Run() {
 	}()
 
 	<-n.ctx.Done()
+	n.be.UnregisterNetwork(n.ctx, n.Name)
+
 	wg.Wait()
 }