-
Notifications
You must be signed in to change notification settings - Fork 4
/
bbc.go
65 lines (53 loc) · 1.4 KB
/
bbc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"context"
"errors"
"fmt"
"net"
"github.com/containernetworking/cni/pkg/types/current"
"github.com/baidubce/baiducloud-cce-cni-driver/pkg/rpc"
log "github.com/baidubce/baiducloud-cce-cni-driver/pkg/util/logger"
)
type bbcENIMultiIP struct {
name string
namespace string
}
var _ networkClient = &bbcENIMultiIP{}
func (client *bbcENIMultiIP) SetupNetwork(
ctx context.Context,
result *current.Result,
ipamConf *IPAMConf,
resp *rpc.AllocateIPReply,
) error {
allocRespNetworkInfo := resp.GetENIMultiIP()
if allocRespNetworkInfo == nil {
err := errors.New(fmt.Sprintf("failed to allocate IP for pod (%v %v): NetworkInfo is nil", client.namespace, client.name))
log.Errorf(ctx, err.Error())
return err
}
log.Infof(ctx, "allocate IP %v for pod(%v %v) successfully", allocRespNetworkInfo.IP, client.namespace, client.name)
allocatedIP := net.ParseIP(allocRespNetworkInfo.IP)
if allocatedIP == nil {
return fmt.Errorf("alloc IP %v format error", allocRespNetworkInfo.IP)
}
version := "4"
addrBits := 32
if allocatedIP.To4() == nil {
version = "6"
addrBits = 128
}
result.IPs = []*current.IPConfig{
{
Version: version,
Address: net.IPNet{IP: allocatedIP, Mask: net.CIDRMask(addrBits, addrBits)},
},
}
return nil
}
func (client *bbcENIMultiIP) TeardownNetwork(
ctx context.Context,
ipamConf *IPAMConf,
resp *rpc.ReleaseIPReply,
) error {
return nil
}