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

🌱 Clean the resource when the addon is not found #1260

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions manager/pkg/processes/hubmanagement/hub_addon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,28 @@ func AddManagedClusterAddonController(mgr ctrl.Manager) error {
}

func (c *managerClusterAddonController) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
if hubStatusManager == nil {
log.Warn("The hub management process should be started")
return ctrl.Result{Requeue: true, RequeueAfter: 5 * time.Second}, nil
}

addon := &addonv1alpha1.ManagedClusterAddOn{}
if err := c.client.Get(ctx, request.NamespacedName, addon); apierrors.IsNotFound(err) {
return ctrl.Result{}, nil
if request.Namespace == "" {
return ctrl.Result{}, nil
}

log.Infof("inactive the agent when the global hub addon(%s) is deleted", request.Namespace)
err := hubStatusManager.inactive(ctx, []models.LeafHubHeartbeat{{
Name: request.Namespace,
}})
return ctrl.Result{}, err
} else if err != nil {
return ctrl.Result{Requeue: true, RequeueAfter: 5 * time.Second}, fmt.Errorf("failed to get addon: %w", err)
}

if !addon.DeletionTimestamp.IsZero() {
if hubStatusManager == nil {
log.Warn("The hub management process should be started")
return ctrl.Result{Requeue: true, RequeueAfter: 5 * time.Second}, nil
}
log.Infof("inactive the agent when the global hub addon(%s) is deleting", addon.Namespace)
err := hubStatusManager.inactive(ctx, []models.LeafHubHeartbeat{{
Name: request.Namespace,
}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (m *mockHubManagement) reactive(ctx context.Context, hubs []models.LeafHubH
return nil
}

func TestManagerClusterAddonController_Reconcile(t *testing.T) {
func TestManagerClusterAddonReconcile(t *testing.T) {
scheme := runtime.NewScheme()
err := addonv1alpha1.AddToScheme(scheme)
assert.NoError(t, err)
Expand All @@ -40,7 +40,7 @@ func TestManagerClusterAddonController_Reconcile(t *testing.T) {
client: fakeClient,
}

t.Run("addon not found", func(t *testing.T) {
t.Run("hub manager is not ready", func(t *testing.T) {
request := ctrl.Request{
NamespacedName: types.NamespacedName{
Namespace: "test-namespace",
Expand All @@ -50,7 +50,7 @@ func TestManagerClusterAddonController_Reconcile(t *testing.T) {

res, err := controller.Reconcile(ctx, request)
assert.NoError(t, err)
assert.Equal(t, ctrl.Result{}, res)
assert.Equal(t, ctrl.Result{Requeue: true, RequeueAfter: 5 * time.Second}, res)
})

t.Run("addon with deletion timestamp", func(t *testing.T) {
Expand Down
Loading