diff --git a/pkg/apis/controlplane/types.go b/pkg/apis/controlplane/types.go index 96667e5f911..2c806f4b69d 100644 --- a/pkg/apis/controlplane/types.go +++ b/pkg/apis/controlplane/types.go @@ -15,12 +15,11 @@ package controlplane import ( - "net" - "strconv" - + "fmt" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" + "net" crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1" statsv1alpha1 "antrea.io/antrea/pkg/apis/stats/v1alpha1" @@ -135,7 +134,7 @@ type IPNet struct { } func (ipn IPNet) String() string { - return ipn.IP.String() + "/" + strconv.Itoa(int(ipn.PrefixLength)) + return fmt.Sprintf("%s/%d", ipn.IP.String(), ipn.PrefixLength) } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/apiserver/registry/networkpolicy/clustergroupmember/rest.go b/pkg/apiserver/registry/networkpolicy/clustergroupmember/rest.go index f7dcd9fded4..f6f510407fa 100644 --- a/pkg/apiserver/registry/networkpolicy/clustergroupmember/rest.go +++ b/pkg/apiserver/registry/networkpolicy/clustergroupmember/rest.go @@ -57,7 +57,8 @@ func (r *REST) Get(ctx context.Context, name string, options *metav1.GetOptions) if len(ipBlocks) > 0 { effectiveIPBlocks := make([]controlplane.IPNet, 0, len(ipBlocks)) for _, ipb := range ipBlocks { - // ClusterGroup ipBlock cannot have except slices + // ClusterGroup ipBlock does not support Except slices, so no need to generate an effective + // list of IPs by removing Except slices from allowed CIDR. effectiveIPBlocks = append(effectiveIPBlocks, ipb.CIDR) } memberList.EffectiveIPBlocks = effectiveIPBlocks diff --git a/pkg/controller/networkpolicy/clustergroup.go b/pkg/controller/networkpolicy/clustergroup.go index f4f6a6da1d6..678d2944ea3 100644 --- a/pkg/controller/networkpolicy/clustergroup.go +++ b/pkg/controller/networkpolicy/clustergroup.go @@ -427,7 +427,7 @@ func (n *NetworkPolicyController) getAssociatedGroupsByName(grpName string) []an } // GetGroupMembers returns the current members of a ClusterGroup. -// If the ClusterGroup is defined by IPBlocks, the returned members will be []controlplane.IPBlock. +// If the ClusterGroup is defined with IPBlocks, the returned members will be []controlplane.IPBlock. // Otherwise, the returned members will be of type controlplane.GroupMemberSet. func (n *NetworkPolicyController) GetGroupMembers(cgName string) (controlplane.GroupMemberSet, []controlplane.IPBlock, error) { groupObj, found, _ := n.internalGroupStore.Get(cgName)