Skip to content

Commit

Permalink
[ExternalNode]Create/Delete AntreaAgentInfo based on ExternalNode (#3757
Browse files Browse the repository at this point in the history
)

Antrea controller watches ExternalNode create and delete event.
It creates AntreaAgentInfo whose name is the same as ExternalNode name
after ExternalNode is created and delete AntreaAgentInfo when
ExternalNode is deleted.

The change also refactors monitoring part for Node case and lets controller
create AntreaAgentInfo for Node too. With this change,
for both Node and ExternalNode cases, it is always
Antrea controller to create/delete AntreaAgentInfo and
it is always Antrea agent to update AntreaAgentInfo.

Signed-off-by: Mengdie Song <[email protected]>
  • Loading branch information
mengdie-song authored May 31, 2022
1 parent 9c7554a commit e7ce899
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 72 deletions.
2 changes: 0 additions & 2 deletions build/charts/antrea/templates/agent/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ rules:
- antreaagentinfos
verbs:
- get
- create
- update
- delete
- apiGroups:
- controlplane.antrea.io
resources:
Expand Down
1 change: 1 addition & 0 deletions build/charts/antrea/templates/controller/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ rules:
- antreaagentinfos
verbs:
- list
- create
- delete
- apiGroups:
- crd.antrea.io
Expand Down
3 changes: 1 addition & 2 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2940,9 +2940,7 @@ rules:
- antreaagentinfos
verbs:
- get
- create
- update
- delete
- apiGroups:
- controlplane.antrea.io
resources:
Expand Down Expand Up @@ -3287,6 +3285,7 @@ rules:
- antreaagentinfos
verbs:
- list
- create
- delete
- apiGroups:
- crd.antrea.io
Expand Down
3 changes: 1 addition & 2 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2940,9 +2940,7 @@ rules:
- antreaagentinfos
verbs:
- get
- create
- update
- delete
- apiGroups:
- controlplane.antrea.io
resources:
Expand Down Expand Up @@ -3287,6 +3285,7 @@ rules:
- antreaagentinfos
verbs:
- list
- create
- delete
- apiGroups:
- crd.antrea.io
Expand Down
3 changes: 1 addition & 2 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2940,9 +2940,7 @@ rules:
- antreaagentinfos
verbs:
- get
- create
- update
- delete
- apiGroups:
- controlplane.antrea.io
resources:
Expand Down Expand Up @@ -3287,6 +3285,7 @@ rules:
- antreaagentinfos
verbs:
- list
- create
- delete
- apiGroups:
- crd.antrea.io
Expand Down
3 changes: 1 addition & 2 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2953,9 +2953,7 @@ rules:
- antreaagentinfos
verbs:
- get
- create
- update
- delete
- apiGroups:
- controlplane.antrea.io
resources:
Expand Down Expand Up @@ -3300,6 +3298,7 @@ rules:
- antreaagentinfos
verbs:
- list
- create
- delete
- apiGroups:
- crd.antrea.io
Expand Down
3 changes: 1 addition & 2 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2940,9 +2940,7 @@ rules:
- antreaagentinfos
verbs:
- get
- create
- update
- delete
- apiGroups:
- controlplane.antrea.io
resources:
Expand Down Expand Up @@ -3287,6 +3285,7 @@ rules:
- antreaagentinfos
verbs:
- list
- create
- delete
- apiGroups:
- crd.antrea.io
Expand Down
3 changes: 2 additions & 1 deletion cmd/antrea-controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func run(o *Options) error {

controllerQuerier := querier.NewControllerQuerier(networkPolicyController, o.config.APIPort)

controllerMonitor := monitor.NewControllerMonitor(crdClient, nodeInformer, controllerQuerier)
externalNodeEnabled := features.DefaultFeatureGate.Enabled(features.ExternalNode)
controllerMonitor := monitor.NewControllerMonitor(crdClient, nodeInformer, externalNodeInformer, controllerQuerier, externalNodeEnabled)

var egressController *egress.EgressController
var externalIPPoolController *externalippool.ExternalIPPoolController
Expand Down
27 changes: 4 additions & 23 deletions pkg/monitor/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"time"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -59,30 +58,20 @@ func (monitor *agentMonitor) syncAgentCRD() {
if monitor.agentCRD, err = monitor.updateAgentCRD(true); err == nil {
return
}
klog.Errorf("Failed to partially update agent monitoring CRD: %v", err)
klog.ErrorS(err, "Failed to partially update agent monitoring CRD")
monitor.agentCRD = nil
}

monitor.agentCRD, err = monitor.getAgentCRD()

if errors.IsNotFound(err) {
monitor.agentCRD, err = monitor.createAgentCRD()
if err != nil {
klog.Errorf("Failed to create agent monitoring CRD: %v", err)
monitor.agentCRD = nil
}
return
}

if err != nil {
klog.Errorf("Failed to get agent monitoring CRD: %v", err)
klog.ErrorS(err, "Failed to get agent monitoring CRD")
monitor.agentCRD = nil
return
}

monitor.agentCRD, err = monitor.updateAgentCRD(false)
if err != nil {
klog.Errorf("Failed to entirely update agent monitoring CRD: %v", err)
klog.ErrorS(err, "Failed to entirely update agent monitoring CRD")
monitor.agentCRD = nil
}
}
Expand All @@ -91,18 +80,10 @@ func (monitor *agentMonitor) syncAgentCRD() {
// So when the pod restarts, it will update this monitoring CRD instead of creating a new one.
func (monitor *agentMonitor) getAgentCRD() (*v1beta1.AntreaAgentInfo, error) {
crdName := monitor.querier.GetNodeConfig().Name
klog.V(2).Infof("Getting agent monitoring CRD %+v", crdName)
klog.V(2).InfoS("Getting agent monitoring CRD", "name", crdName)
return monitor.client.CrdV1beta1().AntreaAgentInfos().Get(context.TODO(), crdName, metav1.GetOptions{})
}

// createAgentCRD creates a new agent CRD.
func (monitor *agentMonitor) createAgentCRD() (*v1beta1.AntreaAgentInfo, error) {
agentCRD := new(v1beta1.AntreaAgentInfo)
monitor.querier.GetAgentInfo(agentCRD, false)
klog.V(2).Infof("Creating agent monitoring CRD %+v", agentCRD)
return monitor.client.CrdV1beta1().AntreaAgentInfos().Create(context.TODO(), agentCRD, metav1.CreateOptions{})
}

// updateAgentCRD updates the monitoring CRD.
func (monitor *agentMonitor) updateAgentCRD(partial bool) (*v1beta1.AntreaAgentInfo, error) {
monitor.querier.GetAgentInfo(monitor.agentCRD, partial)
Expand Down
Loading

0 comments on commit e7ce899

Please sign in to comment.