Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ccb9c70
wip with StrictlyHasSetPolicies approach
huntergregory Oct 12, 2022
a092f05
better approaching of getting all set policies
huntergregory Oct 13, 2022
dea282f
wip for rigorous win dp UTs
huntergregory Oct 13, 2022
bf03f80
marshal setpolicies in hns mock and dont short circuit in UTs
huntergregory Oct 14, 2022
8700de4
policy stuff and update test cases
huntergregory Oct 14, 2022
f69c7a8
marshal ACLs in hns mock
huntergregory Oct 14, 2022
2d0de59
more UTs and minor refinements
huntergregory Oct 14, 2022
ce0b406
option to apply dp or not
huntergregory Oct 17, 2022
4c903f4
address cmp.Equal and t.Helper comments
huntergregory Oct 17, 2022
af2da1b
dpEvent returns error and better defined concurrency
huntergregory Oct 18, 2022
ee91dfd
remove unnecessary logic in concurrent test code
huntergregory Oct 18, 2022
eecb47d
approach #3 emulating cyclonus
huntergregory Oct 20, 2022
03ee497
namespace method for podmetadata
huntergregory Oct 21, 2022
c0cdbc8
refactor Action structure and TestCase wait group behavior
huntergregory Oct 21, 2022
c27f3b4
hnsactions and renaming a file
huntergregory Oct 21, 2022
477d66c
refactor to Serial and ThreadedTestCase structs, and move files to dp…
huntergregory Oct 21, 2022
ba0cf5b
hns latency hard coded to be the same for all threaded test cases
huntergregory Oct 21, 2022
60928b3
fix build error after rebasing
huntergregory Oct 21, 2022
32cd5ab
export fake hns network id
huntergregory Oct 21, 2022
cfc0099
address comments on multierr and terminology
huntergregory Oct 24, 2022
c1bad9d
add comment about pod metadata in controller
huntergregory Oct 24, 2022
e99fba5
pod update and delete actions
huntergregory Oct 24, 2022
67ba42c
move ApplyDPAction to top
huntergregory Oct 24, 2022
12d0dcf
namespace actions and rename some fields of UpdatePod
huntergregory Oct 24, 2022
76f040c
adding code comments
huntergregory Oct 24, 2022
1f304f6
reconcile action
huntergregory Oct 24, 2022
9740ccd
fix bug in key-val ipsets
huntergregory Oct 24, 2022
de6baaf
implement all previous test cases
huntergregory Oct 24, 2022
9bde4b2
fix incorrect error wrapping in dataplane.go
huntergregory Oct 24, 2022
0aaba05
multi-job tests are working. updated terminology from routine to job
huntergregory Oct 24, 2022
67d9518
MultiErrManager instead of dependency for multierr
huntergregory Oct 24, 2022
036a6c8
return to the channel approach for multierr, now using FailNow instea…
huntergregory Oct 24, 2022
8cf6b59
fix some lints
huntergregory Oct 24, 2022
39894d2
fix more lints
huntergregory Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion common/ioshim_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
utilexec "k8s.io/utils/exec"
)

const FakeHNSNetworkID = "1234"

