-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add delete and finalizer to RAGEngine (#646)
**Reason for Change**: Add delete and finalizer to RAGEngine **Requirements** - [ ] added unit tests and e2e tests (if applicable). **Issue Fixed**: <!-- If this PR fixes GitHub issue 4321, add "Fixes #4321" to the next line. --> **Notes for Reviewers**: --------- Signed-off-by: Bangqi Zhu <bangqizhu@microsoft.com> Co-authored-by: Bangqi Zhu <bangqizhu@microsoft.com>
- Loading branch information
1 parent
1d09da0
commit 6b216fc
Showing
9 changed files
with
128 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
|
||
kaitov1alpha1 "github.com/azure/kaito/api/v1alpha1" | ||
"github.com/azure/kaito/pkg/featuregates" | ||
"github.com/azure/kaito/pkg/machine" | ||
"github.com/azure/kaito/pkg/nodeclaim" | ||
"github.com/azure/kaito/pkg/utils/consts" | ||
"k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
// garbageCollectRAGEngine remove finalizer associated with ragengine object. | ||
func (c *RAGEngineReconciler) garbageCollectRAGEngine(ctx context.Context, ragEngineObj *kaitov1alpha1.RAGEngine) (ctrl.Result, error) { | ||
klog.InfoS("garbageCollectRAGEngine", "ragengine", klog.KObj(ragEngineObj)) | ||
|
||
// Check if there are any machines associated with this ragengine. | ||
mList, err := machine.ListMachines(ctx, ragEngineObj, c.Client) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
// We should delete all the machines that are created by this ragengine | ||
for i := range mList.Items { | ||
if deleteErr := c.Delete(ctx, &mList.Items[i], &client.DeleteOptions{}); deleteErr != nil { | ||
klog.ErrorS(deleteErr, "failed to delete the machine", "machine", klog.KObj(&mList.Items[i])) | ||
return ctrl.Result{}, deleteErr | ||
} | ||
} | ||
|
||
if featuregates.FeatureGates[consts.FeatureFlagKarpenter] { | ||
// Check if there are any nodeClaims associated with this ragengine. | ||
ncList, err := nodeclaim.ListNodeClaim(ctx, ragEngineObj, c.Client) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
// We should delete all the nodeClaims that are created by this ragengine | ||
for i := range ncList.Items { | ||
if deleteErr := c.Delete(ctx, &ncList.Items[i], &client.DeleteOptions{}); deleteErr != nil { | ||
klog.ErrorS(deleteErr, "failed to delete the nodeClaim", "nodeClaim", klog.KObj(&ncList.Items[i])) | ||
return ctrl.Result{}, deleteErr | ||
} | ||
} | ||
} | ||
|
||
if controllerutil.RemoveFinalizer(ragEngineObj, consts.RAGEngineFinalizer) { | ||
if updateErr := c.Update(ctx, ragEngineObj, &client.UpdateOptions{}); updateErr != nil { | ||
klog.ErrorS(updateErr, "failed to remove the finalizer from the ragengine", | ||
"ragengine", klog.KObj(ragEngineObj)) | ||
return ctrl.Result{}, updateErr | ||
} | ||
} | ||
|
||
klog.InfoS("successfully removed the ragengine finalizers", | ||
"ragengine", klog.KObj(ragEngineObj)) | ||
return ctrl.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters