-
Notifications
You must be signed in to change notification settings - Fork 260
[NPM] Generic Dataplane interface for windows and linux #984
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 all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7a4dbf8
adding initial dataplane interface
vakalapa 4385d46
adding some skeleton code for crud functions
vakalapa 013aa67
adding dirty cache initial support for ipset manager
vakalapa 3e32783
correcting some go lints
vakalapa a907ea2
Adding some skeleton around os specific files
vakalapa 58d7782
removing interface and adding some network logic
5c5403e
adding apply ipsets logic
6c5afdc
Addressing some comments and also adding comments to code
cf8e556
Fixing some golints
bfff6a5
addressing some comments
4fe2916
adding some golint checks
9441d08
Adding a new field setProperty and also adding structure for policies
14ef65f
applying some comments
9c1c558
correcting a condition
57d78af
Adding some comments
f702d88
Adding some test cases
a9dfbc3
Addressing some comments
a5cbd0b
Addressing more comments
c921c1d
resolving some comments
af60247
resolving some comments
987f820
fixing some comments
ae527f4
removing lock on policymap
d0eb0c6
fixing some golints
15cae9a
Merge branch 'master' into vakr/dataplaneinterface
7c200c5
Merge branch 'master' into vakr/dataplaneinterface
607ba43
merging with master
942f894
fixingsome wrap checks
50315e6
fixing lints
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| package dataplane | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/Azure/azure-container-networking/npm" | ||
| "github.com/Azure/azure-container-networking/npm/pkg/dataplane/ipsets" | ||
| "github.com/Azure/azure-container-networking/npm/pkg/dataplane/policies" | ||
| ) | ||
|
|
||
| type DataPlane struct { | ||
| policyMgr policies.PolicyManager | ||
| ipsetMgr ipsets.IPSetManager | ||
| networkID string | ||
| // key is PodKey | ||
| endpointCache map[string]*NPMEndpoint | ||
| } | ||
|
|
||
| type NPMEndpoint struct { | ||
| Name string | ||
| ID string | ||
| // Map with Key as Network Policy name to to emulate set | ||
| // and value as struct{} for minimal memory consumption | ||
| NetPolReference map[string]struct{} | ||
| } | ||
|
|
||
| func NewDataPlane() *DataPlane { | ||
| return &DataPlane{ | ||
| policyMgr: policies.NewPolicyManager(), | ||
| ipsetMgr: ipsets.NewIPSetManager(), | ||
| endpointCache: make(map[string]*NPMEndpoint), | ||
| } | ||
| } | ||
|
|
||
| // InitializeDataPlane helps in setting up dataplane for NPM | ||
| func (dp *DataPlane) InitializeDataPlane() error { | ||
| return dp.initializeDataPlane() | ||
| } | ||
|
|
||
| // ResetDataPlane helps in cleaning up dataplane sets and policies programmed | ||
| // by NPM, retunring a clean slate | ||
| func (dp *DataPlane) ResetDataPlane() error { | ||
| return dp.resetDataPlane() | ||
| } | ||
|
|
||
| // CreateIPSet takes in a set object and updates local cache with this set | ||
| func (dp *DataPlane) CreateIPSet(set *ipsets.IPSet) error { | ||
| err := dp.ipsetMgr.CreateIPSet(set) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while creating set: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // DeleteSet checks for members and references of the given "set" type ipset | ||
| // if not used then will delete it from cache | ||
| func (dp *DataPlane) DeleteSet(name string) error { | ||
| err := dp.ipsetMgr.DeleteSet(name) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while deleting set: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // DeleteList sanity checks and deletes a list ipset | ||
| func (dp *DataPlane) DeleteList(name string) error { | ||
| err := dp.ipsetMgr.DeleteList(name) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while deleting list: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // AddToSet takes in a list of IPset objects along with IP member | ||
| // and then updates it local cache | ||
| func (dp *DataPlane) AddToSet(setNames []*ipsets.IPSet, ip, podKey string) error { | ||
| err := dp.ipsetMgr.AddToSet(setNames, ip, podKey) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while adding to set: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // RemoveFromSet takes in list of setnames from which a given IP member should be | ||
| // removed and will update the local cache | ||
| func (dp *DataPlane) RemoveFromSet(setNames []string, ip, podKey string) error { | ||
| err := dp.ipsetMgr.RemoveFromSet(setNames, ip, podKey) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while removing from set: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // AddToList takes a list name and list of sets which are to be added as members | ||
| // to given list | ||
| func (dp *DataPlane) AddToList(listName string, setNames []string) error { | ||
| err := dp.ipsetMgr.AddToList(listName, setNames) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while adding to list: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // RemoveFromList takes a list name and list of sets which are to be removed as members | ||
| // to given list | ||
| func (dp *DataPlane) RemoveFromList(listName string, setNames []string) error { | ||
| err := dp.ipsetMgr.RemoveFromList(listName, setNames) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while removing from list: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // UpdatePod is to be called by pod_controller ONLY when a new pod is CREATED. | ||
| func (dp *DataPlane) UpdatePod(pod *npm.NpmPod) error { | ||
| err := dp.updatePod(pod) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while updating pod: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // ApplyDataPlane all the IPSet operations just update cache and update a dirty ipset structure, | ||
| // they do not change apply changes into dataplane. This function needs to be called at the | ||
| // end of IPSet operations of a given controller event, it will check for the dirty ipset list | ||
| // and accordingly makes changes in dataplane. This function helps emulate a single call to | ||
| // dataplane instead of multiple ipset operations calls ipset operations calls to dataplane | ||
| func (dp *DataPlane) ApplyDataPlane() error { | ||
| err := dp.ipsetMgr.ApplyIPSets(dp.networkID) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while applying IPSets: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // AddPolicy takes in a translated NPMNetworkPolicy object and applies on dataplane | ||
| func (dp *DataPlane) AddPolicy(policies *policies.NPMNetworkPolicy) error { | ||
| err := dp.policyMgr.AddPolicy(policies) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while adding policy: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // RemovePolicy takes in network policy name and removes it from dataplane and cache | ||
| func (dp *DataPlane) RemovePolicy(policyName string) error { | ||
| err := dp.policyMgr.RemovePolicy(policyName) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while removing policy: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // UpdatePolicy takes in updated policy object, calculates the delta and applies changes | ||
| // onto dataplane accordingly | ||
| func (dp *DataPlane) UpdatePolicy(policies *policies.NPMNetworkPolicy) error { | ||
| err := dp.policyMgr.UpdatePolicy(policies) | ||
| if err != nil { | ||
| return fmt.Errorf("[DataPlane] error while updating policy: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
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,21 @@ | ||
| package dataplane | ||
|
|
||
| import ( | ||
| "github.com/Azure/azure-container-networking/npm" | ||
| "k8s.io/klog" | ||
| ) | ||
|
|
||
| // initializeDataPlane should be adding required chains and rules | ||
| func (dp *DataPlane) initializeDataPlane() error { | ||
| klog.Infof("Initializing dataplane for linux") | ||
| return nil | ||
| } | ||
|
|
||
| // updatePod is no-op in Linux | ||
| func (dp *DataPlane) updatePod(pod *npm.NpmPod) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (dp *DataPlane) resetDataPlane() error { | ||
| return nil | ||
| } |
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,23 @@ | ||
| package dataplane | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/Azure/azure-container-networking/npm/metrics" | ||
| "github.com/Azure/azure-container-networking/npm/pkg/dataplane/ipsets" | ||
| ) | ||
|
|
||
| func TestNewDataPlane(t *testing.T) { | ||
| metrics.InitializeAll() | ||
| dp := NewDataPlane() | ||
|
|
||
| if dp == nil { | ||
| t.Error("NewDataPlane() returned nil") | ||
| } | ||
| set := ipsets.NewIPSet("test", ipsets.NameSpace) | ||
|
|
||
| err := dp.CreateIPSet(set) | ||
| if err != nil { | ||
| t.Error("CreateIPSet() returned error") | ||
| } | ||
| } |
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,54 @@ | ||
| package dataplane | ||
|
|
||
| import ( | ||
| "github.com/Azure/azure-container-networking/npm" | ||
| "github.com/Microsoft/hcsshim/hcn" | ||
| "k8s.io/klog" | ||
| ) | ||
|
|
||
| const ( | ||
| // Windows specific constants | ||
| AzureNetworkName = "azure" | ||
| ) | ||
|
|
||
| // initializeDataPlane will help gather network and endpoint details | ||
| func (dp *DataPlane) initializeDataPlane() error { | ||
| klog.Infof("Initializing dataplane for windows") | ||
|
|
||
| // Get Network ID | ||
| network, err := hcn.GetNetworkByName(AzureNetworkName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| dp.networkID = network.Id | ||
|
|
||
| endpoints, err := hcn.ListEndpointsOfNetwork(dp.networkID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| for _, endpoint := range endpoints { | ||
| klog.Infof("Endpoints info %+v", endpoint.Policies) | ||
| ep := &NPMEndpoint{ | ||
| Name: endpoint.Name, | ||
| ID: endpoint.Id, | ||
| NetPolReference: make(map[string]struct{}), | ||
| } | ||
|
|
||
| dp.endpointCache[ep.Name] = ep | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // updatePod has two responsibilities in windows | ||
| // 1. Will call into dataplane and updates endpoint references of this pod. | ||
| // 2. Will check for existing applicable network policies and applies it on endpoint | ||
| func (dp *DataPlane) updatePod(pod *npm.NpmPod) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (dp *DataPlane) resetDataPlane() error { | ||
| return nil | ||
| } |
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.