type IOShim struct {
Exec utilexec.Interface
Hns hnswrapper.HnsV2WrapperInterface
Expand All @@ -24,7 +26,7 @@ func NewIOShim() *IOShim {
func NewMockIOShim(calls []testutils.TestCmd) *IOShim {
hns := hnswrapper.NewHnsv2wrapperFake()
network := &hcn.HostComputeNetwork{
Id: "1234",
Id: FakeHNSNetworkID,
Name: "azure",
}

Expand Down
123 changes: 101 additions & 22 deletions network/hnswrapper/hnsv2wrapperfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,13 @@ func (f Hnsv2wrapperFake) GetEndpointByName(endpointName string) (*hcn.HostCompu
}

type FakeHNSCache struct {
networks map[string]*FakeHostComputeNetwork
// networks maps network name to network object
networks map[string]*FakeHostComputeNetwork
// endpoints maps endpoint ID to endpoint object
endpoints map[string]*FakeHostComputeEndpoint
}

// SetPolicy returns the first SetPolicy found with this ID in any network.
func (fCache FakeHNSCache) SetPolicy(setID string) *hcn.SetPolicySetting {
for _, network := range fCache.networks {
for _, policy := range network.Policies {
Expand All @@ -332,6 +335,35 @@ func (fCache FakeHNSCache) SetPolicy(setID string) *hcn.SetPolicySetting {
return nil
}

func (fCache FakeHNSCache) PrettyString() string {
networkStrings := make([]string, 0, len(fCache.networks))
for _, network := range fCache.networks {
networkStrings = append(networkStrings, fmt.Sprintf("[%+v]", network.PrettyString()))
}

endpointStrings := make([]string, 0, len(fCache.endpoints))
for _, endpoint := range fCache.endpoints {
endpointStrings = append(endpointStrings, fmt.Sprintf("[%+v]", endpoint.PrettyString()))
}

return fmt.Sprintf("networks: %s\nendpoints: %s", strings.Join(networkStrings, ","), strings.Join(endpointStrings, ","))
}

// AllSetPolicies returns all SetPolicies in a given network as a map of SetPolicy ID to SetPolicy object.
func (fCache FakeHNSCache) AllSetPolicies(networkID string) map[string]*hcn.SetPolicySetting {
setPolicies := make(map[string]*hcn.SetPolicySetting)
for _, network := range fCache.networks {
if network.ID == networkID {
for _, setPolicy := range network.Policies {
setPolicies[setPolicy.Id] = setPolicy
}
break
}
}
return setPolicies
}

// ACLPolicies returns a map of the inputed Endpoint IDs to Policies with the given policyID.
func (fCache FakeHNSCache) ACLPolicies(epList map[string]string, policyID string) (map[string][]*FakeEndpointPolicy, error) {
aclPols := make(map[string][]*FakeEndpointPolicy)
for ip, epID := range epList {
Expand All @@ -354,6 +386,7 @@ func (fCache FakeHNSCache) ACLPolicies(epList map[string]string, policyID string
return aclPols, nil
}

// GetAllACLs maps all Endpoint IDs to ACLs
func (fCache FakeHNSCache) GetAllACLs() map[string][]*FakeEndpointPolicy {
aclPols := make(map[string][]*FakeEndpointPolicy)
for _, ep := range fCache.endpoints {
Expand All @@ -362,9 +395,20 @@ func (fCache FakeHNSCache) GetAllACLs() map[string][]*FakeEndpointPolicy {
return aclPols
}

// EndpointIP returns the Endpoint's IP or an empty string if the Endpoint doesn't exist.
func (fCache FakeHNSCache) EndpointIP(id string) string {
for _, ep := range fCache.endpoints {
if ep.ID == id {
return ep.IPConfiguration
}
}
return ""
}

type FakeHostComputeNetwork struct {
ID string
Name string
ID string
Name string
// Policies maps SetPolicy ID to SetPolicy object
Policies map[string]*hcn.SetPolicySetting
}

Expand All @@ -376,10 +420,33 @@ func NewFakeHostComputeNetwork(network *hcn.HostComputeNetwork) *FakeHostCompute
}
}

func (fNetwork *FakeHostComputeNetwork) PrettyString() string {
setPolicyStrings := make([]string, 0, len(fNetwork.Policies))
for _, setPolicy := range fNetwork.Policies {
setPolicyStrings = append(setPolicyStrings, fmt.Sprintf("[%+v]", setPolicy))
}
return fmt.Sprintf("ID: %s, Name: %s, SetPolicies: [%s]", fNetwork.ID, fNetwork.Name, strings.Join(setPolicyStrings, ","))
}

func (fNetwork *FakeHostComputeNetwork) GetHCNObj() *hcn.HostComputeNetwork {
setPolicies := make([]hcn.NetworkPolicy, 0)
for _, setPolicy := range fNetwork.Policies {
rawSettings, err := json.Marshal(setPolicy)
if err != nil {
fmt.Printf("FakeHostComputeNetwork: error marshalling SetPolicy: %+v. err: %s\n", setPolicy, err.Error())
continue
}
policy := hcn.NetworkPolicy{
Type: hcn.SetPolicy,
Settings: rawSettings,
}
setPolicies = append(setPolicies, policy)
}

return &hcn.HostComputeNetwork{
Id: fNetwork.ID,
Name: fNetwork.Name,
Id: fNetwork.ID,
Name: fNetwork.Name,
Policies: setPolicies,
}
}

Expand All @@ -404,29 +471,41 @@ func NewFakeHostComputeEndpoint(endpoint *hcn.HostComputeEndpoint) *FakeHostComp
}
}

func (fEndpoint *FakeHostComputeEndpoint) GetHCNObj() *hcn.HostComputeEndpoint {
// NOTE: not including other policy types like perhaps SetPolicies
hcnEndpoint := &hcn.HostComputeEndpoint{
Id: fEndpoint.ID,
Name: fEndpoint.Name,
HostComputeNetwork: fEndpoint.HostComputeNetwork,
Policies: make([]hcn.EndpointPolicy, 0),
func (fEndpoint *FakeHostComputeEndpoint) PrettyString() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that existing methods do this, but the generally accepted style in the wider Go community is for a single letter matching the first letter of the type the method is being implemented on for "this":

func (f *FakeHostComputeEndpoint) PrettyString() string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you suggest keeping the same style throughout the file or adding new methods in the generally accepted way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linters complain if all method receivers are not named the same, so all should be changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, ordinarily I'd say just do it for this one... but if linters are going to be a bother, than it should be done everywhere. Really, I just want to avoid perpetuating bad patterns in the name of consistency with the existing codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the reviewer's sake, can address this in a followup PR since it will create a diff for most of the file

aclStrings := make([]string, 0, len(fEndpoint.Policies))
for _, acl := range fEndpoint.Policies {
aclStrings = append(aclStrings, fmt.Sprintf("[%+v]", acl))
}
return fmt.Sprintf("ID: %s, Name: %s, IP: %s, ACLs: [%s]",
fEndpoint.ID, fEndpoint.Name, fEndpoint.IPConfiguration, strings.Join(aclStrings, ","))
}

for _, fakeEndpointPol := range fEndpoint.Policies {
rawJSON, err := json.Marshal(fakeEndpointPol)
func (fEndpoint *FakeHostComputeEndpoint) GetHCNObj() *hcn.HostComputeEndpoint {
acls := make([]hcn.EndpointPolicy, 0)
for _, acl := range fEndpoint.Policies {
rawSettings, err := json.Marshal(acl)
if err != nil {
fmt.Printf("FAILURE marshalling fake endpoint policy: %s\n", err.Error())
} else {
hcnPolicy := hcn.EndpointPolicy{
Type: hcn.ACL,
Settings: rawJSON,
}
hcnEndpoint.Policies = append(hcnEndpoint.Policies, hcnPolicy)
fmt.Printf("FakeHostComputeEndpoint: error marshalling ACL: %+v. err: %s\n", acl, err.Error())
continue
}
policy := hcn.EndpointPolicy{
Type: hcn.ACL,
Settings: rawSettings,
}
acls = append(acls, policy)
}

return hcnEndpoint
return &hcn.HostComputeEndpoint{
Id: fEndpoint.ID,
Name: fEndpoint.Name,
HostComputeNetwork: fEndpoint.HostComputeNetwork,
IpConfigurations: []hcn.IpConfig{
{
IpAddress: fEndpoint.IPConfiguration,
},
},
Policies: acls,
}
}

func (fEndpoint *FakeHostComputeEndpoint) RemovePolicy(toRemovePol *FakeEndpointPolicy) error {
Expand Down
2 changes: 2 additions & 0 deletions npm/pkg/controlplane/controllers/v2/podController.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ func (c *PodController) cleanUpDeletedPod(cachedNpmPodKey string) error {
func (c *PodController) manageNamedPortIpsets(portList []corev1.ContainerPort, podKey,
podIP, nodeName string, namedPortOperation NamedPortOperation) error {
if util.IsWindowsDP() {
// NOTE: if we support namedport operations, need to be careful of implications of including the node name in the pod metadata below
// since we say the node name is "" in cleanUpDeletedPod
klog.Warningf("Windows Dataplane does not support NamedPort operations. Operation: %s portList is %+v", namedPortOperation, portList)
return nil
}
Expand Down
Loading