Skip to content
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

Support static ipBlock queries for clustergroupmembership #2577

Merged
merged 3 commits into from
Aug 24, 2021

Conversation

Dyanngg
Copy link
Contributor

@Dyanngg Dyanngg commented Aug 11, 2021

Sample output:

curl 127.0.0.1:8001/apis/controlplane.antrea.tanzu.vmware.com/v1beta2/clustergroupmembers/ipb-cg
{
  "kind": "ClusterGroupMembers",
  "apiVersion": "controlplane.antrea.tanzu.vmware.com/v1beta2",
  "metadata": {
    "name": "ipb-cg",
    "creationTimestamp": null
  },
  "effectiveIPBlocks": [
    {
      "ip": "AAAAAAAAAAAAAP//AQAAAA==",
      "prefixLength": 8
    }
  ]
}

@codecov-commenter
Copy link

codecov-commenter commented Aug 11, 2021

Codecov Report

Merging #2577 (93e7983) into main (4aaa90e) will increase coverage by 0.05%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2577      +/-   ##
==========================================
+ Coverage   60.73%   60.78%   +0.05%     
==========================================
  Files         285      286       +1     
  Lines       23045    23053       +8     
==========================================
+ Hits        13996    14013      +17     
+ Misses       7577     7571       -6     
+ Partials     1472     1469       -3     
Flag Coverage Δ
kind-e2e-tests 47.80% <0.00%> (+<0.01%) ⬆️
unit-tests 41.72% <66.66%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/apis/controlplane/types.go 0.00% <0.00%> (ø)
...ntroller/networkpolicy/networkpolicy_controller.go 80.91% <ø> (-0.04%) ⬇️
pkg/controller/networkpolicy/clustergroup.go 65.74% <33.33%> (-0.62%) ⬇️
.../registry/networkpolicy/clustergroupmember/rest.go 88.23% <100.00%> (+4.90%) ⬆️
pkg/apiserver/storage/ram/store.go 78.94% <0.00%> (-1.51%) ⬇️
pkg/agent/nodeportlocal/k8s/npl_controller.go 60.34% <0.00%> (+1.03%) ⬆️
pkg/controller/networkpolicy/status_controller.go 73.20% <0.00%> (+1.96%) ⬆️
...gent/controller/networkpolicy/status_controller.go 75.34% <0.00%> (+2.73%) ⬆️
pkg/apiserver/certificate/certificate.go 76.71% <0.00%> (+6.84%) ⬆️
... and 1 more

func (n *NetworkPolicyController) GetGroupMembers(cgName string) (controlplane.GroupMemberSet, error) {
// If the ClusterGroup is defined by IPBlocks, the returned members will be []controlplane.IPBlock.
// Otherwise, the returned members will be of type controlplane.GroupMemberSet.
func (n *NetworkPolicyController) GetGroupMembers(cgName string) (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we instead return two structs (members, ipb), like how we return (pods, ee) instead of interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a new commit that uses this alternative approach

@Dyanngg Dyanngg force-pushed the cg-show-static-member branch 2 times, most recently from 276c2c7 to 8468a66 Compare August 12, 2021 21:46
@Dyanngg Dyanngg requested a review from abhiraut August 12, 2021 21:47
abhiraut
abhiraut previously approved these changes Aug 12, 2021
@Dyanngg
Copy link
Contributor Author

Dyanngg commented Aug 13, 2021

Fixed lint issue /test-all

@Dyanngg Dyanngg requested a review from abhiraut August 13, 2021 00:23
abhiraut
abhiraut previously approved these changes Aug 13, 2021
@abhiraut abhiraut added this to the Antrea v1.3 release milestone Aug 17, 2021
@abhiraut
Copy link
Contributor

/test-networkpolicy

// IPNet describes an IP network.
type IPNet struct {
IP IPAddress
PrefixLength int32
}

func (ipn IPNet) String() string {
return ipn.IP.String() + "/" + strconv.Itoa(int(ipn.PrefixLength))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return ipn.IP.String() + "/" + strconv.Itoa(int(ipn.PrefixLength))
return fmt.Sprintf("%s/%d", ipn.IP, pn.PrefixLength)

Copy link
Contributor

Choose a reason for hiding this comment

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

done

if len(ipBlocks) > 0 {
effectiveIPBlocks := make([]controlplane.IPNet, 0, len(ipBlocks))
for _, ipb := range ipBlocks {
// ClusterGroup ipBlock cannot have except slices
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

i think the motivation was to showcase that the effective IPs can be calculated easily without the need to remove except slices from the allowed CIDR because ClusterGroup IPBlocks do not support an Except field, unlike K8s NetPol IPblocks

Comment on lines 37 to 42
} else if uid == "cgIPBlock" {
testCIDR := controlplane.IPNet{
IP: controlplane.IPAddress(net.ParseIP("10.0.0.1")),
PrefixLength: int32(24),
}
return nil, []controlplane.IPBlock{{CIDR: testCIDR}}, nil
}
return controlplane.GroupMemberSet{}, nil
return nil, nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

it's not a great way to write that test, hardcoding the uid used in a test case below like this

it feels like fakeQuerier could have 2 maps instead of 1: one map for GroupMemberSets and one map for IPBlocks.

Copy link
Contributor

Choose a reason for hiding this comment

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

oops i missed this one

Copy link
Contributor

Choose a reason for hiding this comment

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

done

@@ -427,11 +427,16 @@ func (n *NetworkPolicyController) getAssociatedGroupsByName(grpName string) []an
}

// GetGroupMembers returns the current members of a ClusterGroup.
func (n *NetworkPolicyController) GetGroupMembers(cgName string) (controlplane.GroupMemberSet, error) {
// If the ClusterGroup is defined by IPBlocks, the returned members will be []controlplane.IPBlock.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/defined by/defined with

Copy link
Contributor

Choose a reason for hiding this comment

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

done

antoninbas
antoninbas previously approved these changes Aug 20, 2021
Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for making the changes

@abhiraut
Copy link
Contributor

/test-all

@antoninbas
Copy link
Contributor

@abhiraut can't merge because of a conflict, PTAL

Dyanngg and others added 3 commits August 23, 2021 11:58
Signed-off-by: Yang Ding <dingyang@vmware.com>
Signed-off-by: Yang Ding <dingyang@vmware.com>
Co-authored-by: abhiraut <rauta@vmware.com>

Signed-off-by: abhiraut <rauta@vmware.com>
@abhiraut
Copy link
Contributor

@abhiraut can't merge because of a conflict, PTAL

rebased

@abhiraut
Copy link
Contributor

/test-all

@antoninbas
Copy link
Contributor

/test-windows-networkpolicy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants