|
| 1 | +package restserver |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/netip" |
| 6 | + |
| 7 | + "github.com/Azure/azure-container-networking/cns" |
| 8 | + "github.com/Azure/azure-container-networking/cns/common" |
| 9 | + "github.com/Azure/azure-container-networking/cns/fakes" |
| 10 | + "github.com/Azure/azure-container-networking/cns/nodesubnet" |
| 11 | + acn "github.com/Azure/azure-container-networking/common" |
| 12 | + "github.com/Azure/azure-container-networking/nmagent" |
| 13 | + "github.com/Azure/azure-container-networking/store" |
| 14 | +) |
| 15 | + |
| 16 | +func GetRestServiceObjectForNodeSubnetTest(generator CNIConflistGenerator) *HTTPRestService { |
| 17 | + config := &common.ServiceConfig{ |
| 18 | + Name: "test", |
| 19 | + Version: "1.0", |
| 20 | + ChannelMode: "AzureHost", |
| 21 | + Store: store.NewMockStore("test"), |
| 22 | + } |
| 23 | + interfaces := nmagent.Interfaces{ |
| 24 | + Entries: []nmagent.Interface{ |
| 25 | + { |
| 26 | + MacAddress: nmagent.MACAddress{0x00, 0x0D, 0x3A, 0xF9, 0xDC, 0xA6}, |
| 27 | + IsPrimary: true, |
| 28 | + InterfaceSubnets: []nmagent.InterfaceSubnet{ |
| 29 | + { |
| 30 | + Prefix: "10.240.0.0/16", |
| 31 | + IPAddress: []nmagent.NodeIP{ |
| 32 | + { |
| 33 | + Address: nmagent.IPAddress(netip.AddrFrom4([4]byte{10, 240, 0, 5})), |
| 34 | + IsPrimary: true, |
| 35 | + }, |
| 36 | + { |
| 37 | + Address: nmagent.IPAddress(netip.AddrFrom4([4]byte{10, 240, 0, 6})), |
| 38 | + IsPrimary: false, |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + }, |
| 43 | + }, |
| 44 | + }, |
| 45 | + } |
| 46 | + |
| 47 | + svc, err := cns.NewService(config.Name, config.Version, config.ChannelMode, config.Store) |
| 48 | + if err != nil { |
| 49 | + return nil |
| 50 | + } |
| 51 | + |
| 52 | + svc.SetOption(acn.OptCnsURL, "") |
| 53 | + svc.SetOption(acn.OptCnsPort, "") |
| 54 | + err = svc.Initialize(config) |
| 55 | + if err != nil { |
| 56 | + return nil |
| 57 | + } |
| 58 | + |
| 59 | + return &HTTPRestService{ |
| 60 | + Service: svc, |
| 61 | + cniConflistGenerator: generator, |
| 62 | + state: &httpRestServiceState{}, |
| 63 | + PodIPConfigState: make(map[string]cns.IPConfigurationStatus), |
| 64 | + nma: &fakes.NMAgentClientFake{ |
| 65 | + GetInterfaceIPInfoF: func(_ context.Context) (nmagent.Interfaces, error) { |
| 66 | + return interfaces, nil |
| 67 | + }, |
| 68 | + }, |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +// SetCNIConflistGenerator sets the CNIConflistGenerator for the HTTPRestService. |
| 73 | +func (service *HTTPRestService) SetCNIConflistGenerator(generator CNIConflistGenerator) { |
| 74 | + service.cniConflistGenerator = generator |
| 75 | +} |
| 76 | + |
| 77 | +// GetNodesubnetIPFetcher gets the nodesubnet.IPFetcher from the HTTPRestService. |
| 78 | +func (service *HTTPRestService) GetNodesubnetIPFetcher() *nodesubnet.IPFetcher { |
| 79 | + return service.nodesubnetIPFetcher |
| 80 | +} |
0 commit comments