-
Notifications
You must be signed in to change notification settings - Fork 260
feat: support for cilium + nodesubnet #3073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
db4166e
feat: support for cilium + nodesubnet
santhoshmprabhu 9cc4ec6
fix: make linter happy
santhoshmprabhu 107ebce
fix: make linter happy
santhoshmprabhu 636ab39
Merge branch 'master' into sanprabhu/cilium-node-subnet
santhoshmprabhu 07a8575
fix: make linter happy
santhoshmprabhu 7f10972
Merge branch 'sanprabhu/cilium-node-subnet' of github.com:Azure/azure…
santhoshmprabhu c59f2dc
test: add test for nodesubnet
santhoshmprabhu fbd60a5
chore: add missing files
santhoshmprabhu 4ee1a90
nicer comment
santhoshmprabhu f94cb77
chore: fix comment typo
santhoshmprabhu a1c4bfe
fix: update cns/restserver/nodesubnet.go
santhoshmprabhu 2f15117
fix: update cns/restserver/restserver.go
santhoshmprabhu 6e8bda0
refactor: address comments
santhoshmprabhu 7879de5
Merge branch 'sanprabhu/cilium-node-subnet' of github.com:Azure/azure…
santhoshmprabhu 0fe2285
Merge branch 'master' into sanprabhu/cilium-node-subnet
santhoshmprabhu 301de9f
fix: address comments
santhoshmprabhu 73424b5
Merge branch 'sanprabhu/cilium-node-subnet' of github.com:Azure/azure…
santhoshmprabhu c4d9408
chore:comment cleanup
santhoshmprabhu 2b210d6
fix: do not use bash in ip config update
santhoshmprabhu a15ee32
fix: address comments
santhoshmprabhu 30c7aa2
fix: make linter happy
santhoshmprabhu a8b4cf1
Merge branch 'master' into sanprabhu/cilium-node-subnet
santhoshmprabhu 356dc69
chore: move pipeline changes out
santhoshmprabhu 56f3d48
Merge branch 'master' into sanprabhu/cilium-node-subnet
santhoshmprabhu b3ac582
test: more elaborate test including checks on IP pool state
santhoshmprabhu 6385042
fix: use comments suitable for documentation
santhoshmprabhu d9b4384
chore: address comments
santhoshmprabhu 2a6881f
chore:make linter happy
santhoshmprabhu f8f724d
fix: address comments
santhoshmprabhu a78a6b1
chore: typo
santhoshmprabhu 800785e
chore: address comments
santhoshmprabhu 03b2531
Merge branch 'master' into sanprabhu/cilium-node-subnet
santhoshmprabhu d06db5d
Merge branch 'master' into sanprabhu/cilium-node-subnet
santhoshmprabhu f764c8a
fix: update comments
santhoshmprabhu 8acfe0c
Merge branch 'sanprabhu/cilium-node-subnet' of github.com:Azure/azure…
santhoshmprabhu 8530f85
Merge branch 'master' into sanprabhu/cilium-node-subnet
santhoshmprabhu 0cae5e4
Merge branch 'master' into sanprabhu/cilium-node-subnet
santhoshmprabhu 50c2a1c
Merge branch 'master' into sanprabhu/cilium-node-subnet
santhoshmprabhu f8bcb26
Merge remote-tracking branch 'origin/master' into sanprabhu/cilium-no…
santhoshmprabhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package restserver | ||
QxBytes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import ( | ||
| "context" | ||
| "net/netip" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/azure-container-networking/cns" | ||
| "github.com/Azure/azure-container-networking/cns/common" | ||
| "github.com/Azure/azure-container-networking/cns/fakes" | ||
| "github.com/Azure/azure-container-networking/cns/nodesubnet" | ||
| acn "github.com/Azure/azure-container-networking/common" | ||
| "github.com/Azure/azure-container-networking/nmagent" | ||
| "github.com/Azure/azure-container-networking/store" | ||
| ) | ||
|
|
||
| func GetRestServiceObjectForNodeSubnetTest(t *testing.T, generator CNIConflistGenerator) *HTTPRestService { | ||
santhoshmprabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| config := &common.ServiceConfig{ | ||
| Name: "test", | ||
| Version: "1.0", | ||
| ChannelMode: "AzureHost", | ||
| Store: store.NewMockStore("test"), | ||
| } | ||
| interfaces := nmagent.Interfaces{ | ||
| Entries: []nmagent.Interface{ | ||
| { | ||
| MacAddress: nmagent.MACAddress{0x00, 0x0D, 0x3A, 0xF9, 0xDC, 0xA6}, | ||
| IsPrimary: true, | ||
| InterfaceSubnets: []nmagent.InterfaceSubnet{ | ||
| { | ||
| Prefix: "10.240.0.0/16", | ||
| IPAddress: []nmagent.NodeIP{ | ||
| { | ||
| Address: nmagent.IPAddress(netip.AddrFrom4([4]byte{10, 240, 0, 5})), | ||
| IsPrimary: true, | ||
| }, | ||
| { | ||
| Address: nmagent.IPAddress(netip.AddrFrom4([4]byte{10, 240, 0, 6})), | ||
| IsPrimary: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| svc, err := cns.NewService(config.Name, config.Version, config.ChannelMode, config.Store) | ||
| if err != nil { | ||
| return nil | ||
| } | ||
|
|
||
| svc.SetOption(acn.OptCnsURL, "") | ||
| svc.SetOption(acn.OptCnsPort, "") | ||
| err = svc.Initialize(config) | ||
| if err != nil { | ||
| return nil | ||
| } | ||
|
|
||
| t.Cleanup(func() { svc.Uninitialize() }) | ||
|
|
||
| return &HTTPRestService{ | ||
| Service: svc, | ||
| cniConflistGenerator: generator, | ||
| state: &httpRestServiceState{}, | ||
| PodIPConfigState: make(map[string]cns.IPConfigurationStatus), | ||
| nma: &fakes.NMAgentClientFake{ | ||
| GetInterfaceIPInfoF: func(_ context.Context) (nmagent.Interfaces, error) { | ||
| return interfaces, nil | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // SetCNIConflistGenerator sets the CNIConflistGenerator for the HTTPRestService. | ||
| func (service *HTTPRestService) SetCNIConflistGenerator(generator CNIConflistGenerator) { | ||
| service.cniConflistGenerator = generator | ||
| } | ||
|
|
||
| // GetNodesubnetIPFetcher gets the nodesubnet.IPFetcher from the HTTPRestService. | ||
| func (service *HTTPRestService) GetNodesubnetIPFetcher() *nodesubnet.IPFetcher { | ||
| return service.nodesubnetIPFetcher | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package restserver | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/netip" | ||
|
|
||
| "github.com/Azure/azure-container-networking/cns" | ||
| "github.com/Azure/azure-container-networking/cns/logger" | ||
| nodesubnet "github.com/Azure/azure-container-networking/cns/nodesubnet" | ||
| "github.com/Azure/azure-container-networking/cns/types" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| var _ nodesubnet.IPConsumer = &HTTPRestService{} | ||
|
|
||
| // Implement the UpdateIPsForNodeSubnet method for HTTPRestService | ||
santhoshmprabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| func (service *HTTPRestService) UpdateIPsForNodeSubnet(secondaryIPs []netip.Addr) error { | ||
| secondaryIPStrs := make([]string, len(secondaryIPs)) | ||
| for i, ip := range secondaryIPs { | ||
| secondaryIPStrs[i] = ip.String() | ||
| } | ||
|
|
||
| networkContainerRequest := nodesubnet.CreateNodeSubnetNCRequest(secondaryIPStrs) | ||
|
|
||
| code, msg := service.saveNetworkContainerGoalState(*networkContainerRequest) | ||
| if code != types.Success { | ||
| return errors.Errorf("failed to save fetched ips. code: %d, message %s", code, msg) | ||
| } | ||
|
|
||
| logger.Debugf("IP change processed successfully") | ||
|
|
||
| // saved NC successfully, generate conflist to indicate CNS is ready | ||
| go service.MustGenerateCNIConflistOnce() | ||
santhoshmprabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
santhoshmprabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return nil | ||
| } | ||
|
|
||
| func (service *HTTPRestService) InitializeNodeSubnet(ctx context.Context, podInfoByIPProvider cns.PodInfoByIPProvider) error { | ||
santhoshmprabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Set orchestrator type | ||
santhoshmprabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| orchestrator := cns.SetOrchestratorTypeRequest{ | ||
| OrchestratorType: cns.KubernetesCRD, | ||
| } | ||
| service.SetNodeOrchestrator(&orchestrator) | ||
|
|
||
| if podInfoByIPProvider == nil { | ||
| logger.Printf("PodInfoByIPProvider is nil, this usually means no saved endpoint state. Skipping reconciliation") | ||
| } else if _, err := nodesubnet.ReconcileInitialCNSState(ctx, service, podInfoByIPProvider); err != nil { | ||
| return errors.Wrap(err, "reconcile initial CNS state") | ||
| } | ||
| // statefile (if any) is reconciled. Initialize the IP fetcher. Start the IP fetcher only after the service is started, | ||
| // and any pending async delete operations are completed. | ||
| service.nodesubnetIPFetcher = nodesubnet.NewIPFetcher(service.nma, service, 0, 0, logger.Log) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (service *HTTPRestService) StartNodeSubnet(ctx context.Context) { | ||
santhoshmprabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| service.nodesubnetIPFetcher.Start(ctx) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package restserver_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/azure-container-networking/cns" | ||
| "github.com/Azure/azure-container-networking/cns/logger" | ||
| "github.com/Azure/azure-container-networking/cns/restserver" | ||
| ) | ||
|
|
||
| // Mock implementation of PodInfoByIPProvider | ||
| type MockPodInfoByIPProvider struct{} | ||
|
|
||
| func (m *MockPodInfoByIPProvider) PodInfoByIP() (res map[string]cns.PodInfo, err error) { | ||
| return res, nil | ||
| } | ||
|
|
||
| // Mock implementation of CNIConflistGenerator | ||
| type MockCNIConflistGenerator struct { | ||
| GenerateCalled chan struct{} | ||
| } | ||
|
|
||
| func (m *MockCNIConflistGenerator) Generate() error { | ||
| close(m.GenerateCalled) | ||
| return nil | ||
| } | ||
|
|
||
| func (m *MockCNIConflistGenerator) Close() error { | ||
| // Implement the Close method logic here if needed | ||
| return nil | ||
| } | ||
|
|
||
| func TestNodeSubnet(t *testing.T) { | ||
santhoshmprabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mockPodInfoProvider := &MockPodInfoByIPProvider{} | ||
|
|
||
| // Create a real HTTPRestService object | ||
santhoshmprabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mockCNIConflistGenerator := &MockCNIConflistGenerator{ | ||
| GenerateCalled: make(chan struct{}), | ||
| } | ||
| service := restserver.GetRestServiceObjectForNodeSubnetTest(t, mockCNIConflistGenerator) | ||
| ctx, cancel := testContext(t) | ||
| defer cancel() | ||
|
|
||
| err := service.InitializeNodeSubnet(ctx, mockPodInfoProvider) | ||
| service.StartNodeSubnet(ctx) | ||
|
|
||
| if service.GetNodesubnetIPFetcher() == nil { | ||
| t.Error("NodeSubnetIPFetcher is not initialized") | ||
| } | ||
|
|
||
| if err != nil { | ||
| t.Fatalf("InitializeNodeSubnet returned an error: %v", err) | ||
| } | ||
|
|
||
tamilmani1989 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| select { | ||
| case <-ctx.Done(): | ||
| t.Errorf("test context done - %s", ctx.Err()) | ||
| return | ||
| case <-mockCNIConflistGenerator.GenerateCalled: | ||
| break | ||
| } | ||
| } | ||
|
|
||
| // testContext creates a context from the provided testing.T that will be | ||
| // canceled if the test suite is terminated. | ||
| func testContext(t *testing.T) (context.Context, context.CancelFunc) { | ||
| if deadline, ok := t.Deadline(); ok { | ||
| return context.WithDeadline(context.Background(), deadline) | ||
| } | ||
| return context.WithCancel(context.Background()) | ||
| } | ||
|
|
||
| func init() { | ||
| logger.InitLogger("testlogs", 0, 0, "./") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.