Skip to content

Commit

Permalink
Namespaced Group membership API
Browse files Browse the repository at this point in the history
Currently Antrea supports ClusterGroup and namespaced Group
CRD, but only provides API for ClusterGroup membership.

This solution adds membership API for namespaced Group at
namespacedgroupmembers.controlplane.antrea.io. The group
association API is still available for both ClusterGroup and
namespaced Group.

Fixes antrea-io#5269

Signed-off-by: Qiyue Yao <yaoq@vmware.com>
  • Loading branch information
qiyueyao committed Aug 10, 2023
1 parent 8ac8a91 commit baa092e
Show file tree
Hide file tree
Showing 20 changed files with 755 additions and 46 deletions.
1 change: 1 addition & 0 deletions hack/update-codegen-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function generate_antrea_client_code {
--plural-exceptions "AntreaNetworkPolicyStats:AntreaNetworkPolicyStats" \
--plural-exceptions "AntreaClusterNetworkPolicyStats:AntreaClusterNetworkPolicyStats" \
--plural-exceptions "ClusterGroupMembers:ClusterGroupMembers" \
--plural-exceptions "NamespacedGroupMembers:NamespacedGroupMembers" \
--go-header-file hack/boilerplate/license_header.go.txt

# Generate listers with K8s codegen tools.
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/controlplane/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&NetworkPolicyStatus{},
&NodeStatsSummary{},
&ClusterGroupMembers{},
&NamespacedGroupMembers{},
&PaginationGetOptions{},
&GroupAssociation{},
&IPGroupAssociation{},
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/controlplane/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ type ClusterGroupMembers struct {
CurrentPage int64
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NamespacedGroupMembers is a list of GroupMember objects or ipBlocks that are currently selected by a Group.
type NamespacedGroupMembers struct {
metav1.TypeMeta
metav1.ObjectMeta
EffectiveMembers []GroupMember
EffectiveIPBlocks []IPNet
TotalMembers int64
TotalPages int64
CurrentPage int64
}

// +k8s:conversion-gen:explicit-from=net/url.Values
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
1 change: 1 addition & 0 deletions pkg/apis/controlplane/v1beta2/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&NetworkPolicyStatus{},
&NodeStatsSummary{},
&ClusterGroupMembers{},
&NamespacedGroupMembers{},
&PaginationGetOptions{},
&GroupAssociation{},
&IPGroupAssociation{},
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/controlplane/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ type ClusterGroupMembers struct {
CurrentPage int64 `json:"currentPage" protobuf:"varint,6,opt,name=currentPage"`
}

// +genclient
// +genclient:onlyVerbs=get
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NamespacedGroupMembers is a list of GroupMember objects or ipBlocks that are currently selected by a Group.
type NamespacedGroupMembers struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
EffectiveMembers []GroupMember `json:"effectiveMembers" protobuf:"bytes,2,rep,name=effectiveMembers"`
EffectiveIPBlocks []IPNet `json:"effectiveIPBlocks" protobuf:"bytes,3,rep,name=effectiveIPBlocks"`
TotalMembers int64 `json:"totalMembers" protobuf:"varint,4,opt,name=totalMembers"`
TotalPages int64 `json:"totalPages" protobuf:"varint,5,opt,name=totalPages"`
CurrentPage int64 `json:"currentPage" protobuf:"varint,6,opt,name=currentPage"`
}

// +k8s:conversion-gen:explicit-from=net/url.Values
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
60 changes: 60 additions & 0 deletions pkg/apis/controlplane/v1beta2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions pkg/apis/controlplane/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions pkg/apis/controlplane/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"antrea.io/antrea/pkg/apiserver/registry/controlplane/egressgroup"
"antrea.io/antrea/pkg/apiserver/registry/controlplane/nodestatssummary"
"antrea.io/antrea/pkg/apiserver/registry/controlplane/supportbundlecollection"
"antrea.io/antrea/pkg/apiserver/registry/namespacedgroupmember"
"antrea.io/antrea/pkg/apiserver/registry/networkpolicy/addressgroup"
"antrea.io/antrea/pkg/apiserver/registry/networkpolicy/appliedtogroup"
"antrea.io/antrea/pkg/apiserver/registry/networkpolicy/clustergroupmember"
Expand Down Expand Up @@ -192,6 +193,7 @@ func installAPIGroup(s *APIServer, c completedConfig) error {
networkPolicyStorage := networkpolicy.NewREST(c.extraConfig.networkPolicyStore)
networkPolicyStatusStorage := networkpolicy.NewStatusREST(c.extraConfig.networkPolicyStatusController)
clusterGroupMembershipStorage := clustergroupmember.NewREST(c.extraConfig.networkPolicyController)
namespacedGroupMembershipStorage := namespacedgroupmember.NewREST(c.extraConfig.networkPolicyController)
groupAssociationStorage := groupassociation.NewREST(c.extraConfig.networkPolicyController)
ipGroupAssociationStorage := ipgroupassociation.NewREST(c.extraConfig.podInformer, c.extraConfig.eeInformer, c.extraConfig.networkPolicyController, c.extraConfig.networkPolicyController)
nodeStatsSummaryStorage := nodestatssummary.NewREST(c.extraConfig.statsAggregator)
Expand All @@ -208,6 +210,7 @@ func installAPIGroup(s *APIServer, c completedConfig) error {
cpv1beta2Storage["groupassociations"] = groupAssociationStorage
cpv1beta2Storage["ipgroupassociations"] = ipGroupAssociationStorage
cpv1beta2Storage["clustergroupmembers"] = clusterGroupMembershipStorage
cpv1beta2Storage["namespacedgroupmembers"] = namespacedGroupMembershipStorage
cpv1beta2Storage["egressgroups"] = egressGroupStorage
cpv1beta2Storage["supportbundlecollections"] = bundleCollectionStorage
cpv1beta2Storage["supportbundlecollections/status"] = bundleCollectionStatusStorage
Expand Down
84 changes: 84 additions & 0 deletions pkg/apiserver/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit baa092e

Please sign in to comment.