Skip to content

Commit

Permalink
Improve Egress API visibility
Browse files Browse the repository at this point in the history
Record event when EgressIP is assigned to the Node interface.

Signed-off-by: Pulkit Jain <[email protected]>
  • Loading branch information
Pulkit Jain committed Dec 11, 2023
1 parent 4ba9451 commit 408448f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions build/charts/antrea/templates/agent/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,9 @@ rules:
- get
- list
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
2 changes: 1 addition & 1 deletion cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ func run(o *Options) error {
}
if o.enableEgress {
egressController, err = egress.NewEgressController(
ofClient, antreaClientProvider, crdClient, ifaceStore, routeClient, nodeConfig.Name, nodeConfig.NodeTransportInterfaceName,
k8sClient, ofClient, antreaClientProvider, crdClient, ifaceStore, routeClient, nodeConfig.Name, nodeConfig.NodeTransportInterfaceName,
memberlistCluster, egressInformer, nodeInformer, podUpdateChannel, serviceCIDRProvider, o.config.Egress.MaxEgressIPsPerNode,
features.DefaultFeatureGate.Enabled(features.EgressTrafficShaping),
)
Expand Down
24 changes: 24 additions & 0 deletions pkg/agent/controller/egress/egress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
coreinformers "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/kubernetes"
scheme2 "k8s.io/client-go/kubernetes/scheme"
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/retry"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog/v2"

"antrea.io/antrea/multicluster/pkg/client/clientset/versioned/scheme"
"antrea.io/antrea/pkg/agent"
"antrea.io/antrea/pkg/agent/interfacestore"
"antrea.io/antrea/pkg/agent/ipassigner"
Expand Down Expand Up @@ -175,9 +181,12 @@ type EgressController struct {
serviceCIDRUpdateRetryDelay time.Duration

trafficShapingEnabled bool

record record.EventRecorder
}

func NewEgressController(
client kubernetes.Interface,
ofClient openflow.Client,
antreaClientGetter agent.AntreaClientProvider,
crdClient clientsetversioned.Interface,
Expand All @@ -196,6 +205,18 @@ func NewEgressController(
if trafficShapingEnabled && !openflow.OVSMetersAreSupported() {
klog.Info("EgressTrafficShaping feature gate is enabled, but it is ignored because OVS meters are not supported.")
}

eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartStructuredLogging(0)
runtime.Must(scheme.AddToScheme(scheme2.Scheme))
eventBroadcaster.StartRecordingToSink(&v1.EventSinkImpl{
Interface: client.CoreV1().Events(""),
})
recorder := eventBroadcaster.NewRecorder(
scheme2.Scheme,
corev1.EventSource{Component: "antrea-agent"},
)

c := &EgressController{
ofClient: ofClient,
routeClient: routeClient,
Expand All @@ -220,6 +241,8 @@ func NewEgressController(
serviceCIDRUpdateRetryDelay: 10 * time.Second,

trafficShapingEnabled: openflow.OVSMetersAreSupported() && trafficShapingEnabled,

record: recorder,
}
ipAssigner, err := newIPAssigner(nodeTransportInterface, egressDummyDevice)
if err != nil {
Expand Down Expand Up @@ -851,6 +874,7 @@ func (c *EgressController) syncEgress(egressName string) error {
if err := c.ipAssigner.AssignIP(desiredEgressIP, egress.Status.EgressNode != c.nodeName); err != nil {
return err
}
c.record.Eventf(egress, corev1.EventTypeNormal, "IPAssigned", "Assigned %s to %s", egress.Name, desiredNode)
} else {
// Unassign the Egress IP from the local Node if it was assigned by the agent.
if err := c.ipAssigner.UnassignIP(desiredEgressIP); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/controller/egress/egress_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func newFakeController(t *testing.T, initObjects []runtime.Object) *fakeControll
podUpdateChannel := channel.NewSubscribableChannel("PodUpdate", 100)
mockServiceCIDRProvider := servicecidrtest.NewMockInterface(controller)
mockServiceCIDRProvider.EXPECT().AddEventHandler(gomock.Any())
egressController, _ := NewEgressController(mockOFClient,
egressController, _ := NewEgressController(k8sClient, mockOFClient,
&antreaClientGetter{clientset},
crdClient,
ifaceStore,
Expand Down

0 comments on commit 408448f

Please sign in to comment.