Skip to content

Commit

Permalink
Address comments to add descriptive names
Browse files Browse the repository at this point in the history
Signed-off-by: abhiraut <[email protected]>
  • Loading branch information
abhiraut committed Aug 9, 2021
1 parent 3d888a1 commit 4eee880
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cmd/antrea-controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func run(o *Options) error {
tfInformer := crdInformerFactory.Crd().V1alpha1().Traceflows()
cgv1a2Informer := crdInformerFactory.Crd().V1alpha2().ClusterGroups()
cgInformer := crdInformerFactory.Crd().V1alpha3().ClusterGroups()
gInformer := crdInformerFactory.Crd().V1alpha3().Groups()
grpInformer := crdInformerFactory.Crd().V1alpha3().Groups()
egressInformer := crdInformerFactory.Crd().V1alpha2().Egresses()
externalIPPoolInformer := crdInformerFactory.Crd().V1alpha2().ExternalIPPools()

Expand Down Expand Up @@ -161,7 +161,7 @@ func run(o *Options) error {
anpInformer,
tierInformer,
cgInformer,
gInformer,
grpInformer,
addressGroupStore,
appliedToGroupStore,
networkPolicyStore,
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/networkpolicy/antreanetworkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (n *NetworkPolicyController) processAppliedTo(namespace string, appliedTo [
for _, at := range appliedTo {
var atg string
if at.Group != "" {
atg = n.processAppliedToGroupForG(namespace, at.Group)
atg = n.processAppliedToGroupForGroup(namespace, at.Group)
} else {
atg = n.createAppliedToGroup(namespace, at.PodSelector, at.NamespaceSelector, at.ExternalEntitySelector)
}
Expand All @@ -208,9 +208,9 @@ func (n *NetworkPolicyController) processAppliedTo(namespace string, appliedTo [
return appliedToGroupNames
}

func (n *NetworkPolicyController) processAppliedToGroupForG(namespace, groupName string) string {
func (n *NetworkPolicyController) processAppliedToGroupForGroup(namespace, groupName string) string {
// Retrieve Group for corresponding entry in the AppliedToGroup.
g, err := n.gLister.Groups(namespace).Get(groupName)
g, err := n.grpLister.Groups(namespace).Get(groupName)
if err != nil {
// This error should not occur as we validate that a Group must exist before
// referencing it in an ANP.
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/networkpolicy/antreanetworkpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func TestDeleteANP(t *testing.T) {
assert.False(t, found, "expected internal NetworkPolicy to be deleted")
}

func TestProcessAppliedToGroupsForG(t *testing.T) {
func TestProcessAppliedToGroupsForGroup(t *testing.T) {
selectorA := metav1.LabelSelector{MatchLabels: map[string]string{"foo1": "bar1"}}
cidr := "10.0.0.0/24"
// gA with selector present in cache
Expand Down Expand Up @@ -629,7 +629,7 @@ func TestProcessAppliedToGroupsForG(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actualAG := npc.processAppliedToGroupForG(tt.namespace, tt.inputG)
actualAG := npc.processAppliedToGroupForGroup(tt.namespace, tt.inputG)
assert.Equal(t, tt.expectedAG, actualAG, "appliedToGroup list does not match")
})
}
Expand Down
16 changes: 2 additions & 14 deletions pkg/controller/networkpolicy/clustergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,7 @@ func (c *NetworkPolicyController) processNextInternalGroupWorkItem() bool {
return true
}

func (n *NetworkPolicyController) syncInternalGroup(key string) error {
// Retrieve the internal Group corresponding to this key.
grpObj, found, _ := n.internalGroupStore.Get(key)
if !found {
klog.V(2).Infof("Internal group %s not found.", key)
n.groupingInterface.DeleteGroup(clusterGroupType, key)
return nil
}
grp := grpObj.(*antreatypes.Group)
if grp.SourceReference.Namespace != "" {
// Sync the Group as a Namespaced Group.
return n.syncNamespacedInternalGroup(grp)
}
func (n *NetworkPolicyController) syncInternalClusterGroup(grp *antreatypes.Group) error {
// Retrieve the ClusterGroup corresponding to this key.
cg, err := n.cgLister.Get(grp.SourceReference.ToString())
if err != nil {
Expand All @@ -231,7 +219,7 @@ func (n *NetworkPolicyController) syncInternalGroup(key string) error {
ServiceReference: grp.ServiceReference,
ChildGroups: grp.ChildGroups,
}
klog.V(2).Infof("Updating existing internal Group %s", key)
klog.V(2).Infof("Updating existing internal Group %s", grp.SourceReference.ToString())
n.internalGroupStore.Update(updatedGrp)
}
// Update the ClusterGroup status to Realized as Antrea has recognized the Group and
Expand Down
18 changes: 17 additions & 1 deletion pkg/controller/networkpolicy/crd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (n *NetworkPolicyController) toAntreaPeerForCRD(peers []v1alpha1.NetworkPol
func (n *NetworkPolicyController) processRefGroupOrClusterGroup(g, namespace string) (string, []controlplane.IPBlock) {
var key string
if namespace != "" {
grp, err := n.gLister.Groups(namespace).Get(g)
grp, err := n.grpLister.Groups(namespace).Get(g)
if err != nil {
klog.Errorf("Group %s/%s not found: %v", namespace, g, err)
return "", nil
Expand Down Expand Up @@ -250,3 +250,19 @@ func getNormalizedNameForSelector(sel *antreatypes.GroupSelector) string {
}
return ""
}

func (n *NetworkPolicyController) syncInternalGroup(key string) error {
// Retrieve the internal Group corresponding to this key.
grpObj, found, _ := n.internalGroupStore.Get(key)
if !found {
klog.V(2).Infof("Internal group %s not found.", key)
n.groupingInterface.DeleteGroup(clusterGroupType, key)
return nil
}
grp := grpObj.(*antreatypes.Group)
if grp.SourceReference.Namespace != "" {
// Sync the Group as a Namespaced Group.
return n.syncInternalNamespacedGroup(grp)
}
return n.syncInternalClusterGroup(grp)
}
4 changes: 2 additions & 2 deletions pkg/controller/networkpolicy/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ func getGroupSourceRef(g *crdv1alpha3.Group) *controlplane.GroupReference {
}
}

func (n *NetworkPolicyController) syncNamespacedInternalGroup(grp *antreatypes.Group) error {
func (n *NetworkPolicyController) syncInternalNamespacedGroup(grp *antreatypes.Group) error {
// Retrieve the Group corresponding to this key.
g, err := n.gLister.Groups(grp.SourceReference.Namespace).Get(grp.SourceReference.Name)
g, err := n.grpLister.Groups(grp.SourceReference.Namespace).Get(grp.SourceReference.Name)
if err != nil {
klog.Infof("Didn't find the %s, skip processing of internal group", grp.SourceReference.ToTypedString())
return nil
Expand Down
20 changes: 10 additions & 10 deletions pkg/controller/networkpolicy/networkpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ type NetworkPolicyController struct {
// once.
cgListerSynced cache.InformerSynced

gInformer crdv1a3informers.GroupInformer
// gLister is able to list/get Groups and is populated by the shared informer passed to
grpInformer crdv1a3informers.GroupInformer
// grpLister is able to list/get Groups and is populated by the shared informer passed to
// NewGroupController.
gLister crdv1a3listers.GroupLister
// gListerSynced is a function which returns true if the Group shared informer has been synced at least
grpLister crdv1a3listers.GroupLister
// grpListerSynced is a function which returns true if the Group shared informer has been synced at least
// once.
gListerSynced cache.InformerSynced
grpListerSynced cache.InformerSynced

// addressGroupStore is the storage where the populated Address Groups are stored.
addressGroupStore storage.Interface
Expand Down Expand Up @@ -237,7 +237,7 @@ func NewNetworkPolicyController(kubeClient clientset.Interface,
anpInformer secinformers.NetworkPolicyInformer,
tierInformer secinformers.TierInformer,
cgInformer crdv1a3informers.ClusterGroupInformer,
gInformer crdv1a3informers.GroupInformer,
grpInformer crdv1a3informers.GroupInformer,
addressGroupStore storage.Interface,
appliedToGroupStore storage.Interface,
internalNetworkPolicyStore storage.Interface,
Expand Down Expand Up @@ -291,9 +291,9 @@ func NewNetworkPolicyController(kubeClient clientset.Interface,
n.cgInformer = cgInformer
n.cgLister = cgInformer.Lister()
n.cgListerSynced = cgInformer.Informer().HasSynced
n.gInformer = gInformer
n.gLister = gInformer.Lister()
n.gListerSynced = gInformer.Informer().HasSynced
n.grpInformer = grpInformer
n.grpLister = grpInformer.Lister()
n.grpListerSynced = grpInformer.Informer().HasSynced
// Add handlers for Namespace events.
n.namespaceInformer.Informer().AddEventHandlerWithResyncPeriod(
cache.ResourceEventHandlerFuncs{
Expand Down Expand Up @@ -448,7 +448,7 @@ func NewNetworkPolicyController(kubeClient clientset.Interface,
resyncPeriod,
)
// Add event handlers for Group notification.
gInformer.Informer().AddEventHandlerWithResyncPeriod(
grpInformer.Informer().AddEventHandlerWithResyncPeriod(
cache.ResourceEventHandlerFuncs{
AddFunc: n.addGroup,
UpdateFunc: n.updateGroup,
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/networkpolicy/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func (g *groupValidator) validateChildGroup(s *crdv1alpha3.Group) (string, bool)
return fmt.Sprintf("cannot set childGroups for Group %s/%s, who has %d parents", s.Namespace, s.Name, len(parentGrps)), false
}
for _, groupname := range s.Spec.ChildGroups {
childGrp, err := g.networkPolicyController.gLister.Groups(s.Namespace).Get(string(groupname))
childGrp, err := g.networkPolicyController.grpLister.Groups(s.Namespace).Get(string(groupname))
if err != nil {
// the childGroup has not been created yet.
continue
Expand Down

0 comments on commit 4eee880

Please sign in to comment.