Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the existence of CRD AntreaAgentInfo before operating on it #4762

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

wenyingd
Copy link
Contributor

@wenyingd wenyingd commented Mar 24, 2023

Antrea Controller checks the existence of AntreaAgentInfo API before creating or deleting the resources for worker Node or ExternalNode.

@@ -365,3 +379,14 @@ func (monitor *controllerMonitor) deleteAgentCRD(name string) error {
}
return nil
}

func (monitor *controllerMonitor) AgentInfoCRDInstalled() bool {
_, err := monitor.apiExtensionClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), antreaAgentInfoCRDName, metav1.GetOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this check is needed? I suppose CRD should be always there? Will CRD be deleted in any case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When antrea is running with agentless mode, CRD of antreaagentinfo may not create as it is not needed.

@@ -365,3 +379,14 @@ func (monitor *controllerMonitor) deleteAgentCRD(name string) error {
}
return nil
}

func (monitor *controllerMonitor) AgentInfoCRDInstalled() bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clientset.Interface has Discovery() which can be used to check if an API exists. We already use it to check EndpointSlice API. This is an example:

func endpointSliceAPIAvailable(k8sClient clientset.Interface) (bool, error) {
resources, err := k8sClient.Discovery().ServerResourcesForGroupVersion(discovery.SchemeGroupVersion.String())
if err != nil {
// The group version doesn't exist.
if errors.IsNotFound(err) {
return false, nil
}
return false, fmt.Errorf("error getting server resources for GroupVersion %s: %v", discovery.SchemeGroupVersion.String(), err)
}
for _, resource := range resources.APIResources {
if resource.Kind == "EndpointSlice" {
return true, nil
}
}
return false, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be a private method, and something like antreaAgentInfoAPIAvailable reflects the implementation more accurately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

Comment on lines 314 to 312
if !c.AgentInfoCRDInstalled() {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just not run these goroutines instead of check the API's existence on every Node event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that at time 1 the antreaagentinfo CRD is not deployed, but at time2 the CRD is applied. If we only have a single check at the initial run, the case is not supported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code doesn't automatically call deleteStaleAgentCRDs and syncNode when the CRD is added after starting controller, right? Then it would just lead to an incomplete situation that some Nodes are handled while others are not, so a restart is needed anyway. Besides, there seems no reason to apply CRD after running controller? Could other features consuming CRD work correctly? But anyway I feel not worth to add repeated API calls to partially support a scenario that we don't have yet.

And I think the point of the PR is to avoid adding a configuration that controls whether to run the AntreaAgentInfo controller, by auto-discovering it. If the auto-discovery becomes more complicated and even double APIs call of normal mode, it may be not worth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

pkg/monitor/controller.go Outdated Show resolved Hide resolved
pkg/monitor/controller.go Outdated Show resolved Hide resolved
@wenyingd wenyingd force-pushed the antreaas branch 3 times, most recently from 25470da to c9b1e6a Compare April 13, 2023 11:55
@@ -365,3 +379,14 @@ func (monitor *controllerMonitor) deleteAgentCRD(name string) error {
}
return nil
}

func (monitor *controllerMonitor) AgentInfoCRDInstalled() bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be a private method, and something like antreaAgentInfoAPIAvailable reflects the implementation more accurately.

pkg/monitor/controller.go Outdated Show resolved Hide resolved
pkg/monitor/controller.go Outdated Show resolved Hide resolved
@wenyingd wenyingd force-pushed the antreaas branch 2 times, most recently from 07922a2 to 73015ee Compare April 14, 2023 10:51
klog.ErrorS(err, "error getting server resources for GroupVersion", "groupVersion", v1beta1.SchemeGroupVersion.String())
return false
}
return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should retry on non-NotFound error, which may mean the APIServer is temporarily unavailable or there is a networking issue. Otherwise it may return wrong result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated accordingly.

go wait.Until(monitor.nodeWorker, time.Second, stopCh)
if monitor.externalNodeEnabled {
go wait.Until(monitor.externalNodeWorker, time.Second, stopCh)
if monitor.antreaAgentInfoAPIAvailable() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should log the result for visibility and troubleshooting. For example:

if monitor.antreaAgentInfoAPIAvailable() {
    klog.InfoS("The AntreaAgentInfo API is available, running node workers")
    monitor.deleteStaleAgentCRDs()
    ...
} else {
    klog.InfoS("The AntreaAgentInfo API is unavailable, will not run node workers")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

pkg/monitor/controller.go Outdated Show resolved Hide resolved
pkg/monitor/controller.go Outdated Show resolved Hide resolved
@wenyingd wenyingd force-pushed the antreaas branch 2 times, most recently from 650d2a7 to b739e68 Compare April 17, 2023 15:31
@wenyingd wenyingd requested a review from tnqn April 24, 2023 05:33
@@ -624,3 +642,38 @@ func TestEnqueueExternalNode(t *testing.T) {
obj, _ := controller.controllerMonitor.externalNodeQueue.Get()
assert.Equal(t, expectedkey, obj.(string))
}

func TestAgentInfoCRDInstalled(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test name inconsistent with func name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

pkg/monitor/controller_test.go Outdated Show resolved Hide resolved
pkg/monitor/controller_test.go Outdated Show resolved Hide resolved
Signed-off-by: wenyingd <wenyingd@vmware.com>
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tnqn
Copy link
Member

tnqn commented Apr 26, 2023

/skip-all

@tnqn tnqn merged commit 97b8e4a into antrea-io:main Apr 26, 2023
jainpulkit22 pushed a commit to urharshitha/antrea that referenced this pull request Apr 28, 2023
@vicky-liu vicky-liu added this to the Antrea v1.12 release milestone May 4, 2023
@wenyingd wenyingd deleted the antreaas branch May 30, 2023 06:49
ceclinux pushed a commit to ceclinux/antrea that referenced this pull request Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants